Browse Source

Externalized swiss map to pygal_map_ch

pull/242/head
Florian Mounier 10 years ago
parent
commit
eb9066991f
  1. 12
      demo/moulinrouge/tests.py
  2. 1
      pygal/__init__.py
  3. 91
      pygal/graph/maps/ch.cantons.svg
  4. 72
      pygal/graph/swissmap.py
  5. 2
      pygal/test/test_config.py

12
demo/moulinrouge/tests.py

@ -2,7 +2,7 @@
# This file is part of pygal
from pygal import (
Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, StackedLine, XY,
CHARTS_BY_NAME, Config, Line, Worldmap, Histogram, Box, SwissMapCantons,
CHARTS_BY_NAME, Config, Line, Worldmap, Histogram, Box,
Pie, Treemap, TimeLine, DateLine,
DateTimeLine, SupranationalWorldmap)
@ -11,11 +11,15 @@ try:
except ImportError:
fr = None
try:
from pygal.maps import ch
except ImportError:
ch = None
from flask import abort
from pygal.style import styles, Style, RotateStyle
from pygal.colors import rotate
from pygal.graph.horizontal import HorizontalGraph
from pygal.graph.swissmap import CANTONS
from random import randint, choice
from datetime import datetime
@ -470,10 +474,10 @@ def get_test_routes(app):
@app.route('/test/swissmap')
def test_swissmap():
smap = SwissMapCantons(style=choice(list(styles.values())))
smap = ch.Cantons(style=choice(list(styles.values())))
for i in range(10):
smap.add('s%d' % i, [
(choice(list(CANTONS.keys())), randint(0, 100))
(choice(list(ch.CANTONS.keys())), randint(0, 100))
for _ in range(randint(1, 5))])
smap.add('links', [{

1
pygal/__init__.py

@ -37,7 +37,6 @@ from pygal.graph.pyramid import Pyramid
from pygal.graph.radar import Radar
from pygal.graph.stackedbar import StackedBar
from pygal.graph.stackedline import StackedLine
from pygal.graph.swissmap import SwissMapCantons
from pygal.graph.time import DateLine, DateTimeLine, TimeLine, TimeDeltaLine
from pygal.graph.treemap import Treemap
from pygal.graph.verticalpyramid import VerticalPyramid

91
pygal/graph/maps/ch.cantons.svg

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 151 KiB

72
pygal/graph/swissmap.py

@ -1,72 +0,0 @@
# -*- coding: utf-8 -*-
# This file is part of pygal
#
# A python svg graph plotting library
# Copyright © 2012-2014 Kozea
#
# This library is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# This library is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
# details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>.
"""
Worldmap chart
"""
from __future__ import division
from pygal.graph.map import BaseMap
from pygal._compat import u
import os
CANTONS = {
'kt-zh': u("ZH"),
'kt-be': u("BE"),
'kt-lu': u("LU"),
'kt-ju': u("JH"),
'kt-ur': u("UR"),
'kt-sz': u("SZ"),
'kt-ow': u("OW"),
'kt-nw': u("NW"),
'kt-gl': u("GL"),
'kt-zg': u("ZG"),
'kt-fr': u("FR"),
'kt-so': u("SO"),
'kt-bl': u("BS"),
'kt-bs': u("BL"),
'kt-sh': u("SH"),
'kt-ar': u("AR"),
'kt-ai': u("AI"),
'kt-sg': u("SG"),
'kt-gr': u("GR"),
'kt-ag': u("AG"),
'kt-tg': u("TG"),
'kt-ti': u("TI"),
'kt-vd': u("VD"),
'kt-vs': u("VS"),
'kt-ne': u("NE"),
'kt-ge': u("GE"),
}
with open(os.path.join(
os.path.dirname(__file__), 'maps',
'ch.cantons.svg')) as file:
CNT_MAP = file.read()
class SwissMapCantons(BaseMap):
"""Swiss Cantons map"""
x_labels = list(CANTONS.keys())
area_names = CANTONS
area_prefix = 'z'
kind = 'canton'
svg_map = CNT_MAP

2
pygal/test/test_config.py

@ -20,7 +20,7 @@
from pygal import (
Line, Dot, Pie, Treemap, Radar, Config, Bar, Funnel, Worldmap,
SupranationalWorldmap, Histogram, Gauge, Box, XY,
Pyramid, HorizontalBar, HorizontalStackedBar, SwissMapCantons,
Pyramid, HorizontalBar, HorizontalStackedBar,
DateTimeLine, TimeLine, DateLine, TimeDeltaLine)
from pygal.graph.map import BaseMap
from pygal._compat import u

Loading…
Cancel
Save