diff --git a/examples/charts/grouped_bars.svg b/examples/charts/grouped_bars.svg index 851cf59..f2969fe 100644 --- a/examples/charts/grouped_bars.svg +++ b/examples/charts/grouped_bars.svg @@ -1,4 +1,4 @@ -ColumnsHelloWorldGoodbyeYellow2.557.50firstsecondthird \ No newline at end of file +ColumnsHelloWorldGoodbyeYellow2.557.50firstsecondthird \ No newline at end of file diff --git a/leather/shapes/category.py b/leather/shapes/category.py index 1f9cf88..b597886 100644 --- a/leather/shapes/category.py +++ b/leather/shapes/category.py @@ -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): @@ -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): diff --git a/leather/shapes/grouped_bars.py b/leather/shapes/grouped_bars.py index 6bb2e82..b834e15 100644 --- a/leather/shapes/grouped_bars.py +++ b/leather/shapes/grouped_bars.py @@ -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): @@ -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): @@ -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) diff --git a/leather/shapes/grouped_columns.py b/leather/shapes/grouped_columns.py index 9450020..82a71e2 100644 --- a/leather/shapes/grouped_columns.py +++ b/leather/shapes/grouped_columns.py @@ -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): @@ -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): diff --git a/tests/test_shapes.py b/tests/test_shapes.py index 5c2012f..52c017b 100644 --- a/tests/test_shapes.py +++ b/tests/test_shapes.py @@ -184,6 +184,7 @@ def test_nulls(self): self.assertEqual(len(paths), 2) + class TestGroupedBars(leather.LeatherTestCase): def setUp(self): self.shape = leather.GroupedBars() @@ -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() @@ -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')