react-native-gifted-charts 1.4.55 → 1.4.56

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
@@ -31,7 +31,7 @@ The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar, Populati
31
31
  The web counterpart of this library is public now. Try out our new reactJS library- [react-gifted-charts](https://www.npmjs.com/package/react-gifted-charts) <br />
32
32
  The exact same piece of code that you write to render charts in react-native, can be used to render charts in reactJS using this library!
33
33
 
34
- ## [Release notes 🎉](release-notes/release-notes.md)
34
+ ## [Release notes (Changelog) 🎉](release-notes/release-notes.md)
35
35
 
36
36
  See the **[release changes by version here.](release-notes/release-notes.md)**
37
37
 
@@ -17,7 +17,7 @@ import { getPropsForAnimated2DWithGradient, useRenderBars, } from 'gifted-charts
17
17
  import Tooltip from '../Components/BarSpecificComponents/tooltip';
18
18
  var RenderBars = function (props) {
19
19
  var _a, _b;
20
- var item = props.item, index = props.index, containerHeight = props.containerHeight, maxValue = props.maxValue, minHeight = props.minHeight, spacing = props.spacing, side = props.side, data = props.data, barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, isThreeD = props.isThreeD, isAnimated = props.isAnimated, rotateLabel = props.rotateLabel, appearingOpacity = props.appearingOpacity, animationDuration = props.animationDuration, autoShiftLabels = props.autoShiftLabels, label = props.label, secondaryLabel = props.secondaryLabel, labelTextStyle = props.labelTextStyle, secondaryLabelTextStyle = props.secondaryLabelTextStyle, xAxisTextNumberOfLines = props.xAxisTextNumberOfLines, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, renderTooltip = props.renderTooltip, selectedIndex = props.selectedIndex, setSelectedIndex = props.setSelectedIndex, horizontal = props.horizontal, rtl = props.rtl, pointerConfig = props.pointerConfig, noOfSectionsBelowXAxis = props.noOfSectionsBelowXAxis, barWidth = props.barWidth, _c = props.labelsDistanceFromXaxis, labelsDistanceFromXaxis = _c === void 0 ? 0 : _c, secondaryXAxis = props.secondaryXAxis, secondaryNoOfSectionsBelowXAxis = props.secondaryNoOfSectionsBelowXAxis, _d = props.barMarginBottom, barMarginBottom = _d === void 0 ? 0 : _d;
20
+ var item = props.item, index = props.index, containerHeight = props.containerHeight, maxValue = props.maxValue, minHeight = props.minHeight, spacing = props.spacing, side = props.side, data = props.data, barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, isThreeD = props.isThreeD, isAnimated = props.isAnimated, rotateLabel = props.rotateLabel, appearingOpacity = props.appearingOpacity, animationDuration = props.animationDuration, autoShiftLabels = props.autoShiftLabels, label = props.label, secondaryLabel = props.secondaryLabel, labelTextStyle = props.labelTextStyle, secondaryLabelTextStyle = props.secondaryLabelTextStyle, xAxisTextNumberOfLines = props.xAxisTextNumberOfLines, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, renderTooltip = props.renderTooltip, selectedIndex = props.selectedIndex, setSelectedIndex = props.setSelectedIndex, horizontal = props.horizontal, rtl = props.rtl, pointerConfig = props.pointerConfig, noOfSectionsBelowXAxis = props.noOfSectionsBelowXAxis, barWidth = props.barWidth, _c = props.labelsDistanceFromXaxis, labelsDistanceFromXaxis = _c === void 0 ? 0 : _c, secondaryXAxis = props.secondaryXAxis, secondaryNoOfSectionsBelowXAxis = props.secondaryNoOfSectionsBelowXAxis, _d = props.barMarginBottom, barMarginBottom = _d === void 0 ? 0 : _d, highlightEnabled = props.highlightEnabled, highlightedBarIndex = props.highlightedBarIndex, lowlightOpacity = props.lowlightOpacity;
21
21
  var _e = useRenderBars(props), heightFactor = _e.heightFactor, barHeight = _e.barHeight, tooltipProps = _e.tooltipProps;
22
22
  var _f = getPropsForAnimated2DWithGradient(__assign(__assign({}, props), { barHeight: barHeight })), commonStyleForBar = _f.commonStyleForBar, barStyleWithBackground = _f.barStyleWithBackground, commonPropsFor2dAnd3dBars = _f.commonPropsFor2dAnd3dBars, isFocused = _f.isFocused, focusedBarConfig = _f.focusedBarConfig, localFrontColor = _f.localFrontColor;
23
23
  var itemOrPropsBarInnerComponent = (_a = item.barInnerComponent) !== null && _a !== void 0 ? _a : props.barInnerComponent;
@@ -140,6 +140,13 @@ var RenderBars = function (props) {
140
140
  var barWrapperStyle = [
141
141
  {
142
142
  // overflow: 'visible',
143
+ opacity: highlightEnabled
144
+ ? highlightedBarIndex === -1
145
+ ? 1
146
+ : highlightedBarIndex === index
147
+ ? 1
148
+ : lowlightOpacity
149
+ : 1,
143
150
  marginBottom: 60 + barMarginBottom + xAxisLabelsVerticalShift - 0.5,
144
151
  width: commonPropsFor2dAnd3dBars.barWidth,
145
152
  height: barHeight,
@@ -181,7 +188,7 @@ var RenderBars = function (props) {
181
188
  : null] }));
182
189
  };
183
190
  return (_jsxs(_Fragment, { children: [pressDisabled ? (_jsx(View, { pointerEvents: "none", style: barWrapperStyle, children: barContent() })) : (_jsx(TouchableOpacity, { activeOpacity: props.activeOpacity || 0.2, onPress: function () {
184
- if (renderTooltip || props.focusBarOnPress) {
191
+ if (renderTooltip || props.focusBarOnPress || highlightEnabled) {
185
192
  if (props.focusedBarIndex === undefined || !props.onPress) {
186
193
  setSelectedIndex(index);
187
194
  }
@@ -22,7 +22,7 @@ if (Platform.OS === 'android') {
22
22
  }
23
23
  var RenderStackBars = function (props) {
24
24
  var _a;
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;
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
28
  return (_jsx(View, { style: [
@@ -72,7 +72,7 @@ var RenderStackBars = function (props) {
72
72
  var static2DSimple = function () {
73
73
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
74
74
  var remainingBarMarginBottom = barMarginBottom;
75
- return (_jsxs(_Fragment, { children: [_jsxs(TouchableOpacity, { disabled: disablePress, activeOpacity: activeOpacity, onPress: function () {
75
+ return (_jsxs(_Fragment, { children: [_jsxs(TouchableOpacity, { disabled: disablePress || (stackHighlightEnabled && !highlightEnabled), activeOpacity: activeOpacity, onPress: function () {
76
76
  setSelectedIndex(index);
77
77
  if (item.onPress) {
78
78
  item.onPress();
@@ -115,7 +115,19 @@ var RenderStackBars = function (props) {
115
115
  var deductedMargin = Math.min(barHeight, marginBottom);
116
116
  remainingBarMarginBottom = Math.max(0, remainingBarMarginBottom - deductedMargin);
117
117
  barHeight -= deductedMargin;
118
- return (_jsxs(TouchableOpacity, { onPress: stackItem.onPress, activeOpacity: activeOpacity, disabled: disablePress || !stackItem.onPress, style: __assign({ position: 'absolute', bottom: getPosition(index, barHeight) + deductedMargin, width: '100%', height: barHeight, backgroundColor: stackItem.color || item.color || props.color || 'black', borderWidth: barBorderWidth !== null && barBorderWidth !== void 0 ? barBorderWidth : 0, borderColor: barBorderColor }, borderRadii), children: [stackItem.showGradient ||
118
+ return (_jsxs(TouchableOpacity, { onPress: function (e) {
119
+ var _a;
120
+ if (stackHighlightEnabled) {
121
+ setSelectedStackIndex(index);
122
+ }
123
+ (_a = stackItem.onPress) === null || _a === void 0 ? void 0 : _a.call(stackItem, e);
124
+ }, activeOpacity: activeOpacity, disabled: disablePress ||
125
+ highlightEnabled ||
126
+ (!stackHighlightEnabled && !stackItem.onPress), style: __assign({ opacity: stackHighlightEnabled
127
+ ? selectedStackIndex === index || selectedStackIndex === -1
128
+ ? 1
129
+ : lowlightOpacity
130
+ : 1, position: 'absolute', bottom: getPosition(index, barHeight) + deductedMargin, width: '100%', height: barHeight, backgroundColor: stackItem.color || item.color || props.color || 'black', borderWidth: barBorderWidth !== null && barBorderWidth !== void 0 ? barBorderWidth : 0, borderColor: barBorderColor }, borderRadii), children: [stackItem.showGradient ||
119
131
  item.showGradient ||
120
132
  props.showGradient ? (_jsx(LinearGradient, { style: __assign({ position: 'absolute', width: '100%', height: '100%' }, borderRadii), start: { x: 0, y: 0 }, end: { x: 0, y: 1 }, colors: [
121
133
  stackItem.gradientColor ||
@@ -158,6 +170,13 @@ var RenderStackBars = function (props) {
158
170
  : 'auto', style: [
159
171
  {
160
172
  // overflow: 'visible',
173
+ opacity: highlightEnabled
174
+ ? highlightedBarIndex === -1
175
+ ? 1
176
+ : highlightedBarIndex === index
177
+ ? 1
178
+ : lowlightOpacity
179
+ : 1,
161
180
  marginBottom: 60 + xAxisLabelsVerticalShift,
162
181
  width: item.stacks[0].barWidth || props.barWidth || 30,
163
182
  height: totalHeight,
@@ -11,7 +11,7 @@ var __assign = (this && this.__assign) || function () {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { useCallback, useEffect, useMemo, useRef } from 'react';
14
- import { Animated, Easing, View } from 'react-native';
14
+ import { Animated, Easing, Pressable, View } from 'react-native';
15
15
  import RenderBars from './RenderBars';
16
16
  import RenderStackBars from './RenderStackBars';
17
17
  import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
@@ -33,7 +33,7 @@ export var BarChart = function (props) {
33
33
  }
34
34
  },
35
35
  };
36
- var _c = useBarChart(__assign(__assign({}, props), { heightValue: heightValue, widthValue: widthValue, opacityValue: opacityValue, parentWidth: (_b = props.parentWidth) !== null && _b !== void 0 ? _b : screenWidth })), lineConfig = _c.lineConfig, hidePointer1 = _c.hidePointer1, pointerItem = _c.pointerItem, pointerY = _c.pointerY, pointerConfig = _c.pointerConfig, pointerColor = _c.pointerColor, pointerX = _c.pointerX, pointerComponent = _c.pointerComponent, pointerHeight = _c.pointerHeight, pointerRadius = _c.pointerRadius, pointerWidth = _c.pointerWidth, autoAdjustPointerLabelPosition = _c.autoAdjustPointerLabelPosition, pointerLabelWidth = _c.pointerLabelWidth, activatePointersOnLongPress = _c.activatePointersOnLongPress, yAxisLabelWidth = _c.yAxisLabelWidth, shiftPointerLabelX = _c.shiftPointerLabelX, pointerLabelHeight = _c.pointerLabelHeight, pointerStripUptoDataPoint = _c.pointerStripUptoDataPoint, pointerStripHeight = _c.pointerStripHeight, shiftPointerLabelY = _c.shiftPointerLabelY, showPointerStrip = _c.showPointerStrip, pointerStripWidth = _c.pointerStripWidth, containerHeight = _c.containerHeight, xAxisThickness = _c.xAxisThickness, pointerStripColor = _c.pointerStripColor, pointerEvents = _c.pointerEvents, setResponderStartTime = _c.setResponderStartTime, setPointerY = _c.setPointerY, setPointerItem = _c.setPointerItem, initialSpacing = _c.initialSpacing, spacing = _c.spacing, data = _c.data, barWidth = _c.barWidth, setPointerX = _c.setPointerX, pointerIndex = _c.pointerIndex, setPointerIndex = _c.setPointerIndex, maxValue = _c.maxValue, responderStartTime = _c.responderStartTime, setResponderActive = _c.setResponderActive, activatePointersDelay = _c.activatePointersDelay, persistPointer = _c.persistPointer, pointerVanishDelay = _c.pointerVanishDelay, containerHeightIncludingBelowXAxis = _c.containerHeightIncludingBelowXAxis, extendedContainerHeight = _c.extendedContainerHeight, totalWidth = _c.totalWidth, stripBehindBars = _c.stripBehindBars, noOfSectionsBelowXAxis = _c.noOfSectionsBelowXAxis, stepHeight = _c.stepHeight, xAxisLabelsVerticalShift = _c.xAxisLabelsVerticalShift, labelsExtraHeight = _c.labelsExtraHeight, stripOverPointer = _c.stripOverPointer, pointerLabelComponent = _c.pointerLabelComponent, setSelectedIndex = _c.setSelectedIndex, isAnimated = _c.isAnimated, animationDuration = _c.animationDuration, side = _c.side, labelWidth = _c.labelWidth, isThreeD = _c.isThreeD, animatedHeight = _c.animatedHeight, appearingOpacity = _c.appearingOpacity, autoShiftLabels = _c.autoShiftLabels, getPropsCommonForBarAndStack = _c.getPropsCommonForBarAndStack, barAndLineChartsWrapperProps = _c.barAndLineChartsWrapperProps, autoShiftLabelsForNegativeStacks = _c.autoShiftLabelsForNegativeStacks;
36
+ var _c = useBarChart(__assign(__assign({}, props), { heightValue: heightValue, widthValue: widthValue, opacityValue: opacityValue, parentWidth: (_b = props.parentWidth) !== null && _b !== void 0 ? _b : screenWidth })), lineConfig = _c.lineConfig, hidePointer1 = _c.hidePointer1, pointerItem = _c.pointerItem, pointerY = _c.pointerY, pointerConfig = _c.pointerConfig, pointerColor = _c.pointerColor, pointerX = _c.pointerX, pointerComponent = _c.pointerComponent, pointerHeight = _c.pointerHeight, pointerRadius = _c.pointerRadius, pointerWidth = _c.pointerWidth, autoAdjustPointerLabelPosition = _c.autoAdjustPointerLabelPosition, pointerLabelWidth = _c.pointerLabelWidth, activatePointersOnLongPress = _c.activatePointersOnLongPress, yAxisLabelWidth = _c.yAxisLabelWidth, shiftPointerLabelX = _c.shiftPointerLabelX, pointerLabelHeight = _c.pointerLabelHeight, pointerStripUptoDataPoint = _c.pointerStripUptoDataPoint, pointerStripHeight = _c.pointerStripHeight, shiftPointerLabelY = _c.shiftPointerLabelY, showPointerStrip = _c.showPointerStrip, pointerStripWidth = _c.pointerStripWidth, containerHeight = _c.containerHeight, xAxisThickness = _c.xAxisThickness, pointerStripColor = _c.pointerStripColor, pointerEvents = _c.pointerEvents, setResponderStartTime = _c.setResponderStartTime, setPointerY = _c.setPointerY, setPointerItem = _c.setPointerItem, initialSpacing = _c.initialSpacing, spacing = _c.spacing, data = _c.data, barWidth = _c.barWidth, setPointerX = _c.setPointerX, pointerIndex = _c.pointerIndex, setPointerIndex = _c.setPointerIndex, maxValue = _c.maxValue, responderStartTime = _c.responderStartTime, setResponderActive = _c.setResponderActive, activatePointersDelay = _c.activatePointersDelay, persistPointer = _c.persistPointer, pointerVanishDelay = _c.pointerVanishDelay, containerHeightIncludingBelowXAxis = _c.containerHeightIncludingBelowXAxis, extendedContainerHeight = _c.extendedContainerHeight, totalWidth = _c.totalWidth, stripBehindBars = _c.stripBehindBars, noOfSectionsBelowXAxis = _c.noOfSectionsBelowXAxis, stepHeight = _c.stepHeight, xAxisLabelsVerticalShift = _c.xAxisLabelsVerticalShift, labelsExtraHeight = _c.labelsExtraHeight, stripOverPointer = _c.stripOverPointer, pointerLabelComponent = _c.pointerLabelComponent, selectedIndex = _c.selectedIndex, setSelectedIndex = _c.setSelectedIndex, selectedStackIndex = _c.selectedStackIndex, setSelectedStackIndex = _c.setSelectedStackIndex, isAnimated = _c.isAnimated, animationDuration = _c.animationDuration, side = _c.side, labelWidth = _c.labelWidth, isThreeD = _c.isThreeD, animatedHeight = _c.animatedHeight, appearingOpacity = _c.appearingOpacity, autoShiftLabels = _c.autoShiftLabels, getPropsCommonForBarAndStack = _c.getPropsCommonForBarAndStack, barAndLineChartsWrapperProps = _c.barAndLineChartsWrapperProps, autoShiftLabelsForNegativeStacks = _c.autoShiftLabelsForNegativeStacks;
37
37
  var stackData = barAndLineChartsWrapperProps.stackData;
38
38
  var labelsAppear = useCallback(function () {
39
39
  opacityValue.setValue(0);
@@ -118,11 +118,36 @@ export var BarChart = function (props) {
118
118
  width: totalWidth,
119
119
  flexDirection: 'row',
120
120
  };
121
+ var activatePointer = function (x) {
122
+ var _a;
123
+ var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
124
+ factor = Math.round(factor);
125
+ factor = Math.min(factor, data.length - 1);
126
+ factor = Math.max(factor, 0);
127
+ var z = initialSpacing +
128
+ (spacing + barWidth) * factor -
129
+ (pointerRadius || pointerWidth / 2) +
130
+ barWidth / 2;
131
+ setPointerX(z);
132
+ setPointerIndex(factor);
133
+ var item, y;
134
+ item = (stackData !== null && stackData !== void 0 ? stackData : data)[factor];
135
+ var stackSum = 0;
136
+ if ('stacks' in item) {
137
+ stackSum = item.stacks.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
138
+ }
139
+ y =
140
+ containerHeight -
141
+ ((stackSum !== null && stackSum !== void 0 ? stackSum : item.value) * containerHeight) / maxValue -
142
+ (pointerRadius || pointerHeight / 2) +
143
+ 10;
144
+ setPointerY(y);
145
+ setPointerItem(item);
146
+ (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onResponderGrant) === null || _a === void 0 ? void 0 : _a.call(pointerConfig);
147
+ };
121
148
  var renderChartContent = function () {
122
149
  if (pointerConfig) {
123
- return (_jsxs(View, { onStartShouldSetResponder: function () { return !!pointerConfig; }, onMoveShouldSetResponder: function () { return !!pointerConfig; }, onResponderGrant: function (evt) {
124
- if (!pointerConfig)
125
- return;
150
+ return (_jsxs(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); }, onStartShouldSetResponder: function () { return !!pointerConfig; }, onMoveShouldSetResponder: function () { return !!pointerConfig; }, onResponderGrant: function (evt) {
126
151
  setResponderStartTime(evt.timeStamp);
127
152
  if (activatePointersOnLongPress) {
128
153
  return;
@@ -131,33 +156,7 @@ export var BarChart = function (props) {
131
156
  if (!activatePointersOnLongPress &&
132
157
  x > (props.width || screenWidth))
133
158
  return;
134
- var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
135
- factor = Math.round(factor);
136
- factor = Math.min(factor, data.length - 1);
137
- factor = Math.max(factor, 0);
138
- var z = initialSpacing +
139
- (spacing + barWidth) * factor -
140
- (pointerRadius || pointerWidth / 2) +
141
- barWidth / 2;
142
- setPointerX(z);
143
- setPointerIndex(factor);
144
- var item, y;
145
- item = (stackData !== null && stackData !== void 0 ? stackData : data)[factor];
146
- var stackSum = 0;
147
- if ('stacks' in item) {
148
- stackSum = item.stacks.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
149
- }
150
- y =
151
- containerHeight -
152
- ((stackSum !== null && stackSum !== void 0 ? stackSum : item.value) * containerHeight) / maxValue -
153
- (pointerRadius || pointerHeight / 2) +
154
- 10;
155
- setPointerY(y);
156
- setPointerItem(item);
157
159
  }, onResponderMove: function (evt) {
158
- var _a;
159
- if (!pointerConfig)
160
- return;
161
160
  if (activatePointersOnLongPress &&
162
161
  evt.timeStamp - responderStartTime < activatePointersDelay) {
163
162
  return;
@@ -169,35 +168,15 @@ export var BarChart = function (props) {
169
168
  if (!activatePointersOnLongPress &&
170
169
  x > (props.width || screenWidth))
171
170
  return;
172
- var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
173
- factor = Math.round(factor);
174
- factor = Math.min(factor, (stackData !== null && stackData !== void 0 ? stackData : data).length - 1);
175
- factor = Math.max(factor, 0);
176
- var z = initialSpacing +
177
- (spacing + barWidth) * factor -
178
- (pointerRadius || pointerWidth / 2) +
179
- barWidth / 2;
180
- var item, y;
181
- setPointerX(z);
182
- setPointerIndex(factor);
183
- item = (stackData !== null && stackData !== void 0 ? stackData : data)[factor];
184
- var stackSum = 0;
185
- if ('stacks' in item) {
186
- (_a = item.stacks) === null || _a === void 0 ? void 0 : _a.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
187
- }
188
- y =
189
- containerHeight -
190
- ((stackSum !== null && stackSum !== void 0 ? stackSum : item.value) * containerHeight) / maxValue -
191
- (pointerRadius || pointerHeight / 2) +
192
- 10;
193
- setPointerY(y);
194
- setPointerItem(item);
171
+ activatePointer(x);
195
172
  }, onResponderEnd: function (evt) {
173
+ var _a;
196
174
  setResponderStartTime(0);
197
175
  setPointerIndex(-1);
198
176
  setResponderActive(false);
199
177
  if (!persistPointer)
200
178
  setTimeout(function () { return setPointerX(0); }, pointerVanishDelay);
179
+ (_a = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.onResponderEnd) === null || _a === void 0 ? void 0 : _a.call(pointerConfig);
201
180
  }, onResponderTerminationRequest: function (evt) { return false; }, style: contentContainerStyle, children: [pointerX > 0 && stripBehindBars ? (_jsx(View, { pointerEvents: pointerEvents !== null && pointerEvents !== void 0 ? pointerEvents : 'none', style: {
202
181
  position: 'absolute',
203
182
  height: extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
@@ -218,13 +197,20 @@ export var BarChart = function (props) {
218
197
  ] })) : null] }));
219
198
  }
220
199
  else {
221
- return _jsx(View, { style: contentContainerStyle, children: renderChart() });
200
+ return (_jsx(Pressable, { style: contentContainerStyle, onPress: function () {
201
+ if (props.highlightEnabled && selectedIndex !== -1)
202
+ setSelectedIndex(-1);
203
+ if (props.stackHighlightEnabled && selectedStackIndex !== -1) {
204
+ setSelectedStackIndex(-1);
205
+ // props.setHighlightedStackIndex?.(-1)
206
+ }
207
+ }, children: renderChart() }));
222
208
  }
223
209
  };
224
210
  var renderChart = function () {
225
211
  if (stackData) {
226
212
  return stackData.map(function (item, index) {
227
- return (_jsx(RenderStackBars, __assign({ stackData: props.stackData || [], isAnimated: isAnimated, animationDuration: animationDuration, stackBorderRadius: props.stackBorderRadius, stackBorderTopLeftRadius: props.stackBorderTopLeftRadius, stackBorderTopRightRadius: props.stackBorderTopRightRadius, stackBorderBottomLeftRadius: props.stackBorderBottomLeftRadius, stackBorderBottomRightRadius: props.stackBorderBottomRightRadius, autoShiftLabelsForNegativeStacks: autoShiftLabelsForNegativeStacks }, getPropsCommonForBarAndStack(item, index)), index));
213
+ return (_jsx(RenderStackBars, __assign({ stackData: props.stackData || [], isAnimated: isAnimated, animationDuration: animationDuration, stackBorderRadius: props.stackBorderRadius, stackBorderTopLeftRadius: props.stackBorderTopLeftRadius, stackBorderTopRightRadius: props.stackBorderTopRightRadius, stackBorderBottomLeftRadius: props.stackBorderBottomLeftRadius, stackBorderBottomRightRadius: props.stackBorderBottomRightRadius, autoShiftLabelsForNegativeStacks: autoShiftLabelsForNegativeStacks, selectedStackIndex: selectedStackIndex, setSelectedStackIndex: setSelectedStackIndex }, getPropsCommonForBarAndStack(item, index)), index));
228
214
  });
229
215
  }
230
216
  else {
@@ -6,8 +6,13 @@ import { renderDataPoints } from './renderDataPoints';
6
6
  import { renderSpecificDataPoints } from './renderSpecificDataPoints';
7
7
  var RenderLineInBarChart = function (props) {
8
8
  var _a;
9
- var yAxisLabelWidth = props.yAxisLabelWidth, initialSpacing = props.initialSpacing, spacing = props.spacing, containerHeight = props.containerHeight, lineConfig = props.lineConfig, maxValue = props.maxValue, animatedWidth = props.animatedWidth, lineBehindBars = props.lineBehindBars, points = props.points, arrowPoints = props.arrowPoints, data = props.data, totalWidth = props.totalWidth, barWidth = props.barWidth, labelsExtraHeight = props.labelsExtraHeight, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, selectedIndex = props.selectedIndex, containerHeightIncludingBelowXAxis = props.containerHeightIncludingBelowXAxis, yAxisOffset = props.yAxisOffset;
9
+ var yAxisLabelWidth = props.yAxisLabelWidth, initialSpacing = props.initialSpacing, spacing = props.spacing, containerHeight = props.containerHeight, lineConfig = props.lineConfig, maxValue = props.maxValue, animatedWidth = props.animatedWidth, lineBehindBars = props.lineBehindBars, points = props.points, arrowPoints = props.arrowPoints, data = props.data, totalWidth = props.totalWidth, barWidth = props.barWidth, labelsExtraHeight = props.labelsExtraHeight, xAxisLabelsVerticalShift = props.xAxisLabelsVerticalShift, selectedIndex = props.selectedIndex, containerHeightIncludingBelowXAxis = props.containerHeightIncludingBelowXAxis, yAxisOffset = props.yAxisOffset, highlightEnabled = props.highlightEnabled, lowlightOpacity = props.lowlightOpacity;
10
10
  var firstBarWidth = (_a = data[0].barWidth) !== null && _a !== void 0 ? _a : barWidth;
11
+ var opacity = highlightEnabled
12
+ ? selectedIndex === -1
13
+ ? 1
14
+ : lowlightOpacity
15
+ : 1;
11
16
  var dataPointsProps = {
12
17
  data: data,
13
18
  lineConfig: lineConfig,
@@ -19,6 +24,7 @@ var RenderLineInBarChart = function (props) {
19
24
  spacing: spacing,
20
25
  selectedIndex: selectedIndex,
21
26
  yAxisOffset: yAxisOffset,
27
+ opacity: opacity,
22
28
  };
23
29
  var specificVerticalLinesProps = {
24
30
  data: data,
@@ -51,7 +57,7 @@ var RenderLineInBarChart = function (props) {
51
57
  width: animatedWidth,
52
58
  zIndex: lineBehindBars ? -1 : 100000,
53
59
  // backgroundColor: 'wheat',
54
- }, children: _jsxs(Svg, { children: [_jsx(Path, { d: points, fill: "none", stroke: lineConfig.color, strokeWidth: lineConfig.thickness, strokeDasharray: lineConfig.strokeDashArray }), renderSpecificVerticalLines(specificVerticalLinesProps), !lineConfig.hideDataPoints
60
+ }, children: _jsxs(Svg, { children: [_jsx(Path, { d: points, fill: "none", opacity: opacity, stroke: lineConfig.color, strokeWidth: lineConfig.thickness, strokeDasharray: lineConfig.strokeDashArray }), renderSpecificVerticalLines(specificVerticalLinesProps), !lineConfig.hideDataPoints
55
61
  ? renderDataPoints(dataPointsProps)
56
62
  : renderSpecificDataPoints(specificDataPointsProps), lineConfig.showArrow && (_jsx(Path, { d: arrowPoints, fill: (_a = lineConfig.arrowConfig) === null || _a === void 0 ? void 0 : _a.fillColor, stroke: (_b = lineConfig.arrowConfig) === null || _b === void 0 ? void 0 : _b.strokeColor, strokeWidth: (_c = lineConfig.arrowConfig) === null || _c === void 0 ? void 0 : _c.strokeWidth }))] }) }));
57
63
  };
@@ -65,7 +71,7 @@ var RenderLineInBarChart = function (props) {
65
71
  width: totalWidth,
66
72
  zIndex: lineBehindBars ? -1 : 100000,
67
73
  // backgroundColor: 'rgba(200,150,150,0.1)'
68
- }, children: _jsxs(Svg, { children: [_jsx(Path, { d: points, fill: "none", stroke: lineConfig.color, strokeWidth: lineConfig.thickness, strokeDasharray: lineConfig.strokeDashArray }), renderSpecificVerticalLines(specificVerticalLinesProps), !lineConfig.hideDataPoints
74
+ }, children: _jsxs(Svg, { children: [_jsx(Path, { d: points, fill: "none", opacity: opacity, stroke: lineConfig.color, strokeWidth: lineConfig.thickness, strokeDasharray: lineConfig.strokeDashArray }), renderSpecificVerticalLines(specificVerticalLinesProps), !lineConfig.hideDataPoints
69
75
  ? renderDataPoints(dataPointsProps)
70
76
  : renderSpecificDataPoints(specificDataPointsProps), lineConfig.showArrow && (_jsx(Path, { d: arrowPoints, fill: (_a = lineConfig.arrowConfig) === null || _a === void 0 ? void 0 : _a.fillColor, stroke: (_b = lineConfig.arrowConfig) === null || _b === void 0 ? void 0 : _b.strokeColor, strokeWidth: (_c = lineConfig.arrowConfig) === null || _c === void 0 ? void 0 : _c.strokeWidth }))] }) }));
71
77
  };
@@ -5,7 +5,7 @@ import { View } from 'react-native';
5
5
  import { getXForLineInBar, getYForLineInBar } from 'gifted-charts-core';
6
6
  import { Rect, Text as CanvasText, Circle } from 'react-native-svg';
7
7
  export var renderDataPoints = function (props) {
8
- 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;
8
+ 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;
9
9
  return data.map(function (item, index) {
10
10
  var _a, _b, _c, _d, _e;
11
11
  if (index < lineConfig.startIndex ||
@@ -28,6 +28,7 @@ export var renderDataPoints = function (props) {
28
28
  return (_jsx(View, { style: [
29
29
  styles.customDataPointContainer,
30
30
  {
31
+ opacity: opacity,
31
32
  height: lineConfig.dataPointsHeight,
32
33
  width: lineConfig.dataPointsWidth,
33
34
  top: containerHeight -
@@ -39,11 +40,11 @@ export var renderDataPoints = function (props) {
39
40
  }
40
41
  if (lineConfig.dataPointsShape === 'rectangular') {
41
42
  return (_jsxs(Fragment, { children: [_jsx(Rect, { x: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing), y: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset) -
42
- lineConfig.dataPointsHeight / 2, width: lineConfig.dataPointsWidth, height: lineConfig.dataPointsHeight, fill: dataPointColor }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, fontSize: item.textFontSize || lineConfig.textFontSize, x: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing) + (item.textShiftX || lineConfig.textShiftX || 0), y: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset) -
43
+ lineConfig.dataPointsHeight / 2, width: lineConfig.dataPointsWidth, height: lineConfig.dataPointsHeight, fill: dataPointColor, opacity: opacity }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, opacity: opacity, fontSize: item.textFontSize || lineConfig.textFontSize, x: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing) + (item.textShiftX || lineConfig.textShiftX || 0), y: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset) -
43
44
  lineConfig.dataPointsHeight / 2 +
44
45
  (item.textShiftY || lineConfig.textShiftY || 0), children: item.dataPointText }))] }, index));
45
46
  }
46
- return (_jsxs(Fragment, { children: [_jsx(Circle, { cx: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing), cy: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset), r: dataPointRadius, fill: dataPointColor }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, fontSize: item.textFontSize || lineConfig.textFontSize, x: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing) + (item.textShiftX || lineConfig.textShiftX || 0), y: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset) -
47
+ return (_jsxs(Fragment, { children: [_jsx(Circle, { cx: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing), cy: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset), r: dataPointRadius, fill: dataPointColor, opacity: opacity }), item.dataPointText && (_jsx(CanvasText, { fill: item.textColor || lineConfig.textColor, opacity: opacity, fontSize: item.textFontSize || lineConfig.textFontSize, x: getXForLineInBar(index, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing) + (item.textShiftX || lineConfig.textShiftX || 0), y: getYForLineInBar(value, lineConfig.shiftY, containerHeight, maxValue, yAxisOffset) -
47
48
  lineConfig.dataPointsHeight / 2 +
48
49
  (item.textShiftY || lineConfig.textShiftY || 0), children: item.dataPointText }))] }, index));
49
50
  });
@@ -16,7 +16,7 @@ var __read = (this && this.__read) || function (o, n) {
16
16
  };
17
17
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
18
18
  import React, { useState } from 'react';
19
- import { TouchableWithoutFeedback, View, Text } from 'react-native';
19
+ import { Pressable, View, Text } from 'react-native';
20
20
  import Svg, { Path, Circle, Text as SvgText, Defs, RadialGradient, Stop, G, Line, } from 'react-native-svg';
21
21
  import { getPieChartMainProps, pieColors, } from 'gifted-charts-core';
22
22
  import { isWebApp, rnVersion } from '../utils';
@@ -28,11 +28,13 @@ export var PieChartMain = function (props) {
28
28
  var wasFirstItemOnPole = false;
29
29
  var _d = __read(useState(0), 2), touchX = _d[0], setTouchX = _d[1];
30
30
  var _e = __read(useState(0), 2), touchY = _e[0], setTouchY = _e[1];
31
+ var _f = __read(useState(0), 2), top = _f[0], setTop = _f[1];
32
+ var _g = __read(useState(0), 2), left = _g[0], setLeft = _g[1];
31
33
  var onPressHandler = function (e) {
32
34
  var x = 0, y = 0;
33
35
  if (isWebApp) {
34
- x = e.clientX;
35
- y = e.clientY;
36
+ x = e.clientX - left;
37
+ y = e.clientY - top;
36
38
  }
37
39
  else {
38
40
  x = e.nativeEvent.locationX;
@@ -65,7 +67,12 @@ export var PieChartMain = function (props) {
65
67
  }
66
68
  }
67
69
  };
68
- return (_jsx(TouchableWithoutFeedback, { onPress: onPressHandler, children: _jsxs(View, { pointerEvents: "box-only", style: [
70
+ return (_jsx(Pressable, { onPress: onPressHandler, children: _jsxs(View, { pointerEvents: "box-only", onLayout: function (e) {
71
+ if (!isWebApp)
72
+ return;
73
+ setTop(e.nativeEvent.layout.top);
74
+ setLeft(e.nativeEvent.layout.left);
75
+ }, style: [
69
76
  {
70
77
  backgroundColor: backgroundColor,
71
78
  height: semiCircle
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.55",
3
+ "version": "1.4.56",
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.57"
29
+ "gifted-charts-core": "0.1.58"
30
30
  },
31
31
  "devDependencies": {
32
32
  "@babel/cli": "^7.24.8",