react-minimal-pie-chart 8.3.0 → 8.4.1

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.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  [![Coveralls][coveralls-badge]][coveralls]
6
6
  [![Bundle size][bundlephobia-badge]][bundlephobia]
7
7
 
8
- Lightweight React **SVG pie charts**, with **versatile options** and **CSS animation** included. **< 2kB** gzipped. [👏 Demo 👏][storybook].
8
+ Lightweight React **SVG pie charts**, with **versatile options** and **CSS animation** included. **~2kB** gzipped. [👏 Demo 👏][storybook].
9
9
 
10
10
  <p align="center">
11
11
  <img
@@ -17,11 +17,11 @@ Lightweight React **SVG pie charts**, with **versatile options** and **CSS anima
17
17
 
18
18
  ## Why?
19
19
 
20
- Because [Recharts][recharts-github] is awesome, but when you just need a simple pie/donought chart, **~~3kB~~ 2kB** are usually enough.
20
+ Because [Recharts][recharts-github] is awesome, but when you just need a simple pie/donought chart, **2kB** are usually enough.
21
21
 
22
22
  | | Size<br>by Bundlefobia | Benchmark Size \* | Loading time<br>on a slow 3g \* |
23
23
  | :----------------------------------------------------: | :-----------------------------------------------------------------------------------------------------: | :---------------: | :-----------------------------: |
24
- | react-minimal-pie-chart (_v8.2.0_) | [![Bundle size: React minimal pie chart][bundlephobia-badge]][bundlephobia] | 1.83 KB | ~38 ms |
24
+ | react-minimal-pie-chart (_v8.4.0_) | [![Bundle size: React minimal pie chart][bundlephobia-badge]][bundlephobia] | 1.93 KB | ~39 ms |
25
25
  | [rechart][recharts-github] (_v1.8.5_) | [![Bundle size: Recharts][recharts-bundlephobia-badge]][recharts-bundlephobia] | 96.9 KB | ~1900 ms |
26
26
  | [victory-pie][victory-pie-github] (_v34.1.3_) | [![Bundle size: Victory pie][victory-pie-bundlephobia-badge]][victory-pie-bundlephobia] | 50.5 KB | ~1100 ms |
27
27
  | [react-apexcharts][react-apexcharts-github] (_v1.3.7_) | [![Bundle size: React apec charts][react-apexcharts-bundlephobia-badge]][react-apexcharts-bundlephobia] | 114.6 KB | ~2300 ms |
@@ -78,17 +78,17 @@ import { PieChart } from 'react-minimal-pie-chart';
78
78
  | **paddingAngle** | `number` | Angle between two segments | - |
79
79
  | **rounded** | `boolean` | Round line caps of each segment | - |
80
80
  | **segmentsShift** | `number`</br>or:</br>`(segmentIndex) => number` | Translates segments radially. If `number` set, provide shift value relative to `viewBoxSize` space. If `function`, return a value for each segment.</br>_(`radius` prop might be adjusted to prevent segments from overflowing chart's boundaries)_ | - |
81
- | **segmentsStyle** | `CSSObject`</br>or:</br>`(segmentIndex) => CSSObject` | Style object assigned to each segment. If `function`, return a value for each segment | - |
81
+ | **segmentsStyle** | `CSSObject`</br>or:</br>`(segmentIndex) => CSSObject` | Style object assigned to each segment. If `function`, return a value for each segment. *(Warning: SVG only supports [its own CSS props][svg-css])*. | - |
82
82
  | **segmentsTabIndex** | `number` | [`tabindex` attribute](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/tabindex) assigned to segments | - |
83
- | [**label**][label-props-docs] | `(labelRenderProps) => string \| number \| ReactElement` | A function returning a label value or the SVG element to be rendered as label | - |
83
+ | [**label**][label-props-docs] | `(labelRenderProps) => string \| number \| ReactElement` | A function returning a label value or the [SVG element][svg-elements] to be rendered as label | - |
84
84
  | **labelPosition** | `number` (%) | Label position from origin. Percentage of chart's radius _(50 === middle point)_ | 50 |
85
- | **labelStyle** | `CSSObject`</br>or:</br>`(segmentIndex) => CSSObject` | Style object assigned to each label. If `function` set, return style for each label | - |
85
+ | **labelStyle** | `CSSObject`</br>or:</br>`(segmentIndex) => CSSObject` | Style object assigned to each label. If `function` set, return style for each label. *(Warning: SVG only supports [its own CSS props][svg-css])*. | - |
86
86
  | **animate** | `boolean` | Animate segments on component mount | - |
87
87
  | **animationDuration** | `number` | Animation duration in ms | 500 |
88
88
  | **animationEasing** | `string` | A [CSS easing function](https://developer.mozilla.org/en-US/docs/Web/CSS/transition-timing-function) | ease-out |
89
89
  | **reveal** | `number` (%) | Turn on CSS animation and reveal just a percentage of each segment | - |
90
90
  | **background** | `string` | Segments' background color | - |
91
- | **children** | `ReactElement` (svg) | Elements rendered as children of SVG element (eg. SVG `defs` and gradient elements) | - |
91
+ | **children** | `ReactElement` (svg) | Elements rendered as children of [SVG element][svg-elements] (eg. SVG `defs` and gradient elements) | - |
92
92
  | **radius** | `number` (user units) | Radius of the pie (relative to `viewBoxSize` space) | 50 |
93
93
  | **center** | `[number, number]` | x and y coordinates of center (relative to `viewBoxSize` space) | [50, 50] |
94
94
  | **viewBoxSize** | `[number, number]` | `width` and `height` of SVG `viewBox` attribute | [100, 100] |
@@ -101,6 +101,12 @@ import { PieChart } from 'react-minimal-pie-chart';
101
101
  | | `.oOo.oOo.oOo.oOo.oOo.oOo.oOo.` | | |
102
102
  <!-- prettier-ignore-end -->
103
103
 
104
+ Prop types are exposed for convenience:
105
+
106
+ ```ts
107
+ import type { PieChartProps } from 'react-minimal-pie-chart';
108
+ ```
109
+
104
110
  ### About `data` prop
105
111
 
106
112
  `data` prop expects an array of chart entries as follows:
@@ -168,17 +174,17 @@ Render segment's percentage as labels:
168
174
  label={({ dataEntry }) => `${Math.round(dataEntry.percentage)} %`}
169
175
  ```
170
176
 
171
- See examples in the [demo source][demo-label-source].
177
+ See examples in the [demo source](https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.2.0/stories/index.tsx#L81).
172
178
 
173
179
  ## How to
174
180
 
175
181
  ### User interactions with the chart
176
182
 
177
- See [demo][demo-interaction] and relative source [here][demo-interaction-source] and [here][demo-interaction-2-source].
183
+ See [demo](https://toomuchdesign.github.io/react-minimal-pie-chart/index.html?path=/story/example-interaction--click-mouseover-mouseout-callbacks) and relative source [here](https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.0.0/stories/InteractionStory.tsx) and [here](https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.0.0/stories/InteractionTabStory.tsx).
178
184
 
179
185
  ### Custom tooltip
180
186
 
181
- See [demo][demo-tooltip] and [relative source][demo-tooltip-source].
187
+ See [demo](https://toomuchdesign.github.io/react-minimal-pie-chart/index.html?path=/story/example-misc--tooltip-integration) and [relative source](https://github.com/toomuchdesign/react-minimal-pie-chart/blob/master/stories/components/Tooltip.tsx).
182
188
 
183
189
  ## Browsers support
184
190
 
@@ -205,11 +211,9 @@ This library uses the `stroke-dasharray` + `stroke-dashoffset` animation strateg
205
211
 
206
212
  - Consider moving storybook deployment to CI
207
213
  - Consider using `transform` to mutate segments/labels positions
208
- - Consider exposing a reduced chart variation including just a subset of the features
209
214
  - Consider abstracting React bindings to re-use business logic with other frameworks
210
- - Remove `defaultProps` in favour of JS default arguments
211
215
  - Provide a way to supply `svg` element with any extra prop
212
- - Consider removing `import type` declaration from generated type definition files (if possible) to ensure Typescript 3.0+ backward compatibility
216
+ - Find a better solution to assign default props
213
217
 
214
218
  ## Contributors
215
219
 
@@ -274,11 +278,7 @@ Thanks to you all ([emoji key](https://github.com/kentcdodds/all-contributors#em
274
278
  [react-vis-bundlephobia]: https://bundlephobia.com/result?p=react-vis
275
279
  [react-vis-github]: https://github.com/uber/react-vis
276
280
  [storybook]: https://toomuchdesign.github.io/react-minimal-pie-chart/index.html
277
- [demo-interaction]: https://toomuchdesign.github.io/react-minimal-pie-chart/index.html?path=/story/interaction--click-mouseover-mouseout-callbacks
278
- [demo-interaction-source]: https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.0.0/stories/InteractionStory.tsx
279
- [demo-interaction-2-source]: https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.0.0/stories/InteractionTabStory.tsx
280
- [demo-tooltip]: https://toomuchdesign.github.io/react-minimal-pie-chart/index.html?path=/story/misc--tooltip-integration
281
- [demo-tooltip-source]: https://github.com/toomuchdesign/react-minimal-pie-chart/blob/master/stories/Tooltip.tsx
282
- [demo-label-source]: https://github.com/toomuchdesign/react-minimal-pie-chart/blob/v8.2.0/stories/index.tsx#L81
283
281
  [data-props-docs]: #about-data-prop
284
282
  [label-props-docs]: #custom-labels-with-label-render-prop
283
+ [svg-elements]: https://developer.mozilla.org/en-US/docs/Web/SVG/Element
284
+ [svg-css]: https://css-tricks.com/svg-properties-and-css/#aa-properties-shared-between-css-and-svg
package/dist/index.js CHANGED
@@ -2,11 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
3
3
  typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ReactMinimalPieChart = {}, global.React));
5
- }(this, (function (exports, React) { 'use strict';
6
-
7
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
8
-
9
- var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
5
+ })(this, (function (exports, React) { 'use strict';
10
6
 
11
7
  function degreesToRadians(degrees) {
12
8
  return degrees * Math.PI / 180;
@@ -32,27 +28,31 @@
32
28
  function isNumber(value) {
33
29
  return typeof value === 'number';
34
30
  }
31
+
32
+ /**
33
+ * Conditionally return a prop or a function prop result
34
+ */
35
35
  function functionProp(prop, payload) {
36
- return typeof prop === 'function' ? prop(payload) : prop;
36
+ return typeof prop === 'function' ?
37
+ // @ts-expect-error: cannot find a way to type 2nd prop arg as anything-but-function
38
+ prop(payload) : prop;
37
39
  }
38
40
 
39
41
  function sumValues(data) {
40
42
  var sum = 0;
41
-
42
43
  for (var i = 0; i < data.length; i++) {
43
44
  sum += data[i].value;
44
45
  }
45
-
46
46
  return sum;
47
- } // Append "percentage", "degrees" and "startAngle" to each data entry
48
-
47
+ }
49
48
 
49
+ // Append "percentage", "degrees" and "startAngle" to each data entry
50
50
  function extendData(_ref) {
51
51
  var data = _ref.data,
52
- totalAngle = _ref.lengthAngle,
53
- totalValue = _ref.totalValue,
54
- paddingAngle = _ref.paddingAngle,
55
- chartStartAngle = _ref.startAngle;
52
+ totalAngle = _ref.lengthAngle,
53
+ totalValue = _ref.totalValue,
54
+ paddingAngle = _ref.paddingAngle,
55
+ chartStartAngle = _ref.startAngle;
56
56
  var total = totalValue || sumValues(data);
57
57
  var normalizedTotalAngle = valueBetween(totalAngle, -360, 360);
58
58
  var numberOfPaddings = Math.abs(normalizedTotalAngle) === 360 ? data.length : data.length - 1;
@@ -60,8 +60,9 @@
60
60
  var degreesTakenByPadding = singlePaddingDegrees * numberOfPaddings;
61
61
  var degreesTakenByPaths = normalizedTotalAngle - degreesTakenByPadding;
62
62
  var lastSegmentEnd = 0;
63
- var extendedData = []; // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?
63
+ var extendedData = [];
64
64
 
65
+ // @NOTE: Shall we evaluate percentage accordingly to dataEntry.value's sign?
65
66
  for (var i = 0; i < data.length; i++) {
66
67
  var dataEntry = data[i];
67
68
  var valueInPercentage = total === 0 ? 0 : dataEntry.value / total * 100;
@@ -74,95 +75,75 @@
74
75
  degrees: degrees
75
76
  }, dataEntry));
76
77
  }
77
-
78
78
  return extendedData;
79
79
  }
80
80
 
81
- function _objectWithoutPropertiesLoose(source, excluded) {
82
- if (source == null) return {};
83
- var target = {};
84
- var sourceKeys = Object.keys(source);
85
- var key, i;
86
-
87
- for (i = 0; i < sourceKeys.length; i++) {
88
- key = sourceKeys[i];
89
- if (excluded.indexOf(key) >= 0) continue;
90
- target[key] = source[key];
81
+ function _objectWithoutPropertiesLoose(r, e) {
82
+ if (null == r) return {};
83
+ var t = {};
84
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
85
+ if (e.includes(n)) continue;
86
+ t[n] = r[n];
91
87
  }
92
-
93
- return target;
88
+ return t;
94
89
  }
95
90
 
91
+ var _excluded$1 = ["dataEntry", "dataIndex"];
96
92
  function ReactMinimalPieChartLabel(_ref) {
97
- _ref.dataEntry;
98
- _ref.dataIndex;
99
- var props = _objectWithoutPropertiesLoose(_ref, ["dataEntry", "dataIndex"]);
93
+ var renderLabel = _ref.renderLabel,
94
+ labelProps = _ref.labelProps;
95
+ var label = renderLabel(labelProps);
100
96
 
101
- return /*#__PURE__*/React__default['default'].createElement("text", Object.assign({
102
- dominantBaseline: "central"
103
- }, props));
97
+ // Default label
98
+ if (typeof label === 'string' || typeof label === 'number') {
99
+ labelProps.dataEntry;
100
+ labelProps.dataIndex;
101
+ var props = _objectWithoutPropertiesLoose(labelProps, _excluded$1);
102
+ return /*#__PURE__*/React.createElement("text", Object.assign({
103
+ dominantBaseline: "central"
104
+ }, props), label);
105
+ }
106
+ if (React.isValidElement(label)) {
107
+ return label;
108
+ }
109
+ return null;
104
110
  }
105
111
 
106
112
  function round(number) {
107
113
  var divisor = 1e14; // 14 decimals
108
-
109
114
  return Math.round((number + Number.EPSILON) * divisor) / divisor;
110
115
  }
111
-
112
116
  function evaluateTextAnchorPosition(_ref) {
113
117
  var labelPosition = _ref.labelPosition,
114
- lineWidth = _ref.lineWidth,
115
- labelHorizontalShift = _ref.labelHorizontalShift;
116
- var dx = round(labelHorizontalShift); // Label in the vertical center
117
-
118
+ lineWidth = _ref.lineWidth,
119
+ labelHorizontalShift = _ref.labelHorizontalShift;
120
+ var dx = round(labelHorizontalShift);
121
+ // Label in the vertical center
118
122
  if (dx === 0) {
119
123
  return 'middle';
120
- } // Outward label
121
-
122
-
124
+ }
125
+ // Outward label
123
126
  if (labelPosition > 100) {
124
127
  return dx > 0 ? 'start' : 'end';
125
- } // Inward label
126
-
127
-
128
+ }
129
+ // Inward label
128
130
  var innerRadius = 100 - lineWidth;
129
-
130
131
  if (labelPosition < innerRadius) {
131
132
  return dx > 0 ? 'end' : 'start';
132
- } // Overlying label
133
-
134
-
135
- return 'middle';
136
- }
137
-
138
- function renderLabelElement(renderLabel, labelProps) {
139
- var label = renderLabel(labelProps);
140
-
141
- if (typeof label === 'string' || typeof label === 'number') {
142
- return /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartLabel, Object.assign({
143
- key: "label-" + (labelProps.dataEntry.key || labelProps.dataIndex)
144
- }, labelProps), label);
145
- }
146
-
147
- if (React__default['default'].isValidElement(label)) {
148
- return label;
149
133
  }
150
-
151
- return null;
134
+ // Overlying label
135
+ return 'middle';
152
136
  }
153
-
154
- function renderLabels(data, props) {
137
+ function makeLabelRenderProps(data, props) {
155
138
  return data.map(function (dataEntry, index) {
156
139
  var _functionProp;
157
-
158
140
  var segmentsShift = (_functionProp = functionProp(props.segmentsShift, index)) != null ? _functionProp : 0;
159
141
  var distanceFromCenter = extractPercentage(props.radius, props.labelPosition) + segmentsShift;
160
-
161
142
  var _shiftVectorAlongAngl = shiftVectorAlongAngle(bisectorAngle(dataEntry.startAngle, dataEntry.degrees), distanceFromCenter),
162
- dx = _shiftVectorAlongAngl.dx,
163
- dy = _shiftVectorAlongAngl.dy; // This object is passed as argument to the "label" function prop
164
-
143
+ dx = _shiftVectorAlongAngl.dx,
144
+ dy = _shiftVectorAlongAngl.dy;
165
145
 
146
+ // This object is passed as argument to the "label" function prop
166
147
  var labelRenderProps = {
167
148
  x: props.center[0],
168
149
  y: props.center[1],
@@ -177,111 +158,135 @@
177
158
  dataIndex: index,
178
159
  style: functionProp(props.labelStyle, index)
179
160
  };
180
- return props.label && renderLabelElement(props.label, labelRenderProps);
161
+ return labelRenderProps;
181
162
  });
182
163
  }
164
+ function renderLabels(data, props) {
165
+ var label = props.label;
166
+ if (label) {
167
+ return makeLabelRenderProps(data, props).map(function (labelRenderProps, index) {
168
+ return /*#__PURE__*/React.createElement(ReactMinimalPieChartLabel, {
169
+ key: "label-" + (labelRenderProps.dataEntry.key || index),
170
+ renderLabel: label,
171
+ labelProps: labelRenderProps
172
+ });
173
+ });
174
+ }
175
+ }
183
176
 
184
- var partialCircle = function partialCircle(cx, cy, r, start, end) {
185
- var length = end - start;
186
- if (length === 0) return [];
187
- var fromX = r * Math.cos(start) + cx;
188
- var fromY = r * Math.sin(start) + cy;
189
- var toX = r * Math.cos(end) + cx;
190
- var toY = r * Math.sin(end) + cy;
191
- var large = Math.abs(length) <= Math.PI ? '0' : '1';
192
- var sweep = length < 0 ? '0' : '1';
193
- return [['M', fromX, fromY], ['A', r, r, 0, large, sweep, toX, toY]];
194
- };
177
+ function getDefaultExportFromCjs (x) {
178
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
179
+ }
180
+
181
+ var svgPartialCircle;
182
+ var hasRequiredSvgPartialCircle;
183
+
184
+ function requireSvgPartialCircle () {
185
+ if (hasRequiredSvgPartialCircle) return svgPartialCircle;
186
+ hasRequiredSvgPartialCircle = 1;
187
+
188
+ // from http://stackoverflow.com/a/18473154
189
+ var partialCircle = function partialCircle(cx, cy, r, start, end) {
190
+ var length = end - start;
191
+ if (length === 0) return [];
192
+ var fromX = r * Math.cos(start) + cx;
193
+ var fromY = r * Math.sin(start) + cy;
194
+ var toX = r * Math.cos(end) + cx;
195
+ var toY = r * Math.sin(end) + cy;
196
+ var large = Math.abs(length) <= Math.PI ? '0' : '1';
197
+ var sweep = length < 0 ? '0' : '1';
198
+ return [['M', fromX, fromY], ['A', r, r, 0, large, sweep, toX, toY]];
199
+ };
200
+ svgPartialCircle = partialCircle;
201
+ return svgPartialCircle;
202
+ }
195
203
 
196
- var svgPartialCircle = partialCircle;
204
+ var svgPartialCircleExports = requireSvgPartialCircle();
205
+ var partialCircle = /*@__PURE__*/getDefaultExportFromCjs(svgPartialCircleExports);
197
206
 
207
+ var _excluded = ["cx", "cy", "lengthAngle", "lineWidth", "radius", "shift", "reveal", "rounded", "startAngle", "title"];
198
208
  function makePathCommands(cx, cy, startAngle, lengthAngle, radius) {
199
209
  var patchedLengthAngle = valueBetween(lengthAngle, -359.999, 359.999);
200
- return svgPartialCircle(cx, cy, // center X and Y
210
+ return partialCircle(cx, cy,
211
+ // center X and Y
201
212
  radius, degreesToRadians(startAngle), degreesToRadians(startAngle + patchedLengthAngle)).map(function (command) {
202
213
  return command.join(' ');
203
214
  }).join(' ');
204
215
  }
205
216
  function ReactMinimalPieChartPath(_ref) {
206
217
  var cx = _ref.cx,
207
- cy = _ref.cy,
208
- lengthAngle = _ref.lengthAngle,
209
- lineWidth = _ref.lineWidth,
210
- radius = _ref.radius,
211
- _ref$shift = _ref.shift,
212
- shift = _ref$shift === void 0 ? 0 : _ref$shift,
213
- reveal = _ref.reveal,
214
- rounded = _ref.rounded,
215
- startAngle = _ref.startAngle,
216
- title = _ref.title,
217
- props = _objectWithoutPropertiesLoose(_ref, ["cx", "cy", "lengthAngle", "lineWidth", "radius", "shift", "reveal", "rounded", "startAngle", "title"]);
218
-
219
- var pathRadius = radius - lineWidth / 2; //@NOTE This shift might be rendered as a translation in future
220
-
218
+ cy = _ref.cy,
219
+ lengthAngle = _ref.lengthAngle,
220
+ lineWidth = _ref.lineWidth,
221
+ radius = _ref.radius,
222
+ _ref$shift = _ref.shift,
223
+ shift = _ref$shift === void 0 ? 0 : _ref$shift,
224
+ reveal = _ref.reveal,
225
+ rounded = _ref.rounded,
226
+ startAngle = _ref.startAngle,
227
+ title = _ref.title,
228
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
229
+ var pathRadius = radius - lineWidth / 2;
230
+ //@NOTE This shift might be rendered as a translation in future
221
231
  var _shiftVectorAlongAngl = shiftVectorAlongAngle(bisectorAngle(startAngle, lengthAngle), shift),
222
- dx = _shiftVectorAlongAngl.dx,
223
- dy = _shiftVectorAlongAngl.dy;
224
-
232
+ dx = _shiftVectorAlongAngl.dx,
233
+ dy = _shiftVectorAlongAngl.dy;
225
234
  var pathCommands = makePathCommands(cx + dx, cy + dy, startAngle, lengthAngle, pathRadius);
226
235
  var strokeDasharray;
227
- var strokeDashoffset; // Animate/hide paths with "stroke-dasharray" + "stroke-dashoffset"
228
- // https://css-tricks.com/svg-line-animation-works/
236
+ var strokeDashoffset;
229
237
 
238
+ // Animate/hide paths with "stroke-dasharray" + "stroke-dashoffset"
239
+ // https://css-tricks.com/svg-line-animation-works/
230
240
  if (isNumber(reveal)) {
231
241
  var pathLength = degreesToRadians(pathRadius) * lengthAngle;
232
242
  strokeDasharray = Math.abs(pathLength);
233
243
  strokeDashoffset = strokeDasharray - extractPercentage(strokeDasharray, reveal);
234
244
  }
235
-
236
- return /*#__PURE__*/React__default['default'].createElement("path", Object.assign({
245
+ return /*#__PURE__*/React.createElement("path", Object.assign({
237
246
  d: pathCommands,
238
247
  fill: "none",
239
248
  strokeWidth: lineWidth,
240
249
  strokeDasharray: strokeDasharray,
241
250
  strokeDashoffset: strokeDashoffset,
242
251
  strokeLinecap: rounded ? 'round' : undefined
243
- }, props), title && /*#__PURE__*/React__default['default'].createElement("title", null, title));
252
+ }, props), title && /*#__PURE__*/React.createElement("title", null, title));
244
253
  }
245
254
 
246
255
  function combineSegmentTransitionsStyle(duration, easing, customStyle) {
247
256
  // Merge chart's animation CSS transition with "transition" found to customStyle
248
257
  var transition = "stroke-dashoffset " + duration + "ms " + easing;
249
-
250
258
  if (customStyle && customStyle.transition) {
251
259
  transition = transition + "," + customStyle.transition;
252
260
  }
253
-
254
261
  return {
255
262
  transition: transition
256
263
  };
257
264
  }
258
-
259
- function getRevealValue(props) {
265
+ function getRevealValue(_ref) {
266
+ var reveal = _ref.reveal,
267
+ animate = _ref.animate;
260
268
  //@NOTE When animation is on, chart has to be fully revealed when reveal is not set
261
- if (props.animate && !isNumber(props.reveal)) {
269
+ if (animate && !isNumber(reveal)) {
262
270
  return 100;
263
271
  }
264
-
265
- return props.reveal;
272
+ return reveal;
266
273
  }
267
-
268
274
  function makeEventHandler(eventHandler, payload) {
269
275
  return eventHandler && function (e) {
270
276
  eventHandler(e, payload);
271
277
  };
272
278
  }
273
-
274
279
  function renderSegments(data, props, revealOverride) {
275
280
  // @NOTE this should go in Path component. Here for performance reasons
276
281
  var reveal = revealOverride != null ? revealOverride : getRevealValue(props);
277
282
  var radius = props.radius,
278
- _props$center = props.center,
279
- cx = _props$center[0],
280
- cy = _props$center[1];
283
+ _props$center = props.center,
284
+ cx = _props$center[0],
285
+ cy = _props$center[1];
281
286
  var lineWidth = extractPercentage(radius, props.lineWidth);
282
287
  var paths = data.map(function (dataEntry, index) {
283
288
  var segmentsStyle = functionProp(props.segmentsStyle, index);
284
- return /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartPath, {
289
+ return /*#__PURE__*/React.createElement(ReactMinimalPieChartPath, {
285
290
  cx: cx,
286
291
  cy: cy,
287
292
  key: dataEntry.key || index,
@@ -304,9 +309,8 @@
304
309
  onMouseOut: makeEventHandler(props.onMouseOut, index)
305
310
  });
306
311
  });
307
-
308
312
  if (props.background) {
309
- paths.unshift( /*#__PURE__*/React__default['default'].createElement(ReactMinimalPieChartPath, {
313
+ paths.unshift(/*#__PURE__*/React.createElement(ReactMinimalPieChartPath, {
310
314
  cx: cx,
311
315
  cy: cy,
312
316
  key: "bg",
@@ -318,7 +322,6 @@
318
322
  stroke: props.background
319
323
  }));
320
324
  }
321
-
322
325
  return paths;
323
326
  }
324
327
 
@@ -335,46 +338,42 @@
335
338
  startAngle: 0,
336
339
  viewBoxSize: [100, 100]
337
340
  };
338
- function ReactMinimalPieChart(props) {
341
+ function makePropsWithDefaults(props) {
342
+ var result = Object.assign({}, defaultProps, props);
343
+
344
+ // @NOTE Object.assign doesn't default properties with undefined value (like React defaultProps does)
345
+ var key;
346
+ for (key in defaultProps) {
347
+ if (props[key] === undefined) {
348
+ // @ts-expect-error: TS cannot ensure we're assigning the expected props accross abjects
349
+ result[key] = defaultProps[key];
350
+ }
351
+ }
352
+ return result;
353
+ }
354
+ function ReactMinimalPieChart(originalProps) {
355
+ var props = makePropsWithDefaults(originalProps);
339
356
  var _useState = React.useState(props.animate ? 0 : null),
340
- revealOverride = _useState[0],
341
- setRevealOverride = _useState[1];
342
-
357
+ revealOverride = _useState[0],
358
+ setRevealOverride = _useState[1];
343
359
  React.useEffect(function () {
344
360
  if (props.animate) {
345
- return startInitialAnimation();
346
- }
347
-
348
- function startInitialAnimation() {
349
- var animationTimerId;
350
- var animationRAFId;
351
- animationTimerId = setTimeout(function () {
352
- animationTimerId = null;
353
- animationRAFId = requestAnimationFrame(function () {
354
- animationRAFId = null;
355
- setRevealOverride(null); // Start animation
356
- });
357
- });
358
- return function () {
359
- animationTimerId && clearTimeout(animationTimerId);
360
- animationRAFId && cancelAnimationFrame(animationRAFId);
361
- };
361
+ // Trigger initial animation
362
+ setRevealOverride(null);
362
363
  }
363
364
  }, []);
364
365
  var extendedData = extendData(props);
365
- return /*#__PURE__*/React__default['default'].createElement("svg", {
366
+ return /*#__PURE__*/React.createElement("svg", {
366
367
  viewBox: "0 0 " + props.viewBoxSize[0] + " " + props.viewBoxSize[1],
367
368
  width: "100%",
368
369
  height: "100%",
369
370
  className: props.className,
370
371
  style: props.style
371
- }, renderSegments(extendedData, props, revealOverride), props.label && renderLabels(extendedData, props), props.children);
372
+ }, renderSegments(extendedData, props, revealOverride), renderLabels(extendedData, props), props.children);
372
373
  }
373
- ReactMinimalPieChart.defaultProps = defaultProps;
374
374
 
375
375
  exports.PieChart = ReactMinimalPieChart;
376
+ exports.pieChartDefaultProps = defaultProps;
376
377
 
377
- Object.defineProperty(exports, '__esModule', { value: true });
378
-
379
- })));
378
+ }));
380
379
  //# sourceMappingURL=index.js.map