react-native-gifted-charts 1.4.69 → 1.4.71

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,21 +1,5 @@
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
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
18
- import { Fragment, useState } from 'react';
2
+ import { Fragment } from 'react';
19
3
  import { styles } from '../../../BarChart/styles';
20
4
  import { TouchableOpacity, View } from 'react-native';
21
5
  import { getXForLineInBar, getYForLineInBar } from 'gifted-charts-core';
@@ -23,8 +7,7 @@ import { Rect, Text as CanvasText, Circle, ForeignObject, } from 'react-native-s
23
7
  import { isWebApp } from '../../../utils';
24
8
  export var renderDataPoints = function (props) {
25
9
  var data = props.data, lineConfig = props.lineConfig, barWidth = props.barWidth, containerHeight = props.containerHeight, maxValue = props.maxValue, firstBarWidth = props.firstBarWidth, yAxisLabelWidth = props.yAxisLabelWidth, spacing = props.spacing, selectedIndex = props.selectedIndex, yAxisOffset = props.yAxisOffset, opacity = props.opacity, svgHeight = props.svgHeight, totalWidth = props.totalWidth;
26
- var focusEnabled = lineConfig.focusEnabled, dataPointLabelComponent = lineConfig.dataPointLabelComponent, showDataPointLabelOnFocus = lineConfig.showDataPointLabelOnFocus, focusedDataPointIndex = lineConfig.focusedDataPointIndex;
27
- var _a = __read(useState(focusedDataPointIndex !== null && focusedDataPointIndex !== void 0 ? focusedDataPointIndex : -1), 2), selectedDataPointIndex = _a[0], setSelectedDataPointIndex = _a[1];
10
+ var focusEnabled = lineConfig.focusEnabled, dataPointLabelComponent = lineConfig.dataPointLabelComponent, showDataPointLabelOnFocus = lineConfig.showDataPointLabelOnFocus, focusedDataPointIndex = lineConfig.focusedDataPointIndex, setFocusedDataPointIndex = lineConfig.setFocusedDataPointIndex;
28
11
  return (_jsxs(_Fragment, { children: [data.map(function (item, index) {
29
12
  var _a, _b, _c;
30
13
  if (index < lineConfig.startIndex ||
@@ -34,10 +17,10 @@ export var renderDataPoints = function (props) {
34
17
  }
35
18
  var currentBarWidth = item.barWidth || barWidth || 30;
36
19
  var customDataPoint = item.customDataPoint || lineConfig.customDataPoint;
37
- var dataPointColor = lineConfig.focusEnabled && index === selectedDataPointIndex
20
+ var dataPointColor = lineConfig.focusEnabled && index === focusedDataPointIndex
38
21
  ? lineConfig.focusedDataPointColor
39
22
  : lineConfig.dataPointsColor;
40
- var dataPointRadius = lineConfig.focusEnabled && index === selectedDataPointIndex
23
+ var dataPointRadius = lineConfig.focusEnabled && index === focusedDataPointIndex
41
24
  ? lineConfig.focusedDataPointRadius
42
25
  : lineConfig.dataPointsRadius;
43
26
  var value = (_a = item.value) !== null && _a !== void 0 ? _a : item.stacks.reduce(function (total, item) { return total + item.value; }, 0);
@@ -57,20 +40,20 @@ export var renderDataPoints = function (props) {
57
40
  },
58
41
  ], onPress: function () {
59
42
  if (focusEnabled)
60
- setSelectedDataPointIndex(index);
43
+ setFocusedDataPointIndex(index);
61
44
  }, children: customDataPoint(item, index) }, index + '.' + value + 'custom'));
62
45
  }
63
46
  if (lineConfig.dataPointsShape === 'rectangular') {
64
47
  return (_jsxs(Fragment, { children: [_jsx(Rect, { x: x, y: y - lineConfig.dataPointsHeight / 2, width: lineConfig.dataPointsWidth, height: lineConfig.dataPointsHeight, fill: dataPointColor, opacity: opacity, onPress: function () {
65
48
  if (focusEnabled)
66
- setSelectedDataPointIndex(index);
49
+ setFocusedDataPointIndex(index);
67
50
  } }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, opacity: opacity, fontSize: item.textFontSize || lineConfig.textFontSize, x: x + (item.textShiftX || lineConfig.textShiftX || 0), y: y -
68
51
  lineConfig.dataPointsHeight / 2 +
69
52
  (item.textShiftY || lineConfig.textShiftY || 0), children: item.dataPointText }))] }, index + '.' + value + 'rect'));
70
53
  }
71
54
  return (_jsxs(Fragment, { children: [_jsx(Circle, { cx: x, cy: y, r: dataPointRadius, fill: dataPointColor, opacity: opacity, onPress: function () {
72
55
  if (focusEnabled)
73
- setSelectedDataPointIndex(index);
56
+ setFocusedDataPointIndex(index);
74
57
  } }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, opacity: opacity, fontSize: item.textFontSize || lineConfig.textFontSize, x: x + (item.textShiftX || lineConfig.textShiftX || 0), y: y -
75
58
  lineConfig.dataPointsHeight / 2 +
76
59
  (item.textShiftY || lineConfig.textShiftY || 0), children: item.dataPointText }))] }, index + '.' + value + 'circ'));
@@ -88,12 +71,12 @@ export var renderDataPoints = function (props) {
88
71
  var y = getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset);
89
72
  if (isWebApp)
90
73
  return (_jsx(ForeignObject, { height: svgHeight, width: totalWidth, x: x - 12, y: y - 24, children: showDataPointLabelOnFocus
91
- ? selectedDataPointIndex === index
74
+ ? focusedDataPointIndex === index
92
75
  ? dataPointLabelComponent === null || dataPointLabelComponent === void 0 ? void 0 : dataPointLabelComponent(item, index)
93
76
  : null
94
77
  : dataPointLabelComponent === null || dataPointLabelComponent === void 0 ? void 0 : dataPointLabelComponent(item, index) }, index + '.' + value + 'label'));
95
78
  return (_jsx(View, { style: { top: y - 24, left: x - 12, position: 'absolute' }, children: showDataPointLabelOnFocus
96
- ? selectedDataPointIndex === index
79
+ ? focusedDataPointIndex === index
97
80
  ? dataPointLabelComponent === null || dataPointLabelComponent === void 0 ? void 0 : dataPointLabelComponent(item, index)
98
81
  : null
99
82
  : dataPointLabelComponent === null || dataPointLabelComponent === void 0 ? void 0 : dataPointLabelComponent(item, index) }, index + '.' + value + 'label'));
@@ -18,17 +18,18 @@ var RenderVerticalLines = function (props) {
18
18
  var showVerticalLines = props.showVerticalLines, // this is the value passed by user (note that it's not the effective value that is computed by traversing through the data array and finding any item for which showVerticalLines is true)
19
19
  verticalLinesAr = props.verticalLinesAr, verticalLinesSpacing = props.verticalLinesSpacing, spacing = props.spacing, initialSpacing = props.initialSpacing, verticalLinesZIndex = props.verticalLinesZIndex, verticalLinesHeight = props.verticalLinesHeight, verticalLinesThickness = props.verticalLinesThickness, verticalLinesColor = props.verticalLinesColor, verticalLinesStrokeDashArray = props.verticalLinesStrokeDashArray, verticalLinesShift = props.verticalLinesShift, verticalLinesUptoDataPoint = props.verticalLinesUptoDataPoint, verticalLinesStrokeLinecap = props.verticalLinesStrokeLinecap, xAxisThickness = props.xAxisThickness, labelsExtraHeight = props.labelsExtraHeight, containerHeight = props.containerHeight, data = props.data, stackData = props.stackData, barWidth = props.barWidth, maxValue = props.maxValue, chartType = props.chartType, containerHeightIncludingBelowXAxis = props.containerHeightIncludingBelowXAxis, totalWidth = props.totalWidth, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift;
20
20
  var getHeightOfVerticalLine = function (index) {
21
+ var _a, _b, _c, _d, _e;
21
22
  if (verticalLinesUptoDataPoint) {
22
23
  if (index < data.length) {
23
24
  return ((data[index].value * containerHeight) / maxValue - xAxisThickness);
24
25
  }
25
26
  else {
26
- return verticalLinesHeight !== null && verticalLinesHeight !== void 0 ? verticalLinesHeight : 0;
27
+ return (_c = (_b = (_a = data === null || data === void 0 ? void 0 : data[index]) === null || _a === void 0 ? void 0 : _a.verticalLineHeight) !== null && _b !== void 0 ? _b : verticalLinesHeight) !== null && _c !== void 0 ? _c : 0;
27
28
  }
28
29
  }
29
30
  else {
30
- return (verticalLinesHeight ||
31
- containerHeightIncludingBelowXAxis - xAxisThickness);
31
+ return ((_e = (_d = data === null || data === void 0 ? void 0 : data[index]) === null || _d === void 0 ? void 0 : _d.verticalLineHeight) !== null && _e !== void 0 ? _e : (verticalLinesHeight ||
32
+ containerHeightIncludingBelowXAxis - xAxisThickness));
32
33
  }
33
34
  };
34
35
  var extendedContainerHeight = containerHeight + 10 + labelsExtraHeight;
@@ -101,7 +102,7 @@ var RenderVerticalLines = function (props) {
101
102
  ? ((_a = item.verticalLineShift) !== null && _a !== void 0 ? _a : verticalLinesShift)
102
103
  : verticalLinesShift;
103
104
  var x = verticalLinesShiftLocal +
104
- 1 +
105
+ 2 +
105
106
  (chartType === chartTypes.BAR // This logic exists because we have renderSpecificVerticalLines in Line Charts which I would love to deprecate at the earliest, because that functionality gets handled here elegantly
106
107
  ? totalSpacing - 1
107
108
  : verticalLinesSpacing
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ type RotatablePieProps = {
3
+ initialAngle: number;
4
+ size: number;
5
+ children: React.ReactNode;
6
+ onAngleChange?: (angle: number) => void;
7
+ };
8
+ export declare function RotatablePie({ initialAngle, size, children, onAngleChange, }: RotatablePieProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
@@ -0,0 +1,132 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __read = (this && this.__read) || function (o, n) {
13
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
14
+ if (!m) return o;
15
+ var i = m.call(o), r, ar = [], e;
16
+ try {
17
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
+ }
19
+ catch (error) { e = { error: error }; }
20
+ finally {
21
+ try {
22
+ if (r && !r.done && (m = i["return"])) m.call(i);
23
+ }
24
+ finally { if (e) throw e.error; }
25
+ }
26
+ return ar;
27
+ };
28
+ import { jsx as _jsx } from "react/jsx-runtime";
29
+ import { useRef, useState, useEffect } from 'react';
30
+ import { View, PanResponder, Animated, StyleSheet, } from 'react-native';
31
+ // ----------------------------------------
32
+ // Ultra-smooth animation helper
33
+ // Throttles to ~60 FPS AND applies low-pass filtering
34
+ // ----------------------------------------
35
+ function createSmoothUpdater(animatedValue, smoothing, fps) {
36
+ if (smoothing === void 0) { smoothing = 0.15; }
37
+ if (fps === void 0) { fps = 60; }
38
+ var frameDelay = 1000 / fps;
39
+ var lastTime = 0;
40
+ var filtered = 0; // low-pass output
41
+ var timeout = null;
42
+ return function (target) {
43
+ var now = Date.now();
44
+ var diff = now - lastTime;
45
+ var update = function () {
46
+ // low-pass filter (natural smoothing)
47
+ filtered = filtered * (1 - smoothing) + target * smoothing;
48
+ animatedValue.setValue(filtered);
49
+ };
50
+ if (diff >= frameDelay) {
51
+ lastTime = now;
52
+ update();
53
+ }
54
+ else {
55
+ clearTimeout(timeout);
56
+ timeout = setTimeout(function () {
57
+ lastTime = Date.now();
58
+ update();
59
+ }, frameDelay - diff);
60
+ }
61
+ };
62
+ }
63
+ export function RotatablePie(_a) {
64
+ var initialAngle = _a.initialAngle, size = _a.size, children = _a.children, onAngleChange = _a.onAngleChange;
65
+ var angle = useRef(new Animated.Value(initialAngle)).current;
66
+ var _b = __read(useState({ x: size / 2, y: size / 2 }), 2), center = _b[0], setCenter = _b[1];
67
+ var gestureStartAngle = useRef(0);
68
+ var startAngle = useRef(initialAngle);
69
+ // Create smooth updater ONCE
70
+ var smoothSetAngle = useRef(createSmoothUpdater(angle, 0.15, 60)).current;
71
+ useEffect(function () {
72
+ angle.setValue(initialAngle);
73
+ startAngle.current = initialAngle;
74
+ }, [initialAngle, angle]);
75
+ useEffect(function () {
76
+ var id = angle.addListener(function (_a) {
77
+ var value = _a.value;
78
+ return onAngleChange === null || onAngleChange === void 0 ? void 0 : onAngleChange(value);
79
+ });
80
+ return function () { return angle.removeListener(id); };
81
+ }, [angle, onAngleChange]);
82
+ var onLayout = function (e) {
83
+ var _a = e.nativeEvent.layout, width = _a.width, height = _a.height;
84
+ setCenter({ x: width / 2, y: height / 2 });
85
+ };
86
+ var getTouchAngleDeg = function (x, y) {
87
+ var dx = x - center.x;
88
+ var dy = y - center.y;
89
+ var rad = Math.atan2(dy, dx);
90
+ return (rad * 180) / Math.PI;
91
+ };
92
+ var panResponder = useRef(PanResponder.create({
93
+ onStartShouldSetPanResponder: function () { return true; },
94
+ onMoveShouldSetPanResponder: function () { return true; },
95
+ onPanResponderGrant: function (evt) {
96
+ var _a = evt.nativeEvent, locationX = _a.locationX, locationY = _a.locationY;
97
+ gestureStartAngle.current = getTouchAngleDeg(locationX, locationY);
98
+ angle.stopAnimation(function (current) {
99
+ startAngle.current = current;
100
+ });
101
+ },
102
+ onPanResponderMove: function (evt) {
103
+ var _a = evt.nativeEvent, locationX = _a.locationX, locationY = _a.locationY;
104
+ var currentAngle = getTouchAngleDeg(locationX, locationY);
105
+ var delta = currentAngle - gestureStartAngle.current;
106
+ if (delta > 180)
107
+ delta -= 360;
108
+ if (delta < -180)
109
+ delta += 360;
110
+ var next = startAngle.current + delta;
111
+ // 🔥 SUPER SMOOTH UPDATE
112
+ smoothSetAngle(next);
113
+ },
114
+ })).current;
115
+ var rotateInterpolation = angle.interpolate({
116
+ inputRange: [-360, 360],
117
+ outputRange: ['-360deg', '360deg'],
118
+ });
119
+ return (_jsx(View, __assign({ onLayout: onLayout, style: [styles.container, { width: size, height: size }] }, panResponder.panHandlers, { children: _jsx(Animated.View, { style: {
120
+ width: size,
121
+ height: size,
122
+ justifyContent: 'center',
123
+ alignItems: 'center',
124
+ transform: [{ rotate: rotateInterpolation }],
125
+ }, children: children }) })));
126
+ }
127
+ var styles = StyleSheet.create({
128
+ container: {
129
+ alignItems: 'center',
130
+ justifyContent: 'center',
131
+ },
132
+ });
@@ -674,6 +674,18 @@ export var LineChart = function (props) {
674
674
  ? renderDataPoints(secondaryLineConfig.hideDataPoints, secondaryData, props.secondaryData, secondaryLineConfig.dataPointsShape, secondaryLineConfig.dataPointsWidth, secondaryLineConfig.dataPointsHeight, secondaryLineConfig.dataPointsColor, secondaryLineConfig.dataPointsRadius, secondaryLineConfig.textColor, secondaryLineConfig.textFontSize, secondaryLineConfig.startIndex, secondaryLineConfig.endIndex, true, secondaryLineConfig.showValuesAsDataPointsText, cumulativeSpacingSecondary, 6666)
675
675
  : null] }));
676
676
  };
677
+ var areaComponent = function (isNthAreaChart, startFillColor, endFillColor, startOpacity, endOpacity, uniqueId, fillPoints, startIndex, endIndex, propsData, clipRangeId, currentLineThickness, spreadAreaData, spacingArray, spreadAreaColor, spreadAreaOpacity) {
678
+ // For Area Chart
679
+ return (_jsxs(_Fragment, { children: [isNthAreaChart &&
680
+ getAreaGradientComponent(startFillColor, endFillColor, startOpacity, endOpacity, uniqueId), isNthAreaChart &&
681
+ (startIndex !== 0 || endIndex !== data.length - 1) &&
682
+ getClipRange(startIndex, endIndex, clipRangeId), isNthAreaChart ? (props.interpolateMissingValues === false &&
683
+ propsData.some(function (item) { return isNaN(item.value); }) ? null : animateOnDataChange && animatedFillPath ? (_jsx(AnimatedPath, { onPress: props.onChartAreaPress, d: animatedFillPath, fill: props.areaGradientId
684
+ ? "url(#".concat(props.areaGradientId, ")")
685
+ : "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness })) : (_jsx(Path, { onPress: props.onChartAreaPress, d: fillPoints, fill: props.areaGradientId
686
+ ? "url(#".concat(props.areaGradientId, ")")
687
+ : "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness }))) : null, spreadAreaData && (_jsx(Path, { d: getSpreadAreaPath(spreadAreaData, getX, getY, spacingArray, props.curvature, curveType), fill: spreadAreaColor || 'rgba(0,0,255,0.2)', stroke: "none", opacity: spreadAreaOpacity !== null && spreadAreaOpacity !== void 0 ? spreadAreaOpacity : 0.3 }))] }));
688
+ };
677
689
  var lineSvgComponent = function (points, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, key, hideDataPoints, data, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray) {
678
690
  var _a, _b;
679
691
  if (!points)
@@ -714,7 +726,7 @@ export var LineChart = function (props) {
714
726
  }
715
727
  return (_jsxs(Svg, { height: svgHeight,
716
728
  // width={widthValue}
717
- onPress: props.onBackgroundPress, children: [lineGradient && getLineGradientComponent(), points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? (ar.map(function (item, index) {
729
+ onPress: props.onBackgroundPress, children: [areaComponent(isNthAreaChart, startFillColor, endFillColor, startOpacity, endOpacity, uniqueId, fillPoints, startIndex, endIndex, propsData, clipRangeId, currentLineThickness, spreadAreaData, spacingArray, spreadAreaColor, spreadAreaOpacity), lineGradient && getLineGradientComponent(), points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? (ar.map(function (item, index) {
718
730
  var lineSvgProps = {
719
731
  d: item.d,
720
732
  fill: 'none',
@@ -733,15 +745,7 @@ export var LineChart = function (props) {
733
745
  lineSvgProps.strokeDasharray = item.strokeDashArray;
734
746
  }
735
747
  return _jsx(Path, __assign({}, lineSvgProps), index);
736
- })) : animateOnDataChange && animatedPath ? (_jsx(AnimatedPath, __assign({}, lineSvgPropsOuter))) : colors ? (_jsx(Defs, { children: _jsx(Mask, { id: "pathMask", children: _jsx(Path, __assign({}, lineSvgPropsOuter, { stroke: colors ? 'white' : color })) }) })) : (_jsx(Path, __assign({}, lineSvgPropsOuter))), colors && getColorBackRects(), isNthAreaChart &&
737
- getAreaGradientComponent(startFillColor, endFillColor, startOpacity, endOpacity, uniqueId), isNthAreaChart &&
738
- (startIndex !== 0 || endIndex !== data.length - 1) &&
739
- getClipRange(startIndex, endIndex, clipRangeId), isNthAreaChart ? (props.interpolateMissingValues === false &&
740
- propsData.some(function (item) { return isNaN(item.value); }) ? null : animateOnDataChange && animatedFillPath ? (_jsx(AnimatedPath, { onPress: props.onChartAreaPress, d: animatedFillPath, fill: props.areaGradientId
741
- ? "url(#".concat(props.areaGradientId, ")")
742
- : "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness })) : (_jsx(Path, { onPress: props.onChartAreaPress, d: fillPoints, fill: props.areaGradientId
743
- ? "url(#".concat(props.areaGradientId, ")")
744
- : "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness }))) : null, spreadAreaData && (_jsx(Path, { d: getSpreadAreaPath(spreadAreaData, getX, getY, spacingArray, props.curvature, curveType), fill: spreadAreaColor || 'rgba(0,0,255,0.2)', stroke: "none", opacity: spreadAreaOpacity !== null && spreadAreaOpacity !== void 0 ? spreadAreaOpacity : 0.3 })), renderSpecificVerticalLines(data, cumulativeSpacing1), renderSpecificVerticalLines(data2, cumulativeSpacing2), renderSpecificVerticalLines(data3, cumulativeSpacing3), renderSpecificVerticalLines(data4, cumulativeSpacing4), renderSpecificVerticalLines(data5, cumulativeSpacing5), (_b = dataSet === null || dataSet === void 0 ? void 0 : dataSet.map(function (set, index) {
748
+ })) : animateOnDataChange && animatedPath ? (_jsx(AnimatedPath, __assign({}, lineSvgPropsOuter))) : colors ? (_jsx(Defs, { children: _jsx(Mask, { id: "pathMask", children: _jsx(Path, __assign({}, lineSvgPropsOuter, { stroke: colors ? 'white' : color })) }) })) : (_jsx(Path, __assign({}, lineSvgPropsOuter))), colors && getColorBackRects(), renderSpecificVerticalLines(data, cumulativeSpacing1), renderSpecificVerticalLines(data2, cumulativeSpacing2), renderSpecificVerticalLines(data3, cumulativeSpacing3), renderSpecificVerticalLines(data4, cumulativeSpacing4), renderSpecificVerticalLines(data5, cumulativeSpacing5), (_b = dataSet === null || dataSet === void 0 ? void 0 : dataSet.map(function (set, index) {
745
749
  return renderSpecificVerticalLines(set === null || set === void 0 ? void 0 : set.data, cumulativeSpacingForSet[index]);
746
750
  })) !== null && _b !== void 0 ? _b : null, isAnimated && !renderDataPointsAfterAnimationEnds // in this condition onPress won't work properly in case of multi-line, so it's suggested to use either renderDataPointsAfterAnimationEnds prop if you want to use onPress for data points
747
751
  ? renderDataPoints(hideDataPoints, data, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, key)
@@ -749,17 +753,6 @@ export var LineChart = function (props) {
749
753
  ? renderDataPointsForEachLine()
750
754
  : null, showArrow && (_jsx(Path, { d: arrowPoints, fill: arrowFillColor, stroke: arrowStrokeColor, strokeWidth: arrowStrokeWidth }))] }));
751
755
  };
752
- // const getClosestValueFromSpacingArray = (spacingArray:number[],x:number):number => {
753
- // let dif=0,prevDif=0,i;
754
- // for(i=0;i<spacingArray.length;i++){
755
- // dif = Math.abs(spacingArray[i]-x)
756
- // if(prevDif!=0 && prevDif<dif){
757
- // break;
758
- // }
759
- // prevDif = dif;
760
- // }
761
- // return i-1;
762
- // }
763
756
  var activatePointers = function (x) {
764
757
  var _a;
765
758
  var factor = (x - initialSpacing) / ((_a = props.spacing1) !== null && _a !== void 0 ? _a : spacing); // getClosestValueFromSpacingArray(cumulativeSpacing1,x-initialSpacing)
@@ -869,6 +862,8 @@ export var LineChart = function (props) {
869
862
  }
870
863
  };
871
864
  var renderLine = function (containerHeightIncludingBelowXAxis, zIndex, points, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, hideDataPoints, paramData, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, key) {
865
+ if (!points)
866
+ return null;
872
867
  return (_jsx(View, { onPointerEnter: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onPointerEnter) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onPointerLeave: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onPointerLeave) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onTouchStart: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onTouchStart) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onTouchEnd: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onTouchEnd) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onMoveShouldSetResponder: function (evt) { return (pointerConfig ? true : false); }, onStartShouldSetResponder: function (evt) {
873
868
  return pointerConfig && activatePointersInstantlyOnTouch ? true : false;
874
869
  }, onResponderGrant: function (evt) {
@@ -934,6 +929,8 @@ export var LineChart = function (props) {
934
929
  ], children: lineSvgComponent(points, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, key, hideDataPoints, paramData, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray) }, key !== null && key !== void 0 ? key : 0));
935
930
  };
936
931
  var renderAnimatedLine = function (containerHeightIncludingBelowXAxis, zIndex, points, animatedWidth, currentLineThickness, color, fillPoints, startFillColor, endFillColor, startOpacity, endOpacity, strokeDashArray, strokeLinecap, showArrow, arrowPoints, arrowStrokeWidth, arrowStrokeColor, arrowFillColor, hideDataPoints, paramsData, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, key) {
932
+ if (!points)
933
+ return null;
937
934
  return (_jsx(Animated.View, { onPointerEnter: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onPointerEnter) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onPointerLeave: function () { var _a; return (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onPointerLeave) === null || _a === void 0 ? void 0 : _a.call(pointerConfig); }, onMoveShouldSetResponder: function (evt) { return (pointerConfig ? true : false); }, onStartShouldSetResponder: function (evt) {
938
935
  return pointerConfig && activatePointersInstantlyOnTouch ? true : false;
939
936
  }, onResponderGrant: function (evt) {
@@ -31,10 +31,11 @@ import { PieChartMain } from './main';
31
31
  import { pieColors, usePieChart } from 'gifted-charts-core';
32
32
  import { isWebApp } from '../utils';
33
33
  import { useState } from 'react';
34
+ import { RotatablePie } from '../Components/Rotatable';
34
35
  export var PieChart = function (props) {
35
36
  if (!props.data)
36
37
  return null;
37
- var _a = usePieChart(props), radius = _a.radius, extraRadius = _a.extraRadius, selectedIndex = _a.selectedIndex, setSelectedIndex = _a.setSelectedIndex, startAngle = _a.startAngle, total = _a.total, donut = _a.donut, isThreeD = _a.isThreeD, semiCircle = _a.semiCircle, inwardExtraLengthForFocused = _a.inwardExtraLengthForFocused, canvasWidth = _a.canvasWidth, canvasHeight = _a.canvasHeight, innerRadius = _a.innerRadius, innerCircleColor = _a.innerCircleColor, innerCircleBorderWidth = _a.innerCircleBorderWidth, innerCircleBorderColor = _a.innerCircleBorderColor, shiftInnerCenterX = _a.shiftInnerCenterX, shiftInnerCenterY = _a.shiftInnerCenterY, tiltAngle = _a.tiltAngle, isDataShifted = _a.isDataShifted, paddingHorizontal = _a.paddingHorizontal, paddingVertical = _a.paddingVertical, data = _a.data, showTooltip = _a.showTooltip, tooltipHorizontalShift = _a.tooltipHorizontalShift, tooltipVerticalShift = _a.tooltipVerticalShift, tooltipComponent = _a.tooltipComponent, getTooltipText = _a.getTooltipText, tooltipBackgroundColor = _a.tooltipBackgroundColor, tooltipBorderRadius = _a.tooltipBorderRadius, tooltipWidth = _a.tooltipWidth, tooltipTextNoOfLines = _a.tooltipTextNoOfLines, textColor = _a.textColor, textSize = _a.textSize, font = _a.font, fontWeight = _a.fontWeight, fontStyle = _a.fontStyle, tooltipSelectedIndex = _a.tooltipSelectedIndex, setTooltipSelectedIndex = _a.setTooltipSelectedIndex;
38
+ var _a = usePieChart(props), radius = _a.radius, extraRadius = _a.extraRadius, selectedIndex = _a.selectedIndex, setSelectedIndex = _a.setSelectedIndex, startAngle = _a.startAngle, total = _a.total, donut = _a.donut, isThreeD = _a.isThreeD, semiCircle = _a.semiCircle, inwardExtraLengthForFocused = _a.inwardExtraLengthForFocused, canvasWidth = _a.canvasWidth, canvasHeight = _a.canvasHeight, innerRadius = _a.innerRadius, innerCircleColor = _a.innerCircleColor, innerCircleBorderWidth = _a.innerCircleBorderWidth, innerCircleBorderColor = _a.innerCircleBorderColor, shiftInnerCenterX = _a.shiftInnerCenterX, shiftInnerCenterY = _a.shiftInnerCenterY, tiltAngle = _a.tiltAngle, isDataShifted = _a.isDataShifted, paddingHorizontal = _a.paddingHorizontal, paddingVertical = _a.paddingVertical, data = _a.data, showTooltip = _a.showTooltip, tooltipHorizontalShift = _a.tooltipHorizontalShift, tooltipVerticalShift = _a.tooltipVerticalShift, tooltipComponent = _a.tooltipComponent, getTooltipText = _a.getTooltipText, tooltipBackgroundColor = _a.tooltipBackgroundColor, tooltipBorderRadius = _a.tooltipBorderRadius, tooltipWidth = _a.tooltipWidth, tooltipTextNoOfLines = _a.tooltipTextNoOfLines, textColor = _a.textColor, textSize = _a.textSize, font = _a.font, fontWeight = _a.fontWeight, fontStyle = _a.fontStyle, tooltipSelectedIndex = _a.tooltipSelectedIndex, setTooltipSelectedIndex = _a.setTooltipSelectedIndex, rotatable = _a.rotatable;
38
39
  var _b = __read(useState(0), 2), touchX = _b[0], setTouchX = _b[1];
39
40
  var _c = __read(useState(0), 2), touchY = _c[0], setTouchY = _c[1];
40
41
  var renderInnerCircle = function (innerRadius, innerCircleBorderWidth) {
@@ -119,28 +120,34 @@ export var PieChart = function (props) {
119
120
  fontStyle: fontStyle,
120
121
  }, children: getTooltipText(tooltipSelectedIndex) }) })) }));
121
122
  };
122
- return (_jsxs(View, { style: {
123
- height: (radius + extraRadius + paddingVertical / 2) *
124
- (props.semiCircle ? 1 : 2),
125
- width: (radius + extraRadius + paddingHorizontal / 2) * 2,
126
- overflow: 'hidden',
127
- }, children: [_jsx(View, { style: { position: 'absolute' }, children: _jsx(PieChartMain, __assign({}, props, { setTouchX: setTouchX, setTouchY: setTouchY, tooltipSelectedIndex: tooltipSelectedIndex, setTooltipSelectedIndex: setTooltipSelectedIndex, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadius: extraRadius })) }), renderInnerCircle(innerRadius, innerCircleBorderWidth), props.data.length > 1 &&
128
- props.data[selectedIndex] && // don't forget to add this one so there are no errors when the data is empty / updating
129
- (props.focusOnPress || props.sectionAutoFocus) &&
130
- selectedIndex !== -1 && (_jsx(View, { pointerEvents: "box-none", style: {
131
- position: 'absolute',
132
- top: -extraRadius,
133
- left: -extraRadius,
134
- zIndex: isWebApp ? -1 : 0, // was not getting displayed in web (using Expo)
135
- }, children: _jsx(PieChartMain, __assign({}, props, { setTouchX: setTouchX, setTouchY: setTouchY, tooltipSelectedIndex: tooltipSelectedIndex, setTooltipSelectedIndex: setTooltipSelectedIndex, data: [
136
- __assign(__assign({}, props.data[selectedIndex]), { color: props.showGradient
137
- ? "url(#grad".concat(selectedIndex, ")")
138
- : props.data[selectedIndex].color ||
139
- pieColors[selectedIndex % 9] }),
140
- {
141
- value: total - props.data[selectedIndex].value,
142
- peripheral: true,
143
- strokeWidth: 0,
144
- },
145
- ], radius: radius + extraRadius, initialAngle: startAngle, innerRadius: props.innerRadius || radius / 2.5, isBiggerPie: true, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadius: extraRadius })) })), renderInnerCircle(innerRadius - inwardExtraLengthForFocused, inwardExtraLengthForFocused ? 0 : innerCircleBorderWidth), showTooltip && tooltipSelectedIndex !== -1 ? renderTooltip() : null] }));
123
+ var PieChartBody = function () {
124
+ return (_jsxs(View, { style: {
125
+ height: (radius + extraRadius + paddingVertical / 2) *
126
+ (props.semiCircle ? 1 : 2),
127
+ width: (radius + extraRadius + paddingHorizontal / 2) * 2,
128
+ overflow: 'hidden',
129
+ }, children: [_jsx(View, { style: { position: 'absolute' }, children: _jsx(PieChartMain, __assign({}, props, { setTouchX: setTouchX, setTouchY: setTouchY, tooltipSelectedIndex: tooltipSelectedIndex, setTooltipSelectedIndex: setTooltipSelectedIndex, selectedIndex: selectedIndex, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadius: extraRadius })) }), renderInnerCircle(innerRadius, innerCircleBorderWidth), props.data.length > 1 &&
130
+ props.data[selectedIndex] && // don't forget to add this one so there are no errors when the data is empty / updating
131
+ (props.focusOnPress || props.sectionAutoFocus) &&
132
+ selectedIndex !== -1 && (_jsx(View, { pointerEvents: "box-none", style: {
133
+ position: 'absolute',
134
+ top: -extraRadius,
135
+ left: -extraRadius,
136
+ zIndex: isWebApp ? -1 : 0, // was not getting displayed in web (using Expo)
137
+ }, children: _jsx(PieChartMain, __assign({}, props, { setTouchX: setTouchX, setTouchY: setTouchY, tooltipSelectedIndex: tooltipSelectedIndex, setTooltipSelectedIndex: setTooltipSelectedIndex, data: [
138
+ __assign(__assign({}, props.data[selectedIndex]), { color: props.showGradient
139
+ ? "url(#grad".concat(selectedIndex, ")")
140
+ : props.data[selectedIndex].color ||
141
+ pieColors[selectedIndex % 9] }),
142
+ {
143
+ value: total - props.data[selectedIndex].value,
144
+ peripheral: true,
145
+ strokeWidth: 0,
146
+ },
147
+ ], radius: radius + extraRadius, initialAngle: startAngle, innerRadius: props.innerRadius || radius / 2.5, isBiggerPie: true, selectedIndex: selectedIndex, setSelectedIndex: setSelectedIndex, paddingHorizontal: paddingHorizontal, paddingVertical: paddingVertical, extraRadius: extraRadius })) })), renderInnerCircle(innerRadius - inwardExtraLengthForFocused, inwardExtraLengthForFocused ? 0 : innerCircleBorderWidth), showTooltip && tooltipSelectedIndex !== -1 ? renderTooltip() : null] }));
148
+ };
149
+ if (rotatable && !semiCircle) {
150
+ return (_jsx(RotatablePie, { children: [_jsx(PieChartBody, {}, "PieChartBody")], initialAngle: startAngle, size: radius * 2 }));
151
+ }
152
+ return _jsx(PieChartBody, {});
146
153
  };
@@ -92,18 +92,19 @@ export var PieChartMain = function (props) {
92
92
  }) }), data.length === 1 || !total ? (_jsx(_Fragment, { children: _jsx(Circle, { cx: cx, cy: cy, r: radius, fill: showGradient
93
93
  ? "url(#grad".concat(0, ")")
94
94
  : ((_a = data[0]) === null || _a === void 0 ? void 0 : _a.color) || pieColors[0 % 9] }) })) : (data.map(function (item, index) {
95
- var _a = coordinates[index], sx = _a.sx, sy = _a.sy, ax = _a.ax, ay = _a.ay;
95
+ var _a;
96
+ var _b = coordinates[index], sx = _b.sx, sy = _b.sy, ax = _b.ax, ay = _b.ay;
96
97
  if (isBiggerPie && index)
97
98
  return null;
98
99
  return (_jsx(Path, { d: "M ".concat(cx + (item.shiftX || 0), " ").concat(cy + (item.shiftY || 0), " L ").concat(sx, " ").concat(sy, " A ").concat(radius, " ").concat(radius, " 0 ").concat(semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0, " 1 ").concat(ax, " ").concat(ay, " L ").concat(cx + (item.shiftX || 0), " ").concat(cy + (item.shiftY || 0)), stroke: item.strokeColor || strokeColor, strokeWidth: props.focusOnPress && props.selectedIndex === index
99
100
  ? 0
100
101
  : item.strokeWidth === 0
101
102
  ? 0
102
- : item.strokeWidth || strokeWidth, fill: props.selectedIndex === index || item.peripheral
103
+ : item.strokeWidth || strokeWidth, fill: item.peripheral
103
104
  ? 'none'
104
105
  : showGradient
105
106
  ? "url(#grad".concat(index, ")")
106
- : item.color || pieColors[index % 9] }, index + 'a'));
107
+ : item.color || pieColors[isBiggerPie ? (_a = props.selectedIndex) !== null && _a !== void 0 ? _a : 0 % 9 : index % 9] }, index + 'a'));
107
108
  })), (showText || showInnerComponent || showExternalLabels) &&
108
109
  data.map(function (item, index) {
109
110
  var _a, _b, _c, _d, _e, _f, _g, _h, _j;
@@ -162,7 +163,7 @@ export var PieChartMain = function (props) {
162
163
  item.textSize ||
163
164
  textSize, fill: item.textBackgroundColor || textBackgroundColor })) : null, showText && (_jsx(SvgText, { fill: item.textColor ||
164
165
  textColor ||
165
- pieColors[(index + 2) % 9], fontSize: item.textSize || textSize, fontFamily: item.font || font, fontWeight: item.fontWeight || fontWeight, fontStyle: item.fontStyle || fontStyle || 'normal', x: x +
166
+ 'black', fontSize: item.textSize || textSize, fontFamily: item.font || font, fontWeight: item.fontWeight || fontWeight, fontStyle: item.fontStyle || fontStyle || 'normal', x: x +
166
167
  (item.shiftTextX || 0) -
167
168
  (item.textSize || textSize) / 1.8, y: y + (item.shiftTextY || 0), children: item.text || (showValuesAsLabels ? item.value + '' : '') })), localPieInnerComponent ? (_jsx(G, { x: x - pieInnerComponentHeight / 2, y: y - pieInnerComponentWidth / 2, children: (_j = localPieInnerComponent === null || localPieInnerComponent === void 0 ? void 0 : localPieInnerComponent(item, index)) !== null && _j !== void 0 ? _j : null })) : null] }, index));
168
169
  })] }), isThreeD && shadow && !semiCircle ? (_jsx(View, { style: {