Browse Source

Darken extra colors for serie len

pull/242/head
Florian Mounier 9 years ago
parent
commit
6ebf6d2e5f
  1. 5
      demo/moulinrouge/tests.py
  2. 14
      docs/documentation/builtin_styles.rst
  3. 2
      pygal/graph/time.py
  4. 15
      pygal/style.py
  5. 9
      pygal/svg.py
  6. 9
      pygal/util.py

5
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()

14
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
----

2
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):

15
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,

9
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"""

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

Loading…
Cancel
Save