react-native-gifted-charts 1.4.57 → 1.4.59

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
@@ -7,7 +7,7 @@
7
7
  <a href="https://www.npmjs.com/package/react-native-gifted-charts">
8
8
  <img src="/demos/npmIcon.png" height="auto" width="28" height="28" />
9
9
  </a> &nbsp; &nbsp;
10
- <a href="https://discord.gg/ptdwsw48">
10
+ <a href="https://discord.gg/FBbu9duJxs">
11
11
  <img src="/demos/discord.png" height="auto" width="30" height="30" />
12
12
  </a>
13
13
  </p>
@@ -25,7 +25,29 @@ var RenderStackBars = function (props) {
25
25
  var barBackgroundPattern = props.barBackgroundPattern, patternId = props.patternId, stackData = props.stackData, item = props.item, index = props.index, containerHeight = props.containerHeight, spacing = props.spacing, rotateLabel = props.rotateLabel, label = props.label, labelTextStyle = props.labelTextStyle, xAxisTextNumberOfLines = props.xAxisTextNumberOfLines, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, renderTooltip = props.renderTooltip, selectedIndex = props.selectedIndex, setSelectedIndex = props.setSelectedIndex, activeOpacity = props.activeOpacity, _b = props.animationDuration, animationDuration = _b === void 0 ? BarDefaults.animationDuration : _b, barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, stackBorderRadius = props.stackBorderRadius, stackBorderTopLeftRadius = props.stackBorderTopLeftRadius, stackBorderTopRightRadius = props.stackBorderTopRightRadius, stackBorderBottomLeftRadius = props.stackBorderBottomLeftRadius, stackBorderBottomRightRadius = props.stackBorderBottomRightRadius, showValuesAsTopLabel = props.showValuesAsTopLabel, _c = props.autoShiftLabelsForNegativeStacks, autoShiftLabelsForNegativeStacks = _c === void 0 ? true : _c, _d = props.labelsDistanceFromXaxis, labelsDistanceFromXaxis = _d === void 0 ? 0 : _d, horizontal = props.horizontal, secondaryStepHeight = props.secondaryStepHeight, secondaryStepValue = props.secondaryStepValue, secondaryNegativeStepHeight = props.secondaryNegativeStepHeight, secondaryNegativeStepValue = props.secondaryNegativeStepValue, barMarginBottom = props.barMarginBottom, highlightEnabled = props.highlightEnabled, highlightedBarIndex = props.highlightedBarIndex, lowlightOpacity = props.lowlightOpacity, stackHighlightEnabled = props.stackHighlightEnabled, selectedStackIndex = props.selectedStackIndex, setSelectedStackIndex = props.setSelectedStackIndex;
26
26
  var _e = useRenderStackBars(__assign(__assign({}, props), { secondaryStepHeight: secondaryStepHeight, secondaryStepValue: secondaryStepValue, secondaryNegativeStepHeight: secondaryNegativeStepHeight, secondaryNegativeStepValue: secondaryNegativeStepValue })), containsNegativeValue = _e.containsNegativeValue, noAnimation = _e.noAnimation, localBarInnerComponent = _e.localBarInnerComponent, borderRadius = _e.borderRadius, borderTopLeftRadius = _e.borderTopLeftRadius, borderTopRightRadius = _e.borderTopRightRadius, borderBottomLeftRadius = _e.borderBottomLeftRadius, borderBottomRightRadius = _e.borderBottomRightRadius, disablePress = _e.disablePress, totalHeight = _e.totalHeight, height = _e.height, setHeight = _e.setHeight, getBarHeight = _e.getBarHeight, getPosition = _e.getPosition, lowestBarPosition = _e.lowestBarPosition, getStackBorderRadii = _e.getStackBorderRadii, tooltipProps = _e.tooltipProps;
27
27
  var renderLabel = function (label, labelTextStyle) {
28
- return (_jsx(View, { style: [
28
+ return (_jsx(TouchableOpacity, { disabled: disablePress || (stackHighlightEnabled && !highlightEnabled), activeOpacity: activeOpacity, onPress: function () {
29
+ setSelectedIndex(index);
30
+ if (item.onPress) {
31
+ item.onPress();
32
+ }
33
+ else if (props.onPress) {
34
+ props.onPress(item, index);
35
+ }
36
+ }, onLongPress: function () {
37
+ if (item.onLongPress) {
38
+ item.onLongPress();
39
+ }
40
+ else if (props.onLongPress) {
41
+ props.onLongPress(item, index);
42
+ }
43
+ }, onPressOut: function () {
44
+ if (item.onPressOut) {
45
+ item.onPressOut();
46
+ }
47
+ else if (props.onPressOut) {
48
+ props.onPressOut(item, index);
49
+ }
50
+ }, style: [
29
51
  {
30
52
  width: (item.labelWidth ||
31
53
  props.labelWidth ||
@@ -34,7 +56,7 @@ var RenderStackBars = function (props) {
34
56
  30) +
35
57
  spacing / 2,
36
58
  position: 'absolute',
37
- bottom: autoShiftLabelsForNegativeStacks
59
+ bottom: !labelsDistanceFromXaxis && autoShiftLabelsForNegativeStacks
38
60
  ? containsNegativeValue
39
61
  ? -0
40
62
  : -6 - xAxisTextNumberOfLines * 18
@@ -201,12 +201,14 @@ export var BarChart = function (props) {
201
201
  }
202
202
  else {
203
203
  return (_jsx(Pressable, { style: contentContainerStyle, onPress: function () {
204
+ var _a;
204
205
  if (props.highlightEnabled && selectedIndex !== -1)
205
206
  setSelectedIndex(-1);
206
207
  if (props.stackHighlightEnabled && selectedStackIndex !== -1) {
207
208
  setSelectedStackIndex(-1);
208
209
  // props.setHighlightedStackIndex?.(-1)
209
210
  }
211
+ (_a = props.onBackgroundPress) === null || _a === void 0 ? void 0 : _a.call(props);
210
212
  }, children: renderChart() }));
211
213
  }
212
214
  };
@@ -1,14 +1,14 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { View } from 'react-native';
3
3
  export var Pointer = function (props) {
4
- var pointerX = props.pointerX, pointerYLocal = props.pointerYLocal, pointerComponent = props.pointerComponent, pointerHeight = props.pointerHeight, pointerRadius = props.pointerRadius, pointerWidth = props.pointerWidth, pointerItemLocal = props.pointerItemLocal, pointerColorLocal = props.pointerColorLocal;
4
+ var pointerX = props.pointerX, pointerYLocal = props.pointerYLocal, pointerComponent = props.pointerComponent, pointerHeight = props.pointerHeight, pointerRadius = props.pointerRadius, pointerWidth = props.pointerWidth, pointerItemLocal = props.pointerItemLocal, pointerColorLocal = props.pointerColorLocal, pointerIndex = props.pointerIndex;
5
5
  if (isNaN(pointerYLocal) || typeof pointerYLocal !== 'number')
6
6
  return null;
7
7
  return (_jsx(View, { style: {
8
8
  position: 'absolute',
9
9
  left: pointerX + 1 + (pointerX.pointerShiftX || 0),
10
10
  top: pointerYLocal - 4,
11
- }, children: pointerComponent ? (pointerComponent()) : (_jsx(View, { style: {
11
+ }, children: pointerComponent ? (pointerComponent(pointerItemLocal, pointerIndex)) : (_jsx(View, { style: {
12
12
  height: pointerHeight || pointerRadius * 2,
13
13
  width: pointerWidth || pointerRadius * 2,
14
14
  marginTop: (pointerItemLocal === null || pointerItemLocal === void 0 ? void 0 : pointerItemLocal.pointerShiftY) || 0,
@@ -301,7 +301,10 @@ export var LineChart = function (props) {
301
301
  item.customDataPoint ||
302
302
  props.customDataPoint;
303
303
  dataPointLabelComponent =
304
- item.focusedDataPointLabelComponent || item.dataPointLabelComponent;
304
+ item.focusedDataPointLabelComponent ||
305
+ item.dataPointLabelComponent ||
306
+ props.focusedDataPointLabelComponent ||
307
+ props.dataPointLabelComponent;
305
308
  }
306
309
  else {
307
310
  dataPointsShape = item.dataPointShape || dataPtsShape;
@@ -313,7 +316,8 @@ export var LineChart = function (props) {
313
316
  text = '';
314
317
  }
315
318
  customDataPoint = item.customDataPoint || props.customDataPoint;
316
- dataPointLabelComponent = item.dataPointLabelComponent;
319
+ dataPointLabelComponent =
320
+ item.dataPointLabelComponent || props.dataPointLabelComponent;
317
321
  }
318
322
  if (showValuesAsDataPointsText) {
319
323
  text = originalDataFromProps[index].value;
@@ -380,7 +384,7 @@ export var LineChart = function (props) {
380
384
  dataPointsHeight / 2 +
381
385
  (item.textShiftY || props.textShiftY || 0), children: !showTextOnFocus && !showValuesAsDataPointsText
382
386
  ? item.dataPointText
383
- : text })) : null) : null] }))] }, index));
387
+ : text })) : null) : null, index === selectedIndex ? _jsx(Text, { children: '' }) : null] }))] }, index));
384
388
  });
385
389
  };
386
390
  var renderSpecificVerticalLines = function (dataForRender, spacingArray) {
@@ -426,6 +430,7 @@ export var LineChart = function (props) {
426
430
  pointerWidth: pointerWidth,
427
431
  pointerItemLocal: pointerItemLocal_1,
428
432
  pointerColorLocal: pointerColorLocal_1,
433
+ pointerIndex: pIndex,
429
434
  }) }, 'dSetPts' + index));
430
435
  });
431
436
  }
@@ -490,6 +495,7 @@ export var LineChart = function (props) {
490
495
  pointerWidth: pointerWidth,
491
496
  pointerItemLocal: pointerItemLocal,
492
497
  pointerColorLocal: pointerColorLocal,
498
+ pointerIndex: pointerIndex,
493
499
  });
494
500
  };
495
501
  var renderStripAndLabel = function () {
@@ -658,7 +664,8 @@ export var LineChart = function (props) {
658
664
  // return i-1;
659
665
  // }
660
666
  var activatePointers = function (x) {
661
- var factor = (x - initialSpacing) / spacing; // getClosestValueFromSpacingArray(cumulativeSpacing1,x-initialSpacing)
667
+ var _a;
668
+ var factor = (x - initialSpacing) / ((_a = props.spacing1) !== null && _a !== void 0 ? _a : spacing); // getClosestValueFromSpacingArray(cumulativeSpacing1,x-initialSpacing)
662
669
  factor = Math.round(factor);
663
670
  factor = Math.min(factor, (data0 !== null && data0 !== void 0 ? data0 : data).length - 1);
664
671
  factor = Math.max(factor, 0);
@@ -790,6 +797,9 @@ export var LineChart = function (props) {
790
797
  setResponderActive(true);
791
798
  }
792
799
  var x = evt.nativeEvent.locationX;
800
+ var px = evt.nativeEvent.pageX;
801
+ if (yAxisLabelWidth != -1 && x == px)
802
+ return; // if locationX and pageX are equal, it means pointer has gone out of the chart, but this is not the case when yAxisLabelWidth is -1
793
803
  if (!activatePointersOnLongPress &&
794
804
  x > (props.width || Dimensions.get('window').width))
795
805
  return;
@@ -79,7 +79,7 @@ export var PieChart = function (props) {
79
79
  borderRightWidth: 0.5,
80
80
  borderRightColor: innerCircleColor,
81
81
  },
82
- ], children: _jsx(View, { style: { marginTop: semiCircle ? -0.5 * innerRadius : 0 }, children: props.centerLabelComponent ? props.centerLabelComponent() : null }) }));
82
+ ], children: _jsx(View, { style: { marginTop: semiCircle ? -0.5 * innerRadius : 0 }, children: props.centerLabelComponent ? props.centerLabelComponent(selectedIndex) : null }) }));
83
83
  }
84
84
  return null;
85
85
  };
@@ -105,8 +105,10 @@ export var PieChartMain = function (props) {
105
105
  : item.color || pieColors[index % 9] }, index + 'a'));
106
106
  })), (showText || showInnerComponent || showExternalLabels) &&
107
107
  data.map(function (item, index) {
108
- var _a, _b, _c, _d, _e, _f, _g;
108
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
109
109
  var localPieInnerComponent = (_a = item.pieInnerComponent) !== null && _a !== void 0 ? _a : props.pieInnerComponent;
110
+ var pieInnerComponentHeight = (_b = props.pieInnerComponentHeight) !== null && _b !== void 0 ? _b : 0;
111
+ var pieInnerComponentWidth = (_c = props.pieInnerComponentWidth) !== null && _c !== void 0 ? _c : 0;
110
112
  if (isBiggerPie && index)
111
113
  return null;
112
114
  if (!props.data[index].value)
@@ -146,14 +148,14 @@ export var PieChartMain = function (props) {
146
148
  y = cy;
147
149
  }
148
150
  }
149
- var _h = getExternaLabelProperties(item, mx, my, cx, cy, prevSide, prevLabelComponentX, index === data.length - 1, // isLast
150
- wasFirstItemOnPole), labelLineColor = _h.labelLineColor, labelLineThickness = _h.labelLineThickness, labelComponentHeight = _h.labelComponentHeight, inX = _h.inX, inY = _h.inY, outX = _h.outX, outY = _h.outY, finalX = _h.finalX, labelComponentX = _h.labelComponentX, labelComponentY = _h.labelComponentY, localExternalLabelComponent = _h.localExternalLabelComponent, isRightHalf = _h.isRightHalf;
151
+ var _k = getExternaLabelProperties(item, mx, my, cx, cy, prevSide, prevLabelComponentX, index === data.length - 1, // isLast
152
+ wasFirstItemOnPole), labelLineColor = _k.labelLineColor, labelLineThickness = _k.labelLineThickness, labelComponentHeight = _k.labelComponentHeight, inX = _k.inX, inY = _k.inY, outX = _k.outX, outY = _k.outY, finalX = _k.finalX, labelComponentX = _k.labelComponentX, labelComponentY = _k.labelComponentY, localExternalLabelComponent = _k.localExternalLabelComponent, isRightHalf = _k.isRightHalf;
151
153
  prevSide = isRightHalf ? 'right' : 'left';
152
154
  prevLabelComponentX = labelComponentX;
153
155
  if (index === 0)
154
156
  wasFirstItemOnPole = labelComponentY !== outY;
155
- return (_jsxs(React.Fragment, { children: [showExternalLabels ? (_jsxs(G, { children: [_jsx(Line, { x1: inX, x2: outX, y1: inY, y2: outY, stroke: labelLineColor, strokeWidth: labelLineThickness }), _jsx(Line, { x1: outX, x2: finalX, y1: outY, y2: outY, stroke: labelLineColor, strokeWidth: labelLineThickness }), localExternalLabelComponent ? (_jsx(G, { x: labelComponentX, y: labelComponentY + labelComponentHeight / 2, children: (_b = localExternalLabelComponent === null || localExternalLabelComponent === void 0 ? void 0 : localExternalLabelComponent(item, index)) !== null && _b !== void 0 ? _b : null })) : null] })) : null, showTextBackground ? (_jsx(Circle, { cx: x + ((_d = (_c = item.shiftTextBackgroundX) !== null && _c !== void 0 ? _c : item.shiftTextX) !== null && _d !== void 0 ? _d : 0), cy: y +
156
- ((_f = (_e = item.shiftTextBackgroundY) !== null && _e !== void 0 ? _e : item.shiftTextY) !== null && _f !== void 0 ? _f : 0) -
157
+ return (_jsxs(React.Fragment, { children: [showExternalLabels ? (_jsxs(G, { children: [_jsx(Line, { x1: inX, x2: outX, y1: inY, y2: outY, stroke: labelLineColor, strokeWidth: labelLineThickness }), _jsx(Line, { x1: outX, x2: finalX, y1: outY, y2: outY, stroke: labelLineColor, strokeWidth: labelLineThickness }), localExternalLabelComponent ? (_jsx(G, { x: labelComponentX, y: labelComponentY + labelComponentHeight / 2, children: (_d = localExternalLabelComponent === null || localExternalLabelComponent === void 0 ? void 0 : localExternalLabelComponent(item, index)) !== null && _d !== void 0 ? _d : null })) : null] })) : null, showTextBackground ? (_jsx(Circle, { cx: x + ((_f = (_e = item.shiftTextBackgroundX) !== null && _e !== void 0 ? _e : item.shiftTextX) !== null && _f !== void 0 ? _f : 0), cy: y +
158
+ ((_h = (_g = item.shiftTextBackgroundY) !== null && _g !== void 0 ? _g : item.shiftTextY) !== null && _h !== void 0 ? _h : 0) -
157
159
  (item.textSize || textSize) / 4, r: item.textBackgroundRadius ||
158
160
  props.textBackgroundRadius ||
159
161
  item.textSize ||
@@ -161,7 +163,7 @@ export var PieChartMain = function (props) {
161
163
  textColor ||
162
164
  pieColors[(index + 2) % 9], fontSize: item.textSize || textSize, fontFamily: item.font || font, fontWeight: item.fontWeight || fontWeight, fontStyle: item.fontStyle || fontStyle || 'normal', x: x +
163
165
  (item.shiftTextX || 0) -
164
- (item.textSize || textSize) / 1.8, y: y + (item.shiftTextY || 0), children: item.text || (showValuesAsLabels ? item.value + '' : '') })), localPieInnerComponent ? (_jsx(G, { x: x, y: y, children: (_g = localPieInnerComponent === null || localPieInnerComponent === void 0 ? void 0 : localPieInnerComponent(item, index)) !== null && _g !== void 0 ? _g : null })) : null] }, index));
166
+ (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));
165
167
  })] }), isThreeD && shadow && !semiCircle ? (_jsx(View, { style: {
166
168
  width: radius * 2,
167
169
  height: radius * 2,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.57",
3
+ "version": "1.4.59",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar, Population Pyramid and Radar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "dist/index.js",
6
6
  "files": [
@@ -26,7 +26,7 @@
26
26
  "registry": "https://registry.npmjs.org/"
27
27
  },
28
28
  "dependencies": {
29
- "gifted-charts-core": "0.1.59"
29
+ "gifted-charts-core": "0.1.61"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/cli": "^7.24.8",