Browse Source

Merge branch 'master' of github.com:Kozea/pygal

pull/39/head
Anaèle Digoin 11 years ago
parent
commit
b32dc58460
  1. 2
      demo/moulinrouge/__init__.py
  2. 7
      demo/moulinrouge/tests.py
  3. 4
      pygal/config.py
  4. 2
      pygal/css/base.css
  5. 2
      pygal/css/style.css
  6. 2
      pygal/graph/dot.py
  7. 4
      pygal/graph/graph.py
  8. 23
      pygal/style.py
  9. 6
      pygal/svg.py
  10. 20
      pygal/test/test_style.py

2
demo/moulinrouge/__init__.py

@ -96,7 +96,7 @@ def create_app():
@app.route("/sparkline/<style>")
def sparkline(style):
line = pygal.Line(style=styles[style])
line = pygal.Line(style=styles[style], pretty_print=True)
line.add('_', [random.randrange(0, 10) for _ in range(25)])
return Response(
line.render_sparkline(height=40), mimetype='image/svg+xml')

7
demo/moulinrouge/tests.py

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

4
pygal/config.py

@ -149,6 +149,8 @@ class Config(object):
20, int, "Look",
"Margin around chart")
tooltip_border_radius = Key(0, int, "Look", "Tooltip border radius")
############ Label ############
x_labels = Key(
None, list, "Label",
@ -235,7 +237,7 @@ class Config(object):
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")

2
pygal/css/base.css

@ -18,7 +18,7 @@
* along with pygal. If not, see <http://www.gnu.org/licenses/>.
*/
/*
/*
* Font-sizes from config, override with care
*/

2
pygal/css/style.css

@ -18,7 +18,7 @@
* along with pygal. If not, see <http://www.gnu.org/licenses/>.
*/
/*
/*
* Styles from config
*/

2
pygal/graph/dot.py

@ -52,7 +52,7 @@ class Dot(Graph):
self.svg.node(dots, 'circle', cx=x, cy=y, r=size,
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)
def _compute(self):

4
pygal/graph/graph.py

@ -109,7 +109,9 @@ class Graph(BaseGraph):
a = self.svg.node(self.nodes['tooltip'], 'a')
self.svg.node(a, 'rect',
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')
self.svg.node(text, 'tspan', class_='label')
self.svg.node(text, 'tspan', class_='value')

23
pygal/style.py

@ -19,7 +19,30 @@
"""
Charts styling
"""
from __future__ import division
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):

6
pygal/svg.py

@ -60,6 +60,7 @@ class Svg(object):
def add_styles(self):
"""Add the css to the svg"""
all_css = []
for css in ['base.css'] + list(self.graph.css):
if urlparse(css).scheme:
self.processing_instructions.append(
@ -76,8 +77,9 @@ class Svg(object):
font_sizes=self.graph.font_sizes())
if not self.graph.pretty_print:
css_text = minify_css(css_text)
self.node(
self.defs, 'style', type='text/css').text = css_text
all_css.append(css_text)
self.node(
self.defs, 'style', type='text/css').text = '\n'.join(all_css)
def add_scripts(self):
"""Add the js to the svg"""

20
pygal/test/test_style.py

@ -16,7 +16,7 @@
#
# You should have received a copy of the GNU Lesser General Public License
# 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():
@ -102,3 +102,21 @@ def test_colors():
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