Browse Source

Fixes supranational code leaving ghost generic

pull/63/head
Jean-Marc Martins 12 years ago
parent
commit
f781b56a7a
  1. 19
      pygal/ghost.py
  2. 1
      pygal/graph/__init__.py
  3. 11
      pygal/i18n.py
  4. 6
      pygal/test/test_config.py
  5. 4
      pygal/test/test_graph.py
  6. 10
      pygal/util.py

19
pygal/ghost.py

@ -29,7 +29,6 @@ import sys
from pygal.config import Config from pygal.config import Config
from pygal._compat import u, is_list_like from pygal._compat import u, is_list_like
from pygal.graph import CHARTS_NAMES from pygal.graph import CHARTS_NAMES
from pygal.i18n import SUPRANATIONAL
from pygal.util import prepare_values from pygal.util import prepare_values
from uuid import uuid4 from uuid import uuid4
@ -66,29 +65,11 @@ class Ghost(object):
"""Add a serie to this graph""" """Add a serie to this graph"""
if not is_list_like(values) and not isinstance(values, dict): if not is_list_like(values) and not isinstance(values, dict):
values = [values] values = [values]
values = self.replace_supranationals(values)
if secondary: if secondary:
self.raw_series2.append((title, values)) self.raw_series2.append((title, values))
else: else:
self.raw_series.append((title, values)) self.raw_series.append((title, values))
def replace_supranationals(self, values):
"""Replaces the values if it contains a supranational code."""
from pygal import Worldmap
if not isinstance(self, Worldmap):
return values
for suprakey in SUPRANATIONAL.keys():
if suprakey in values:
if not isinstance(values, dict):
del values[values.index(suprakey)]
values.extend(SUPRANATIONAL[suprakey])
else:
values.update(
dict([(code, values[suprakey])
for code in SUPRANATIONAL[suprakey]]))
del values[suprakey]
return values
def make_series(self, series): def make_series(self, series):
return prepare_values(series, self.config, self.cls) return prepare_values(series, self.config, self.cls)

1
pygal/graph/__init__.py

@ -38,5 +38,6 @@ CHARTS_NAMES = [
'Gauge', 'Gauge',
'DateY', 'DateY',
'Worldmap', 'Worldmap',
'SupranationalWorldmap',
'Histogram' 'Histogram'
] ]

11
pygal/i18n.py

@ -185,9 +185,12 @@ COUNTRIES = {
'zw': 'Zimbabwe' 'zw': 'Zimbabwe'
} }
EUROPE = ['bg', 'cs', 'da', 'de', 'et', 'el', 'en', 'es', 'fr', 'ga', 'hr', EUROPE = ['at', 'be', 'bg', 'hr', 'cy', 'cz', 'dk', 'ee', 'fi', 'fr', 'de',
'it', 'lt', 'lv', 'hu', 'mt', 'nl', 'pl', 'pt', 'ro', 'sk', 'sl', 'gr', 'hu', 'ie', 'it', 'lv', 'lt', 'lu', 'mt', 'nl', 'pl', 'pt',
'fi', 'sv'] 'ro', 'sk', 'si', 'es', 'se', 'gb']
EUR = ['be', 'de', 'ie', 'gr', 'es', 'fr', 'it', 'cy', 'lu', 'mt', 'nl', 'at',
'pt', 'si', 'sk', 'fi', 'ee']
OECD = ['au', 'at', 'be', 'ca', 'cl', 'cz', 'dk', 'ee', 'fi', 'fr', 'de', 'gr', OECD = ['au', 'at', 'be', 'ca', 'cl', 'cz', 'dk', 'ee', 'fi', 'fr', 'de', 'gr',
'hu', 'is', 'ie', 'il', 'it', 'jp', 'kr', 'lu', 'mx', 'nl', 'nz', 'no', 'hu', 'is', 'ie', 'il', 'it', 'jp', 'kr', 'lu', 'mx', 'nl', 'nz', 'no',
@ -196,7 +199,7 @@ OECD = ['au', 'at', 'be', 'ca', 'cl', 'cz', 'dk', 'ee', 'fi', 'fr', 'de', 'gr',
NAFTA = ['ca', 'mx', 'us'] NAFTA = ['ca', 'mx', 'us']
SUPRANATIONAL = {'europe': EUROPE, 'oecd': OECD, 'nafta': NAFTA} SUPRANATIONAL = {'europe': EUROPE, 'oecd': OECD, 'nafta': NAFTA, 'eur': EUR}
def set_countries(countries): def set_countries(countries):

6
pygal/test/test_config.py

@ -17,7 +17,8 @@
# You should have received a copy of the GNU Lesser General Public License # You should have received a copy of the GNU Lesser General Public License
# along with pygal. If not, see <http://www.gnu.org/licenses/>. # along with pygal. If not, see <http://www.gnu.org/licenses/>.
from pygal import ( from pygal import (
Line, Dot, Pie, Radar, Config, Bar, Funnel, Worldmap, Histogram, Gauge) Line, Dot, Pie, Radar, Config, Bar, Funnel, Worldmap,
SupranationalWorldmap, Histogram, Gauge)
from pygal._compat import u from pygal._compat import u
from pygal.test.utils import texts from pygal.test.utils import texts
from pygal.test import pytest_generate_tests, make_data from pygal.test import pytest_generate_tests, make_data
@ -259,7 +260,8 @@ def test_no_data():
def test_include_x_axis(Chart): def test_include_x_axis(Chart):
chart = Chart() chart = Chart()
if Chart in (Pie, Radar, Funnel, Dot, Gauge, Worldmap, Histogram): if Chart in (Pie, Radar, Funnel, Dot, Gauge, Worldmap,
SupranationalWorldmap, Histogram):
return return
if not chart.cls._dual: if not chart.cls._dual:
data = 100, 200, 150 data = 100, 200, 150

4
pygal/test/test_graph.py

@ -70,7 +70,7 @@ def test_metadata(Chart):
v = range(7) v = range(7)
if Chart == pygal.XY: if Chart == pygal.XY:
v = list(map(lambda x: (x, x + 1), v)) v = list(map(lambda x: (x, x + 1), v))
elif Chart == pygal.Worldmap: elif Chart == pygal.Worldmap or Chart == pygal.SupranationalWorldmap:
v = list(map(lambda x: x, i18n.COUNTRIES)) v = list(map(lambda x: x, i18n.COUNTRIES))
chart.add('Serie with metadata', [ chart.add('Serie with metadata', [
@ -94,7 +94,7 @@ def test_metadata(Chart):
if Chart == pygal.Pie: if Chart == pygal.Pie:
# Slices with value 0 are not rendered # Slices with value 0 are not rendered
assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value')) assert len(v) - 1 == len(q('.tooltip-trigger').siblings('.value'))
elif Chart != pygal.Worldmap: elif Chart != pygal.Worldmap and Chart != pygal.SupranationalWorldmap:
# Tooltip are not working on worldmap # Tooltip are not working on worldmap
assert len(v) == len(q('.tooltip-trigger').siblings('.value')) assert len(v) == len(q('.tooltip-trigger').siblings('.value'))

10
pygal/util.py

@ -300,9 +300,10 @@ def prepare_values(raw, config, cls):
from pygal.graph.datey import DateY from pygal.graph.datey 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.supranationalworldmap import SupranationalWorldmap
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 = cls.x_labels config.x_labels = cls.x_labels
if config.zero == 0 and issubclass(cls, Worldmap): if config.zero == 0 and issubclass(cls, (Worldmap, SupranationalWorldmap)):
config.zero = 1 config.zero = 1
for key in ('x_labels', 'y_labels'): for key in ('x_labels', 'y_labels'):
@ -332,7 +333,7 @@ def prepare_values(raw, config, cls):
metadata = {} metadata = {}
values = [] values = []
if isinstance(raw_values, dict): if isinstance(raw_values, dict):
if issubclass(cls, Worldmap): if issubclass(cls, (Worldmap, SupranationalWorldmap)):
raw_values = list(raw_values.items()) raw_values = list(raw_values.items())
else: else:
value_list = [None] * width value_list = [None] * width
@ -364,8 +365,9 @@ def prepare_values(raw, config, cls):
value = (None, None) value = (None, None)
elif not is_list_like(value): elif not is_list_like(value):
value = (value, config.zero) value = (value, config.zero)
if issubclass(cls, DateY) or issubclass(cls, Worldmap): if issubclass(cls, DateY) or issubclass(
value = (adapter(value[0]), value[1]) cls, (Worldmap, SupranationalWorldmap)):
value = (adapter(value[0]), value[1])
else: else:
value = list(map(adapter, value)) value = list(map(adapter, value))
else: else:

Loading…
Cancel
Save