Browse Source

Cycle colors in css

pull/8/head
Florian Mounier 13 years ago
parent
commit
41f1ecd11b
  1. 5
      pygal/graph/radar.py
  2. 4
      pygal/style.py
  3. 60
      pygal/test/test_style.py
  4. 11
      pygal/util.py

5
pygal/graph/radar.py

@ -109,8 +109,9 @@ class Radar(Line):
x_pos = [.5 * pi + i * delta for i in range(self._len + 1)] x_pos = [.5 * pi + i * delta for i in range(self._len + 1)]
for serie in self.series: for serie in self.series:
vals = list(serie.values) vals = list(serie.values)
vals.append(vals[0]) # TODO: Fix metadata add here
serie.metadata.append(serie.metadata[0]) # vals.append(vals[0])
# serie.metadata.append(serie.metadata[0])
vals = [val if val != None else 0 for val in vals] vals = [val if val != None else 0 for val in vals]
serie.points = [ serie.points = [
(v, x_pos[i]) (v, x_pos[i])

4
pygal/style.py

@ -19,6 +19,7 @@
""" """
Charts styling Charts styling
""" """
from pygal.util import cycle_fill
class Style(object): class Style(object):
@ -50,6 +51,7 @@ class Style(object):
@property @property
def colors(self): def colors(self):
"""Get the css color list""" """Get the css color list"""
def color(tupl): def color(tupl):
"""Make a color css""" """Make a color css"""
return ( return (
@ -57,7 +59,7 @@ class Style(object):
' stroke: {1};\n' ' stroke: {1};\n'
' fill: {1};\n' ' fill: {1};\n'
'}}\n'.format(*tupl)) '}}\n'.format(*tupl))
return '\n'.join(map(color, enumerate(self._colors))) return '\n'.join(map(color, enumerate(cycle_fill(self._colors, 16))))
def to_dict(self): def to_dict(self):
config = {} config = {}

60
pygal/test/test_style.py

@ -41,4 +41,64 @@ def test_colors():
stroke: rgb(12, 231, 3); stroke: rgb(12, 231, 3);
fill: rgb(12, 231, 3); fill: rgb(12, 231, 3);
} }
.color-4 {
stroke: red;
fill: red;
}
.color-5 {
stroke: #231A3b;
fill: #231A3b;
}
.color-6 {
stroke: #ff0;
fill: #ff0;
}
.color-7 {
stroke: rgb(12, 231, 3);
fill: rgb(12, 231, 3);
}
.color-8 {
stroke: red;
fill: red;
}
.color-9 {
stroke: #231A3b;
fill: #231A3b;
}
.color-10 {
stroke: #ff0;
fill: #ff0;
}
.color-11 {
stroke: rgb(12, 231, 3);
fill: rgb(12, 231, 3);
}
.color-12 {
stroke: red;
fill: red;
}
.color-13 {
stroke: #231A3b;
fill: #231A3b;
}
.color-14 {
stroke: #ff0;
fill: #ff0;
}
.color-15 {
stroke: rgb(12, 231, 3);
fill: rgb(12, 231, 3);
}
''' '''

11
pygal/util.py

@ -24,6 +24,7 @@ Various utils
from __future__ import division from __future__ import division
from decimal import Decimal from decimal import Decimal
from math import floor, pi, log, log10, ceil from math import floor, pi, log, log10, ceil
from itertools import cycle
ORDERS = u"yzafpnµm kMGTPEZY" ORDERS = u"yzafpnµm kMGTPEZY"
@ -189,6 +190,7 @@ def get_texts_box(texts, fs):
def decorate(svg, node, metadata): def decorate(svg, node, metadata):
"""Add metedata next to a node"""
if hasattr(metadata, 'xlink'): if hasattr(metadata, 'xlink'):
xlink = metadata.xlink xlink = metadata.xlink
if not isinstance(xlink, dict): if not isinstance(xlink, dict):
@ -202,6 +204,15 @@ def decorate(svg, node, metadata):
return node return node
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) < 16:
short_list.append(list_cycle.next())
return short_list
# Stolen from brownie http://packages.python.org/Brownie/ # Stolen from brownie http://packages.python.org/Brownie/
class cached_property(object): class cached_property(object):
"""Optimize a static property""" """Optimize a static property"""

Loading…
Cancel
Save