diff --git a/demo/moulinrouge/tests.py b/demo/moulinrouge/tests.py index c4ba3e7..c661412 100644 --- a/demo/moulinrouge/tests.py +++ b/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': { diff --git a/docs/changelog.rst b/docs/changelog.rst index b02eb57..764140f 100644 --- a/docs/changelog.rst +++ b/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 ===== diff --git a/docs/documentation/configuration/value.rst b/docs/documentation/configuration/value.rst index 12b7874..426f0ef 100644 --- a/docs/documentation/configuration/value.rst +++ b/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, diff --git a/pygal/graph/map.py b/pygal/graph/map.py index 72cac70..9e21e0e 100644 --- a/pygal/graph/map.py +++ b/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) diff --git a/pygal/svg.py b/pygal/svg.py index ef80915..c52685d 100644 --- a/pygal/svg.py +++ b/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( diff --git a/pygal/util.py b/pygal/util.py index 6f68dd5..0c83ba6 100644 --- a/pygal/util.py +++ b/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' % (