Florian Mounier 10 years ago
parent
commit
90a91b76b5
  1. 26
      demo/moulinrouge/tests.py
  2. 179
      pygal/graph/ch.cantons.svg
  3. 16
      pygal/graph/swissmap.py
  4. 8
      pygal/test/test_config.py
  5. 12
      pygal/test/test_graph.py
  6. 10
      pygal/util.py

26
demo/moulinrouge/tests.py

@ -3,10 +3,12 @@
from pygal import ( from pygal import (
Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, StackedLine, XY, Bar, Gauge, Pyramid, Funnel, Dot, StackedBar, StackedLine, XY,
CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box, CHARTS_BY_NAME, Config, Line, DateY, Worldmap, Histogram, Box,
FrenchMap_Departments, FrenchMap_Regions, Pie, Treemap, TimeLine, DateLine) FrenchMap_Departments, FrenchMap_Regions, Pie, Treemap, TimeLine, DateLine,
SwissMap_Cantons)
from pygal.style import styles, Style, RotateStyle from pygal.style import styles, Style, RotateStyle
from pygal.colors import rotate from pygal.colors import rotate
from pygal.graph.frenchmap import DEPARTMENTS, REGIONS from pygal.graph.frenchmap import DEPARTMENTS, REGIONS
from pygal.graph.swissmap import CANTONS
from random import randint, choice from random import randint, choice
from datetime import datetime from datetime import datetime
@ -475,6 +477,26 @@ def get_test_routes(app):
fmap.title = 'French map' fmap.title = 'French map'
return fmap.render_response() return fmap.render_response()
@app.route('/test/swissmap')
def test_swissmap():
smap = SwissMap_Cantons(style=choice(list(styles.values())))
for i in range(10):
smap.add('s%d' % i, [
(choice(list(CANTONS.keys())), randint(0, 100))
for _ in range(randint(1, 5))])
smap.add('links', [{
'value': ('kt-vs', 10),
'label': '\o/',
'xlink': 'http://google.com?q=69'
}, {
'value': ('bt', 20),
'label': 'Y',
}])
smap.add('6th', [3, 5, 34, 12])
smap.title = 'Swiss map'
return smap.render_response()
@app.route('/test/frenchmapregions') @app.route('/test/frenchmapregions')
def test_frenchmapregions(): def test_frenchmapregions():
fmap = FrenchMap_Regions(style=choice(list(styles.values()))) fmap = FrenchMap_Regions(style=choice(list(styles.values())))
@ -624,7 +646,7 @@ def get_test_routes(app):
return graph.render_response() return graph.render_response()
@app.route('/test/inverse_y_axis/<chart>') @app.route('/test/inverse_y_axis/<chart>')
def test_inverse_y_axis(chart): def test_inverse_y_axis_for(chart):
graph = CHARTS_BY_NAME[chart](**dict(inverse_y_axis=True)) graph = CHARTS_BY_NAME[chart](**dict(inverse_y_axis=True))
graph.add('inverse', [1, 2, 3, 12, 24, 36]) graph.add('inverse', [1, 2, 3, 12, 24, 36])
return graph.render_response() return graph.render_response()

179
pygal/graph/ch.cantons.svg

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 152 KiB

After

Width:  |  Height:  |  Size: 151 KiB

16
pygal/graph/swissmap.py

@ -22,7 +22,6 @@ Worldmap chart
""" """
from __future__ import division from __future__ import division
from collections import defaultdict
from pygal.ghost import ChartCollection from pygal.ghost import ChartCollection
from pygal.util import cut, cached_property, decorate from pygal.util import cut, cached_property, decorate
from pygal.graph.graph import Graph from pygal.graph.graph import Graph
@ -36,6 +35,7 @@ CANTONS = {
'kt-zh': u("ZĂĽrich"), 'kt-zh': u("ZĂĽrich"),
'kt-be': u("Bern"), 'kt-be': u("Bern"),
'kt-lu': u("Luzern"), 'kt-lu': u("Luzern"),
'kt-ju': u("Jura"),
'kt-ur': u("Uri"), 'kt-ur': u("Uri"),
'kt-sz': u("Schwyz"), 'kt-sz': u("Schwyz"),
'kt-ow': u("Obwalden"), 'kt-ow': u("Obwalden"),
@ -44,7 +44,7 @@ CANTONS = {
'kt-zg': u("Zug"), 'kt-zg': u("Zug"),
'kt-fr': u("Freiburg"), 'kt-fr': u("Freiburg"),
'kt-so': u("Solothurn"), 'kt-so': u("Solothurn"),
'kt-bl': u("Basel-Stadt "), 'kt-bl': u("Basel-Stadt"),
'kt-bs': u("Basle-Land"), 'kt-bs': u("Basle-Land"),
'kt-sh': u("Schaffhausen"), 'kt-sh': u("Schaffhausen"),
'kt-ar': u("Appenzell Ausseroden"), 'kt-ar': u("Appenzell Ausseroden"),
@ -56,14 +56,11 @@ CANTONS = {
'kt-ti': u("Tessin"), 'kt-ti': u("Tessin"),
'kt-vd': u("Waadt"), 'kt-vd': u("Waadt"),
'kt-vs': u("Wallis"), 'kt-vs': u("Wallis"),
'ke-ne': u("Neuenburg"), 'kt-ne': u("Neuenburg"),
'ke-ge': u("Genf"), 'kt-ge': u("Genf"),
} }
with open(os.path.join( with open(os.path.join(
os.path.dirname(__file__), os.path.dirname(__file__),
'ch.cantons.svg')) as file: 'ch.cantons.svg')) as file:
@ -165,9 +162,6 @@ class SwissMapCantons(SwissMapCantons):
svg_map = CNT_MAP svg_map = CNT_MAP
kind = 'canton' kind = 'canton'
class SwissMap(ChartCollection): class SwissMap(ChartCollection):
Cantons = SwissMapCantons Cantons = SwissMapCantons

8
pygal/test/test_config.py

@ -21,7 +21,7 @@ from pygal import (
Line, Dot, Pie, Treemap, Radar, Config, Bar, Funnel, Worldmap, Line, Dot, Pie, Treemap, Radar, Config, Bar, Funnel, Worldmap,
SupranationalWorldmap, Histogram, Gauge, Box, XY, SupranationalWorldmap, Histogram, Gauge, Box, XY,
Pyramid, DateY, HorizontalBar, HorizontalStackedBar, Pyramid, DateY, HorizontalBar, HorizontalStackedBar,
FrenchMap_Regions, FrenchMap_Departments, FrenchMap_Regions, FrenchMap_Departments, SwissMap_Cantons,
DateTimeLine, TimeLine, DateLine, TimeDeltaLine) DateTimeLine, TimeLine, DateLine, TimeDeltaLine)
from pygal._compat import u from pygal._compat import u
from pygal.test.utils import texts from pygal.test.utils import texts
@ -275,7 +275,7 @@ def test_include_x_axis(Chart):
chart = Chart() chart = Chart()
if Chart in (Pie, Treemap, Radar, Funnel, Dot, Gauge, Worldmap, if Chart in (Pie, Treemap, Radar, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram, Box, SupranationalWorldmap, Histogram, Box,
FrenchMap_Regions, FrenchMap_Departments): FrenchMap_Regions, FrenchMap_Departments, SwissMap_Cantons):
return return
if not chart.cls._dual: if not chart.cls._dual:
data = 100, 200, 150 data = 100, 200, 150
@ -362,7 +362,7 @@ def test_x_label_major(Chart):
if Chart in ( if Chart in (
Pie, Treemap, Funnel, Dot, Gauge, Worldmap, Pie, Treemap, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram, Box, SupranationalWorldmap, Histogram, Box,
FrenchMap_Regions, FrenchMap_Departments, FrenchMap_Regions, FrenchMap_Departments, SwissMap_Cantons,
Pyramid, DateY, DateTimeLine, TimeLine, DateLine, Pyramid, DateY, DateTimeLine, TimeLine, DateLine,
TimeDeltaLine): TimeDeltaLine):
return return
@ -407,7 +407,7 @@ def test_y_label_major(Chart):
if Chart in ( if Chart in (
Pie, Treemap, Funnel, Dot, Gauge, Worldmap, Pie, Treemap, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram, Box, SupranationalWorldmap, Histogram, Box,
FrenchMap_Regions, FrenchMap_Departments, FrenchMap_Regions, FrenchMap_Departments, SwissMap_Cantons,
HorizontalBar, HorizontalStackedBar, HorizontalBar, HorizontalStackedBar,
Pyramid, DateTimeLine, TimeLine, DateLine, Pyramid, DateTimeLine, TimeLine, DateLine,
TimeDeltaLine, DateY): TimeDeltaLine, DateY):

12
pygal/test/test_graph.py

@ -24,6 +24,7 @@ import sys
import pytest import pytest
from pygal import i18n from pygal import i18n
from pygal.graph.frenchmap import DEPARTMENTS, REGIONS from pygal.graph.frenchmap import DEPARTMENTS, REGIONS
from pygal.graph.swissmap import CANTONS
from pygal.util import cut from pygal.util import cut
from pygal._compat import u from pygal._compat import u
from pygal.test import make_data from pygal.test import make_data
@ -86,6 +87,8 @@ def test_metadata(Chart):
v = [(i, k) for k, i in enumerate(REGIONS.keys())] v = [(i, k) for k, i in enumerate(REGIONS.keys())]
elif Chart == pygal.FrenchMap_Departments: elif Chart == pygal.FrenchMap_Departments:
v = [(i, k) for k, i in enumerate(DEPARTMENTS.keys())] v = [(i, k) for k, i in enumerate(DEPARTMENTS.keys())]
elif Chart == pygal.SwissMap_Cantons:
v = [(i, k) for k, i in enumerate(CANTONS.keys())]
chart.add('Serie with metadata', [ chart.add('Serie with metadata', [
v[0], v[0],
@ -110,7 +113,8 @@ def test_metadata(Chart):
assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value')) assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
elif Chart not in ( elif Chart not in (
pygal.Worldmap, pygal.SupranationalWorldmap, pygal.Worldmap, pygal.SupranationalWorldmap,
pygal.FrenchMap_Regions, pygal.FrenchMap_Departments): pygal.FrenchMap_Regions, pygal.FrenchMap_Departments,
pygal.SwissMap_Cantons):
# Tooltip are not working on maps # Tooltip are not working on maps
assert len(v) == len(q('.tooltip-trigger').siblings('.value')) assert len(v) == len(q('.tooltip-trigger').siblings('.value'))
@ -193,7 +197,8 @@ def test_values_by_dict(Chart):
if not issubclass(Chart, ( if not issubclass(Chart, (
pygal.Worldmap, pygal.Worldmap,
pygal.FrenchMap_Departments, pygal.FrenchMap_Departments,
pygal.FrenchMap_Regions)): pygal.FrenchMap_Regions,
pygal.SwissMap_Cantons)):
chart1.add('A', {'red': 10, 'green': 12, 'blue': 14}) chart1.add('A', {'red': 10, 'green': 12, 'blue': 14})
chart1.add('B', {'green': 11, 'red': 7}) chart1.add('B', {'green': 11, 'red': 7})
chart1.add('C', {'blue': 7}) chart1.add('C', {'blue': 7})
@ -378,7 +383,8 @@ def test_labels_with_links(Chart):
if issubclass(chart.cls, if issubclass(chart.cls,
(pygal.graph.worldmap.Worldmap, (pygal.graph.worldmap.Worldmap,
pygal.graph.frenchmap.FrenchMapDepartments)): pygal.graph.frenchmap.FrenchMapDepartments,
pygal.graph.swissmap.SwissMapCantons)):
# No country is found in this case so: # No country is found in this case so:
assert len(links) == 4 # 3 links and 1 tooltip assert len(links) == 4 # 3 links and 1 tooltip
else: else:

10
pygal/util.py

@ -335,14 +335,14 @@ def prepare_values(raw, config, cls, offset=0):
"""Prepare the values to start with sane values""" """Prepare the values to start with sane values"""
from pygal.serie import Serie from pygal.serie import Serie
from pygal.config import SerieConfig from pygal.config import SerieConfig
from pygal.graph.time import DateY
from pygal.graph.histogram import Histogram from pygal.graph.histogram import Histogram
from pygal.graph.worldmap import Worldmap from pygal.graph.worldmap import Worldmap
from pygal.graph.frenchmap import FrenchMapDepartments from pygal.graph.frenchmap import FrenchMapDepartments
from pygal.graph.swissmap import SwissMapCantons from pygal.graph.swissmap import SwissMapCantons
if config.x_labels is None and hasattr(cls, 'x_labels'): if config.x_labels is None and hasattr(cls, 'x_labels'):
config.x_labels = list(map(to_unicode, cls.x_labels)) config.x_labels = list(map(to_unicode, cls.x_labels))
if config.zero == 0 and issubclass(cls, (Worldmap, FrenchMapDepartments,SwissMapCantons)): if config.zero == 0 and issubclass(cls, (
Worldmap, FrenchMapDepartments, SwissMapCantons)):
config.zero = 1 config.zero = 1
for key in ('x_labels', 'y_labels'): for key in ('x_labels', 'y_labels'):
@ -377,7 +377,8 @@ def prepare_values(raw, config, cls, offset=0):
metadata = {} metadata = {}
values = [] values = []
if isinstance(raw_values, dict): if isinstance(raw_values, dict):
if issubclass(cls, (Worldmap, FrenchMapDepartments,SwissMapCantons)): if issubclass(cls, (
Worldmap, FrenchMapDepartments, SwissMapCantons)):
raw_values = list(raw_values.items()) raw_values = list(raw_values.items())
else: else:
value_list = [None] * width value_list = [None] * width
@ -412,7 +413,8 @@ def prepare_values(raw, config, cls, offset=0):
if x_adapter: if x_adapter:
value = (x_adapter(value[0]), adapter(value[1])) value = (x_adapter(value[0]), adapter(value[1]))
if issubclass( if issubclass(
cls, (Worldmap, FrenchMapDepartments,SwissMapCantons)): cls, (
Worldmap, FrenchMapDepartments, SwissMapCantons)):
value = (adapter(value[0]), value[1]) value = (adapter(value[0]), value[1])
else: else:
value = list(map(adapter, value)) value = list(map(adapter, value))

Loading…
Cancel
Save