From b9e6efc79bccc7c89b63f1fe6867a54cfee26440 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Plasse?= Date: Wed, 2 Apr 2014 15:45:26 +0200 Subject: [PATCH 1/5] Add python 3.4 for tox --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index aa1206e..20cb90c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26,py27,py32,py33 +envlist = py26,py27,py32,py33,py34 [testenv] sitepackages=True From 986860cab66f577e2a4246e9aabb3137df5a8e69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Plasse?= Date: Wed, 2 Apr 2014 15:48:11 +0200 Subject: [PATCH 2/5] Add new config option for hiding all dots except major labeled ones --- pygal/config.py | 4 ++++ pygal/graph/line.py | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/pygal/config.py b/pygal/config.py index b19472e..08f23c9 100644 --- a/pygal/config.py +++ b/pygal/config.py @@ -140,6 +140,10 @@ class Config(MetaConfig('ConfigBase', (object,), {})): show_dots = Key(True, bool, "Look", "Set to false to remove dots") + show_only_major_dots = Key( + False, bool, "Look", + "Set to true to show only major dots according to their majored label") + dots_size = Key(2.5, float, "Look", "Radius of the dots") stroke = Key( diff --git a/pygal/graph/line.py b/pygal/graph/line.py index b24c746..bf34ef6 100644 --- a/pygal/graph/line.py +++ b/pygal/graph/line.py @@ -67,10 +67,30 @@ class Line(Graph): points = serie.points view_values = list(map(self.view, points)) if self.show_dots: + if self.show_only_major_dots: + major_dots_index = [] + if self.x_labels: + if self.x_labels_major: + major_dots_index = [] + for major in self.x_labels_major: + start = -1 + while True: + try: + index = self.x_labels.index( + major, start + 1) + except ValueError: + break + else: + major_dots_index.append(index) + start = index + elif self.x_labels_major_every: + major_dots_index = range( + 0, len(self.x_labels), self.x_labels_major_every) + for i, (x, y) in enumerate(view_values): - if None in (x, y): + if None in (x, y) or (self.show_only_major_dots + and i not in major_dots_index): continue - metadata = serie.metadata.get(i) classes = [] if x > self.view.width / 2: From aa18bc813362ee4db7e264550e34535533e91e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Plasse?= Date: Wed, 2 Apr 2014 15:48:50 +0200 Subject: [PATCH 3/5] Test new 'show_only_major_dots' option --- pygal/test/test_line.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pygal/test/test_line.py b/pygal/test/test_line.py index 55cad41..b673f14 100644 --- a/pygal/test/test_line.py +++ b/pygal/test/test_line.py @@ -92,3 +92,11 @@ def test_not_equal_x_labels(): assert len(q(".axis.x")) == 1 assert q(".axis.x text").map(texts) == ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] + + +def test_only_major_dots(): + line = Line(show_only_major_dots=True, x_labels_major_every=3) + line.add('test', range(12)) + line.x_labels = map(str, range(12)) + q = line.render_pyquery() + assert len(q(".dots")) == 4 From aa344741e3cac987b1be5501dc08df07dcdc419b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Plasse?= Date: Wed, 2 Apr 2014 15:49:20 +0200 Subject: [PATCH 4/5] simple graph with 'show_only_major_dots' option --- demo/moulinrouge/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index 7bd6084..813a4f6 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -419,4 +419,14 @@ def get_test_routes(app): line.x_labels = map(str, range(11)) return line.render_response() + @app.route('/test/major_dots') + def test_major_dots(): + line = Line(x_labels_major_every=3, show_only_major_dots=True) + line.add('test', range(12)) + line.x_labels = [ + 'lol', 'lol1', 'lol2', 'lol3', 'lol4', 'lol5', + 'lol6', 'lol7', 'lol8', 'lol9', 'lol10', 'lol11'] + line.x_labels_major = ['lol3'] + return line.render_response() + return filter(lambda x: x.startswith('test'), locals()) From 65b3a60848554c4e12bd253c7c0e91590f3d302a Mon Sep 17 00:00:00 2001 From: Guillaume Ayoub Date: Tue, 15 Apr 2014 18:21:46 +0200 Subject: [PATCH 5/5] Add python3.4 in tox --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index aa1206e..20cb90c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26,py27,py32,py33 +envlist = py26,py27,py32,py33,py34 [testenv] sitepackages=True