-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add rough timescale support. Closes #14.
- Loading branch information
Showing
7 changed files
with
99 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ Scales | |
.. autoclass:: leather.Linear | ||
|
||
.. autoclass:: leather.Ordinal | ||
|
||
.. autoclass:: leather.Temporal |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
|
||
from datetime import date, datetime, time | ||
|
||
from leather.scales.base import Scale | ||
|
||
|
||
class Temporal(Scale): | ||
""" | ||
A scale that linearly maps date/datetime values from a domain to a range. | ||
:param domain_min: | ||
The minimum date/datetime of the input domain. | ||
:param domain_max: | ||
The maximum date/datetime of the input domain. | ||
""" | ||
def __init__(self, domain_min, domain_max): | ||
self._min = domain_min | ||
self._max = domain_max | ||
|
||
def project(self, value, range_min, range_max): | ||
""" | ||
Project a value in this scale's domain to a target range. | ||
""" | ||
pos = (value - self._min) / (self._max - self._min) | ||
|
||
return ((range_max - range_min) * pos) + range_min | ||
|
||
def project_interval(self, value, range_min, range_max): | ||
""" | ||
Project a value in this scale's domain to an interval in the target | ||
range. This is used for places :class:`.Bars` and :class:`.Columns`. | ||
""" | ||
raise NotImplementedError | ||
|
||
def ticks(self, count): | ||
""" | ||
Generate a series of ticks for this scale. | ||
""" | ||
size = (self._max - self._min) / (count - 1) | ||
|
||
return [self._min + (size * i) for i in range(count)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,136 +1,18 @@ | ||
#!/usr/bin/env python | ||
|
||
import random | ||
from datetime import date, datetime | ||
|
||
import leather | ||
|
||
dot_data = [(random.randint(0, 250), random.randint(0, 250)) for i in range(100)] | ||
|
||
def colorizer(x, y, i): | ||
return 'rgb(%i, %i, %i)' % (x, y, 150) | ||
data = [ | ||
(datetime(2010, 1, 1), 4), | ||
(datetime(2011, 5, 4), 3), | ||
(datetime(2012, 6, 1, 11), 5), | ||
(datetime(2013, 1, 1), 6), | ||
(datetime(2014, 12, 1), 10) | ||
] | ||
|
||
chart = leather.Chart('Well that was easy') | ||
chart.add_dots(dot_data, color=colorizer) | ||
chart = leather.Chart("X axis ftw") | ||
chart.add_lines(data) | ||
chart.to_svg('test.svg') | ||
|
||
# dot_data = [ | ||
# (0, 3), | ||
# (4, 5), | ||
# (7, 9), | ||
# (8, 4) | ||
# ] | ||
# | ||
# line_data = [ | ||
# (0, 4), | ||
# (1, 3), | ||
# (2, 5), | ||
# (5, 6), | ||
# (9, 10) | ||
# ] | ||
# | ||
# chart = leather.Chart() | ||
# # chart.set_x_scale(leather.Linear(0, 20)) | ||
# chart.add_dots(dot_data) | ||
# chart.add_lines(line_data) | ||
# chart.to_svg('test.svg') | ||
|
||
# bar_data = [ | ||
# (3, 'foo'), | ||
# (5, 'bing blaarg murg'), | ||
# (9, 'baz'), | ||
# (4, 'blurg') | ||
# ] | ||
# | ||
# def colorizer(x, y, i): | ||
# if y == 'baz': | ||
# return 'yellow' | ||
# else: | ||
# return 'blue' | ||
# | ||
# chart = leather.Chart('Bar charts are fun') | ||
# chart.add_dots(bar_data, color=colorizer) | ||
# chart.to_svg('test.svg') | ||
# | ||
# data = [[ | ||
# (0, 3), | ||
# (4, 5), | ||
# (7, 9), | ||
# (8, 4) | ||
# ], [ | ||
# (0, 4), | ||
# (1, 3), | ||
# (2, 5), | ||
# (5, 6), | ||
# (9, 10) | ||
# ],[ | ||
# (0, 4), | ||
# (1, 3), | ||
# (2, 5), | ||
# (5, 6), | ||
# (9, 10) | ||
# ]] | ||
# | ||
# grid = leather.Grid() | ||
# | ||
# chart = leather.Chart('Chart A') | ||
# chart.add_lines(data[0]) | ||
# grid.add_chart(chart) | ||
# | ||
# chart = leather.Chart('Chart B') | ||
# chart.add_dots(data[1]) | ||
# grid.add_chart(chart) | ||
# | ||
# chart = leather.Chart('Chart C') | ||
# chart.add_dots(data[2]) | ||
# grid.add_chart(chart) | ||
# | ||
# grid.to_svg('test.svg') | ||
|
||
# data = [[ | ||
# (0, 3), | ||
# (4, 5), | ||
# (7, 9), | ||
# (8, 4) | ||
# ], [ | ||
# (0, 4), | ||
# (1, 3), | ||
# (2, 3), | ||
# (10, 7), | ||
# (15, 5) | ||
# ], [ | ||
# (0, 4), | ||
# (5, 5), | ||
# (6, 6), | ||
# (7, 7), | ||
# (8, 8) | ||
# ], [ | ||
# (4, 4), | ||
# (6, 3), | ||
# (7, 5), | ||
# (8, 6), | ||
# (12, 10) | ||
# ]] | ||
# | ||
# lattice = leather.Lattice(data, leather.Lines('purple'), ['A', 'B', 'C', 'D']) | ||
# | ||
# lattice.to_svg('test.svg', 1200, 600) | ||
|
||
# data = [ | ||
# (3, 1), | ||
# (5, 3), | ||
# (9, 12), | ||
# (4, 15) | ||
# ] | ||
# | ||
# chart = leather.Chart() | ||
# chart.add_bars(data) | ||
# chart.to_svg('test.svg') | ||
|
||
# chart = leather.Chart() | ||
# chart.set_x_scale(leather.Linear(0, 20)) | ||
# chart.set_x_axis(leather.Axis(ticks=5)) | ||
# chart.set_y_scale(leather.Linear(0, 20)) | ||
# chart.set_y_axis(leather.Axis(ticks=5)) | ||
# chart.add_dots(data) | ||
# | ||
# chart.to_svg('test.svg') |