newsworthycharts 1.57.1__tar.gz → 1.57.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. newsworthycharts-1.57.3/PKG-INFO +13 -0
  2. newsworthycharts-1.57.1/newsworthycharts.egg-info/PKG-INFO → newsworthycharts-1.57.3/README.rst +15 -13
  3. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/__init__.py +1 -1
  4. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/categoricalchart.py +3 -2
  5. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/chart.py +6 -6
  6. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/choroplethmap.py +0 -1
  7. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/map.py +7 -2
  8. newsworthycharts-1.57.3/newsworthycharts.egg-info/PKG-INFO +13 -0
  9. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/setup.py +1 -2
  10. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_choropleth_maps.py +22 -1
  11. newsworthycharts-1.57.1/PKG-INFO +0 -962
  12. newsworthycharts-1.57.1/README.rst +0 -949
  13. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/LICENSE.txt +0 -0
  14. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/MANIFEST.in +0 -0
  15. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/bubblemap.py +0 -0
  16. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/custom/__init__.py +0 -0
  17. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/custom/climate_cars.py +0 -0
  18. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/datawrapper.py +0 -0
  19. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/__init__.py +0 -0
  20. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/color_fn.py +0 -0
  21. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/colors.py +0 -0
  22. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/datalist.py +0 -0
  23. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/formatter.py +0 -0
  24. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/geography.py +0 -0
  25. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/locator.py +0 -0
  26. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/mimetypes.py +0 -0
  27. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/lib/utils.py +0 -0
  28. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/maps/se-4.gpkg +0 -0
  29. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/maps/se-7.gpkg +0 -0
  30. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/rangeplot.py +0 -0
  31. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/rc/newsworthy +0 -0
  32. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/scatterplot.py +0 -0
  33. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/seasonalchart.py +0 -0
  34. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/serialchart.py +0 -0
  35. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/storage.py +0 -0
  36. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/stripechart.py +0 -0
  37. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/translations/datawrapper_regions.csv +0 -0
  38. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/translations/regions.py +0 -0
  39. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts/translations/se_municipalities.csv +0 -0
  40. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts.egg-info/SOURCES.txt +0 -0
  41. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts.egg-info/dependency_links.txt +0 -0
  42. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts.egg-info/not-zip-safe +0 -0
  43. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts.egg-info/requires.txt +0 -0
  44. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/newsworthycharts.egg-info/top_level.txt +0 -0
  45. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/setup.cfg +0 -0
  46. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_categorical_chart.py +0 -0
  47. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_custom_climate_cars.py +0 -0
  48. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_data_list.py +0 -0
  49. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_datawrapper.py +0 -0
  50. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_main.py +0 -0
  51. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_rangeplot.py +0 -0
  52. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_scatterplot.py +0 -0
  53. {newsworthycharts-1.57.1 → newsworthycharts-1.57.3}/test/test_serial_chart.py +0 -0
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.1
2
+ Name: newsworthycharts
3
+ Version: 1.57.3
4
+ Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
+ Home-page: https://github.com/jplusplus/newsworthycharts
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.57.3.tar.gz
7
+ Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
+ Author-email: stockholm@jplusplus.org
9
+ License: MIT
10
+ Requires-Python: >=3.9
11
+ License-File: LICENSE.txt
12
+
13
+ Matplotlib wrapper to create charts and publish them on Amazon S3
@@ -1,16 +1,3 @@
1
- Metadata-Version: 2.1
2
- Name: newsworthycharts
3
- Version: 1.57.1
4
- Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
- Home-page: https://github.com/jplusplus/newsworthycharts
6
- Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.57.1.tar.gz
7
- Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
- Author-email: stockholm@jplusplus.org
9
- License: MIT
10
- Requires-Python: >=3.9
11
- Description-Content-Type: text/x-rst
12
- License-File: LICENSE.txt
13
-
14
1
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
15
2
 
16
3
  It is written and maintained for `Newsworthy <https://www.newsworthy.se/en/>`_, but could possibly come in handy for other people as well.
@@ -180,8 +167,13 @@ These settings are available for all chart types:
180
167
  - base_map = None
181
168
  - missing_label = None # Add a label for no data
182
169
 
170
+ `basemap` can be `{ISO}-{level}` or `{ISO}|{subset}-{level}`.
171
+ For example, `se-4` will show Swedish counties, while `se|03-7` will show municipalities (`se-7`) starting with `03`.
172
+
183
173
  **ChoroplethMap**
184
174
 
175
+ _Inherits from Map_
176
+
185
177
  **ProgressChart**
186
178
 
187
179
  **RangePlot**
@@ -224,6 +216,16 @@ Roadmap
224
216
  Changelog
225
217
  ---------
226
218
 
219
+ - 1.57.3
220
+
221
+ - Make NW region keys work with map subsets (e.g. `SE|03-7`)
222
+ - Don't crash on subsequent calls to basemap parser
223
+
224
+ - 1.57.2
225
+
226
+ - reduce excessive padding in categorical vertical charts
227
+ - improved padding and margin logic for titles/subtitles (taking line spacing into account)
228
+
227
229
  - 1.57.1
228
230
 
229
231
  - Fix missing outline in choropleth maps
@@ -1,4 +1,4 @@
1
- __version__ = "1.57.1"
1
+ __version__ = "1.57.3"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -16,7 +16,7 @@ class CategoricalChart(Chart):
16
16
  self.stacked = False
17
17
  self.legend = True
18
18
 
19
- # Optional: specify a list of colors (for mulitple datasets)
19
+ # Optional: specify a list of colors (for multiple datasets)
20
20
  self.colors = None
21
21
 
22
22
  def _add_data(self):
@@ -144,8 +144,8 @@ class CategoricalChart(Chart):
144
144
  kwargs["bottom"] = cum_values[i - 1]
145
145
  self.ax.bar(bar_pos, values, **kwargs)
146
146
 
147
- margin = 0.02 # above and below first/last bar on horizontal
148
147
  if self.bar_orientation == "horizontal":
148
+ margin = 0.02 # above and below first/last bar on horizontal
149
149
  self.ax.set_yticks(bar_pos)
150
150
  self.ax.set_yticklabels(categories)
151
151
  self.ax.invert_yaxis()
@@ -158,6 +158,7 @@ class CategoricalChart(Chart):
158
158
  self._fig.subplots_adjust(left=margin)
159
159
 
160
160
  elif self.bar_orientation == "vertical":
161
+ margin = 0.01 # above and below first/last bar on horizontal
161
162
  self.ax.margins(margin, 0)
162
163
  self.ax.set_xticks(bar_pos)
163
164
  self.ax.set_xticklabels(categories)
@@ -168,7 +168,7 @@ class Chart(object):
168
168
  ismath=False,
169
169
  )
170
170
  num_lines = len(obj._get_wrapped_text().split("\n"))
171
- return (h * num_lines) / float(self._h)
171
+ return (h * (num_lines * 1.4)) / float(self._h) # 1.4 is the line spacing used everywhere
172
172
 
173
173
  def _rel_height(self, obj):
174
174
  """ Get the relative height of a chart object to the whole canvas.
@@ -273,7 +273,7 @@ class Chart(object):
273
273
  def _add_title(self, title_text):
274
274
  """Add a title."""
275
275
  # y=1 wraps title heavily, hence .9999
276
- text = self._fig.suptitle(title_text, wrap=True, x=0, y=0.985,
276
+ text = self._fig.suptitle(title_text, wrap=True, x=0, y=0.999,
277
277
  horizontalalignment="left",
278
278
  multialignment="left",
279
279
  fontproperties=self._title_font)
@@ -755,7 +755,7 @@ class Chart(object):
755
755
  rel_height = 0
756
756
  if self._title_elem:
757
757
  rel_height += self._text_rel_height(self._title_elem)
758
- # Adds a fixes margin below
758
+ # Adds a fixed margin below
759
759
  rel_height += 30 / self._h
760
760
  return rel_height
761
761
 
@@ -764,8 +764,8 @@ class Chart(object):
764
764
  rel_height = 0
765
765
  if self._subtitle_elem:
766
766
  rel_height += self._text_rel_height(self._subtitle_elem)
767
- # Adds a fixes margin below
768
- rel_height += 30 / self._h
767
+ # Adds a fixed margin below
768
+ rel_height += 15 / self._h
769
769
  return rel_height
770
770
 
771
771
  @property
@@ -773,7 +773,7 @@ class Chart(object):
773
773
  rel_height = 0
774
774
  if self._note_elem:
775
775
  rel_height += self._text_rel_height(self._note_elem)
776
- # Adds a fixes margin below
776
+ # Adds a fixed margin below
777
777
  rel_height += 10 / self._h
778
778
  return rel_height
779
779
 
@@ -2,7 +2,6 @@
2
2
  Simple choropleths for common administrative areas
3
3
  """
4
4
  from .map import Map
5
- from shapely.geometry.multipolygon import MultiPolygon
6
5
  import geopandas as gpd
7
6
  import numpy as np
8
7
  import pandas as pd
@@ -99,7 +99,12 @@ class Map(Chart):
99
99
  def _normalize_region_code(self, code):
100
100
  code = code.upper().replace("_", "-")
101
101
  # Apply translation, if we find and applicable one
102
- region_translation = REGION_TRANSLATIONS.get(self.base_map, {})
102
+
103
+ # normalize basemap name, so that `se|03-7` is treated as `se-7
104
+ # region_translation = REGION_TRANSLATIONS.get(self.base_map, {})
105
+ _base_map, _subdivisions, _subset, *opts = self.parse_basemap()
106
+ region_translation = REGION_TRANSLATIONS.get(f"{_base_map}-{_subdivisions}", {})
107
+
103
108
  region_translation = {k.upper(): v for k, v in region_translation.items()}
104
109
  code = region_translation.get(code, code)
105
110
  return code
@@ -132,7 +137,7 @@ class Map(Chart):
132
137
  if len(_) > 1:
133
138
  [base_map, subset] = _
134
139
 
135
- if not self.df:
140
+ if self.df is None:
136
141
  __dir = pathlib.Path(__file__).parent.resolve()
137
142
  try:
138
143
  self.df = gpd.read_file(f"{__dir}/maps/{base_map}-{subdivisions}.gpkg")
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.1
2
+ Name: newsworthycharts
3
+ Version: 1.57.3
4
+ Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
+ Home-page: https://github.com/jplusplus/newsworthycharts
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.57.3.tar.gz
7
+ Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
+ Author-email: stockholm@jplusplus.org
9
+ License: MIT
10
+ Requires-Python: >=3.9
11
+ License-File: LICENSE.txt
12
+
13
+ Matplotlib wrapper to create charts and publish them on Amazon S3
@@ -14,8 +14,7 @@ setup(
14
14
  name="newsworthycharts",
15
15
  version=version,
16
16
  description="Matplotlib wrapper to create charts and publish them on Amazon S3",
17
- long_description=readme(),
18
- long_description_content_type='text/x-rst',
17
+ long_description="Matplotlib wrapper to create charts and publish them on Amazon S3",
19
18
  url=repo,
20
19
  author="Jens Finnäs and Leo Wallentin, J++ Stockholm",
21
20
  author_email="stockholm@jplusplus.org",
@@ -24,6 +24,7 @@ def test_rendering():
24
24
  c = ChoroplethMap.init_from(chart_obj, storage=ds)
25
25
  c.render("test", "png")
26
26
 
27
+
27
28
  def test_map_with_nw_regions():
28
29
  container = {}
29
30
  ds = DictStorage(container)
@@ -40,9 +41,29 @@ def test_map_with_nw_regions():
40
41
  ]
41
42
  ],
42
43
  }
43
- c = ChoroplethMap.init_from(chart_obj, storage=local_storage)
44
+ c = ChoroplethMap.init_from(chart_obj, storage=ds)
45
+ c.render("map_with_nw_ids", "png")
46
+
47
+
48
+ def test_map_with_nw_regions_and_subsets():
49
+ container = {}
50
+ ds = DictStorage(container)
51
+
52
+ chart_obj = {
53
+ "width": 800,
54
+ "height": 600,
55
+ "base_map": "se|03-7",
56
+ "data": [
57
+ [
58
+ ("Uppsala kommun", 3),
59
+ ("Enköpings kommun", 2),
60
+ ]
61
+ ],
62
+ }
63
+ c = ChoroplethMap.init_from(chart_obj, storage=ds)
44
64
  c.render("map_with_nw_ids", "png")
45
65
 
66
+
46
67
  def test_invalid_region():
47
68
  container = {}
48
69
  ds = DictStorage(container)