gifted-charts-core 0.1.11 → 0.1.12

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.1.11",
3
+ "version": "0.1.12",
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": [
@@ -469,6 +469,8 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
469
469
  if (animateOnDataChange && animations) {
470
470
  animations.forEach((item, index) => {
471
471
  item.addListener((val) => {
472
+ if (typeof data[index] === 'undefined') { return; }
473
+
472
474
  const temp = data[index]?.value ?? 0
473
475
  data[index].value = val?.value ?? 0
474
476
  let pp = ''
@@ -17,14 +17,18 @@ var __read = (this && this.__read) || function (o, n) {
17
17
  import { useEffect, useState } from 'react';
18
18
  import { getTextSizeForPieLabels } from '../utils';
19
19
  export var usePieChart = function (props) {
20
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u;
20
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v;
21
21
  var radius = (_a = props.radius) !== null && _a !== void 0 ? _a : 120;
22
22
  var extraRadiusForFocused = (_b = props.extraRadiusForFocused) !== null && _b !== void 0 ? _b : (((_c = props.focusOnPress) !== null && _c !== void 0 ? _c : props.sectionAutoFocus) ? radius / 10 : 0);
23
23
  var pi = props.semiCircle ? Math.PI / 2 : Math.PI;
24
- var _v = __read(useState(-1), 2), selectedIndex = _v[0], setSelectedIndex = _v[1]; // at the start, nothing is selected
24
+ var _w = __read(useState((_d = props.focusedPieIndex) !== null && _d !== void 0 ? _d : -1), 2), selectedIndex = _w[0], setSelectedIndex = _w[1]; // at the start, nothing is selected
25
25
  // because we're going to use a useEffect, we need startAngle and total to be state variables
26
- var _w = __read(useState((_d = props.initialAngle) !== null && _d !== void 0 ? _d : (props.semiCircle ? -pi : 0)), 2), startAngle = _w[0], setStartAngle = _w[1];
27
- var _x = __read(useState(0), 2), total = _x[0], setTotal = _x[1];
26
+ var _x = __read(useState((_e = props.initialAngle) !== null && _e !== void 0 ? _e : (props.semiCircle ? -pi : 0)), 2), startAngle = _x[0], setStartAngle = _x[1];
27
+ var _y = __read(useState(0), 2), total = _y[0], setTotal = _y[1];
28
+ useEffect(function () {
29
+ var _a;
30
+ setSelectedIndex((_a = props.focusedPieIndex) !== null && _a !== void 0 ? _a : -1);
31
+ }, [props.focusedPieIndex]);
28
32
  useEffect(function () {
29
33
  var _a;
30
34
  // Update the total, this could be use to replace the forEach : const newTotal = props.data.reduce((acc, item) => acc + item.value, 0);
@@ -63,30 +67,30 @@ export var usePieChart = function (props) {
63
67
  }
64
68
  }
65
69
  }, [selectedIndex]);
66
- var pro = props.pro, data = props.data, donut = props.donut, isThreeD = props.isThreeD, semiCircle = props.semiCircle, _y = props.inwardExtraLengthForFocused, inwardExtraLengthForFocused = _y === void 0 ? 0 : _y, _z = props.isAnimated, isAnimated = _z === void 0 ? false : _z, edgesRadius = props.edgesRadius;
67
- var endAngle = (_e = props.endAngle) !== null && _e !== void 0 ? _e : startAngle + Math.PI * (semiCircle ? 1 : 2);
70
+ var pro = props.pro, data = props.data, donut = props.donut, isThreeD = props.isThreeD, semiCircle = props.semiCircle, _z = props.inwardExtraLengthForFocused, inwardExtraLengthForFocused = _z === void 0 ? 0 : _z, _0 = props.isAnimated, isAnimated = _0 === void 0 ? false : _0, edgesRadius = props.edgesRadius;
71
+ var endAngle = (_f = props.endAngle) !== null && _f !== void 0 ? _f : startAngle + Math.PI * (semiCircle ? 1 : 2);
68
72
  var canvasWidth = radius * 2;
69
73
  var canvasHeight = isThreeD ? radius * 2.3 : radius * 2;
70
- var strokeWidth = (_f = props.strokeWidth) !== null && _f !== void 0 ? _f : 0;
71
- var innerRadius = (_g = props.innerRadius) !== null && _g !== void 0 ? _g : radius / 2.5;
72
- var innerCircleColor = (_j = (_h = props.innerCircleColor) !== null && _h !== void 0 ? _h : props.backgroundColor) !== null && _j !== void 0 ? _j : 'white';
73
- var innerCircleBorderWidth = (_k = props.innerCircleBorderWidth) !== null && _k !== void 0 ? _k : (props.innerCircleBorderColor ? strokeWidth || 2 : 0);
74
- var innerCircleBorderColor = (_l = props.innerCircleBorderColor) !== null && _l !== void 0 ? _l : 'lightgray';
75
- var shiftInnerCenterX = (_m = props.shiftInnerCenterX) !== null && _m !== void 0 ? _m : 0;
76
- var shiftInnerCenterY = (_o = props.shiftInnerCenterY) !== null && _o !== void 0 ? _o : 0;
77
- var tiltAngle = (_p = props.tiltAngle) !== null && _p !== void 0 ? _p : '55deg';
74
+ var strokeWidth = (_g = props.strokeWidth) !== null && _g !== void 0 ? _g : 0;
75
+ var innerRadius = (_h = props.innerRadius) !== null && _h !== void 0 ? _h : radius / 2.5;
76
+ var innerCircleColor = (_k = (_j = props.innerCircleColor) !== null && _j !== void 0 ? _j : props.backgroundColor) !== null && _k !== void 0 ? _k : 'white';
77
+ var innerCircleBorderWidth = (_l = props.innerCircleBorderWidth) !== null && _l !== void 0 ? _l : (props.innerCircleBorderColor ? strokeWidth || 2 : 0);
78
+ var innerCircleBorderColor = (_m = props.innerCircleBorderColor) !== null && _m !== void 0 ? _m : 'lightgray';
79
+ var shiftInnerCenterX = (_o = props.shiftInnerCenterX) !== null && _o !== void 0 ? _o : 0;
80
+ var shiftInnerCenterY = (_p = props.shiftInnerCenterY) !== null && _p !== void 0 ? _p : 0;
81
+ var tiltAngle = (_q = props.tiltAngle) !== null && _q !== void 0 ? _q : '55deg';
78
82
  var isDataShifted = false;
79
83
  data.forEach(function (item) {
80
84
  if (item.shiftX || item.shiftY) {
81
85
  isDataShifted = true;
82
86
  }
83
87
  });
84
- var textSize = getTextSizeForPieLabels((_q = props.textSize) !== null && _q !== void 0 ? _q : 0, radius);
85
- var paddingHorizontal = ((_r = props.paddingHorizontal) !== null && _r !== void 0 ? _r : props.labelsPosition === 'onBorder')
86
- ? ((_s = props.textBackgroundRadius) !== null && _s !== void 0 ? _s : textSize) * 2 + 6
88
+ var textSize = getTextSizeForPieLabels((_r = props.textSize) !== null && _r !== void 0 ? _r : 0, radius);
89
+ var paddingHorizontal = ((_s = props.paddingHorizontal) !== null && _s !== void 0 ? _s : props.labelsPosition === 'onBorder')
90
+ ? ((_t = props.textBackgroundRadius) !== null && _t !== void 0 ? _t : textSize) * 2 + 6
87
91
  : 0;
88
- var paddingVertical = ((_t = props.paddingVertical) !== null && _t !== void 0 ? _t : props.labelsPosition === 'onBorder')
89
- ? ((_u = props.textBackgroundRadius) !== null && _u !== void 0 ? _u : textSize) * 2 + 6
92
+ var paddingVertical = ((_u = props.paddingVertical) !== null && _u !== void 0 ? _u : props.labelsPosition === 'onBorder')
93
+ ? ((_v = props.textBackgroundRadius) !== null && _v !== void 0 ? _v : textSize) * 2 + 6
90
94
  : 0;
91
95
  return {
92
96
  radius: radius,
@@ -44,13 +44,19 @@ export const usePieChart = (props: IPieChartPropsType): IusePieChart => {
44
44
  props.extraRadiusForFocused ??
45
45
  (props.focusOnPress ?? props.sectionAutoFocus ? radius / 10 : 0)
46
46
  const pi = props.semiCircle ? Math.PI / 2 : Math.PI
47
- const [selectedIndex, setSelectedIndex] = useState(-1) // at the start, nothing is selected
47
+ const [selectedIndex, setSelectedIndex] = useState(
48
+ props.focusedPieIndex ?? -1
49
+ ) // at the start, nothing is selected
48
50
  // because we're going to use a useEffect, we need startAngle and total to be state variables
49
51
  const [startAngle, setStartAngle] = useState(
50
52
  props.initialAngle ?? (props.semiCircle ? -pi : 0)
51
53
  )
52
54
  const [total, setTotal] = useState(0)
53
55
 
56
+ useEffect(() => {
57
+ setSelectedIndex(props.focusedPieIndex ?? -1)
58
+ }, [props.focusedPieIndex])
59
+
54
60
  useEffect(() => {
55
61
  // Update the total, this could be use to replace the forEach : const newTotal = props.data.reduce((acc, item) => acc + item.value, 0);
56
62
  let newTotal = 0
@@ -58,6 +58,7 @@ export interface PieChartPropsType {
58
58
  edgesRadius?: number;
59
59
  isAnimated?: boolean;
60
60
  animationDuration?: number;
61
+ focusedPieIndex?: number;
61
62
  }
62
63
  export interface pieDataItem {
63
64
  value: number;
@@ -61,6 +61,7 @@ export interface PieChartPropsType {
61
61
  edgesRadius?: number
62
62
  isAnimated?: boolean
63
63
  animationDuration?: number
64
+ focusedPieIndex?: number
64
65
  }
65
66
  export interface pieDataItem {
66
67
  value: number
@@ -544,7 +544,8 @@ export var getAxesAndRulesProps = function (props, stepValue, negativeStepValue,
544
544
  formatYLabel: props.formatYLabel
545
545
  };
546
546
  if (((_c = props.secondaryYAxis) !== null && _c !== void 0 ? _c : (_d = props.lineConfig) === null || _d === void 0 ? void 0 : _d.isSecondary) &&
547
- maxValue !== undefined) {
547
+ maxValue !== undefined &&
548
+ secondaryYAxis.maxValue === undefined) {
548
549
  axesAndRulesProps.secondaryYAxis = __assign(__assign({}, secondaryYAxis), { maxValue: maxValue });
549
550
  }
550
551
  return axesAndRulesProps;
@@ -743,7 +743,8 @@ export const getAxesAndRulesProps = (
743
743
  }
744
744
  if (
745
745
  (props.secondaryYAxis ?? props.lineConfig?.isSecondary) &&
746
- maxValue !== undefined
746
+ maxValue !== undefined &&
747
+ secondaryYAxis.maxValue === undefined
747
748
  ) {
748
749
  axesAndRulesProps.secondaryYAxis = { ...secondaryYAxis, maxValue }
749
750
  }