gifted-charts-core 0.0.49 → 0.0.50

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gifted-charts-core",
3
- "version": "0.0.49",
3
+ "version": "0.0.50",
4
4
  "description": "Mathematical and logical utilities used by react-gifted-charts and react-native-gifted-charts",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -10,7 +10,6 @@ interface IusePiePro {
10
10
  initial: string;
11
11
  dInitial: string[];
12
12
  dFinal: string[];
13
- isAnimating?: boolean;
14
13
  getStartCaps: (index: number, item: pieDataItem) => string;
15
14
  getEndCaps: (index: number, item: pieDataItem) => string;
16
15
  getTextCoordinates: (index: number, labelPos?: LabelsPosition) => {
@@ -1,3 +1,28 @@
1
+ var __read = (this && this.__read) || function (o, n) {
2
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
3
+ if (!m) return o;
4
+ var i = m.call(o), r, ar = [], e;
5
+ try {
6
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
+ }
8
+ catch (error) { e = { error: error }; }
9
+ finally {
10
+ try {
11
+ if (r && !r.done && (m = i["return"])) m.call(i);
12
+ }
13
+ finally { if (e) throw e.error; }
14
+ }
15
+ return ar;
16
+ };
17
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
+ if (ar || !(i in from)) {
20
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
+ ar[i] = from[i];
22
+ }
23
+ }
24
+ return to.concat(ar || Array.prototype.slice.call(from));
25
+ };
1
26
  import { defaultAnimationDuration } from '../utils/constants';
2
27
  export var usePiePro = function (props) {
3
28
  var _a, _b;
@@ -5,7 +30,7 @@ export var usePiePro = function (props) {
5
30
  var endAngle = (_a = props.endAngle) !== null && _a !== void 0 ? _a : startAngle + Math.PI * (semiCircle ? 1 : 2);
6
31
  var total = data.reduce(function (acc, item) { return acc + item.value; }, 0);
7
32
  var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
8
- var endAngleLocal = 0;
33
+ // let endAngleLocal = 0
9
34
  var addValues = function (index) {
10
35
  if (index < 0)
11
36
  return 0;
@@ -21,7 +46,7 @@ export var usePiePro = function (props) {
21
46
  : 'mid';
22
47
  var getCoordinates = function (index, additionalValue, addInOnlyStart, addInOnlyEnd) {
23
48
  var addedValue = addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
24
- var angle = (addedValue / total) * endAngleLocal + startAngle;
49
+ var angle = (addedValue / total) * endAngle + startAngle;
25
50
  var startInnerX = radius + Math.cos(angle) * innerRadius;
26
51
  var startInnerY = radius - Math.sin(angle) * innerRadius;
27
52
  var startOuterX = radius + Math.cos(angle) * radius;
@@ -29,7 +54,7 @@ export var usePiePro = function (props) {
29
54
  var value = addValues(index - 1) +
30
55
  data[index].value +
31
56
  (addInOnlyStart ? 0 : additionalValue !== null && additionalValue !== void 0 ? additionalValue : 0);
32
- angle = (value / total) * endAngleLocal + startAngle;
57
+ angle = (value / total) * endAngle + startAngle;
33
58
  var endOuterX = radius + Math.cos(angle) * radius;
34
59
  var endOuterY = radius - Math.sin(angle) * radius;
35
60
  var endInnerX = radius + Math.cos(angle) * innerRadius;
@@ -47,7 +72,7 @@ export var usePiePro = function (props) {
47
72
  };
48
73
  var getTextCoordinates = function (index, labelPos) {
49
74
  var value = addValues(index - 1) + data[index].value / 2;
50
- var angle = (value / total) * endAngleLocal + startAngle;
75
+ var angle = (value / total) * endAngle + startAngle;
51
76
  var labelPosition = labelPos || labelsPosition;
52
77
  var x = radius +
53
78
  Math.cos(angle) *
@@ -128,12 +153,15 @@ export var usePiePro = function (props) {
128
153
  var path = "M".concat(endInnerX, ",").concat(endInnerY, " A").concat(edgeRadius, ",").concat(edgeRadius, " 0 0 1 ").concat(endOuterX, ",").concat(endOuterY);
129
154
  return path;
130
155
  };
131
- var dInitial = data.map(function (item, index) {
156
+ var dataForInitialPath = isAnimated
157
+ ? data
158
+ : __spreadArray(__spreadArray([], __read(data), false), [{ value: total * 100 }], false);
159
+ var dataForFinalPath = isAnimated ? data : __spreadArray(__spreadArray([], __read(data), false), [{ value: 0 }], false);
160
+ var dInitial = dataForInitialPath.map(function (item, index) {
132
161
  return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
133
162
  });
134
- endAngleLocal = endAngle;
135
163
  initial = '';
136
- var dFinal = data.map(function (item, index) {
164
+ var dFinal = dataForFinalPath.map(function (item, index) {
137
165
  return "".concat(initial || getInitial(item), " ").concat(donut ? getDonutPath(index, item) : getPath(index));
138
166
  });
139
167
  return {
@@ -1,4 +1,3 @@
1
- import { useEffect, useState } from 'react'
2
1
  import { defaultAnimationDuration } from '../utils/constants'
3
2
  import { PieChartPropsType, pieDataItem } from './types'
4
3
  import { LabelsPosition } from '../utils/types'
@@ -13,7 +12,6 @@ interface IusePiePro {
13
12
  initial: string
14
13
  dInitial: string[]
15
14
  dFinal: string[]
16
- isAnimating?: boolean
17
15
  getStartCaps: (index: number, item: pieDataItem) => string
18
16
  getEndCaps: (index: number, item: pieDataItem) => string
19
17
  getTextCoordinates: (
@@ -39,7 +37,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
39
37
  const total = data.reduce((acc, item) => acc + item.value, 0)
40
38
  const animationDuration = props.animationDuration ?? defaultAnimationDuration
41
39
 
42
- let endAngleLocal = 0
40
+ // let endAngleLocal = 0
43
41
 
44
42
  const addValues = (index: number) => {
45
43
  if (index < 0) return 0
@@ -61,7 +59,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
61
59
  ) => {
62
60
  const addedValue =
63
61
  addValues(index - 1) + (addInOnlyEnd ? 0 : additionalValue ?? 0)
64
- let angle = (addedValue / total) * endAngleLocal + startAngle
62
+ let angle = (addedValue / total) * endAngle + startAngle
65
63
  const startInnerX = radius + Math.cos(angle) * innerRadius
66
64
  const startInnerY = radius - Math.sin(angle) * innerRadius
67
65
  const startOuterX = radius + Math.cos(angle) * radius
@@ -71,7 +69,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
71
69
  addValues(index - 1) +
72
70
  data[index].value +
73
71
  (addInOnlyStart ? 0 : additionalValue ?? 0)
74
- angle = (value / total) * endAngleLocal + startAngle
72
+ angle = (value / total) * endAngle + startAngle
75
73
 
76
74
  const endOuterX = radius + Math.cos(angle) * radius
77
75
  const endOuterY = radius - Math.sin(angle) * radius
@@ -93,7 +91,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
93
91
 
94
92
  const getTextCoordinates = (index: number, labelPos?: LabelsPosition) => {
95
93
  const value = addValues(index - 1) + data[index].value / 2
96
- const angle = (value / total) * endAngleLocal + startAngle
94
+ const angle = (value / total) * endAngle + startAngle
97
95
 
98
96
  const labelPosition: LabelsPosition = labelPos || labelsPosition
99
97
 
@@ -219,16 +217,20 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
219
217
  return path
220
218
  }
221
219
 
222
- const dInitial = data.map(
220
+ const dataForInitialPath = isAnimated
221
+ ? data
222
+ : [...data, { value: total * 100 }]
223
+ const dataForFinalPath = isAnimated ? data : [...data, { value: 0 }]
224
+
225
+ const dInitial = dataForInitialPath.map(
223
226
  (item, index) =>
224
227
  `${initial || getInitial(item)} ${
225
228
  donut ? getDonutPath(index, item) : getPath(index)
226
229
  }`
227
230
  )
228
231
 
229
- endAngleLocal = endAngle
230
232
  initial = ''
231
- const dFinal = data.map(
233
+ const dFinal = dataForFinalPath.map(
232
234
  (item, index) =>
233
235
  `${initial || getInitial(item)} ${
234
236
  donut ? getDonutPath(index, item) : getPath(index)