newsworthycharts 1.64.1__tar.gz → 1.65.1__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 (52) hide show
  1. {newsworthycharts-1.64.1/newsworthycharts.egg-info → newsworthycharts-1.65.1}/PKG-INFO +10 -16
  2. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/README.rst +8 -0
  3. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/__init__.py +1 -1
  4. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/categoricalchart.py +6 -2
  5. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/chart.py +23 -0
  6. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/datalist.py +12 -0
  7. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/serialchart.py +7 -4
  8. newsworthycharts-1.65.1/newsworthycharts/translations/.~lock.datawrapper_regions.csv# +1 -0
  9. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1/newsworthycharts.egg-info}/PKG-INFO +10 -16
  10. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts.egg-info/SOURCES.txt +1 -0
  11. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts.egg-info/dependency_links.txt +0 -0
  12. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts.egg-info/not-zip-safe +0 -0
  13. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts.egg-info/requires.txt +0 -0
  14. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts.egg-info/top_level.txt +0 -0
  15. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_categorical_chart.py +20 -0
  16. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/LICENSE.txt +0 -0
  17. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/MANIFEST.in +0 -0
  18. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/bubblemap.py +0 -0
  19. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/choroplethmap.py +0 -0
  20. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/custom/__init__.py +0 -0
  21. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/custom/climate_cars.py +0 -0
  22. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/datawrapper.py +0 -0
  23. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/__init__.py +0 -0
  24. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/color_fn.py +0 -0
  25. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/colors.py +0 -0
  26. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/formatter.py +0 -0
  27. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/geography.py +0 -0
  28. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/locator.py +0 -0
  29. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/mimetypes.py +0 -0
  30. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/lib/utils.py +0 -0
  31. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/map.py +0 -0
  32. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/maps/se-4.gpkg +0 -0
  33. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/maps/se-7.gpkg +0 -0
  34. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/rangeplot.py +0 -0
  35. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/rc/newsworthy +0 -0
  36. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/scatterplot.py +0 -0
  37. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/seasonalchart.py +0 -0
  38. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/storage.py +0 -0
  39. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/stripechart.py +0 -0
  40. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/translations/datawrapper_regions.csv +0 -0
  41. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/translations/regions.py +0 -0
  42. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/newsworthycharts/translations/se_municipalities.csv +0 -0
  43. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/setup.cfg +0 -0
  44. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/setup.py +0 -0
  45. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_choropleth_maps.py +0 -0
  46. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_custom_climate_cars.py +0 -0
  47. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_data_list.py +0 -0
  48. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_datawrapper.py +0 -0
  49. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_main.py +0 -0
  50. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_rangeplot.py +0 -0
  51. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_scatterplot.py +0 -0
  52. {newsworthycharts-1.64.1 → newsworthycharts-1.65.1}/test/test_serial_chart.py +0 -0
@@ -1,29 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.64.1
3
+ Version: 1.65.1
4
4
  Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
5
  Home-page: https://github.com/jplusplus/newsworthycharts
6
- Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.64.1.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.65.1.tar.gz
7
7
  Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
8
  Author-email: stockholm@jplusplus.org
9
9
  License: MIT
10
10
  Requires-Python: >=3.9
11
11
  Description-Content-Type: text/x-rst
12
12
  License-File: LICENSE.txt
13
- Requires-Dist: boto3>=1.26
14
- Requires-Dist: matplotlib==3.9.2
15
- Requires-Dist: langcodes>=3.3
16
- Requires-Dist: Babel<3,>=2.14.0
17
- Requires-Dist: PyYAML>=3
18
- Requires-Dist: adjustText==0.7.3
19
- Requires-Dist: numpy>2
20
- Requires-Dist: python-dateutil<3,>=2
21
- Requires-Dist: Pillow==11.0.0
22
- Requires-Dist: requests>=2.22
23
- Requires-Dist: matplotlib-label-lines==0.5.1
24
- Requires-Dist: geopandas>=1
25
- Requires-Dist: mapclassify==2.8.1
26
- Requires-Dist: puremagic>=1
27
13
 
28
14
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
29
15
 
@@ -259,6 +245,14 @@ Roadmap
259
245
  Changelog
260
246
  ---------
261
247
 
248
+ - 1.65.1
249
+
250
+ - Fixed legend bug in ProgressChart
251
+
252
+ - 1.65.0
253
+
254
+ - Stacked data with percentages summing to very close to 100 % will now be treated as 100 %, assuming rounding error artifacts
255
+
262
256
  - 1.64.1
263
257
 
264
258
  - Fixed assumption about y axis being the value axis in tick cleaning
@@ -232,6 +232,14 @@ Roadmap
232
232
  Changelog
233
233
  ---------
234
234
 
235
+ - 1.65.1
236
+
237
+ - Fixed legend bug in ProgressChart
238
+
239
+ - 1.65.0
240
+
241
+ - Stacked data with percentages summing to very close to 100 % will now be treated as 100 %, assuming rounding error artifacts
242
+
235
243
  - 1.64.1
236
244
 
237
245
  - Fixed assumption about y axis being the value axis in tick cleaning
@@ -1,4 +1,4 @@
1
- __version__ = "1.64.1"
1
+ __version__ = "1.65.1"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -20,6 +20,10 @@ class CategoricalChart(Chart):
20
20
  # Optional: specify a list of colors (for multiple datasets)
21
21
  self.colors = None
22
22
 
23
+ @property
24
+ def values_will_be_stacked(self):
25
+ return self.stacked
26
+
23
27
  def _add_pie_data(self):
24
28
  if len(self.data) > 1:
25
29
  raise ValueError("Pie chart takes one data series only.")
@@ -288,13 +292,13 @@ class ProgressChart(CategoricalChart):
288
292
  def __init__(self, *args, **kwargs):
289
293
  self.target = None
290
294
  self.target_label = None
291
- self.legend = False
292
295
 
293
296
  # should value labels be rendered?
294
297
  self.value_labels = None # "progress"|"remaining"
295
298
 
296
299
  super().__init__(*args, **kwargs)
297
300
  self.stacked = True
301
+ self.legend = False
298
302
 
299
303
  def _add_data(self):
300
304
  if self.target is None:
@@ -335,7 +339,7 @@ class ProgressChart(CategoricalChart):
335
339
 
336
340
  # rect.set_linewidth(1)
337
341
  # rect.set_edgecolor(color_progress)
338
-
342
+
339
343
  # LABELING: Target
340
344
  if self.target_label:
341
345
  offset = 25
@@ -550,6 +550,20 @@ class Chart(object):
550
550
  if len(ticks_) <= 1 and self.data:
551
551
  self.value_axis.set_ticks([0, self.data.max_val])
552
552
 
553
+ # Special handling for stacked percents, where, we want to fix any rounding errors,
554
+ # to make sure value max is 100 %, and not something like 100.00000000000001 (which
555
+ # may cause an extra tick to show up
556
+ if self.units == "percent" and self.values_will_be_stacked:
557
+ max_val = max(self.data.stacked_values)
558
+ diff = abs(1 - max_val)
559
+ _decimals = self.decimals if self.decimals is not None else 2
560
+ if diff < (pow(10, -_decimals) / 100): # 0.01 / 100 for 2 decimals, etc
561
+ value_lim = self.ax.get_ylim() if value_axis == "_y" else self.ax.get_xlim()
562
+ if value_axis == "_y":
563
+ self.ax.set_ylim(value_lim[0], 1)
564
+ else:
565
+ self.ax.set_xlim(value_lim[0], 1)
566
+
553
567
  for a in self.annotations:
554
568
  self._annotate_point(a["text"], a["xy"], a["direction"])
555
569
  if self.ylabel is not None:
@@ -794,6 +808,15 @@ class Chart(object):
794
808
  def units(self):
795
809
  return self._units
796
810
 
811
+ @property
812
+ def values_will_be_stacked(self):
813
+ """
814
+ Are the values from more than one dataseries going to be stacked or grouped together,
815
+ e.g. a stacked barchart?
816
+ This is used to to sanitize the value axis, and work around rounding errors.
817
+ """
818
+ return False
819
+
797
820
  @units.setter
798
821
  def units(self, val: str):
799
822
  """ Units, used for number formatting. Note that 'degrees' is designed
@@ -184,6 +184,18 @@ class DataSet(MutableSequence):
184
184
  self.max_val = max(self.max_val, max(values))
185
185
  return v
186
186
 
187
+ @property
188
+ def values(self):
189
+ """ Return values from each data serie """
190
+ return [[to_float(x[1]) for x in s] for s in self.list]
191
+
192
+ @property
193
+ def stacked_values(self):
194
+ """Returns the sum of all y values in each x """
195
+ # converts None to np.na for np.sum()
196
+ values = array(self.values, dtype=float)
197
+ return np.nansum(values, axis=0).tolist()
198
+
187
199
  def __len__(self):
188
200
  return len(self.list)
189
201
 
@@ -143,6 +143,10 @@ class SerialChart(Chart):
143
143
  return "down"
144
144
  return "up"
145
145
 
146
+ @property
147
+ def values_will_be_stacked(self):
148
+ return (len(self.data) > 1) and all([t == "bars" for t in self.type])
149
+
146
150
  def _add_data(self):
147
151
 
148
152
  series = self.data
@@ -150,7 +154,6 @@ class SerialChart(Chart):
150
154
  # For backwards compatibility: Convert type = "line" -> type = ["line"]
151
155
  if type(self.type) is str:
152
156
  self.type = [self.type] * len(series)
153
- is_stacked = (len(series) > 1) and all([t == "bars" for t in self.type])
154
157
 
155
158
  if self.allow_broken_y_axis is None:
156
159
  if "bars" in self.type:
@@ -323,7 +326,7 @@ class SerialChart(Chart):
323
326
  hl_color_for_series = self._nwc_style["strong_color"]
324
327
  elif i == 0:
325
328
  base_color_for_series = self._nwc_style["strong_color"]
326
- elif is_stacked:
329
+ elif self.values_will_be_stacked:
327
330
  hl_color_for_series = self._nwc_style["strong_color"]
328
331
  base_color_for_series = self._nwc_style["qualitative_colors"][i]
329
332
  else:
@@ -370,7 +373,7 @@ class SerialChart(Chart):
370
373
  # bar_kwargs["edgecolor"] = "white"
371
374
  # bar_kwargs["linewidth"] = 0 # 1
372
375
 
373
- if is_stacked and i > 0:
376
+ if self.values_will_be_stacked and i > 0:
374
377
  if self.baseline != 0:
375
378
  raise Exception("Setting a baseline is not supported for stacked bars")
376
379
  # To make stacked bars we need to set bottom value
@@ -545,7 +548,7 @@ class SerialChart(Chart):
545
548
  ymax = self.ymax
546
549
  padding_top = 0
547
550
  else:
548
- if is_stacked:
551
+ if self.values_will_be_stacked:
549
552
  ymax = self.data.stacked_max_val
550
553
  else:
551
554
  ymax = self.data.max_val + self.baseline
@@ -0,0 +1 @@
1
+ ,jens,jens-XPS-13,10.02.2020 11:26,file:///home/jens/.config/libreoffice/4;
@@ -1,29 +1,15 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.64.1
3
+ Version: 1.65.1
4
4
  Summary: Matplotlib wrapper to create charts and publish them on Amazon S3
5
5
  Home-page: https://github.com/jplusplus/newsworthycharts
6
- Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.64.1.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.65.1.tar.gz
7
7
  Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
8
  Author-email: stockholm@jplusplus.org
9
9
  License: MIT
10
10
  Requires-Python: >=3.9
11
11
  Description-Content-Type: text/x-rst
12
12
  License-File: LICENSE.txt
13
- Requires-Dist: boto3>=1.26
14
- Requires-Dist: matplotlib==3.9.2
15
- Requires-Dist: langcodes>=3.3
16
- Requires-Dist: Babel<3,>=2.14.0
17
- Requires-Dist: PyYAML>=3
18
- Requires-Dist: adjustText==0.7.3
19
- Requires-Dist: numpy>2
20
- Requires-Dist: python-dateutil<3,>=2
21
- Requires-Dist: Pillow==11.0.0
22
- Requires-Dist: requests>=2.22
23
- Requires-Dist: matplotlib-label-lines==0.5.1
24
- Requires-Dist: geopandas>=1
25
- Requires-Dist: mapclassify==2.8.1
26
- Requires-Dist: puremagic>=1
27
13
 
28
14
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
29
15
 
@@ -259,6 +245,14 @@ Roadmap
259
245
  Changelog
260
246
  ---------
261
247
 
248
+ - 1.65.1
249
+
250
+ - Fixed legend bug in ProgressChart
251
+
252
+ - 1.65.0
253
+
254
+ - Stacked data with percentages summing to very close to 100 % will now be treated as 100 %, assuming rounding error artifacts
255
+
262
256
  - 1.64.1
263
257
 
264
258
  - Fixed assumption about y axis being the value axis in tick cleaning
@@ -36,6 +36,7 @@ newsworthycharts/lib/utils.py
36
36
  newsworthycharts/maps/se-4.gpkg
37
37
  newsworthycharts/maps/se-7.gpkg
38
38
  newsworthycharts/rc/newsworthy
39
+ newsworthycharts/translations/.~lock.datawrapper_regions.csv#
39
40
  newsworthycharts/translations/datawrapper_regions.csv
40
41
  newsworthycharts/translations/regions.py
41
42
  newsworthycharts/translations/se_municipalities.csv
@@ -338,3 +338,23 @@ def test_progress_chart_with_multiple_targets():
338
338
  c = ProgressChart.init_from(chart_obj, storage=local_storage)
339
339
 
340
340
  c.render("progress_chart_with_multiple_targets", "png")
341
+
342
+ def test_basic_progress_chart():
343
+ chart_obj = {
344
+ "data": [
345
+ [
346
+ ("A", .9404),
347
+ ("B", .8868),
348
+ ("C", .8260),
349
+ ],
350
+ ],
351
+ "target": 1,
352
+ "value_labels": "progress",
353
+ "width": 700,
354
+ "height": 400,
355
+ "units": "percent",
356
+ "bar_orientation": "horizontal",
357
+ "title": "Inga mål uppnås"
358
+ }
359
+ c = ProgressChart.init_from(chart_obj, storage=local_storage)
360
+ c.render("progress_chart_basic", "png")