From 1cadf77a24384e7190ab3348c172fd6f872b050e Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Thu, 14 Jul 2016 17:50:52 -0500 Subject: [PATCH 01/29] Added the clockwise gauge changes from niosega --- pygal/config.py | 5 +++++ pygal/graph/gauge.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index e1e7ce14..73b5b589 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -258,6 +258,11 @@ class Config(CommonConfig): str) # Look # + clockwise = Key( + False, bool, "Look", + "Clockwise", + "Set to True to make the gauge clockwise.") + title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 974fafd1..ecede69e 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,9 +23,10 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate +from pygal.util import alter, compute_scale, cut, decorate, compose from pygal.view import PolarThetaLogView, PolarThetaView +TEMPCLOCK = false class Gauge(Graph): @@ -44,6 +45,12 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) + + def clockwiser(self, point): + x_0, _ = self.view((0,90)) + new_x = 2*x_0 - point[0] + return (new_x, point[1]) + def needle(self, serie): """Draw a needle for each value""" @@ -52,8 +59,12 @@ def needle(self, serie): if theta is None: continue - def point(x, y): - return '%f %f' % self.view((x, y)) + def point(x, y): + if self.clockwise: + transform = compose(self.clockwiser, self.view) + else: + transform = self.view + return '%f %f' % transform((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -74,19 +85,24 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) + + sweep_flag = '0' if self.clockwise else '1' alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), + sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) + if self.clockwise: + x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -95,7 +111,14 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - + if self.clockwise: + for i in range(int(len(self._y_labels)/2)): + (label_1, theta_1) = self._y_labels[i] + (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] + temp_theta = theta_2 + self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) + self._y_labels[i] = (label_1, temp_theta) + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') From f081a825ad71b2480c02d869d5d88dc9d59770c3 Mon Sep 17 00:00:00 2001 From: Jace Sheu Date: Tue, 19 Jul 2016 13:27:24 -0500 Subject: [PATCH 02/29] Revert "Added the clockwise gauge changes from niosega" --- pygal/config.py | 5 ----- pygal/graph/gauge.py | 33 +++++---------------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 73b5b589..e1e7ce14 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -258,11 +258,6 @@ class Config(CommonConfig): str) # Look # - clockwise = Key( - False, bool, "Look", - "Clockwise", - "Set to True to make the gauge clockwise.") - title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index ecede69e..974fafd1 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,10 +23,9 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate, compose +from pygal.util import alter, compute_scale, cut, decorate from pygal.view import PolarThetaLogView, PolarThetaView -TEMPCLOCK = false class Gauge(Graph): @@ -45,12 +44,6 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) - - def clockwiser(self, point): - x_0, _ = self.view((0,90)) - new_x = 2*x_0 - point[0] - return (new_x, point[1]) - def needle(self, serie): """Draw a needle for each value""" @@ -59,12 +52,8 @@ def needle(self, serie): if theta is None: continue - def point(x, y): - if self.clockwise: - transform = compose(self.clockwiser, self.view) - else: - transform = self.view - return '%f %f' % transform((x, y)) + def point(x, y): + return '%f %f' % self.view((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -85,24 +74,19 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) - - sweep_flag = '0' if self.clockwise else '1' alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), - sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) - if self.clockwise: - x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -111,14 +95,7 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - if self.clockwise: - for i in range(int(len(self._y_labels)/2)): - (label_1, theta_1) = self._y_labels[i] - (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] - temp_theta = theta_2 - self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) - self._y_labels[i] = (label_1, temp_theta) - + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') From 7e02da55df05d7733d4f2767234eb68d2f548de6 Mon Sep 17 00:00:00 2001 From: Feargal Walsh Date: Tue, 19 Jul 2016 13:28:10 -0500 Subject: [PATCH 03/29] Revert "Added the clockwise gauge changes from niosega" --- pygal/config.py | 5 ----- pygal/graph/gauge.py | 33 +++++---------------------------- 2 files changed, 5 insertions(+), 33 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 73b5b589..e1e7ce14 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -258,11 +258,6 @@ class Config(CommonConfig): str) # Look # - clockwise = Key( - False, bool, "Look", - "Clockwise", - "Set to True to make the gauge clockwise.") - title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index ecede69e..974fafd1 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,10 +23,9 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate, compose +from pygal.util import alter, compute_scale, cut, decorate from pygal.view import PolarThetaLogView, PolarThetaView -TEMPCLOCK = false class Gauge(Graph): @@ -45,12 +44,6 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) - - def clockwiser(self, point): - x_0, _ = self.view((0,90)) - new_x = 2*x_0 - point[0] - return (new_x, point[1]) - def needle(self, serie): """Draw a needle for each value""" @@ -59,12 +52,8 @@ def needle(self, serie): if theta is None: continue - def point(x, y): - if self.clockwise: - transform = compose(self.clockwiser, self.view) - else: - transform = self.view - return '%f %f' % transform((x, y)) + def point(x, y): + return '%f %f' % self.view((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -85,24 +74,19 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) - - sweep_flag = '0' if self.clockwise else '1' alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), - sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) - if self.clockwise: - x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -111,14 +95,7 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - if self.clockwise: - for i in range(int(len(self._y_labels)/2)): - (label_1, theta_1) = self._y_labels[i] - (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] - temp_theta = theta_2 - self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) - self._y_labels[i] = (label_1, temp_theta) - + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') From 760d53e8c6bd6f3ad66fa723af0c62f1c1fa3055 Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Tue, 19 Jul 2016 13:58:51 -0500 Subject: [PATCH 04/29] Added tests to see if the clockwise graph plots --- .idea/inspectionProfiles/Project_Default.xml | 15 +++++++++ .../inspectionProfiles/profiles_settings.xml | 7 ++++ .idea/vcs.xml | 6 ++++ pygal/graph/gauge.py | 33 ++++++++++++++++--- pygal/test/conftest.py | 2 +- pygal/test/test_gauge.py | 28 ++++++++++++++++ 6 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/vcs.xml create mode 100644 pygal/test/test_gauge.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 00000000..ab978c5c --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 00000000..3b312839 --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,7 @@ + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 00000000..94a25f7f --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 974fafd1..ecede69e 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,9 +23,10 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate +from pygal.util import alter, compute_scale, cut, decorate, compose from pygal.view import PolarThetaLogView, PolarThetaView +TEMPCLOCK = false class Gauge(Graph): @@ -44,6 +45,12 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) + + def clockwiser(self, point): + x_0, _ = self.view((0,90)) + new_x = 2*x_0 - point[0] + return (new_x, point[1]) + def needle(self, serie): """Draw a needle for each value""" @@ -52,8 +59,12 @@ def needle(self, serie): if theta is None: continue - def point(x, y): - return '%f %f' % self.view((x, y)) + def point(x, y): + if self.clockwise: + transform = compose(self.clockwiser, self.view) + else: + transform = self.view + return '%f %f' % transform((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -74,19 +85,24 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) + + sweep_flag = '0' if self.clockwise else '1' alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), + sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) + if self.clockwise: + x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -95,7 +111,14 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - + if self.clockwise: + for i in range(int(len(self._y_labels)/2)): + (label_1, theta_1) = self._y_labels[i] + (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] + temp_theta = theta_2 + self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) + self._y_labels[i] = (label_1, temp_theta) + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') diff --git a/pygal/test/conftest.py b/pygal/test/conftest.py index e6f08f48..8ff8aac1 100644 --- a/pygal/test/conftest.py +++ b/pygal/test/conftest.py @@ -23,7 +23,7 @@ import pygal from pygal.etree import etree import sys -from . import get_data +#from . import get_data @pytest.fixture diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py new file mode 100644 index 00000000..a27b561f --- /dev/null +++ b/pygal/test/test_gauge.py @@ -0,0 +1,28 @@ +from unittest import TestCase +from pygal import Gauge + + +class TestGauge(TestCase): + def test_chartplots(self): + gauge_chart = Gauge(human_readable =True) + gauge_chart.title = 'DeltaBlue V8 benchmark results' + gauge_chart.range = [0, 10000] + gauge_chart.add('Chrome', 8212) + gauge_chart.add('Firefox', 8099) + gauge_chart.add('Opera', 2933) + gauge_chart.add('IE', 41) + + assert gauge_chart.render() + + def test_anticclockplots(self): + + gauge_chartcwise = Gauge(human_readable = True,clockwise = True) + + gauge_chartcwise.title = 'DeltaBlue V8 benchmark results' + gauge_chartcwise.range = [0, 10000] + gauge_chartcwise.add('Chrome', 8212) + gauge_chartcwise.add('Firefox', 8099) + gauge_chartcwise.add('Opera', 2933) + gauge_chartcwise.add('IE', 41) + + assert gauge_chartcwise.render() From 78e79893d8a92b6f9e0aa7b3a9c7d2966262e239 Mon Sep 17 00:00:00 2001 From: Jace Sheu Date: Tue, 19 Jul 2016 14:34:46 -0500 Subject: [PATCH 05/29] Revert "Revert "Added the clockwise gauge changes from niosega"" --- pygal/config.py | 5 +++++ pygal/graph/gauge.py | 33 ++++++++++++++++++++++++++++----- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index e1e7ce14..73b5b589 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -258,6 +258,11 @@ class Config(CommonConfig): str) # Look # + clockwise = Key( + False, bool, "Look", + "Clockwise", + "Set to True to make the gauge clockwise.") + title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 974fafd1..ecede69e 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,9 +23,10 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate +from pygal.util import alter, compute_scale, cut, decorate, compose from pygal.view import PolarThetaLogView, PolarThetaView +TEMPCLOCK = false class Gauge(Graph): @@ -44,6 +45,12 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) + + def clockwiser(self, point): + x_0, _ = self.view((0,90)) + new_x = 2*x_0 - point[0] + return (new_x, point[1]) + def needle(self, serie): """Draw a needle for each value""" @@ -52,8 +59,12 @@ def needle(self, serie): if theta is None: continue - def point(x, y): - return '%f %f' % self.view((x, y)) + def point(x, y): + if self.clockwise: + transform = compose(self.clockwiser, self.view) + else: + transform = self.view + return '%f %f' % transform((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -74,19 +85,24 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) + + sweep_flag = '0' if self.clockwise else '1' alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), + sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) + if self.clockwise: + x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -95,7 +111,14 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - + if self.clockwise: + for i in range(int(len(self._y_labels)/2)): + (label_1, theta_1) = self._y_labels[i] + (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] + temp_theta = theta_2 + self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) + self._y_labels[i] = (label_1, temp_theta) + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') From f831811126864083fea2653f04a33f4dd0cfefb1 Mon Sep 17 00:00:00 2001 From: Connor Moore Date: Tue, 19 Jul 2016 14:59:38 -0500 Subject: [PATCH 06/29] Fixed the clockwise plotting, and added tests. --- pygal/graph/gauge.py | 3 +-- pygal/test/test_gauge.py | 27 +++++++++++++++++++++++++++ pygal/util.py | 5 ++++- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 pygal/test/test_gauge.py diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index ecede69e..6be04897 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -26,7 +26,6 @@ from pygal.util import alter, compute_scale, cut, decorate, compose from pygal.view import PolarThetaLogView, PolarThetaView -TEMPCLOCK = false class Gauge(Graph): @@ -197,4 +196,4 @@ def _compute_y_labels(self): def _plot(self): """Plot all needles""" for serie in self.series: - self.needle(serie) + self.needle(serie) \ No newline at end of file diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py new file mode 100644 index 00000000..4d20d08d --- /dev/null +++ b/pygal/test/test_gauge.py @@ -0,0 +1,27 @@ +from pygal import Gauge + +def test_render(): + """Tests that a gauge plots""" + chart = Gauge() + chart.range = [0,40] + chart.add('Connor', 21) + chart.add('Mike', 30) + chart.add('Jules', 10) + assert chart.render() + +def test_difference(): + """Tests the difference between a clockwise and counter clockwise graph""" + chart = Gauge() + chart.range = [0, 10000] + chart.add('Chrome', 8212) + chart.add('Firefox', 8099) + chart.add('Opera', 2933) + chart.add('IE', 41) + + clock_chart = Gauge(clockwise=True) + clock_chart.range = [0, 10000] + clock_chart.add('Chrome', 8212) + clock_chart.add('Firefox', 8099) + clock_chart.add('Opera', 2933) + clock_chart.add('IE', 41) + assert clock_chart.render() != chart.render() \ No newline at end of file diff --git a/pygal/util.py b/pygal/util.py index 4bfcb2a0..64dacd21 100644 --- a/pygal/util.py +++ b/pygal/util.py @@ -309,7 +309,10 @@ def minify_css(css): def compose(f, g): """Chain functions""" fun = lambda *args, **kwargs: f(g(*args, **kwargs)) - fun.__name__ = "%s o %s" % (f.__name__, g.__name__) + try: + fun.__name__ = "%s o %s" % (f.__name__, g.__name__) + except: + fun.__name__ = f.__name__ return fun From 38f1f99e0f4c7c531ecc3f7695ee0cd86679d0e4 Mon Sep 17 00:00:00 2001 From: psheu Date: Tue, 19 Jul 2016 15:48:35 -0500 Subject: [PATCH 07/29] Exception too broad warning fixed --- pygal/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygal/util.py b/pygal/util.py index 64dacd21..ce26f1b4 100644 --- a/pygal/util.py +++ b/pygal/util.py @@ -311,7 +311,7 @@ def compose(f, g): fun = lambda *args, **kwargs: f(g(*args, **kwargs)) try: fun.__name__ = "%s o %s" % (f.__name__, g.__name__) - except: + except AttributeError: fun.__name__ = f.__name__ return fun From 00cae97875b36cea9036c00f937d58012c5b743f Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Wed, 20 Jul 2016 11:12:36 -0500 Subject: [PATCH 08/29] Added a test to check clockwise graphs renders --- pygal/config.py | 8 ++++++++ pygal/graph/gauge.py | 26 ++++++++++++-------------- pygal/test/test_gauge.py | 14 +++++++++++++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index e1e7ce14..8e2e3c06 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -257,6 +257,12 @@ class Config(CommonConfig): "Useful for adding gradients / patterns…", str) + clockwise = Key( + False, bool, "Look", + "Clockwise", + "Set to True to make the gauge clockwise." + ) + # Look # title = Key( None, str, "Look", @@ -398,6 +404,8 @@ class Config(CommonConfig): "are closed at the first value with a missing " "'x' (default), 'y' or 'either'") + + # Value # x_value_formatter = Key( formatters.default, callable, "Value", diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 6be04897..3652a427 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -28,7 +28,6 @@ class Gauge(Graph): - """Gauge graph class""" needle_width = 1 / 20 @@ -44,12 +43,11 @@ def _set_view(self): self.width - self.margin_box.x, self.height - self.margin_box.y, self._box) - + def clockwiser(self, point): - x_0, _ = self.view((0,90)) - new_x = 2*x_0 - point[0] - return (new_x, point[1]) - + x_0, _ = self.view((0, 90)) + new_x = 2 * x_0 - point[0] + return (new_x, point[1]) def needle(self, serie): """Draw a needle for each value""" @@ -58,7 +56,7 @@ def needle(self, serie): if theta is None: continue - def point(x, y): + def point(x, y): if self.clockwise: transform = compose(self.clockwiser, self.view) else: @@ -84,7 +82,7 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) - + sweep_flag = '0' if self.clockwise else '1' alter( @@ -111,13 +109,13 @@ def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") if self.clockwise: - for i in range(int(len(self._y_labels)/2)): + for i in range(int(len(self._y_labels) / 2)): (label_1, theta_1) = self._y_labels[i] - (label_2, theta_2) = self._y_labels[len(self._y_labels)-i-1] + (label_2, theta_2) = self._y_labels[len(self._y_labels) - i - 1] temp_theta = theta_2 - self._y_labels[len(self._y_labels)-i-1] = (label_2, theta_1) - self._y_labels[i] = (label_1, temp_theta) - + self._y_labels[len(self._y_labels) - i - 1] = (label_2, theta_1) + self._y_labels[i] = (label_1, temp_theta) + for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') @@ -196,4 +194,4 @@ def _compute_y_labels(self): def _plot(self): """Plot all needles""" for serie in self.series: - self.needle(serie) \ No newline at end of file + self.needle(serie) diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py index 4d20d08d..be1e2a63 100644 --- a/pygal/test/test_gauge.py +++ b/pygal/test/test_gauge.py @@ -1,4 +1,5 @@ from pygal import Gauge +import pytest def test_render(): """Tests that a gauge plots""" @@ -9,6 +10,15 @@ def test_render(): chart.add('Jules', 10) assert chart.render() + +def test_ccrender(): + clock_chart = Gauge(clockwise=True) + clock_chart.range = [0, 40] + clock_chart.add('Connor', 21) + clock_chart.add('Mike', 30) + clock_chart.add('Jules', 10) + assert clock_chart.render() + def test_difference(): """Tests the difference between a clockwise and counter clockwise graph""" chart = Gauge() @@ -24,4 +34,6 @@ def test_difference(): clock_chart.add('Firefox', 8099) clock_chart.add('Opera', 2933) clock_chart.add('IE', 41) - assert clock_chart.render() != chart.render() \ No newline at end of file + assert clock_chart.render() != chart.render() + + From 766ec10a9ec1742b729ec25928141e4f07c383cf Mon Sep 17 00:00:00 2001 From: Connor Moore Date: Wed, 20 Jul 2016 13:35:23 -0500 Subject: [PATCH 09/29] Added description to a gauge test, and changed clockwise variable in config. --- pygal/config.py | 10 ++++------ pygal/test/test_gauge.py | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 8e2e3c06..be8cb7b7 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -256,14 +256,12 @@ class Config(CommonConfig): list, "Misc", "Extraneous defs to be inserted in svg", "Useful for adding gradients / patterns…", str) - + # Look # clockwise = Key( - False, bool, "Look", - "Clockwise", - "Set to True to make the gauge clockwise." - ) + False, bool, "Look", + "Clockwise", + "Set to True to make the gauge clockwise.") - # Look # title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py index be1e2a63..54d9a410 100644 --- a/pygal/test/test_gauge.py +++ b/pygal/test/test_gauge.py @@ -12,6 +12,7 @@ def test_render(): def test_ccrender(): + """Tests that a clockwise gauge plots""" clock_chart = Gauge(clockwise=True) clock_chart.range = [0, 40] clock_chart.add('Connor', 21) From a7944a7f11f6220fb0d4ee387562ed5992f44287 Mon Sep 17 00:00:00 2001 From: Connor Moore Date: Wed, 20 Jul 2016 16:15:53 -0500 Subject: [PATCH 10/29] Preliminary work for bar values. --- pygal/config.py | 5 +++++ pygal/graph/bar.py | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pygal/config.py b/pygal/config.py index be8cb7b7..777af32e 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -257,6 +257,11 @@ class Config(CommonConfig): "Useful for adding gradients / patterns…", str) # Look # + bar_values = Key( + False, bool, "Look", + "Bar Values", + "Set to True to display a bar's value atop the bar.") + clockwise = Key( False, bool, "Look", "Clockwise", diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 488b759a..73a88772 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -140,6 +140,13 @@ def _compute(self): self._x_pos = [(i + .5) / self._len for i in range(self._len)] + def bar_values(self,x,y,width,height): + """Prints the bar's values atop the bar, only if the bar_values kwarg is True.""" + transpose = swap if self.horizontal else ident + x_center, y_center = transpose((x + width / 2, y + height / 2)) + x_top, y_top = transpose((x + width, y + height)) + + def _plot(self): """Draw bars for series and secondary series""" for serie in self.series: From 6fa975b451af98a32d5a0c31079282155053cfe1 Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Thu, 21 Jul 2016 01:22:21 -0500 Subject: [PATCH 11/29] Added test that checks if bar_values has been instantiated properly, --- .idea/inspectionProfiles/profiles_settings.xml | 4 ++-- pygal/test/test_config.py | 14 +++++++++++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml index 3b312839..c60c33bb 100644 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/pygal/test/test_config.py b/pygal/test/test_config.py index 11001c92..df28354e 100644 --- a/pygal/test/test_config.py +++ b/pygal/test/test_config.py @@ -102,6 +102,7 @@ class LineConfig(Config): def test_config_alterations_class(): """Assert a config can be changed on config class""" + class LineConfig(Config): no_prefix = True show_legend = False @@ -125,6 +126,7 @@ class LineConfig(Config): def test_config_alterations_instance(): """Assert a config can be changed on instance""" + class LineConfig(Config): no_prefix = True show_legend = False @@ -149,6 +151,7 @@ class LineConfig(Config): def test_config_alterations_kwargs(): """Assert a config can be changed with keyword args""" + class LineConfig(Config): no_prefix = True show_legend = False @@ -541,15 +544,15 @@ def test_formatters(Chart): if Chart._dual or Chart == Box: return chart = Chart(formatter=lambda x, chart, serie: '%s%s$' % ( - x, serie.title)) + x, serie.title)) chart.add('_a', [1, 2, {'value': 3, 'formatter': lambda x: u('%s¥') % x}]) chart.add('_b', [4, 5, 6], formatter=lambda x: u('%s€') % x) chart.x_labels = [2, 4, 6] chart.x_labels_major = [4] q = chart.render_pyquery() assert set([v.text for v in q(".value")]) == set(( - u('4€'), u('5€'), u('6€'), '1_a$', '2_a$', u('3¥')) + ( - ('6_a$', u('15€')) if Chart in (Pie, SolidGauge) else ())) + u('4€'), u('5€'), u('6€'), '1_a$', '2_a$', u('3¥')) + ( + ('6_a$', u('15€')) if Chart in (Pie, SolidGauge) else ())) def test_classes(Chart): @@ -574,3 +577,8 @@ def test_classes(Chart): chart = Chart(classes=('graph', _ellipsis)) assert chart.render_pyquery().attr('class') == 'graph pygal-chart' + + +def test_bar_value(Chart): + chart = Chart() + assert chart.bar_values == False From dcd627938b36f5d257c29c44790ea74cda13f189 Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Thu, 21 Jul 2016 14:25:50 -0500 Subject: [PATCH 12/29] Just familiarising myself with tests really,but this just proves that the kwarg was put in correctly. --- pygal/graph/bar.py | 1 + pygal/test/test_bar.py | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 73a88772..b254fc87 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -141,6 +141,7 @@ def _compute(self): self._x_pos = [(i + .5) / self._len for i in range(self._len)] def bar_values(self,x,y,width,height): + """Prints the bar's values atop the bar, only if the bar_values kwarg is True.""" transpose = swap if self.horizontal else ident x_center, y_center = transpose((x + width / 2, y + height / 2)) diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 631990b0..a9c99580 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -18,6 +18,9 @@ # along with pygal. If not, see . """Bar chart related tests""" +from unittest import TestCase + + from pygal import Bar @@ -35,3 +38,10 @@ def test_simple_bar(): assert len(q(".axis.y")) == 1 assert len(q(".legend")) == 2 assert len(q(".plot .series rect")) == 2 * 3 + + +def test_Bar_Value_is_False(): + assert Bar(bar_values=False) + + + From c20e1f2629f87d562ae494073ac9389792a57da2 Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Thu, 21 Jul 2016 15:28:53 -0500 Subject: [PATCH 13/29] Added some half pseudocode/half real code to the bar_values method in the bar module as an idea as how we might get it to print the values, also tried to write a test that would only pass if we get it to print out in test_bar but I couldn't get it to recognise the print_values **kwarg. Everything I did is commmented out to make sure I didn't break the code --- pygal/graph/bar.py | 4 ++++ pygal/graph/graph.py | 1 + pygal/test/test_bar.py | 12 ++++++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index b254fc87..7060f746 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -146,6 +146,10 @@ def bar_values(self,x,y,width,height): transpose = swap if self.horizontal else ident x_center, y_center = transpose((x + width / 2, y + height / 2)) x_top, y_top = transpose((x + width, y + height)) + #for serie in self.series: + # self.point(x_top,y_top) + #print_values_postion(point) + def _plot(self): diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 23e0669f..d3eb90e3 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -928,6 +928,7 @@ def _draw(self): self._post_compute() self._compute_margin() self._decorate() + #self._bar_values() if self.series and self._has_data() and self._values: self._plot() else: diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index a9c99580..34cce674 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -20,9 +20,11 @@ """Bar chart related tests""" from unittest import TestCase - +from wheel.signatures import assertTrue from pygal import Bar +from pygal.graph.graph import Graph +from pygal import Config def test_simple_bar(): @@ -41,7 +43,13 @@ def test_simple_bar(): def test_Bar_Value_is_False(): - assert Bar(bar_values=False) + """Test to check the bar_value is initialised as false""" + + + assert Bar(bar_values=False) + +#def test_bar_values(CommonConfig): +# assert self.Bar(print_values==True) From 47aad7ad71797c05c4df3c437f35eb4395fea7b1 Mon Sep 17 00:00:00 2001 From: Connor Moore Date: Sun, 24 Jul 2016 17:39:12 -0500 Subject: [PATCH 14/29] Added percentages for each series to graph and bar --- pygal/graph/bar.py | 22 ++++++++++------------ pygal/graph/graph.py | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 73a88772..acfa248e 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -62,7 +62,9 @@ def _bar(self, serie, parent, x, y, i, zero, secondary=False): def _tooltip_and_print_values( self, serie_node, serie, parent, i, val, metadata, - x, y, width, height): + x, y, width, height, total): + percent = ((float(val)/total)*100) + #print('{0:.2f}%'.format(percent)) transpose = swap if self.horizontal else ident x_center, y_center = transpose((x + width / 2, y + height / 2)) x_top, y_top = transpose((x + width, y + height)) @@ -75,7 +77,6 @@ def _tooltip_and_print_values( self._tooltip_data( parent, val, x_center, y_center, "centered", self._get_x_label(i)) - if self.print_values_position == 'top': if self.horizontal: x = x_bottom + sign * self.style.value_font_size / 2 @@ -93,7 +94,7 @@ def _tooltip_and_print_values( else: x = x_center y = y_center - self._static_value(serie_node, val, x, y, metadata, "middle") + self._static_value(serie_node, val, percent, x, y, metadata, "middle") def bar(self, serie, rescale=False): """Draw a bar graph for a serie""" @@ -103,7 +104,8 @@ def bar(self, serie, rescale=False): points = self._rescale(serie.points) else: points = serie.points - + total = sum(list(filter(None, serie.values))) + print(total) for i, (x, y) in enumerate(points): if None in (x, y) or (self.logarithmic and y <= 0): continue @@ -124,7 +126,7 @@ def bar(self, serie, rescale=False): self._tooltip_and_print_values( serie_node, serie, bar, i, val, metadata, - x_, y_, width, height) + x_, y_, width, height, total) def _compute(self): """Compute y min and max and y scale and set labels""" @@ -140,16 +142,12 @@ def _compute(self): self._x_pos = [(i + .5) / self._len for i in range(self._len)] - def bar_values(self,x,y,width,height): - """Prints the bar's values atop the bar, only if the bar_values kwarg is True.""" - transpose = swap if self.horizontal else ident - x_center, y_center = transpose((x + width / 2, y + height / 2)) - x_top, y_top = transpose((x + width, y + height)) - - def _plot(self): """Draw bars for series and secondary series""" + total = 0 for serie in self.series: self.bar(serie) + total += sum(list(filter(None, serie.values))) for serie in self.secondary_series: self.bar(serie, True) + print(total) \ No newline at end of file diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 23e0669f..c4db1ee0 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -491,12 +491,12 @@ def _tooltip_data(self, node, value, x, y, classes=None, xlabel=None): self.svg.node(node, 'desc', class_="x_label").text = to_str(xlabel) - def _static_value(self, serie_node, value, x, y, metadata, + def _static_value(self, serie_node, value, percent, x, y, metadata, align_text='left', classes=None): """Write the print value""" label = metadata and metadata.get('label') classes = classes and [classes] or [] - + print('{0:.2f}%'.format(percent)) if self.print_labels and label: label_cls = classes + ['label'] if self.print_values: From dec511aac8f41f3b9eb7f443c369c345385c351b Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Sun, 24 Jul 2016 23:43:32 -0500 Subject: [PATCH 15/29] ease enter the commit message for your changes. Lines starting modified: pygal/config.py modified: pygal/graph/bar.py modified: pygal/graph/graph.py modified: pygal/test/test_bar.py modified: pygal/view.py --- pygal/config.py | 2 ++ pygal/graph/bar.py | 19 +++++++++++++++---- pygal/graph/graph.py | 5 +++++ pygal/test/test_bar.py | 30 ++++++++++++++++++++++++++++-- pygal/view.py | 2 +- 5 files changed, 51 insertions(+), 7 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 777af32e..9ce33d99 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -509,6 +509,8 @@ class Config(CommonConfig): "Label string length truncation threshold", "None = auto, Negative for none") + print_percentage = Key(False,bool,"Text","Display percentage of total values") + # Misc # js = Key( ('//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js',), diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 7060f746..a0f48676 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -60,6 +60,15 @@ def _bar(self, serie, parent, x, y, i, zero, secondary=False): class_='rect reactive tooltip-trigger'), serie.metadata.get(i)) return x, y, width, height + + def calc_percent(self,raw_series): + total = map(sum(self.raw_series[0])) + + for i, val in enumerate(self.raw_series): + perc = (val/total)*100 + print(perc) + return perc + def _tooltip_and_print_values( self, serie_node, serie, parent, i, val, metadata, x, y, width, height): @@ -141,14 +150,16 @@ def _compute(self): self._x_pos = [(i + .5) / self._len for i in range(self._len)] def bar_values(self,x,y,width,height): - + #if bar_values == True: """Prints the bar's values atop the bar, only if the bar_values kwarg is True.""" transpose = swap if self.horizontal else ident x_center, y_center = transpose((x + width / 2, y + height / 2)) x_top, y_top = transpose((x + width, y + height)) - #for serie in self.series: - # self.point(x_top,y_top) - #print_values_postion(point) + # for serie in self.series: + #self.bar(serie) + # set print values to true + # self.print_value == True + # self.print_values_postion('top') diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index d3eb90e3..eb718b4c 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -49,6 +49,7 @@ def _decorate(self): self._make_x_title() self._make_y_title() + def _axes(self): """Draw axes""" self._y_axis() @@ -943,3 +944,7 @@ def _has_data(self): if v is not None]) for s in self.raw_series ]) + + + + diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 34cce674..35fd448f 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -44,12 +44,38 @@ def test_simple_bar(): def test_Bar_Value_is_False(): """Test to check the bar_value is initialised as false""" + assert Bar(bar_values=False) - assert Bar(bar_values=False) +def test_difference(): + bar = Bar(bar_values=False) + rng = [-3, -32, -39] + bar.add('test1', rng) + bar.add('test2', map(abs, rng)) + bar.x_labels = map(str, rng) + bar_labelled = Bar(bar_values=True) + rng = [-3, -32, -39] + bar_labelled.add('test1', rng) + bar + bar_labelled.add('test2', map(abs, rng)) + bar.labelled = map(str, rng) + assert bar == bar_labelled -#def test_bar_values(CommonConfig): +# def test_bar_values(CommonConfig): # assert self.Bar(print_values==True) + + + + +def test_calc_percent(): + bar = Bar() + rng = [-3, -32, -39] + bar.add('test1', rng) + bar.add('test2', map(abs, rng)) + bar.x_labels = map(str, rng) + + + + assert bar.calc_percent(rng) is float \ No newline at end of file diff --git a/pygal/view.py b/pygal/view.py index 9360a584..a106b7ee 100644 --- a/pygal/view.py +++ b/pygal/view.py @@ -26,7 +26,7 @@ class Margin(object): - """Class reprensenting a margin (top, right, left, bottom)""" + """Class representing a margin (top, right, left, bottom)""" def __init__(self, top, right, bottom, left): """Create the margin object from the top, right, left, bottom margin""" From 3347daca322b4e599b12d419f0e7a7e7992bb83e Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Mon, 25 Jul 2016 20:22:15 -0500 Subject: [PATCH 16/29] I added the percent values as a *kwargs argument, and added a comparison to to differentiate between print values, and print percent. --- pygal/config.py | 11 ++++++----- pygal/graph/bar.py | 5 ----- pygal/graph/graph.py | 26 +++++++++++++++++--------- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 777af32e..87b48341 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -257,11 +257,6 @@ class Config(CommonConfig): "Useful for adding gradients / patterns…", str) # Look # - bar_values = Key( - False, bool, "Look", - "Bar Values", - "Set to True to display a bar's value atop the bar.") - clockwise = Key( False, bool, "Look", "Clockwise", @@ -509,6 +504,12 @@ class Config(CommonConfig): "Label string length truncation threshold", "None = auto, Negative for none") + percent_values = Key( + False, bool, "Look", + "Bar Values", + "Set to True to display a bar's percentage contribution per series atop the bar.") + + # Misc # js = Key( ('//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js',), diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index acfa248e..7a62614d 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -64,7 +64,6 @@ def _tooltip_and_print_values( self, serie_node, serie, parent, i, val, metadata, x, y, width, height, total): percent = ((float(val)/total)*100) - #print('{0:.2f}%'.format(percent)) transpose = swap if self.horizontal else ident x_center, y_center = transpose((x + width / 2, y + height / 2)) x_top, y_top = transpose((x + width, y + height)) @@ -105,7 +104,6 @@ def bar(self, serie, rescale=False): else: points = serie.points total = sum(list(filter(None, serie.values))) - print(total) for i, (x, y) in enumerate(points): if None in (x, y) or (self.logarithmic and y <= 0): continue @@ -144,10 +142,7 @@ def _compute(self): def _plot(self): """Draw bars for series and secondary series""" - total = 0 for serie in self.series: self.bar(serie) - total += sum(list(filter(None, serie.values))) for serie in self.secondary_series: self.bar(serie, True) - print(total) \ No newline at end of file diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index c4db1ee0..c8492539 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -496,7 +496,7 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, """Write the print value""" label = metadata and metadata.get('label') classes = classes and [classes] or [] - print('{0:.2f}%'.format(percent)) + per_str = ('{0:.2f}%'.format(percent)) if self.print_labels and label: label_cls = classes + ['label'] if self.print_values: @@ -513,14 +513,22 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, val_cls = classes + ['value'] if self.dynamic_print_values: val_cls.append('showable') - - self.svg.node( - serie_node['text_overlay'], 'text', - class_=' '.join(val_cls), - x=x, - y=y + self.style.value_font_size / 3, - attrib={'text-anchor': align_text} - ).text = value if self.print_zeroes or value != '0' else '' + if self.percent_values: + self.svg.node( + serie_node['text_overlay'], 'text', + class_=' '.join(val_cls), + x=x, + y=y + self.style.value_font_size / 3, + attrib={'text-anchor': align_text} + ).text = per_str if self.print_zeroes or per_str != '0.00%' else '' + else: + self.svg.node( + serie_node['text_overlay'], 'text', + class_=' '.join(val_cls), + x=x, + y=y + self.style.value_font_size / 3, + attrib={'text-anchor': align_text} + ).text = value if self.print_zeroes or value != '0' else '' def _points(self, x_pos): """ From 95143578d1532daa85c771dc7091f1bdc7a47cf1 Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Mon, 25 Jul 2016 21:29:56 -0500 Subject: [PATCH 17/29] Fixed the printing a little bit. --- .../inspectionProfiles/profiles_settings.xml | 4 ++-- .idea/misc.xml | 7 +++++++ .idea/modules.xml | 8 ++++++++ .idea/pygalfork.iml | 19 +++++++++++++++++++ pygal/graph/graph.py | 9 +++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pygalfork.iml diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml index 3b312839..c60c33bb 100644 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -1,7 +1,7 @@ - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..5ceb1699 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..23e2f695 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pygalfork.iml b/.idea/pygalfork.iml new file mode 100644 index 00000000..1f11eea6 --- /dev/null +++ b/.idea/pygalfork.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index c8492539..6dda6055 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -513,6 +513,7 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, val_cls = classes + ['value'] if self.dynamic_print_values: val_cls.append('showable') + if self.percent_values: self.svg.node( serie_node['text_overlay'], 'text', @@ -520,7 +521,15 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, x=x, y=y + self.style.value_font_size / 3, attrib={'text-anchor': align_text} + ).text = value if self.print_zeroes or value != '0' else '' + self.svg.node( + serie_node['text_overlay'], 'text', + class_=' '.join(val_cls), + x=x, + y=y + 4/3*(self.style.value_font_size), + attrib={'text-anchor': align_text} ).text = per_str if self.print_zeroes or per_str != '0.00%' else '' + else: self.svg.node( serie_node['text_overlay'], 'text', From 8c162e60b559beb763cdb138c8984f4f2a5cd809 Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Tue, 26 Jul 2016 00:34:38 -0500 Subject: [PATCH 18/29] Tests added --- pygal/test/test_bar.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 35fd448f..38af296a 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -66,16 +66,34 @@ def test_difference(): # assert self.Bar(print_values==True) +def test_calc_percent(): + bar = Bar() + rng = [-3, -32, -39] + bar.add('test1', rng) + bar.add('test2', map(abs, rng)) + bar.x_labels = map(str, rng) -def test_calc_percent(): + assert bar.calc_percent(rng) is float + +def test_bar_percent_difference(): bar = Bar() rng = [-3, -32, -39] bar.add('test1', rng) bar.add('test2', map(abs, rng)) bar.x_labels = map(str, rng) + barpercent = Bar(percent_values=True) + rng = [-3, -32, -39] + barpercent.add('test1', rng) + barpercent.add('test2', map(abs, rng)) + barpercent.x_labels = map(str, rng) + + assert (bar != barpercent) + + + + - assert bar.calc_percent(rng) is float \ No newline at end of file From beb8121f7cc6230fb28e062acc9f924bcceb9c1b Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Tue, 26 Jul 2016 21:10:37 -0500 Subject: [PATCH 19/29] Test that needs to pass in order for the graph to be formatted correctly added --- pygal/graph/bar.py | 4 ++++ pygal/test/test_bar.py | 16 ++++++++++++++++ pygal/test/test_graph.py | 13 +++++++++---- 3 files changed, 29 insertions(+), 4 deletions(-) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 7a62614d..e0bd4105 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -146,3 +146,7 @@ def _plot(self): self.bar(serie) for serie in self.secondary_series: self.bar(serie, True) + + def bar_newfont_size(self): + pass + diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 38af296a..65536f1c 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -93,6 +93,22 @@ def test_bar_percent_difference(): assert (bar != barpercent) +def test_percent_formatting(): + line_chart = Bar(print_values=True, percent_values=True, print_values_position='top') + line_chart.title = 'Browser usage evolution (in %)' + line_chart.x_labels = map(str, range(2002, 2013)) + line_chart.add('Firefox', [None, None, 0, 16.6, 25, 31, 36.4, 45.5, 46.3, 42.8, 37.1]) + line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3]) + line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1]) + line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]) + line_chart.render_in_browser() + + for serie in line_chart.series: + factor = len(serie) + + assert(line_chart.bar_newfont_size == line_chart.value_font_size/factor) + + diff --git a/pygal/test/test_graph.py b/pygal/test/test_graph.py index 21226474..52d21a9b 100644 --- a/pygal/test/test_graph.py +++ b/pygal/test/test_graph.py @@ -20,6 +20,10 @@ """Generate tests for different chart types with different data""" import os +from unittest import TestCase + +from pygal.graph.bar import Bar + import pygal import uuid import sys @@ -431,10 +435,11 @@ def test_long_title(Chart, datas): """Test chart rendering with a long title""" chart = Chart( title="A chart is a graphical representation of data, in which " - "'the data is represented by symbols, such as bars in a bar chart, " - "lines in a line chart, or slices in a pie chart'. A chart can " - "represent tabular numeric data, functions or some kinds of " - "qualitative structure and provides different info.") + "'the data is represented by symbols, such as bars in a bar chart, " + "lines in a line chart, or slices in a pie chart'. A chart can " + "represent tabular numeric data, functions or some kinds of " + "qualitative structure and provides different info.") chart = make_data(chart, datas) q = chart.render_pyquery() assert len(q('.titles text')) == 5 + From 85da39ec809702ff23722cb22c9dc8c0e57356e6 Mon Sep 17 00:00:00 2001 From: psheu Date: Tue, 26 Jul 2016 22:12:25 -0500 Subject: [PATCH 20/29] Ratio bar value font size --- .idea/misc.xml | 2 +- .idea/pygalfork.iml | 2 +- pygal/graph/bar.py | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 5ceb1699..85d89325 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + diff --git a/.idea/pygalfork.iml b/.idea/pygalfork.iml index 1f11eea6..4b2ed338 100644 --- a/.idea/pygalfork.iml +++ b/.idea/pygalfork.iml @@ -2,7 +2,7 @@ - + diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 7a62614d..6b12ef4a 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -83,7 +83,7 @@ def _tooltip_and_print_values( else: x = x_center y = y_bottom - sign * self.style.value_font_size / 2 - elif self.print_values_position == 'bottom': + elif self.print_values_positio2 == 'bottom': if self.horizontal: x = x_top + sign * self.style.value_font_size / 2 y = y_center @@ -93,6 +93,8 @@ def _tooltip_and_print_values( else: x = x_center y = y_center + + self.style.value_font_size = width / 1.5 self._static_value(serie_node, val, percent, x, y, metadata, "middle") def bar(self, serie, rescale=False): From 5b45dccb20e5f527114432d63f66415c92270869 Mon Sep 17 00:00:00 2001 From: psheu Date: Tue, 26 Jul 2016 22:15:56 -0500 Subject: [PATCH 21/29] Ratio bar value font size --- pygal/graph/bar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 6b12ef4a..560b9ab6 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -94,7 +94,7 @@ def _tooltip_and_print_values( x = x_center y = y_center - self.style.value_font_size = width / 1.5 + self.style.value_font_size = width / 1.41421 self._static_value(serie_node, val, percent, x, y, metadata, "middle") def bar(self, serie, rescale=False): From 14b2f2b97b9d2e6e420289e45e6387564839c76a Mon Sep 17 00:00:00 2001 From: psheu Date: Tue, 26 Jul 2016 22:27:17 -0500 Subject: [PATCH 22/29] Reconfigure print values loop in graph --- pygal/graph/graph.py | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 6dda6055..5d94f38c 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -509,12 +509,11 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, ).text = label y += self.style.value_font_size - if self.print_values or self.dynamic_print_values: + if self.print_values or self.dynamic_print_values or self.percent_values: val_cls = classes + ['value'] if self.dynamic_print_values: val_cls.append('showable') - - if self.percent_values: + if self.print_values: self.svg.node( serie_node['text_overlay'], 'text', class_=' '.join(val_cls), @@ -522,6 +521,7 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, y=y + self.style.value_font_size / 3, attrib={'text-anchor': align_text} ).text = value if self.print_zeroes or value != '0' else '' + elif self.percent_values: self.svg.node( serie_node['text_overlay'], 'text', class_=' '.join(val_cls), @@ -530,15 +530,6 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, attrib={'text-anchor': align_text} ).text = per_str if self.print_zeroes or per_str != '0.00%' else '' - else: - self.svg.node( - serie_node['text_overlay'], 'text', - class_=' '.join(val_cls), - x=x, - y=y + self.style.value_font_size / 3, - attrib={'text-anchor': align_text} - ).text = value if self.print_zeroes or value != '0' else '' - def _points(self, x_pos): """ Convert given data values into drawable points (x, y) From 5f009ce19b0bb22a3ac39462c1756d1a14bff02a Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Tue, 26 Jul 2016 23:28:58 -0500 Subject: [PATCH 23/29] Commit --- .idea/misc.xml | 4 ++++ .idea/modules.xml | 8 ++++++++ .idea/pygalfork.iml | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pygalfork.iml diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 00000000..5f7ced05 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 00000000..23e2f695 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pygalfork.iml b/.idea/pygalfork.iml new file mode 100644 index 00000000..1f11eea6 --- /dev/null +++ b/.idea/pygalfork.iml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file From 5265c95141e2e2f7d4ba15a16fc9d6287086cf1c Mon Sep 17 00:00:00 2001 From: feargswalsh92 Date: Wed, 27 Jul 2016 00:52:51 -0500 Subject: [PATCH 24/29] Render test added --- pygal/graph/bar.py | 4 +++- pygal/test/test_bar.py | 26 +++++++++----------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index 835b34d3..ab5963b0 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -83,7 +83,7 @@ def _tooltip_and_print_values( else: x = x_center y = y_bottom - sign * self.style.value_font_size / 2 - elif self.print_values_positio2 == 'bottom': + elif self.print_values_position == 'bottom': if self.horizontal: x = x_top + sign * self.style.value_font_size / 2 y = y_center @@ -95,6 +95,8 @@ def _tooltip_and_print_values( y = y_center self.style.value_font_size = width / 1.41421 + + self._static_value(serie_node, val, percent, x, y, metadata, "middle") def bar(self, serie, rescale=False): diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 65536f1c..058c5a2b 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -56,26 +56,16 @@ def test_difference(): bar_labelled = Bar(bar_values=True) rng = [-3, -32, -39] bar_labelled.add('test1', rng) - bar + bar_labelled.add('test2', map(abs, rng)) + bar_labelled.add('test2', map(abs, rng)) bar.labelled = map(str, rng) - assert bar == bar_labelled + assert bar != bar_labelled # def test_bar_values(CommonConfig): # assert self.Bar(print_values==True) -def test_calc_percent(): - bar = Bar() - rng = [-3, -32, -39] - bar.add('test1', rng) - bar.add('test2', map(abs, rng)) - bar.x_labels = map(str, rng) - - - - assert bar.calc_percent(rng) is float def test_bar_percent_difference(): bar = Bar() @@ -93,7 +83,7 @@ def test_bar_percent_difference(): assert (bar != barpercent) -def test_percent_formatting(): +def test_chart_renders(): line_chart = Bar(print_values=True, percent_values=True, print_values_position='top') line_chart.title = 'Browser usage evolution (in %)' line_chart.x_labels = map(str, range(2002, 2013)) @@ -101,12 +91,14 @@ def test_percent_formatting(): line_chart.add('Chrome', [None, None, None, None, None, None, 0, 3.9, 10.8, 23.8, 35.3]) line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1]) line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]) - line_chart.render_in_browser() + assert line_chart.render() + +#def test_length_is_int: + # line_chart_series = line_chart((filter(None, line_chart.values))) + # for serie in line_chart_series: + #assertTrue len(line_chart_series) ==int,"Length is int") - for serie in line_chart.series: - factor = len(serie) - assert(line_chart.bar_newfont_size == line_chart.value_font_size/factor) From c1593264fb439b6fb2ce9625a89fa1dfa959d3ce Mon Sep 17 00:00:00 2001 From: psheu Date: Wed, 27 Jul 2016 13:49:43 -0500 Subject: [PATCH 25/29] Reconfigure print values loop in graph --- pygal/graph/graph.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 5d94f38c..ce4d92d8 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -521,7 +521,7 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, y=y + self.style.value_font_size / 3, attrib={'text-anchor': align_text} ).text = value if self.print_zeroes or value != '0' else '' - elif self.percent_values: + if self.percent_values: self.svg.node( serie_node['text_overlay'], 'text', class_=' '.join(val_cls), From e40c581f6c36a79633386f73ae596fde73cc949c Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Wed, 27 Jul 2016 18:51:25 -0500 Subject: [PATCH 26/29] Removed Gauge functionality. --- .idea/inspectionProfiles/Project_Default.xml | 15 ---------- .../inspectionProfiles/profiles_settings.xml | 7 ----- .idea/misc.xml | 11 ------- .idea/modules.xml | 8 ----- .idea/pygalfork.iml | 23 -------------- pygal/config.py | 5 ---- pygal/graph/gauge.py | 28 +++-------------- pygal/test/test_gauge.py | 30 ------------------- pygal/util.py | 5 +--- 9 files changed, 5 insertions(+), 127 deletions(-) delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/inspectionProfiles/profiles_settings.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/pygalfork.iml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index ab978c5c..00000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml deleted file mode 100644 index c60c33bb..00000000 --- a/.idea/inspectionProfiles/profiles_settings.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index d216e800..00000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,11 +0,0 @@ - - -<<<<<<< HEAD - -======= - - - ->>>>>>> 14b2f2b97b9d2e6e420289e45e6387564839c76a - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 23e2f695..00000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/pygalfork.iml b/.idea/pygalfork.iml deleted file mode 100644 index 9e42342f..00000000 --- a/.idea/pygalfork.iml +++ /dev/null @@ -1,23 +0,0 @@ - - - - -<<<<<<< HEAD - -======= - ->>>>>>> 14b2f2b97b9d2e6e420289e45e6387564839c76a - - - - - - - - \ No newline at end of file diff --git a/pygal/config.py b/pygal/config.py index 87b48341..2ffb898c 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -257,11 +257,6 @@ class Config(CommonConfig): "Useful for adding gradients / patterns…", str) # Look # - clockwise = Key( - False, bool, "Look", - "Clockwise", - "Set to True to make the gauge clockwise.") - title = Key( None, str, "Look", "Graph title.", "Leave it to None to disable title.") diff --git a/pygal/graph/gauge.py b/pygal/graph/gauge.py index 3652a427..974fafd1 100644 --- a/pygal/graph/gauge.py +++ b/pygal/graph/gauge.py @@ -23,11 +23,12 @@ from pygal._compat import is_str from pygal.graph.graph import Graph -from pygal.util import alter, compute_scale, cut, decorate, compose +from pygal.util import alter, compute_scale, cut, decorate from pygal.view import PolarThetaLogView, PolarThetaView class Gauge(Graph): + """Gauge graph class""" needle_width = 1 / 20 @@ -44,11 +45,6 @@ def _set_view(self): self.height - self.margin_box.y, self._box) - def clockwiser(self, point): - x_0, _ = self.view((0, 90)) - new_x = 2 * x_0 - point[0] - return (new_x, point[1]) - def needle(self, serie): """Draw a needle for each value""" serie_node = self.svg.serie(serie) @@ -57,11 +53,7 @@ def needle(self, serie): continue def point(x, y): - if self.clockwise: - transform = compose(self.clockwiser, self.view) - else: - transform = self.view - return '%f %f' % transform((x, y)) + return '%f %f' % self.view((x, y)) val = self._format(serie, i) metadata = serie.metadata.get(i) @@ -83,23 +75,18 @@ def point(x, y): if self.logarithmic: w = min(w, self._min - self._min * 10 ** -10) - sweep_flag = '0' if self.clockwise else '1' - alter( self.svg.node( - gauges, 'path', d='M %s L %s A %s 1 0 %s %s Z' % ( + gauges, 'path', d='M %s L %s A %s 1 0 1 %s Z' % ( point(.85, theta), point(self.needle_width, theta - w), '%f %f' % (self.needle_width, self.needle_width), - sweep_flag, point(self.needle_width, theta + w), ), class_='line reactive tooltip-trigger'), metadata) x, y = self.view((.75, theta)) - if self.clockwise: - x, y = self.clockwiser((x, y)) self._tooltip_data( gauges, val, x, y, xlabel=self._get_x_label(i)) @@ -108,13 +95,6 @@ def point(x, y): def _y_axis(self, draw_axes=True): """Override y axis to plot a polar axis""" axis = self.svg.node(self.nodes['plot'], class_="axis x gauge") - if self.clockwise: - for i in range(int(len(self._y_labels) / 2)): - (label_1, theta_1) = self._y_labels[i] - (label_2, theta_2) = self._y_labels[len(self._y_labels) - i - 1] - temp_theta = theta_2 - self._y_labels[len(self._y_labels) - i - 1] = (label_2, theta_1) - self._y_labels[i] = (label_1, temp_theta) for i, (label, theta) in enumerate(self._y_labels): guides = self.svg.node(axis, class_='guides') diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py index 54d9a410..49192578 100644 --- a/pygal/test/test_gauge.py +++ b/pygal/test/test_gauge.py @@ -1,5 +1,4 @@ from pygal import Gauge -import pytest def test_render(): """Tests that a gauge plots""" @@ -9,32 +8,3 @@ def test_render(): chart.add('Mike', 30) chart.add('Jules', 10) assert chart.render() - - -def test_ccrender(): - """Tests that a clockwise gauge plots""" - clock_chart = Gauge(clockwise=True) - clock_chart.range = [0, 40] - clock_chart.add('Connor', 21) - clock_chart.add('Mike', 30) - clock_chart.add('Jules', 10) - assert clock_chart.render() - -def test_difference(): - """Tests the difference between a clockwise and counter clockwise graph""" - chart = Gauge() - chart.range = [0, 10000] - chart.add('Chrome', 8212) - chart.add('Firefox', 8099) - chart.add('Opera', 2933) - chart.add('IE', 41) - - clock_chart = Gauge(clockwise=True) - clock_chart.range = [0, 10000] - clock_chart.add('Chrome', 8212) - clock_chart.add('Firefox', 8099) - clock_chart.add('Opera', 2933) - clock_chart.add('IE', 41) - assert clock_chart.render() != chart.render() - - diff --git a/pygal/util.py b/pygal/util.py index ce26f1b4..4bfcb2a0 100644 --- a/pygal/util.py +++ b/pygal/util.py @@ -309,10 +309,7 @@ def minify_css(css): def compose(f, g): """Chain functions""" fun = lambda *args, **kwargs: f(g(*args, **kwargs)) - try: - fun.__name__ = "%s o %s" % (f.__name__, g.__name__) - except AttributeError: - fun.__name__ = f.__name__ + fun.__name__ = "%s o %s" % (f.__name__, g.__name__) return fun From 3a87fc1a2cfa09f8b4e1a17175aa8d86293c40d8 Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Wed, 27 Jul 2016 19:09:44 -0500 Subject: [PATCH 27/29] cleaning up again. --- pygal/config.py | 3 --- pygal/graph/bar.py | 6 ------ pygal/graph/graph.py | 10 ++-------- pygal/test/test_bar.py | 29 ----------------------------- 4 files changed, 2 insertions(+), 46 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index 2ffb898c..fa575fc3 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -397,8 +397,6 @@ class Config(CommonConfig): "are closed at the first value with a missing " "'x' (default), 'y' or 'either'") - - # Value # x_value_formatter = Key( formatters.default, callable, "Value", @@ -504,7 +502,6 @@ class Config(CommonConfig): "Bar Values", "Set to True to display a bar's percentage contribution per series atop the bar.") - # Misc # js = Key( ('//kozea.github.io/pygal.js/2.0.x/pygal-tooltips.min.js',), diff --git a/pygal/graph/bar.py b/pygal/graph/bar.py index ab5963b0..3a8cabba 100644 --- a/pygal/graph/bar.py +++ b/pygal/graph/bar.py @@ -95,8 +95,6 @@ def _tooltip_and_print_values( y = y_center self.style.value_font_size = width / 1.41421 - - self._static_value(serie_node, val, percent, x, y, metadata, "middle") def bar(self, serie, rescale=False): @@ -150,7 +148,3 @@ def _plot(self): self.bar(serie) for serie in self.secondary_series: self.bar(serie, True) - - def bar_newfont_size(self): - pass - diff --git a/pygal/graph/graph.py b/pygal/graph/graph.py index 3839136a..12a66b37 100644 --- a/pygal/graph/graph.py +++ b/pygal/graph/graph.py @@ -49,7 +49,6 @@ def _decorate(self): self._make_x_title() self._make_y_title() - def _axes(self): """Draw axes""" self._y_axis() @@ -527,7 +526,7 @@ def _static_value(self, serie_node, value, percent, x, y, metadata, serie_node['text_overlay'], 'text', class_=' '.join(val_cls), x=x, - y=y + 4/3*(self.style.value_font_size), + y=y + 4/3*self.style.value_font_size, attrib={'text-anchor': align_text} ).text = per_str if self.print_zeroes or per_str != '0.00%' else '' @@ -845,7 +844,7 @@ def _compute_x_labels_major(self): elif self.x_labels_major_count: label_count = len(self._x_labels) major_count = self.x_labels_major_count - if (major_count >= label_count): + if major_count >= label_count: self._x_labels_major = [label[0] for label in self._x_labels] else: @@ -937,7 +936,6 @@ def _draw(self): self._post_compute() self._compute_margin() self._decorate() - #self._bar_values() if self.series and self._has_data() and self._values: self._plot() else: @@ -952,7 +950,3 @@ def _has_data(self): if v is not None]) for s in self.raw_series ]) - - - - diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index 058c5a2b..d04825c0 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -18,13 +18,7 @@ # along with pygal. If not, see . """Bar chart related tests""" -from unittest import TestCase - -from wheel.signatures import assertTrue - from pygal import Bar -from pygal.graph.graph import Graph -from pygal import Config def test_simple_bar(): @@ -42,11 +36,6 @@ def test_simple_bar(): assert len(q(".plot .series rect")) == 2 * 3 -def test_Bar_Value_is_False(): - """Test to check the bar_value is initialised as false""" - assert Bar(bar_values=False) - - def test_difference(): bar = Bar(bar_values=False) rng = [-3, -32, -39] @@ -62,11 +51,6 @@ def test_difference(): assert bar != bar_labelled -# def test_bar_values(CommonConfig): - -# assert self.Bar(print_values==True) - - def test_bar_percent_difference(): bar = Bar() rng = [-3, -32, -39] @@ -92,16 +76,3 @@ def test_chart_renders(): line_chart.add('IE', [85.8, 84.6, 84.7, 74.5, 66, 58.6, 54.7, 44.8, 36.2, 26.6, 20.1]) line_chart.add('Others', [14.2, 15.4, 15.3, 8.9, 9, 10.4, 8.9, 5.8, 6.7, 6.8, 7.5]) assert line_chart.render() - -#def test_length_is_int: - # line_chart_series = line_chart((filter(None, line_chart.values))) - # for serie in line_chart_series: - #assertTrue len(line_chart_series) ==int,"Length is int") - - - - - - - - From 9295272491f264ac83d150a4c06f7c873aa8a5b7 Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Wed, 27 Jul 2016 19:15:32 -0500 Subject: [PATCH 28/29] removed .idea --- .idea/vcs.xml | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 .idea/vcs.xml diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7f..00000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 67a81a9fd9b885870c0127cac78bd80260a95db0 Mon Sep 17 00:00:00 2001 From: cmoore12 Date: Wed, 27 Jul 2016 20:06:02 -0500 Subject: [PATCH 29/29] fixed testing problems --- pygal/test/test_bar.py | 3 +++ pygal/test/test_gauge.py | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/pygal/test/test_bar.py b/pygal/test/test_bar.py index d04825c0..18f293fa 100644 --- a/pygal/test/test_bar.py +++ b/pygal/test/test_bar.py @@ -37,6 +37,7 @@ def test_simple_bar(): def test_difference(): + """Tests the difference between labeled graphs and unlabeled graphs""" bar = Bar(bar_values=False) rng = [-3, -32, -39] bar.add('test1', rng) @@ -52,6 +53,7 @@ def test_difference(): def test_bar_percent_difference(): + """Tests the difference between percent labeled graphs and unlabeled graphs""" bar = Bar() rng = [-3, -32, -39] bar.add('test1', rng) @@ -68,6 +70,7 @@ def test_bar_percent_difference(): def test_chart_renders(): + """Tests that print values and percent values renders""" line_chart = Bar(print_values=True, percent_values=True, print_values_position='top') line_chart.title = 'Browser usage evolution (in %)' line_chart.x_labels = map(str, range(2002, 2013)) diff --git a/pygal/test/test_gauge.py b/pygal/test/test_gauge.py index 49192578..80a853be 100644 --- a/pygal/test/test_gauge.py +++ b/pygal/test/test_gauge.py @@ -1,5 +1,28 @@ +# -*- coding: utf-8 -*- +# This file is part of pygal +# +# A python svg graph plotting library +# Copyright © 2012-2016 Kozea +# +# This library is free software: you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) any +# later version. +# +# This library is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with pygal. If not, see . + +"""Gauge Chart related tests.""" + + from pygal import Gauge + def test_render(): """Tests that a gauge plots""" chart = Gauge()