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] 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: