Skip to content

Commit

Permalink
Fix zero line rendering. Closes #31.
Browse files Browse the repository at this point in the history
  • Loading branch information
onyxfish committed May 25, 2016
1 parent 3718efd commit bf92490
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
0.3.0
-----

* Zero lines now render above other tick marks. (#31)
* Fixed rendering of :class:`.Bar` and :class:`.Column` shapes for negative values.
* Refactored the :class:`.Lattice` API.

Expand Down
11 changes: 10 additions & 1 deletion leather/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,17 @@ def to_svg(self, width, height, scale, orient):
tick_values = scale.ticks(self._ticks)
tick_count = len(tick_values)

zero_tick_group = None

for i, value in enumerate(tick_values):
# Tick group
tick_group = ET.Element('g')
tick_group.set('class', 'tick')
group.append(tick_group)

if value == 0:
zero_tick_group = tick_group
else:
group.append(tick_group)

# Tick line
projected_value = scale.project(value, range_min, range_max)
Expand Down Expand Up @@ -160,6 +166,9 @@ def to_svg(self, width, height, scale, orient):

tick_group.append(label)

if zero_tick_group:
group.append(zero_tick_group)

return group


Expand Down
10 changes: 5 additions & 5 deletions test.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import leather

data = [
(-3, 'foo', -3),
(5, 'bar', 5),
(-9, 'baz', -9)
(-1, -1),
(0, 0),
(1, 1)
]

chart = leather.Chart('Negative columns')
chart.add_bars(data)
chart = leather.Chart()
chart.add_lines(data)
chart.to_svg('test.svg')
2 changes: 1 addition & 1 deletion tests/test_axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def test_formatter(value, i, count):

svg = self.render_chart(chart)

self.assertTickLabels(svg, 'bottom', ['0+', '25+', '50+', '75+', '100+'])
self.assertTickLabels(svg, 'bottom', ['25+', '50+', '75+', '100+', '0+'])
12 changes: 6 additions & 6 deletions tests/test_chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ def test_set_scales(self):

svg = self.render_chart(chart)

self.assertTickLabels(svg, 'left', ['0.0', '5.0', '10.0', '15.0', '20.0'])
self.assertTickLabels(svg, 'bottom', ['0.0', '5.0', '10.0', '15.0', '20.0'])
self.assertTickLabels(svg, 'left', ['5.0', '10.0', '15.0', '20.0', '0.0'])
self.assertTickLabels(svg, 'bottom', ['5.0', '10.0', '15.0', '20.0', '0.0'])

def test_add_scales(self):
chart = leather.Chart()
Expand All @@ -68,8 +68,8 @@ def test_add_scales(self):

svg = self.render_chart(chart)

self.assertTickLabels(svg, 'left', ['0.0', '5.0', '10.0', '15.0', '20.0'])
self.assertTickLabels(svg, 'bottom', ['0.0', '5.0', '10.0', '15.0', '20.0'])
self.assertTickLabels(svg, 'left', ['5.0', '10.0', '15.0', '20.0', '0.0'])
self.assertTickLabels(svg, 'bottom', ['5.0', '10.0', '15.0', '20.0', '0.0'])

def test_set_axes(self):
chart = leather.Chart()
Expand All @@ -80,7 +80,7 @@ def test_set_axes(self):
svg = self.render_chart(chart)

self.assertTickLabels(svg, 'left', ['3.0', '6.0', '9.0'])
self.assertTickLabels(svg, 'bottom', ['0.0', '4.0', '8.0'])
self.assertTickLabels(svg, 'bottom', ['4.0', '8.0', '0.0'])

def test_add_axes(self):
chart = leather.Chart()
Expand All @@ -91,4 +91,4 @@ def test_add_axes(self):
svg = self.render_chart(chart)

self.assertTickLabels(svg, 'left', ['3.0', '6.0', '9.0'])
self.assertTickLabels(svg, 'bottom', ['0.0', '4.0', '8.0'])
self.assertTickLabels(svg, 'bottom', ['4.0', '8.0', '0.0'])

0 comments on commit bf92490

Please sign in to comment.