Skip to content

Commit

Permalink
Columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed May 17, 2016
1 parent f08a814 commit 9a6d6f6
Show file tree
Hide file tree
Showing 22 changed files with 41 additions and 12 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.DS_Store
*.pyc
*.swp
*.swo
.tox
*.egg-info
docs/_build
dist
.coverage
build
.proof
.ipynb_checkpoints
.idea
1 change: 1 addition & 0 deletions leather/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
from leather.legend import Legend
from leather.scales.linear import LinearScale
from leather.scales.ordinal import OrdinalScale
from leather.shapes.column import Column
from leather.shapes.dot import Dot
from leather.shapes.line import Line
Binary file removed leather/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/axis.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/chart.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/grid.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/legend.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/renderable.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/series.cpython-35.pyc
Binary file not shown.
Binary file removed leather/__pycache__/utils.cpython-35.pyc
Binary file not shown.
14 changes: 11 additions & 3 deletions leather/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
from leather.scales.linear import LinearScale
from leather.scales.ordinal import OrdinalScale
from leather.series import Series
from leather.shapes.column import Column
from leather.shapes.dot import Dot
from leather.shapes.line import Line
from leather.utils import Box

DEFAULT_DOT = Dot()
DEFAULT_LINE = Line()
DEFAULT_COLUMN = Column()

class Chart(object):
"""
Expand Down Expand Up @@ -47,17 +49,23 @@ def add_series(self, series, shape):
# Validate added series has same scale types as other series?
#if x_datum isinstance(number)

def add_dot(self, data, name=None, id=None, classes=None):
"""
Shortcut method for adding a dotted series to the chart.
"""
self.add_series(Series(data, name=name, id=id, classes=classes), DEFAULT_DOT)

def add_line(self, data, name=None, id=None, classes=None):
"""
Shortcut method for adding a line series to the chart.
"""
self.add_series(Series(data, name=name, id=id, classes=classes), DEFAULT_LINE)

def add_dot(self, data, name=None, id=None, classes=None):
def add_column(self, data, name=None, id=None, classes=None):
"""
Shortcut method for adding a dotted series to the chart.
Shortcut method for adding a column series to the chart.
"""
self.add_series(Series(data, name=name, id=id, classes=classes), DEFAULT_DOT)
self.add_series(Series(data, name=name, id=id, classes=classes), DEFAULT_COLUMN)

def _validate_dimension(self, scale, axis, orient, data_index):
if not axis:
Expand Down
Binary file removed leather/scales/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file removed leather/scales/__pycache__/base.cpython-35.pyc
Binary file not shown.
Binary file removed leather/scales/__pycache__/linear.cpython-35.pyc
Binary file not shown.
Binary file removed leather/scales/__pycache__/ordinal.cpython-35.pyc
Binary file not shown.
12 changes: 9 additions & 3 deletions leather/scales/ordinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ def project(self, value, range):

return pos

def project_interval(self, value, range, interval):
# TKTK
pass
def project_interval(self, value, range):
segments = len(self.domain)
segment_size = (range[1] - range[0]) / segments
gap = segment_size * 0.05

a = range[0] + (self.domain.index(value) * segment_size) + gap
b = range[0] + ((self.domain.index(value) + 1) * segment_size) - gap

return (a, b)

def ticks(self, count):
return self.domain
Binary file removed leather/shapes/__pycache__/__init__.cpython-35.pyc
Binary file not shown.
Binary file removed leather/shapes/__pycache__/base.cpython-35.pyc
Binary file not shown.
Binary file removed leather/shapes/__pycache__/dot.cpython-35.pyc
Binary file not shown.
Binary file removed leather/shapes/__pycache__/line.cpython-35.pyc
Binary file not shown.
11 changes: 6 additions & 5 deletions leather/shapes/column.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ def to_svg(self, bbox, x_scale, y_scale, series):
group = ET.Element('g')

for x, y in series.data:
proj_x = x_scale.project(x, [bbox.left, bbox.right])
x1, x2 = x_scale.project_interval(x, [bbox.left, bbox.right])
proj_y = y_scale.project(y, [bbox.bottom, bbox.top])

# TKTK
group.append(ET.Element('circle',
cx=six.text_type(proj_x),
cy=six.text_type(proj_y),
r=six.text_type(self.radius),
group.append(ET.Element('rect',
x=six.text_type(x1),
y=six.text_type(proj_y),
width=six.text_type(x2 - x1),
height=six.text_type(bbox.bottom - proj_y),
fill=self.color
))

Expand Down
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@
]

chart = leather.Chart()
chart.add_column(line_data)
chart.add_dot(dot_data)
chart.add_line(line_data)
chart.to_svg('test.svg')

0 comments on commit 9a6d6f6

Please sign in to comment.