Skip to content

Commit

Permalink
Minor clean up. wireservice#26
Browse files Browse the repository at this point in the history
  • Loading branch information
nbedi committed Jun 16, 2016
1 parent fdef462 commit f4eab2b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion examples/charts/grouped_bars.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions leather/shapes/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def legend_labels(self, series, palette):
for i, value in enumerate(legend_values):
if i >= color_count:
raise ValueError('Fill color must have length greater than or equal to the number of unique values in all categories.')

label_colors.append((value, colors[i]))

elif callable(colors):
Expand All @@ -55,7 +55,7 @@ def legend_to_svg(self, series, palette):
"""
label_colors = self.legend_labels(series, palette)
item_groups = []

if hasattr(self, '_stroke_color'):
if self._stroke_color:
if callable(self._stroke_color):
Expand Down
9 changes: 4 additions & 5 deletions leather/shapes/grouped_bars.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from leather.series import CategorySeries
from leather.shapes.category import CategoryShape
from leather.utils import Y, Z
from leather import theme


class GroupedBars(CategoryShape):
Expand All @@ -16,7 +15,7 @@ class GroupedBars(CategoryShape):
:param fill_color:
A sequence of colors to fill the bars. The sequence must have length
greater than or equal to the number of unique values in all categories.
greater than or equal to the number of unique values in all categories.
You may also specify a :func:`.style_function`.
"""
def __init__(self, fill_color=None):
Expand Down Expand Up @@ -56,9 +55,9 @@ def to_svg(self, width, height, x_scale, y_scale, series, palette):

y1, y2 = y_scale.project_interval(d.z, height, 0)

group_width = (y2 - y1) / category_counts[d.z]
y2 = y1 + (group_width * (seen_counts[d.z] + 1)) + 1
y1 = y1 + (group_width * seen_counts[d.z])
group_height = (y2 - y1) / category_counts[d.z]
y2 = y1 + (group_height * (seen_counts[d.z] + 1)) + 1
y1 = y1 + (group_height * seen_counts[d.z])

proj_x = x_scale.project(d.x, 0, width)

Expand Down
3 changes: 1 addition & 2 deletions leather/shapes/grouped_columns.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from leather.series import CategorySeries
from leather.shapes.category import CategoryShape
from leather.utils import X, Z
from leather import theme


class GroupedColumns(CategoryShape):
Expand All @@ -16,7 +15,7 @@ class GroupedColumns(CategoryShape):
:param fill_color:
A sequence of colors to fill the columns. The sequence must have length
greater than or equal to the number of unique values in all categories.
greater than or equal to the number of unique values in all categories.
You may also specify a :func:`.style_function`.
"""
def __init__(self, fill_color=None):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def test_nulls(self):

self.assertEqual(len(paths), 2)


class TestGroupedBars(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.GroupedBars()
Expand Down Expand Up @@ -256,6 +257,7 @@ def test_nulls(self):
self.assertEqual(float(rects[0].get('x')), 0)
self.assertEqual(float(rects[0].get('width')), 0)


class TestGroupedColumns(leather.LeatherTestCase):
def setUp(self):
self.shape = leather.GroupedColumns()
Expand Down Expand Up @@ -289,7 +291,7 @@ def test_invalid_fill_color(self):
series = leather.CategorySeries(self.rows)

with self.assertRaises(ValueError):
group = self.shape.to_svg(100, 200, self.ordinal, self.linear, series, ['one', 'two'])
group = self.shape.to_svg(100, 200, self.ordinal, self.linear, series, ['one', 'two']) # noqa

with self.assertRaises(ValueError):
shape = leather.GroupedColumns('red')
Expand Down

0 comments on commit f4eab2b

Please sign in to comment.