Skip to content

Commit

Permalink
Add french maps
Browse files Browse the repository at this point in the history
  • Loading branch information
paradoxxxzero committed Feb 21, 2014
1 parent 606d246 commit 4fc5621
Show file tree
Hide file tree
Showing 10 changed files with 947 additions and 205 deletions.
65 changes: 53 additions & 12 deletions demo/moulinrouge/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
# This file is part of pygal
from pygal import (
Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, XY,
CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box)
CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box,
FrenchMap_Departments, FrenchMap_Regions)
from pygal.style import styles
from pygal.graph.frenchmap import DEPARTMENTS, REGIONS
from random import randint, choice


def get_test_routes(app):
Expand Down Expand Up @@ -329,14 +332,13 @@ def test_datey():

@app.route('/test/worldmap')
def test_worldmap():
import random
map = Worldmap(style=random.choice(styles.values()))

map.add('1st', [('fr', 100), ('us', 10)])
map.add('2nd', [('jp', 1), ('ru', 7), ('uk', 0)])
map.add('3rd', ['ch', 'cz', 'ca', 'cn'])
map.add('4th', {'br': 12, 'bo': 1, 'bu': 23, 'fr': 34})
map.add('5th', [{
wmap = Worldmap(style=choice(list(styles.values())))

wmap.add('1st', [('fr', 100), ('us', 10)])
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'
Expand All @@ -348,8 +350,47 @@ def test_worldmap():
'value': ('mw', 40),
'label': 'Last'
}])
map.add('6th', [3, 5, 34, 12])
map.title = 'World Map !!'
return map.render_response()
wmap.add('6th', [3, 5, 34, 12])
wmap.title = 'World Map !!'
return wmap.render_response()

@app.route('/test/frenchmapdepartments')
def test_frenchmapdepartments():
fmap = FrenchMap_Departments(style=choice(list(styles.values())))
for i in range(10):
fmap.add('s%d' % i, [
(choice(list(DEPARTMENTS.keys())), randint(0, 100)) for _ in range(randint(1, 5))])

fmap.add('links', [{
'value': ('69', 10),
'label': '\o/',
'xlink': 'http://google.com?q=69'
}, {
'value': ('42', 20),
'label': 'Y',
}])
fmap.add('6th', [3, 5, 34, 12])
fmap.title = 'French map'
return fmap.render_response()

@app.route('/test/frenchmapregions')
def test_frenchmapregions():
fmap = FrenchMap_Regions(style=choice(list(styles.values())))
for i in range(10):
fmap.add('s%d' % i, [
(choice(list(REGIONS.keys())), randint(0, 100))
for _ in range(randint(1, 5))])

fmap.add('links', [{
'value': ('02', 10),
'label': '\o/',
'xlink': 'http://google.com?q=69'
}, {
'value': ('72', 20),
'label': 'Y',
}])
fmap.add('6th', [91, 2, 41])
fmap.title = 'French map'
return fmap.render_response()

return filter(lambda x: x.startswith('test'), locals())
8 changes: 4 additions & 4 deletions pygal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@
__version__ = '1.3.1'
import sys
from pygal.config import Config
from pygal.ghost import Ghost
from pygal.graph import CHARTS_NAMES
from pygal.ghost import Ghost, REAL_CHARTS

CHARTS = []
CHARTS_BY_NAME = {}

for NAME in CHARTS_NAMES:
for NAME in REAL_CHARTS.keys():
_CHART = type(NAME, (Ghost,), {})
CHARTS.append(_CHART)
CHARTS_BY_NAME[NAME] = _CHART
setattr(sys.modules[__name__], NAME, _CHART)


__all__ = CHARTS_NAMES + [Config.__name__, 'CHARTS', 'CHARTS_BY_NAME']
__all__ = list(CHARTS_BY_NAME.keys()) + [
Config.__name__, 'CHARTS', 'CHARTS_BY_NAME']
4 changes: 2 additions & 2 deletions pygal/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
fill: {{ style.foreground_light }};
}

{{ id }}.country {
{{ id }}.map-element {
fill: {{ style.foreground }};
stroke: {{ style.plot_background }} !important;
opacity: .9;
Expand All @@ -124,7 +124,7 @@
transition: 250ms;
}

{{ id }}.country:hover {
{{ id }}.map-element:hover {
opacity: 1;
stroke-width: 10;
}
Expand Down
13 changes: 12 additions & 1 deletion pygal/ghost.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,23 @@
from uuid import uuid4


class ChartCollection(object):
pass


REAL_CHARTS = {}
for NAME in CHARTS_NAMES:
mod_name = 'pygal.graph.%s' % NAME.lower()
__import__(mod_name)
mod = sys.modules[mod_name]
REAL_CHARTS[NAME] = getattr(mod, NAME)
chart = getattr(mod, NAME)
if issubclass(chart, ChartCollection):
for name, chart in chart.__dict__.items():
if name.startswith('_'):
continue
REAL_CHARTS['%s_%s' % (NAME, name)] = chart
else:
REAL_CHARTS[NAME] = chart


class Ghost(object):
Expand Down
3 changes: 2 additions & 1 deletion pygal/graph/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,6 @@
'Worldmap',
'SupranationalWorldmap',
'Histogram',
'Box'
'Box',
'FrenchMap'
]
328 changes: 328 additions & 0 deletions pygal/graph/fr.departments.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions pygal/graph/fr.regions.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4fc5621

Please sign in to comment.