Browse Source

Support multi title in worldmap

pull/35/head
Florian Mounier 12 years ago
parent
commit
b6c92232bd
  1. 3
      demo/moulinrouge/tests.py
  2. 12
      pygal/graph/worldmap.py

3
demo/moulinrouge/tests.py

@ -269,7 +269,7 @@ def get_test_routes(app):
map.add('1st', [('fr', 100), ('us', 10)]) map.add('1st', [('fr', 100), ('us', 10)])
map.add('2nd', [('jp', 1), ('ru', 7), ('uk', 0)]) map.add('2nd', [('jp', 1), ('ru', 7), ('uk', 0)])
map.add('3rd', ['ch', 'cz', 'ca', 'cn']) map.add('3rd', ['ch', 'cz', 'ca', 'cn'])
map.add('4th', {'br': 12, 'bo': 1, 'bu': 23}) map.add('4th', {'br': 12, 'bo': 1, 'bu': 23, 'fr': 34})
map.add('5th', [{ map.add('5th', [{
'value': ('tw', 10), 'value': ('tw', 10),
'label': 'First label', 'label': 'First label',
@ -283,6 +283,7 @@ def get_test_routes(app):
'label': 'Last' 'label': 'Last'
}]) }])
map.add('6th', [3, 5, 34, 12]) map.add('6th', [3, 5, 34, 12])
map.title = 'World Map !!'
return map.render_response() return map.render_response()
return filter(lambda x: x.startswith('test'), locals()) return filter(lambda x: x.startswith('test'), locals())

12
pygal/graph/worldmap.py

@ -80,8 +80,6 @@ class Worldmap(Graph):
continue continue
cls = country.get('class', '').split(' ') cls = country.get('class', '').split(' ')
cls.append('color-%d' % i) cls.append('color-%d' % i)
cls.append('tooltip-trigger')
cls.append('reactive')
country.set('class', ' '.join(cls)) country.set('class', ' '.join(cls))
country.set( country.set(
'style', 'fill-opacity: %f' % ( 'style', 'fill-opacity: %f' % (
@ -98,7 +96,15 @@ class Worldmap(Graph):
node.append(country) node.append(country)
parent.insert(index, node) parent.insert(index, node)
self.svg.node(country, 'title').text = '%s: %d' % ( last_node = len(country) > 0 and country[-1]
if last_node is not None and last_node.tag == 'title':
title_node = last_node
text = title_node.text + '\n'
else:
title_node = self.svg.node(country, 'title')
text = ''
title_node.text = text + '[%s] %s: %d' % (
serie.title,
self.country_names[country_code], value) self.country_names[country_code], value)
self.nodes['plot'].append(map) self.nodes['plot'].append(map)

Loading…
Cancel
Save