Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hungarian county map #222

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

e3krisztian
Copy link

This is a county map (~NUTS-3) implementation for Hungary.
It would be fantastic if you could integrate it into pygal.

The svg map is from wikimedia (exact location is in the commit message), its license says "public domain", it is there since 2007, I have hand-adjusted it to work with pygal.
The support code is copy-paste-edit derived from frenchmap.py.

I can do some adjustments still if needed.


The following are things I wanted/planned to do, but could not (mostly time constraint).

Using NUTS based area addressing (http://en.wikipedia.org/wiki/NUTS_of_Hungary) instead of county names.

Write tests. It is a bigger effort: I felt copying test_frenchmap.py would not add real value.

The pygal map implementation has some strict assumptions about the .svg used for displaying the map, so when expectations are changed, the country map might no longer work until updated. My feeling is that svg files should be checked against the assumptions in a test.

Current assumptions such a test could check for (I have run into these specific problems):

  • elements with class map-elements being iterable (e.g. <g> elements, not <path>-s)
  • class property being formatted as expected ("{area_prefix}{area_code} {kind} map-element").

Demo code/documentation: have not found the place to put. Please find below the code I wanted to add (edit it as you please).


# coding: utf-8
from __future__ import unicode_literals

# the above 2 lines are needed for accents in county names!

from pygal import HungarianCountyMap
from pygal.style import Style

# it looks like this is the way to set the color when creating a heatmap
# all colors under a single entry are differring only in fill-opacity
style = Style(colors=('#208060', '#ff8040'))

hu_map = HungarianCountyMap(style=style, show_legend=False)
hu_map.title = 'Values from dictionary'
hu_map.add('Speciál', dict(tolna=9.3))
hu_map.add(
    'Árnyalat',
    dict(
        (name, n)
        for (n, name) in enumerate(hu_map.area_names)))

# render_in_browser renders the svg in a file ending in .html
# which is displayed inproperly for me: accented text shows as raw utf-8 bytes
hu_map.render_in_browser()
# coding: utf-8
from __future__ import unicode_literals

# the above 2 lines are needed for accents in county names!

from pygal import HungarianCountyMap
from pygal.style import CleanStyle

hu_map = HungarianCountyMap(style=CleanStyle, width=400, height=200)
hu_map.title = '3 regions (NUTS-2)'
# see http://en.wikipedia.org/wiki/NUTS_of_Hungary
hu_map.add('Közép-Magyarország', ['pest', 'budapest'])
hu_map.add('Dél-Dunántúl', ['baranya', 'somogy', 'tolna'])
hu_map.add('Nyugat-Dunántúl', ['zala', 'vas', 'gyms'])

# render_in_browser renders the svg in a file ending in .html
# which is displayed inproperly for me: accented text shows as raw utf-8 bytes
hu_map.render_to_file('hungary-test-output.svg')
# open the generated file manually in a web-browser to see output

- svg edited:
 - added <g> around <path>-s
 - moved class attribute from <path> to <g>
 - formatted class attribute so that BaseMap could find & color parts
 - added viewBox
- copied frenchmap.py to hungarianmap.py and edited
- exported the new class from pygal/__init__.py
@paradoxxxzero
Copy link
Member

Hi thank you very much for your pull request.

I am moving maps into external packages (#225).
Would you be interested in maintaining your map as a package ? See https://github.com/Kozea/pygal_maps_fr for the structure.

@HughP
Copy link

HughP commented Oct 4, 2017

@paradoxxxzero Is it possible to make the pygal package a daughter of github a group? and then to have the map modules also listed there? I understand the architecture choice to move maps to their own packages, and to be independently maintained. It seems a bit dis-organized to have maps in several (200+) repositories... It seems that little thought has been given to: When we (pygal users) want 1) to see what maps do work with with pygal (informational, i.e there is no map for Nepal) and 2) what map modules there are for use with pygal (I am assuming that these are separate download modules), where are we supposed to go?

I suggest that it would be great to have all these resources in one place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants