newsworthycharts 1.64.1__py3-none-any.whl → 1.65.1__py3-none-any.whl

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.
@@ -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
newsworthycharts/chart.py CHANGED
@@ -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
@@ -0,0 +1,8 @@
1
+ """Custom charts for bredbandsutredningen.
2
+ """
3
+
4
+ from newsworthycharts import CategoricalChart
5
+
6
+ class BroadbandTargetChart(CategoricalChart):
7
+ def _add_data(self):
8
+ super(BroadbandTargetChart, self)._add_data()
@@ -0,0 +1,20 @@
1
+ from newsworthycharts import SerialChart
2
+ import numpy as np
3
+
4
+ class TemperatueChart(SerialChart):
5
+ def _add_data(self):
6
+ self.color_fn = "positive_negative"
7
+ if len(self.data) != 1:
8
+ raise ValueError("TemperatueChart takes one and only one data series.")
9
+
10
+ dates = [x[0] for x in self.data[0]]
11
+ values = [x[1] for x in self.data[0]]
12
+ s = np.array(values, dtype=np.float)
13
+ mean = np.nanmean(s)
14
+ vs_mean = s - mean
15
+ self.data[0] = list(zip(dates, vs_mean.tolist()))
16
+ self._ymin = np.nanmin(vs_mean)
17
+ self.data.max_val = np.nanmax(vs_mean)
18
+
19
+
20
+ super(TemperatueChart, self)._add_data()
@@ -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;
@@ -0,0 +1 @@
1
+ ,jens,jens-XPS-13-9310,20.03.2023 13:52,file:///home/jens/.config/libreoffice/4;
@@ -1,29 +1,29 @@
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
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
27
 
28
28
  This module contains methods for producing graphs and publishing them on Amazon S3, or in the location of your choice.
29
29
 
@@ -259,6 +259,14 @@ Roadmap
259
259
  Changelog
260
260
  ---------
261
261
 
262
+ - 1.65.1
263
+
264
+ - Fixed legend bug in ProgressChart
265
+
266
+ - 1.65.0
267
+
268
+ - Stacked data with percentages summing to very close to 100 % will now be treated as 100 %, assuming rounding error artifacts
269
+
262
270
  - 1.64.1
263
271
 
264
272
  - Fixed assumption about y axis being the value axis in tick cleaning
@@ -1,22 +1,24 @@
1
- newsworthycharts/__init__.py,sha256=dmPNkMtUZM0_DdBiIY2EBtI1-pTzeqER4SH0paV-6fU,1160
1
+ newsworthycharts/__init__.py,sha256=EGDm4UzvQMtB6QL_R1B1b9K2q75byHoVZtmNgz2imX4,1160
2
2
  newsworthycharts/bubblemap.py,sha256=nkocWmpiFgfjEuJGAsthjY5X7Q56jXWsZHUGXw4PwgE,2587
3
- newsworthycharts/categoricalchart.py,sha256=4qzx17QcJX-Xw7COwyL_atIEgeVkNnlgS3B1v4-Q6dQ,15648
4
- newsworthycharts/chart.py,sha256=KIb-x0krYD7KStlqwsZK2aGn3CRxIUAdetJXKVCUc5w,32989
3
+ newsworthycharts/categoricalchart.py,sha256=wLrS8H69Sx3FT-0r3w3ZOIC83IHb8HCHD0zTsXiIiNA,15737
4
+ newsworthycharts/chart.py,sha256=y-OjOcFYL4YaqgJEdUyqN6sAqk-8a0wOz5vjktRCr6E,34170
5
5
  newsworthycharts/choroplethmap.py,sha256=bCLf4kcchp1C2djg5AxcOM8BdbaMj0xg7UHrZsDafhI,8013
6
6
  newsworthycharts/datawrapper.py,sha256=RRkAVTpfP4updKxUIBaSmKuBi2RUVPaBRF8HDQhlGGA,11250
7
7
  newsworthycharts/map.py,sha256=c409jEO4L8Yr780sJRC0RchR44roAlgOUDAkuk1SfRg,6057
8
8
  newsworthycharts/rangeplot.py,sha256=NE1W9TnmlpK6T3RvBJOU3nd73EXqkj17OY9i5zlw_cQ,8366
9
9
  newsworthycharts/scatterplot.py,sha256=l2w2JkA_4WzxQG9XG1Pn62IlJOdCMm1VemMiZL0rEfU,4959
10
10
  newsworthycharts/seasonalchart.py,sha256=rr55yqJUkaYDR9Ik98jes6574oY1U8t8LwoLE3gClW4,1967
11
- newsworthycharts/serialchart.py,sha256=WrCWyDDRkXBXSqNyIhoBnm7A5RR2_wlluFPYirq_Snw,27686
11
+ newsworthycharts/serialchart.py,sha256=_TBZiOyU-TtnnkJGbP4yZcTlypdIpbxHK4AjE4Su3k8,27787
12
12
  newsworthycharts/storage.py,sha256=myERhlpvXyExXxUByBq9eW1bWkCyfH9SwTZbsWSyy3Q,4301
13
13
  newsworthycharts/stripechart.py,sha256=9B6PX2MyLuKNQ8W0OGdKbP0-U32kju0K_NHHwwz_J68,1547
14
14
  newsworthycharts/custom/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
15
15
  newsworthycharts/custom/climate_cars.py,sha256=WyNLgjgRCv_zRrzVuk_BmcigFSzpzudjEAYmdvdBe8I,9407
16
+ newsworthycharts/custom/pts.py,sha256=B_7y0rwvUMSlGoGopqlaS9RipjRrQ7cc4NXmQV_U31E,220
17
+ newsworthycharts/custom/temperature.py,sha256=8WE5xXTzP1zLc655ltqdE7ypl2pguC6kX9HG_paW4BE,679
16
18
  newsworthycharts/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
19
  newsworthycharts/lib/color_fn.py,sha256=ck65GzTS9oPgHUCnKDwX2z8zlnNyzncw97MmhXwi8z8,1282
18
20
  newsworthycharts/lib/colors.py,sha256=U04TDkvoMQkcldRFXfnwyLOTwq1SWW2se-Ad-DNcw9o,485
19
- newsworthycharts/lib/datalist.py,sha256=Lmb37IXZi9fqrV4qAZRFDtH4ctMDpOqH-ITV62mfarQ,5807
21
+ newsworthycharts/lib/datalist.py,sha256=rO7kA0-waYOLMj4AqcksjPWBmn3q1cPyV0xxEUqkukA,6206
20
22
  newsworthycharts/lib/formatter.py,sha256=GNH43hE0bC17OgiV8LYH3YUrEhm7OJh9XzfSV4HVtHo,4838
21
23
  newsworthycharts/lib/geography.py,sha256=K0_teFmuPJwXX7Py-amJB_1YY5_gL2kBYhz1LrRCyTg,584
22
24
  newsworthycharts/lib/locator.py,sha256=rJHdgiA0LASRzdLINhTeU5zOoq1TCMgge4KOBWSagnM,3041
@@ -25,11 +27,13 @@ newsworthycharts/lib/utils.py,sha256=l4SUVB-8lnm3XHqHNo5KgZuZNv_VaFnrH76hrZmDq1s
25
27
  newsworthycharts/maps/se-4.gpkg,sha256=oWw5j7FPVpI0ig67jNDim8qSn5SG8rcHp0014-uTKZM,290816
26
28
  newsworthycharts/maps/se-7.gpkg,sha256=Vmvqudq_ZtgV0sd6TY6kuk7vzqmYZCJmaxtsJ87q2a8,331776
27
29
  newsworthycharts/rc/newsworthy,sha256=vbYTav1w3DmB5tpaaV7Xl5q7TQJsc9eou6pLCoWc2vs,1589
30
+ newsworthycharts/translations/.~lock.datawrapper_regions.csv#,sha256=lISyvTWrw8LTG01qMC_F5RxDwamXBeq9vJRKKwBYtRg,75
31
+ newsworthycharts/translations/.~lock.se_municipalities.csv#,sha256=MEff-0d958fdtjBWyt0UnzZWf8OBFx-6PFKeGqGR8NM,80
28
32
  newsworthycharts/translations/datawrapper_regions.csv,sha256=fzZcQRX6RFMlNNP8mpgfYNdR3Y0QAlQxDXk8FXTaWWI,9214
29
33
  newsworthycharts/translations/regions.py,sha256=Nv1McQjggD4S3JRu82rDMTG3pqUVR13E5-FBpSYbm98,239
30
34
  newsworthycharts/translations/se_municipalities.csv,sha256=br_mm-IvzQtj_W55_ATREhJ97jWnCweBFlDAVY2EBxA,7098
31
- newsworthycharts-1.64.1.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
32
- newsworthycharts-1.64.1.dist-info/METADATA,sha256=koJ9oSSiQ0dqjLNaj1D2qLzYAQHzca6qT5G2mHGHsz0,30533
33
- newsworthycharts-1.64.1.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
34
- newsworthycharts-1.64.1.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
35
- newsworthycharts-1.64.1.dist-info/RECORD,,
35
+ newsworthycharts-1.65.1.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
36
+ newsworthycharts-1.65.1.dist-info/METADATA,sha256=tGThxBsEGRsa_-sZGyAbldfJZQEdW9h-JxqN5kpGJSs,30708
37
+ newsworthycharts-1.65.1.dist-info/WHEEL,sha256=bFJAMchF8aTQGUgMZzHJyDDMPTO3ToJ7x23SLJa1SVo,92
38
+ newsworthycharts-1.65.1.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
39
+ newsworthycharts-1.65.1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (74.1.2)
2
+ Generator: bdist_wheel (0.45.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5