diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index b9f6f09..b77bcf7 100644 --- a/demo/moulinrouge/tests.py +++ b/demo/moulinrouge/tests.py @@ -564,9 +564,10 @@ def get_test_routes(app): @app.route('/test/64colors') def test_64_colors(): - colors = [rotate('#ff0000', i * 360 / 64) for i in range(64)] + n = 64 + colors = [rotate('#ff0000', i * 360 / n) for i in range(n)] pie = Pie(style=Style(colors=colors)) - for i in range(64): + for i in range(n): pie.add(str(i), 1) return pie.render_response() diff --git a/docs/documentation/builtin_styles.rst b/docs/documentation/builtin_styles.rst index f0b18d4..9c67834 100644 --- a/docs/documentation/builtin_styles.rst +++ b/docs/documentation/builtin_styles.rst @@ -18,6 +18,20 @@ Default chart.add('E', [7, 4, 2, 1, 2, 10, 0]) +DarkStyle +--------- + +.. pygal-code:: + + from pygal.style import DarkStyle + chart = pygal.StackedLine(fill=True, interpolate='cubic', style=DarkStyle) + chart.add('A', [1, 3, 5, 16, 13, 3, 7]) + chart.add('B', [5, 2, 3, 2, 5, 7, 17]) + chart.add('C', [6, 10, 9, 7, 3, 1, 0]) + chart.add('D', [2, 3, 5, 9, 12, 9, 5]) + chart.add('E', [7, 4, 2, 1, 2, 10, 0]) + + Neon ---- diff --git a/pygal/graph/time.py b/pygal/graph/time.py index 648b0c2..879b2f3 100644 --- a/pygal/graph/time.py +++ b/pygal/graph/time.py @@ -71,7 +71,7 @@ def time_to_seconds(x): ) * 10 ** 6 + x.microsecond) / 10 ** 6 # Clamp to valid time - return max(0, min(x, 24 * 3600 - 10 ** -6)) + return x and max(0, min(x, 24 * 3600 - 10 ** -6)) def seconds_to_time(x): diff --git a/pygal/style.py b/pygal/style.py index 9aa3695..7966e04 100644 --- a/pygal/style.py +++ b/pygal/style.py @@ -19,7 +19,7 @@ """Charts styling classes""" from __future__ import division -from pygal.util import cycle_fill + from pygal import colors from pygal.colors import darken, lighten @@ -76,7 +76,17 @@ class Style(object): '}}\n') % (prefix, prefix)).format(*tupl) if len(self.colors) < len_: - colors = cycle_fill(self.colors, len_) + missing = len_ - len(self.colors) + cycles = 1 + missing // len(self.colors) + colors = [] + for i in range(0, cycles + 1): + for color_ in self.colors: + colors.append(darken(color_, 33 * i / cycles)) + if len(colors) >= len_: + break + else: + continue + break else: colors = self.colors[:len_] @@ -339,6 +349,7 @@ class SolidColorStyle(Style): styles = {'default': DefaultStyle, + 'dark': DarkStyle, 'light': LightStyle, 'neon': NeonStyle, 'clean': CleanStyle, diff --git a/pygal/svg.py b/pygal/svg.py index 06c3bd8..fe85b71 100644 --- a/pygal/svg.py +++ b/pygal/svg.py @@ -200,18 +200,15 @@ class Svg(object): plot=self.node( self.graph.nodes['plot'], class_='series serie-%d color-%d' % ( - serie.index, serie.index % len( - self.graph.style.colors))), + serie.index, serie.index)), overlay=self.node( self.graph.nodes['overlay'], class_='series serie-%d color-%d' % ( - serie.index, serie.index % len( - self.graph.style.colors))), + serie.index, serie.index)), text_overlay=self.node( self.graph.nodes['text_overlay'], class_='series serie-%d color-%d' % ( - serie.index, serie.index % len( - self.graph.style.colors)))) + serie.index, serie.index))) def line(self, node, coords, close=False, **kwargs): """Draw a svg line""" diff --git a/pygal/util.py b/pygal/util.py index a8fc5d9..52680b4 100644 --- a/pygal/util.py +++ b/pygal/util.py @@ -257,15 +257,6 @@ def alter(node, metadata): dict((k, str(v)) for k, v in metadata['node'].items())) -def cycle_fill(short_list, max_len): - """Fill a list to max_len using a cycle of it""" - short_list = list(short_list) - list_cycle = cycle(short_list) - while len(short_list) < max_len: - short_list.append(next(list_cycle)) - return short_list - - def truncate(string, index): """Truncate a string at index and add ...""" if len(string) > index and index > 0: