newsworthycharts 1.63.5__py3-none-any.whl → 1.64.0__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.63.5"
1
+ __version__ = "1.64.0"
2
2
 
3
3
  from .chart import Chart
4
4
  from .choroplethmap import ChoroplethMap
@@ -15,11 +15,43 @@ class CategoricalChart(Chart):
15
15
  self.annotation_rotation = 0
16
16
  self.stacked = False
17
17
  self.legend = True
18
+ self.type = "bars"
18
19
 
19
20
  # Optional: specify a list of colors (for multiple datasets)
20
21
  self.colors = None
21
22
 
23
+ def _add_pie_data(self):
24
+ if len(self.data) > 1:
25
+ raise ValueError("Pie chart takes one data series only.")
26
+ self.legend = False
27
+ self.show_ticks = False
28
+
29
+ data = self.data[0]
30
+ values = [to_float(x[1]) for x in data]
31
+ labels = [x[0] for x in data]
32
+
33
+ if self.colors is not None:
34
+ colors = self.colors
35
+ else:
36
+ colors = [self._nwc_style["qualitative_colors"][i] for i in range(len(values))]
37
+
38
+ explode = [0.1 if x == self.highlight else 0 for x in labels]
39
+
40
+ self.ax.pie(
41
+ values,
42
+ labels=labels,
43
+ startangle=90,
44
+ colors=colors,
45
+ explode=explode
46
+ )
47
+ self.ax.axis('equal')
48
+
49
+ self._setup_legend()
50
+
22
51
  def _add_data(self):
52
+ if self.type == "pie":
53
+ self._add_pie_data()
54
+ return
23
55
  allowed_orientations = ["horizontal", "vertical"]
24
56
  if self.bar_orientation not in allowed_orientations:
25
57
  raise ValueError(f"Valid oriantations: {allowed_orientations}")
newsworthycharts/chart.py CHANGED
@@ -138,10 +138,12 @@ class Chart(object):
138
138
  return self._get_formatter(self.units)
139
139
 
140
140
  def _get_formatter(self, units):
141
- formatter = Formatter(self._language,
142
- decimals=self.decimals,
143
- force_decimals=self.force_decimals,
144
- scale="celsius")
141
+ formatter = Formatter(
142
+ self._language,
143
+ decimals=self.decimals,
144
+ force_decimals=self.force_decimals,
145
+ scale="celsius",
146
+ )
145
147
  if units == "percent":
146
148
  return FuncFormatter(formatter.percent)
147
149
  elif units == "degrees":
@@ -522,20 +524,30 @@ class Chart(object):
522
524
  if try_dec > 2:
523
525
  keep_trying = False
524
526
  try_dec += 1
525
- # Remove duplicate y ticks (most should be gone as per above)
527
+
526
528
  ticks = self.value_axis.get_ticklabels()
527
529
  ticks_ = [x for (i, x) in enumerate(ticks) if ticks[i - 1].get_text() != x.get_text()]
528
- if len(ticks_) == 2 and self.data and self.data.max_val:
530
+ # remove non integer ticks
531
+ if self.decimals == 0:
532
+ y = [float(x._y) for x in ticks]
533
+ if self.units == "percent":
534
+ y = [x for x in y if (x * 100).is_integer()]
535
+ else:
536
+ y = [x for x in y if x.is_integer()]
537
+ self.value_axis.set_ticks(y)
538
+ # Remove duplicate y ticks (most should be gone as per above)
539
+ elif len(ticks_) == 2 and self.data:
529
540
  # When only two ticks we want them on top and bottom
530
541
  self.value_axis.set_ticks([float(ticks[0]._y), self.data.max_val])
531
542
  elif len(ticks_) < len(ticks):
532
543
  y = [float(x._y) for x in ticks_]
533
544
  self.value_axis.set_ticks(y)
534
- elif self.decimals == 0:
535
- # remove non integer ticks
536
- y = [float(x._y) for x in ticks]
537
- y = [x for x in y if x.is_integer()]
538
- self.value_axis.set_ticks(y)
545
+
546
+ # Force a second tick if we ended up having just one
547
+ ticks = self.value_axis.get_ticklabels()
548
+ ticks_ = [x for (i, x) in enumerate(ticks) if ticks[i - 1].get_text() != x.get_text()]
549
+ if len(ticks_) <= 1 and self.data:
550
+ self.value_axis.set_ticks([0, self.data.max_val])
539
551
 
540
552
  for a in self.annotations:
541
553
  self._annotate_point(a["text"], a["xy"], a["direction"])
@@ -171,8 +171,19 @@ class DataSet(MutableSequence):
171
171
 
172
172
  def __init__(self, *args):
173
173
  self.list = list()
174
+ self.min_val = inf
175
+ self.max_val = -inf
174
176
  self.extend(list(args))
175
177
 
178
+ def check(self, v):
179
+ # Update metadata with newly added data
180
+ values = [to_float(x[1]) for x in v]
181
+ values = [x for x in values if x is not None]
182
+ if values:
183
+ self.min_val = min(self.min_val, min(values))
184
+ self.max_val = max(self.max_val, max(values))
185
+ return v
186
+
176
187
  def __len__(self):
177
188
  return len(self.list)
178
189
 
@@ -183,9 +194,11 @@ class DataSet(MutableSequence):
183
194
  del self.list[i]
184
195
 
185
196
  def __setitem__(self, i, v):
197
+ v = self.check(v)
186
198
  self.list[i] = v
187
199
 
188
200
  def insert(self, i, v):
201
+ v = self.check(v)
189
202
  self.list.insert(i, v)
190
203
 
191
204
  def __str__(self):
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: newsworthycharts
3
- Version: 1.63.5
3
+ Version: 1.64.0
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.63.5.tar.gz
6
+ Download-URL: https://github.com/jplusplus/newsworthycharts/archive/1.64.0.tar.gz
7
7
  Author: Jens Finnäs and Leo Wallentin, J++ Stockholm
8
8
  Author-email: stockholm@jplusplus.org
9
9
  License: MIT
@@ -154,7 +154,7 @@ These settings are available for all chart types:
154
154
 
155
155
  **SerialChart**
156
156
 
157
- - type = 'line' # line|bars
157
+ - type = 'line' # line|bars, or a list of types for each data serie
158
158
  - bar_width = 0.9 # percent of data point width
159
159
  - allow_broken_y_axis = True|False # default depends on chart type
160
160
  - baseline = 0 # The “zero” line. Useful for plotting deviations, e.g. temperatures above/below mean
@@ -181,11 +181,12 @@ _ Inherits from SerialChart _
181
181
 
182
182
  **CategoricalChart**
183
183
 
184
- - bar_orientation = "horizontal" # [horizontal|vertical]
185
184
  - annotation_rotation = 0
186
- - stacked = False
187
- - legend = True
185
+ - bar_orientation = "horizontal" # [horizontal|vertical]
188
186
  - colors = None # A dictionary of colors
187
+ - legend = True
188
+ - stacked = False
189
+ - type = "bars" # [bars|pie]
189
190
 
190
191
  **CategoricalChartWithReference**
191
192
 
@@ -254,6 +255,14 @@ Roadmap
254
255
  Changelog
255
256
  ---------
256
257
 
258
+ - 1.64.0
259
+
260
+ - Improved handling of value axis in categorical charts
261
+ - Make sure at least one value axis tick is always printed
262
+ - Experimental support for simple, single series pie charts in CategoricalChart
263
+ - Fixed bug introduced in 1.63.3, where `decimals` and `units: percent` would not work together
264
+ - Fixed weird edge case when ticks would be offset for small numbers
265
+
257
266
  - 1.63.5
258
267
 
259
268
  - Improved edge case handling when using fixed decimal places and remove duplicated ticks
@@ -1,7 +1,7 @@
1
- newsworthycharts/__init__.py,sha256=elEV2GIioxyMzFQUkHwXEsdCH1gR3LwXYvLY4CU7yjs,1160
1
+ newsworthycharts/__init__.py,sha256=Ar8KT2Z_t3lWJ367gTYTFtMKii3FmyxKPDhlK3qrz2s,1160
2
2
  newsworthycharts/bubblemap.py,sha256=nkocWmpiFgfjEuJGAsthjY5X7Q56jXWsZHUGXw4PwgE,2587
3
- newsworthycharts/categoricalchart.py,sha256=LwOZ3VbNy9vzvoK0s77AkbfMt4CXVDSAhnsnBInUIrE,14764
4
- newsworthycharts/chart.py,sha256=-GHmdO0Q0YURamo9z4HG1mveTNsxaRSpQZFtGXhUe28,32431
3
+ newsworthycharts/categoricalchart.py,sha256=4qzx17QcJX-Xw7COwyL_atIEgeVkNnlgS3B1v4-Q6dQ,15648
4
+ newsworthycharts/chart.py,sha256=5JqEsWZUNefgXyhpznXcV5U1j-IOScsGWQoCijVMo9c,32841
5
5
  newsworthycharts/choroplethmap.py,sha256=bCLf4kcchp1C2djg5AxcOM8BdbaMj0xg7UHrZsDafhI,8013
6
6
  newsworthycharts/datawrapper.py,sha256=RRkAVTpfP4updKxUIBaSmKuBi2RUVPaBRF8HDQhlGGA,11250
7
7
  newsworthycharts/map.py,sha256=c409jEO4L8Yr780sJRC0RchR44roAlgOUDAkuk1SfRg,6057
@@ -16,7 +16,7 @@ newsworthycharts/custom/climate_cars.py,sha256=WyNLgjgRCv_zRrzVuk_BmcigFSzpzudjE
16
16
  newsworthycharts/lib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
17
17
  newsworthycharts/lib/color_fn.py,sha256=ck65GzTS9oPgHUCnKDwX2z8zlnNyzncw97MmhXwi8z8,1282
18
18
  newsworthycharts/lib/colors.py,sha256=U04TDkvoMQkcldRFXfnwyLOTwq1SWW2se-Ad-DNcw9o,485
19
- newsworthycharts/lib/datalist.py,sha256=fsO_esZBt4Aw_4n_l2LuswAYArbM-8Z8G9DAXo1oVZU,5376
19
+ newsworthycharts/lib/datalist.py,sha256=Lmb37IXZi9fqrV4qAZRFDtH4ctMDpOqH-ITV62mfarQ,5807
20
20
  newsworthycharts/lib/formatter.py,sha256=GNH43hE0bC17OgiV8LYH3YUrEhm7OJh9XzfSV4HVtHo,4838
21
21
  newsworthycharts/lib/geography.py,sha256=K0_teFmuPJwXX7Py-amJB_1YY5_gL2kBYhz1LrRCyTg,584
22
22
  newsworthycharts/lib/locator.py,sha256=rJHdgiA0LASRzdLINhTeU5zOoq1TCMgge4KOBWSagnM,3041
@@ -28,8 +28,8 @@ newsworthycharts/rc/newsworthy,sha256=vbYTav1w3DmB5tpaaV7Xl5q7TQJsc9eou6pLCoWc2v
28
28
  newsworthycharts/translations/datawrapper_regions.csv,sha256=fzZcQRX6RFMlNNP8mpgfYNdR3Y0QAlQxDXk8FXTaWWI,9214
29
29
  newsworthycharts/translations/regions.py,sha256=Nv1McQjggD4S3JRu82rDMTG3pqUVR13E5-FBpSYbm98,239
30
30
  newsworthycharts/translations/se_municipalities.csv,sha256=br_mm-IvzQtj_W55_ATREhJ97jWnCweBFlDAVY2EBxA,7098
31
- newsworthycharts-1.63.5.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
32
- newsworthycharts-1.63.5.dist-info/METADATA,sha256=nKWWpnOJdxul89NpEJAsxcsB44S0PEUCxi1FY83jePo,29775
33
- newsworthycharts-1.63.5.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
34
- newsworthycharts-1.63.5.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
35
- newsworthycharts-1.63.5.dist-info/RECORD,,
31
+ newsworthycharts-1.64.0.dist-info/LICENSE.txt,sha256=Sq6kGICrehbhC_FolNdXf0djKjTpv3YqjFCIYsxdQN4,1069
32
+ newsworthycharts-1.64.0.dist-info/METADATA,sha256=Bd6gWjBOcSYe5uGZju_Ohtt_lqmkd1I_KOjsTzyFpZs,30226
33
+ newsworthycharts-1.64.0.dist-info/WHEEL,sha256=cVxcB9AmuTcXqmwrtPhNK88dr7IR_b6qagTj0UvIEbY,91
34
+ newsworthycharts-1.64.0.dist-info/top_level.txt,sha256=dn_kzIj8UgUCMsh1PHdVEQJHVGSsN7Z8YJF-8xXa8n0,17
35
+ newsworthycharts-1.64.0.dist-info/RECORD,,