From fdef4625d28538cc338d7608599678d6227ab9d7 Mon Sep 17 00:00:00 2001 From: Neil Bedi Date: Thu, 16 Jun 2016 13:50:35 -0400 Subject: [PATCH] Fix ordering calc. #26 --- examples/charts/grouped_bars.svg | 2 +- examples/charts/grouped_columns.svg | 2 +- leather/shapes/grouped_bars.py | 6 +++--- leather/shapes/grouped_columns.py | 6 +++--- tests/test_shapes.py | 6 ++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/charts/grouped_bars.svg b/examples/charts/grouped_bars.svg index ad7a800..851cf59 100644 --- a/examples/charts/grouped_bars.svg +++ b/examples/charts/grouped_bars.svg @@ -1,4 +1,4 @@ -BarsHelloWorldGoodbyeYellow2.557.50firstsecondthird \ No newline at end of file +ColumnsHelloWorldGoodbyeYellow2.557.50firstsecondthird \ No newline at end of file diff --git a/examples/charts/grouped_columns.svg b/examples/charts/grouped_columns.svg index 744f692..36b8930 100644 --- a/examples/charts/grouped_columns.svg +++ b/examples/charts/grouped_columns.svg @@ -1,4 +1,4 @@ -ColumnsHelloWorldGoodbyeYellowfirstsecondthird2.557.50 \ No newline at end of file +ColumnsHelloWorldGoodbyeYellowfirstsecondthird2.557.50 \ No newline at end of file diff --git a/leather/shapes/grouped_bars.py b/leather/shapes/grouped_bars.py index 54f3496..6bb2e82 100644 --- a/leather/shapes/grouped_bars.py +++ b/leather/shapes/grouped_bars.py @@ -56,9 +56,9 @@ def to_svg(self, width, height, x_scale, y_scale, series, palette): y1, y2 = y_scale.project_interval(d.z, height, 0) - group_height = (y1 - y2) / category_counts[d.z] - y1 = y2 + (group_height * (seen_counts[d.z] + 1)) - 1 - y2 = y2 + (group_height * seen_counts[d.z]) + 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]) proj_x = x_scale.project(d.x, 0, width) diff --git a/leather/shapes/grouped_columns.py b/leather/shapes/grouped_columns.py index 47ef114..9450020 100644 --- a/leather/shapes/grouped_columns.py +++ b/leather/shapes/grouped_columns.py @@ -56,9 +56,9 @@ def to_svg(self, width, height, x_scale, y_scale, series, palette): x1, x2 = x_scale.project_interval(d.z, 0, width) - group_width = (x1 - x2) / category_counts[d.z] - x1 = x2 + (group_width * (seen_counts[d.z] + 1)) + 1 - x2 = x2 + (group_width * seen_counts[d.z]) + group_width = (x2 - x1) / category_counts[d.z] + x2 = x1 + (group_width * (seen_counts[d.z] + 1)) + 1 + x1 = x1 + (group_width * seen_counts[d.z]) proj_y = y_scale.project(d.y, height, 0) diff --git a/tests/test_shapes.py b/tests/test_shapes.py index 3fcc286..5c2012f 100644 --- a/tests/test_shapes.py +++ b/tests/test_shapes.py @@ -209,6 +209,8 @@ def test_to_svg(self): self.assertEqual(len(rects), 7) self.assertEqual(float(rects[1].get('x')), 0) self.assertEqual(float(rects[1].get('width')), 100) + self.assertEqual(float(rects[3].get('y')), 36) + self.assertEqual(float(rects[3].get('height')), 14) self.assertEqual(rects[1].get('fill'), 'white') def test_invalid_fill_color(self): @@ -279,8 +281,8 @@ def test_to_svg(self): self.assertEqual(len(rects), 7) self.assertEqual(float(rects[1].get('y')), 100) self.assertEqual(float(rects[1].get('height')), 100) - self.assertEqual(float(rects[3].get('y')), 120) - self.assertEqual(float(rects[3].get('height')), 80) + self.assertEqual(float(rects[3].get('x')), 50) + self.assertEqual(float(rects[3].get('width')), 16) self.assertEqual(rects[1].get('fill'), 'white') def test_invalid_fill_color(self):