Browse Source

Add tooltip support in metadata to add a title (#249).

pull/264/head
Florian Mounier 10 years ago
parent
commit
0ddcc0d3a2
  1. 48
      demo/moulinrouge/tests.py
  2. 2
      docs/changelog.rst
  3. 1
      docs/documentation/configuration/value.rst
  4. 2
      pygal/graph/map.py
  5. 4
      pygal/svg.py
  6. 4
      pygal/util.py

48
demo/moulinrouge/tests.py

@ -488,27 +488,30 @@ def get_test_routes(app):
def test_worldmap():
wmap = world.World(print_values=True, style=choice(list(styles.values())))
# wmap.js = ('http://l:2343/2.0.x/pygal-tooltips.js',)
wmap.add('1st', [('fr', 100), {
'value': ('us', 10),
'node': {'style': 'fill: red'}
}
])
wmap.add('2nd', [('jp', 1), ('ru', 7), ('uk', 0)])
wmap.add('3rd', ['ch', 'cz', 'ca', 'cn'])
wmap.add('4th', {'br': 12, 'bo': 1, 'bu': 23, 'fr': 34})
wmap.add('5th', [{
'value': ('tw', 10),
'label': 'First label',
'xlink': 'http://google.com?q=tw',
}, {
'value': ('bw', 20),
'label': 'Second one',
'xlink': 'http://google.com?q=bw',
'node': {'style': 'fill: blue'}
}, {
'value': ('mw', 40),
'label': 'Last'
}])
# wmap.add('1st', [('fr', 100), {
# 'value': ('us', 10),
# 'node': {'style': 'fill: red'}
# }
# ])
# wmap.add('2nd', [('jp', 1), ('ru', 7), ('uk', 0)])
# wmap.add('3rd', ['ch', 'cz', 'ca', 'cn'])
# wmap.add('4th', {'jp': 12, 'bo': 1, 'bu': 23, 'fr': 34})
# wmap.add('5th', [{
# 'value': ('tw', 10),
# 'label': 'First label',
# 'xlink': 'http://google.com?q=tw',
# }, {
# 'value': ('bw', 20),
# 'label': 'Second one',
# 'xlink': 'http://google.com?q=bw',
# 'node': {'style': 'fill: blue'}
# }, {
# 'value': ('mw', 40),
# 'label': 'Last'
# }])
wmap.add('_', {'us': 1})
wmap.add('-', {'us': 2})
wmap.add('.', {'us': 3})
wmap.title = 'World Map !!'
wmap.value_formatter = lambda x: '%d%%' % x
return wmap.render_response()
@ -701,6 +704,7 @@ def get_test_routes(app):
@app.route('/test/pie_serie_radius')
def test_pie_serie_radius():
pie = Pie()
pie.js = ('http://a.zi:2343/2.0.x/pygal-tooltips.js',)
for i in range(10):
pie.add(str(i), i, inner_radius=(10 - i) / 10)
@ -862,10 +866,12 @@ def get_test_routes(app):
# link on chart and label
chart.add({
'title': 'Red',
'tooltip': 'Cramoisi',
'xlink': {'href': 'http://en.wikipedia.org/wiki/Red'}
}, [{
'value': 2,
'label': 'This is red',
'tooltip': 'LOOLLOLOLO',
'xlink': {'href': 'http://en.wikipedia.org/wiki/Red'}}])
chart.add({'title': 'Yellow', 'xlink': {

2
docs/changelog.rst

@ -13,6 +13,8 @@ Changelog
* (Re)Add xlink in desc to show on tooltip
* Activate element on tooltip hovering. (#106)
* Fix radar axis behaviour (#247)
* Add tooltip support in metadata to add a title (#249).
2.0.0
=====

1
docs/documentation/configuration/value.rst

@ -153,6 +153,7 @@ Finally legends can be link with the same mechanism:
chart = pygal.Bar()
chart.add({
'title': 'First',
'tooltip': 'It is the first actually',
'xlink': {'href': 'http://en.wikipedia.org/wiki/First'}
}, [{
'value': 2,

2
pygal/graph/map.py

@ -96,7 +96,7 @@ class BaseMap(Graph):
cls.append('serie-%d' % i)
cls.append('series')
area.set('class', ' '.join(cls))
area.set('style', 'fill-opacity: %f' % (ratio))
area.set('style', 'fill-opacity: %f' % ratio)
metadata = serie.metadata.get(j)

4
pygal/svg.py

@ -143,7 +143,9 @@ class Svg(object):
dct = get_js_dict()
# Config adds
dct['legends'] = self.graph._legends + self.graph._secondary_legends
dct['legends'] = [
l.get('title') if isinstance(l, dict) else l
for l in self.graph._legends + self.graph._secondary_legends]
common_script.text = " = ".join(
("window.config", json.dumps(

4
pygal/util.py

@ -235,6 +235,10 @@ def decorate(svg, node, metadata):
svg.node(node, 'desc', class_='xlink').text = to_unicode(
xlink.get('href'))
if 'tooltip' in metadata:
svg.node(node, 'title').text = to_unicode(
metadata['tooltip'])
if 'color' in metadata:
color = metadata.pop('color')
node.attrib['style'] = 'fill: %s; stroke: %s' % (

Loading…
Cancel
Save