Browse Source

Minor fixes + add darken and lighten functions to style, which are broken btw

pull/35/merge
Florian Mounier 12 years ago
parent
commit
a50bfaa98c
  1. 7
      demo/moulinrouge/tests.py
  2. 4
      pygal/config.py
  3. 2
      pygal/graph/dot.py
  4. 4
      pygal/graph/graph.py
  5. 23
      pygal/style.py
  6. 20
      pygal/test/test_style.py

7
demo/moulinrouge/tests.py

@ -26,14 +26,14 @@ def get_test_routes(app):
@app.route('/test/bar_links') @app.route('/test/bar_links')
def test_bar_links(): def test_bar_links():
bar = Bar(style=styles['neon']) bar = Bar(style=styles['neon'])
# bar.js = ('http://l:2343/svg.jquery.js', bar.js = ('http://l:2343/svg.jquery.js',
# 'http://l:2343/pygal-tooltips.js') 'http://l:2343/pygal-tooltips.js')
bar.add('1234', [ bar.add('1234', [
{'value': 10, {'value': 10,
'label': 'Ten', 'label': 'Ten',
'xlink': 'http://google.com?q=10'}, 'xlink': 'http://google.com?q=10'},
{'value': 20, {'value': 20,
'label': 'Twenty', 'tooltip': 'Twenty',
'xlink': 'http://google.com?q=20'}, 'xlink': 'http://google.com?q=20'},
30, 30,
{'value': 40, {'value': 40,
@ -117,7 +117,6 @@ def get_test_routes(app):
def test_dot(): def test_dot():
dot = Dot() dot = Dot()
dot.x_labels = map(str, range(4)) dot.x_labels = map(str, range(4))
dot.add('a', [1, lnk(3, 'Foo'), 5, 3]) dot.add('a', [1, lnk(3, 'Foo'), 5, 3])
dot.add('b', [2, 2, 0, 2]) dot.add('b', [2, 2, 0, 2])
dot.add('c', [5, 1, 5, lnk(3, 'Bar')]) dot.add('c', [5, 1, 5, lnk(3, 'Bar')])

4
pygal/config.py

@ -149,6 +149,8 @@ class Config(object):
20, int, "Look", 20, int, "Look",
"Margin around chart") "Margin around chart")
tooltip_border_radius = Key(0, int, "Look", "Tooltip border radius")
############ Label ############ ############ Label ############
x_labels = Key( x_labels = Key(
None, list, "Label", None, list, "Label",
@ -235,7 +237,7 @@ class Config(object):
value_font_size = Key(8, int, "Text", "Value font size") value_font_size = Key(8, int, "Text", "Value font size")
tooltip_font_size = Key(20, int, "Text", "Tooltip font size") tooltip_font_size = Key(16, int, "Text", "Tooltip font size")
title_font_size = Key(16, int, "Text", "Title font size") title_font_size = Key(16, int, "Text", "Title font size")

2
pygal/graph/dot.py

@ -52,7 +52,7 @@ class Dot(Graph):
self.svg.node(dots, 'circle', cx=x, cy=y, r=size, self.svg.node(dots, 'circle', cx=x, cy=y, r=size,
class_='dot reactive tooltip-trigger') class_='dot reactive tooltip-trigger')
self._tooltip_data(dots, value, x, y) self._tooltip_data(dots, value, x, y, classes='centered')
self._static_value(serie_node, value, x, y) self._static_value(serie_node, value, x, y)
def _compute(self): def _compute(self):

4
pygal/graph/graph.py

@ -109,7 +109,9 @@ class Graph(BaseGraph):
a = self.svg.node(self.nodes['tooltip'], 'a') a = self.svg.node(self.nodes['tooltip'], 'a')
self.svg.node(a, 'rect', self.svg.node(a, 'rect',
id="tooltip-box", id="tooltip-box",
rx=5, ry=5, width=0, height=0) rx=self.tooltip_border_radius,
ry=self.tooltip_border_radius,
width=0, height=0)
text = self.svg.node(a, 'text', class_='text') text = self.svg.node(a, 'text', class_='text')
self.svg.node(text, 'tspan', class_='label') self.svg.node(text, 'tspan', class_='label')
self.svg.node(text, 'tspan', class_='value') self.svg.node(text, 'tspan', class_='value')

23
pygal/style.py

@ -19,7 +19,30 @@
""" """
Charts styling Charts styling
""" """
from __future__ import division
from pygal.util import cycle_fill from pygal.util import cycle_fill
from colorsys import rgb_to_hls, hls_to_rgb
def darken(color, percent):
assert color[0] == '#', '#rrggbb and #rgb format are supported'
color = color[1:]
assert len(color) in (3, 6), '#rrggbb and #rgb format are supported'
if len(color) == 3:
color = [a for b in zip(color, color) for a in b]
return '#%02x%02x%02x' % tuple(
map(lambda x: 255 * x,
hls_to_rgb(*(
lambda h, l, s: (h, max(0, min(1, l - percent / 100)), s))(
*rgb_to_hls(*map(
lambda x: int(''.join(x), 16) / 255,
zip(color[::2], color[1::2])))
))))
def lighten(color, percent):
return darken(color, -percent)
class Style(object): class Style(object):

20
pygal/test/test_style.py

@ -16,7 +16,7 @@
# #
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from pygal.style import Style from pygal.style import Style, darken, lighten
def test_colors(): def test_colors():
@ -102,3 +102,21 @@ def test_colors():
fill: rgb(12, 231, 3); fill: rgb(12, 231, 3);
} }
''' '''
def test_darken():
assert darken('#800', 20) == '#220000'
assert darken('#ffffff', 10) == '#e6e6e6'
assert darken('#f3148a', 25) == '#810747'
assert darken('#121212', 1) == '#0f0f0f'
assert darken('#999999', 100) == '#000000'
assert darken('#1479ac', 8) == '#105f87'
def test_lighten():
assert lighten('#800', 20) == '#ee0000'
assert lighten('#ffffff', 10) == '#ffffff'
assert lighten('#f3148a', 25) == '#f98dc6'
assert lighten('#121212', 1) == '#151515'
assert lighten('#999999', 100) == '#ffffff'
assert lighten('#1479ac', 8) == '#1893d1'

Loading…
Cancel
Save