react-native-gifted-charts 1.4.15 → 1.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.15",
3
+ "version": "1.4.17",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "registry": "https://registry.npmjs.org/"
26
26
  },
27
27
  "dependencies": {
28
- "gifted-charts-core": "^0.1.11"
28
+ "gifted-charts-core": "^0.1.15"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@babel/core": "^7.22.5",
@@ -11,6 +11,7 @@ import {
11
11
  barDataItem,
12
12
  AxesAndRulesDefaults,
13
13
  } from 'gifted-charts-core';
14
+ import Tooltip from '../Components/BarSpecificComponents/tooltip';
14
15
 
15
16
  const RenderBars = (props: RenderBarsPropsType) => {
16
17
  const {
@@ -57,6 +58,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
57
58
  stepValue,
58
59
  negativeStepHeight,
59
60
  negativeStepValue,
61
+ autoCenterTooltip,
60
62
  } = props;
61
63
 
62
64
  const heightFactor =
@@ -328,7 +330,10 @@ const RenderBars = (props: RenderBarsPropsType) => {
328
330
  const barContent = () => {
329
331
  const isBarBelowXaxisAndInvisible =
330
332
  item.value < 0 && !noOfSectionsBelowXAxis;
331
- const animated2DWithGradient = (noGradient, noAnimation) => (
333
+ const animated2DWithGradient = (
334
+ noGradient: boolean,
335
+ noAnimation: boolean,
336
+ ) => (
332
337
  <Animated2DWithGradient
333
338
  {...commonPropsFor2Dand3Dbars}
334
339
  animationDuration={animationDuration || 800}
@@ -400,6 +405,20 @@ const RenderBars = (props: RenderBarsPropsType) => {
400
405
  );
401
406
  };
402
407
 
408
+ const tooltipProps = {
409
+ barHeight,
410
+ barWidth: item.barWidth || barWidth,
411
+ item,
412
+ index,
413
+ isLast: index === data.length - 1,
414
+ leftSpacing,
415
+ leftShiftForLastIndexTooltip,
416
+ leftShiftForTooltip: item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0,
417
+ renderTooltip,
418
+ autoCenterTooltip,
419
+ horizontal,
420
+ };
421
+
403
422
  return (
404
423
  <>
405
424
  {pressDisabled ? (
@@ -440,19 +459,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
440
459
  </TouchableOpacity>
441
460
  )}
442
461
  {renderTooltip && selectedIndex === index && (
443
- <View
444
- style={{
445
- position: 'absolute',
446
- bottom: barHeight + 60,
447
- left:
448
- index === data.length - 1
449
- ? leftSpacing - leftShiftForLastIndexTooltip
450
- : leftSpacing -
451
- (item?.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
452
- zIndex: 1000,
453
- }}>
454
- {renderTooltip(item, index)}
455
- </View>
462
+ <Tooltip {...tooltipProps} />
456
463
  )}
457
464
  </>
458
465
  );
@@ -14,6 +14,7 @@ import {
14
14
  BarDefaults,
15
15
  StackedBarChartPropsType,
16
16
  } from 'gifted-charts-core';
17
+ import Tooltip from '../Components/BarSpecificComponents/tooltip';
17
18
 
18
19
  if (Platform.OS === 'android') {
19
20
  UIManager.setLayoutAnimationEnabledExperimental &&
@@ -34,12 +35,9 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
34
35
  xAxisTextNumberOfLines,
35
36
  xAxisLabelsVerticalShift,
36
37
  renderTooltip,
37
- leftShiftForTooltip,
38
- leftShiftForLastIndexTooltip,
39
38
  selectedIndex,
40
39
  setSelectedIndex,
41
40
  activeOpacity,
42
- stackData,
43
41
  animationDuration = BarDefaults.animationDuration,
44
42
  barBorderWidth,
45
43
  barBorderColor,
@@ -51,6 +49,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
51
49
  showValuesAsTopLabel,
52
50
  autoShiftLabelsForNegativeStacks = true,
53
51
  labelsDistanceFromXaxis = 0,
52
+ horizontal,
54
53
  } = props;
55
54
  const {
56
55
  cotainsNegative,
@@ -61,7 +60,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
61
60
  borderTopRightRadius,
62
61
  borderBottomLeftRadius,
63
62
  borderBottomRightRadius,
64
- leftSpacing,
65
63
  disablePress,
66
64
  totalHeight,
67
65
  height,
@@ -70,6 +68,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
70
68
  getPosition,
71
69
  lowestBarPosition,
72
70
  getStackBorderRadii,
71
+ tooltipProps,
73
72
  } = useRenderStackBars(props);
74
73
 
75
74
  const renderLabel = (label: String, labelTextStyle: any) => {
@@ -85,10 +84,10 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
85
84
  : -labelsDistanceFromXaxis,
86
85
  },
87
86
  rotateLabel
88
- ? props.horizontal
87
+ ? horizontal
89
88
  ? {transform: [{rotate: '330deg'}]}
90
89
  : {transform: [{rotate: '60deg'}]}
91
- : props.horizontal
90
+ : horizontal
92
91
  ? {transform: [{rotate: '-90deg'}]}
93
92
  : {},
94
93
  ]}>
@@ -268,7 +267,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
268
267
  alignItems: 'center',
269
268
  },
270
269
  cotainsNegative && {transform: [{translateY: totalHeight * 2}]},
271
- props.horizontal &&
270
+ horizontal &&
272
271
  !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
273
272
  item.topLabelContainerStyle,
274
273
  ]}>
@@ -331,19 +330,6 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
331
330
  }
332
331
  : null,
333
332
  ]}>
334
- {/* {props.showVerticalLines && (
335
- <View
336
- style={{
337
- zIndex: props.verticalLinesZIndex,
338
- position: 'absolute',
339
- height: (containerHeight || 200) + 15,
340
- width: props.verticalLinesThickness,
341
- bottom: 0,
342
- left: (item.barWidth || props.barWidth || 30) / 2,
343
- backgroundColor: props.verticalLinesColor,
344
- }}
345
- />
346
- )} */}
347
333
  {(props.showXAxisIndices || item.showXAxisIndex) && (
348
334
  <View
349
335
  style={{
@@ -364,19 +350,7 @@ const RenderStackBars = (props: StackedBarChartPropsType) => {
364
350
  {renderLabel(label || '', labelTextStyle)}
365
351
  </View>
366
352
  {renderTooltip && selectedIndex === index && (
367
- <View
368
- style={{
369
- position: 'absolute',
370
- bottom: totalHeight + 60,
371
- left:
372
- index === stackData.length - 1
373
- ? leftSpacing - leftShiftForLastIndexTooltip
374
- : leftSpacing -
375
- (item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0),
376
- zIndex: 1000,
377
- }}>
378
- {renderTooltip(item, index)}
379
- </View>
353
+ <Tooltip {...tooltipProps} />
380
354
  )}
381
355
  </>
382
356
  );
@@ -16,7 +16,7 @@ export const BarChart = (props: BarChartPropsType) => {
16
16
  const scrollRef = props.scrollRef ?? useRef(null);
17
17
  const remainingScrollViewProps = {
18
18
  onScroll: (ev: any) => props.onScroll?.(ev),
19
- onTouchStart: evt => {
19
+ onTouchStart: (evt: any) => {
20
20
  if (props.renderTooltip) {
21
21
  setSelectedIndex(-1);
22
22
  }
@@ -141,7 +141,7 @@ export const BarChart = (props: BarChartPropsType) => {
141
141
  });
142
142
  };
143
143
 
144
- const renderStripAndLabel = pointerLabelComponent => {
144
+ const renderStripAndLabel = (pointerLabelComponent: any) => {
145
145
  let pointerItemLocal,
146
146
  pointerYLocal = pointerY;
147
147
 
@@ -204,12 +204,16 @@ export const BarChart = (props: BarChartPropsType) => {
204
204
  barWidth / 2;
205
205
  setPointerX(z);
206
206
  setPointerIndex(factor);
207
+
207
208
  let item, y;
208
209
  item = (props.stackData ?? data)[factor];
209
- const stackSum = item.stacks?.reduce(
210
- (acc, stack) => acc + (stack.value ?? 0),
211
- 0,
212
- );
210
+ let stackSum = 0;
211
+ if ('stacks' in item) {
212
+ stackSum = item.stacks.reduce(
213
+ (acc: number, stack: any) => acc + (stack.value ?? 0),
214
+ 0,
215
+ );
216
+ }
213
217
  y =
214
218
  containerHeight -
215
219
  ((stackSum ?? item.value) * containerHeight) / maxValue -
@@ -248,10 +252,13 @@ export const BarChart = (props: BarChartPropsType) => {
248
252
  setPointerX(z);
249
253
  setPointerIndex(factor);
250
254
  item = (props.stackData ?? data)[factor];
251
- const stackSum = item.stacks?.reduce(
252
- (acc, stack) => acc + (stack.value ?? 0),
253
- 0,
254
- );
255
+ let stackSum = 0;
256
+ if ('stacks' in item) {
257
+ item.stacks?.reduce(
258
+ (acc: number, stack: any) => acc + (stack.value ?? 0),
259
+ 0,
260
+ );
261
+ }
255
262
  y =
256
263
  containerHeight -
257
264
  ((stackSum ?? item.value) * containerHeight) / maxValue -
@@ -326,6 +333,7 @@ export const BarChart = (props: BarChartPropsType) => {
326
333
  return props.stackData.map((item, index) => {
327
334
  return (
328
335
  <RenderStackBars
336
+ key={index}
329
337
  stackData={props.stackData || []}
330
338
  isAnimated={isAnimated}
331
339
  animationDuration={animationDuration}
@@ -342,6 +350,7 @@ export const BarChart = (props: BarChartPropsType) => {
342
350
  } else {
343
351
  return data.map((item, index) => (
344
352
  <RenderBars
353
+ key={index}
345
354
  data={data}
346
355
  side={side}
347
356
  minHeight={props.minHeight ?? (isAnimated && !isThreeD ? 0.1 : 0)}
@@ -376,6 +385,7 @@ export const BarChart = (props: BarChartPropsType) => {
376
385
  scrollRef={scrollRef}
377
386
  renderChartContent={renderChartContent}
378
387
  remainingScrollViewProps={remainingScrollViewProps}
388
+ nestedScrollEnabled={props.nestedScrollEnabled}
379
389
  />
380
390
  );
381
391
  };
@@ -53,6 +53,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
53
53
  onEndReached,
54
54
  onStartReached,
55
55
  onMomentumScrollEnd,
56
+ nestedScrollEnabled,
56
57
  extraWidthDueToDataPoint = 0, // extraWidthDueToDataPoint will be receved from props onlhy in case of LineCharts, for other charts it will be undefined and will default to 0
57
58
  } = props;
58
59
 
@@ -125,6 +126,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
125
126
  onScrollBeginDrag={() => {
126
127
  setCanMomentum(true);
127
128
  }}
129
+ nestedScrollEnabled={nestedScrollEnabled}
128
130
  onMomentumScrollEnd={({nativeEvent}) => {
129
131
  if (onMomentumScrollEnd) {
130
132
  onMomentumScrollEnd();
@@ -7,10 +7,12 @@ import {
7
7
  yAxisSides,
8
8
  HorizSectionsType,
9
9
  horizSectionPropTypes,
10
+ chartTypes,
10
11
  } from 'gifted-charts-core';
11
12
 
12
13
  export const renderHorizSections = (props: horizSectionPropTypes) => {
13
14
  const {
15
+ chartType,
14
16
  width,
15
17
  noOfSectionsBelowXAxis,
16
18
  totalWidth,
@@ -199,10 +201,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
199
201
  ) =>
200
202
  horizSections.map((sectionItems, index) => {
201
203
  let label = getLabelTextsForSecondaryYAxis(sectionItems.value, index);
202
- if (
203
- secondaryYAxisConfig.hideOrigin &&
204
- index === secondaryHorizSections.length - 1
205
- ) {
204
+ if (secondaryYAxisConfig.hideOrigin && index === 0) {
206
205
  label = '';
207
206
  }
208
207
  return (
@@ -330,6 +329,12 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
330
329
  );
331
330
  };
332
331
 
332
+ const leftShiftForRIghtYaxis =
333
+ (width ? width + 20 : totalWidth) +
334
+ yAxisLabelWidth / 2 +
335
+ endSpacing -
336
+ (chartType === chartTypes.BAR ? 40 : 60);
337
+
333
338
  return (
334
339
  <>
335
340
  {onlyReferenceLines ? (
@@ -411,7 +416,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
411
416
  : stepHeight,
412
417
  },
413
418
  yAxisSide === yAxisSides.RIGHT && {
414
- left: (width ?? totalWidth) + yAxisLabelWidth / 2,
419
+ left: leftShiftForRIghtYaxis,
415
420
  },
416
421
  horizontal &&
417
422
  !yAxisAtTop && {
@@ -5,7 +5,7 @@ import {renderSpecificVerticalLines} from './renderSpecificVerticalLines';
5
5
  import {renderDataPoints} from './renderDataPoints';
6
6
  import {renderSpecificDataPoints} from './renderSpecificDataPoints';
7
7
 
8
- const RenderLineInBarChart = props => {
8
+ const RenderLineInBarChart = (props: any) => {
9
9
  const {
10
10
  yAxisLabelWidth,
11
11
  initialSpacing,
@@ -4,7 +4,7 @@ import {View} from 'react-native';
4
4
  import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
5
5
  import {Rect, Text as CanvasText, Circle} from 'react-native-svg';
6
6
 
7
- export const renderDataPoints = props => {
7
+ export const renderDataPoints = (props: any) => {
8
8
  const {
9
9
  data,
10
10
  lineConfig,
@@ -22,7 +22,8 @@ export const renderDataPoints = props => {
22
22
  const currentBarWidth = item.barWidth || barWidth || 30;
23
23
  const customDataPoint = item.customDataPoint || lineConfig.customDataPoint;
24
24
  const value =
25
- item.value ?? item.stacks.reduce((total, item) => total + item.value, 0);
25
+ item.value ??
26
+ item.stacks.reduce((total: number, item: any) => total + item.value, 0);
26
27
  if (customDataPoint) {
27
28
  return (
28
29
  <View
@@ -2,7 +2,7 @@ import React, {Fragment} from 'react';
2
2
  import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
3
3
  import {Circle, Rect, Text as CanvasText} from 'react-native-svg';
4
4
 
5
- export const renderSpecificDataPoints = props => {
5
+ export const renderSpecificDataPoints = (props: any) => {
6
6
  const {
7
7
  data,
8
8
  barWidth,
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import {Rect} from 'react-native-svg';
3
3
 
4
- export const renderSpecificVerticalLines = props => {
4
+ export const renderSpecificVerticalLines = (props: any) => {
5
5
  const {
6
6
  data,
7
7
  barWidth,
@@ -3,7 +3,7 @@ import {View} from 'react-native';
3
3
  import {chartTypes} from 'gifted-charts-core';
4
4
  import {Line, Svg} from 'react-native-svg';
5
5
 
6
- const RenderVerticalLines = props => {
6
+ const RenderVerticalLines = (props: any) => {
7
7
  const {
8
8
  verticalLinesAr,
9
9
  verticalLinesSpacing,
@@ -29,7 +29,7 @@ const RenderVerticalLines = props => {
29
29
  xAxisLabelsVerticalShift,
30
30
  } = props;
31
31
 
32
- const getHeightOfVerticalLine = index => {
32
+ const getHeightOfVerticalLine = (index: number) => {
33
33
  if (verticalLinesUptoDataPoint) {
34
34
  if (index < data.length) {
35
35
  return (
@@ -107,8 +107,8 @@ const RenderVerticalLines = props => {
107
107
  (chartType === chartTypes.BAR
108
108
  ? totalSpacing - 1
109
109
  : verticalLinesSpacing
110
- ? verticalLinesSpacing * (index + 1)
111
- : index * spacing + (initialSpacing - 2));
110
+ ? verticalLinesSpacing * (index + 1)
111
+ : index * spacing + (initialSpacing - 2));
112
112
 
113
113
  return (
114
114
  <Line
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import Svg, {Defs, Rect} from 'react-native-svg';
3
3
 
4
- const BarBackgroundPattern = props => {
4
+ const BarBackgroundPattern = (props: any) => {
5
5
  const {
6
6
  barBackgroundPatternFromItem,
7
7
  barBackgroundPatternFromProps,
@@ -10,20 +10,20 @@ const BarBackgroundPattern = props => {
10
10
  } = props;
11
11
  return (
12
12
  <Svg>
13
- <Defs>
14
- {barBackgroundPatternFromItem
15
- ? barBackgroundPatternFromItem()
16
- : barBackgroundPatternFromProps()}
17
- </Defs>
18
- <Rect
19
- stroke="transparent"
20
- x="1"
21
- y="1"
22
- width="100%"
23
- height="100%"
24
- fill={`url(#${patternIdFromItem ?? patternIdFromProps})`}
25
- />
26
- </Svg>
13
+ <Defs>
14
+ {barBackgroundPatternFromItem
15
+ ? barBackgroundPatternFromItem()
16
+ : barBackgroundPatternFromProps()}
17
+ </Defs>
18
+ <Rect
19
+ stroke="transparent"
20
+ x="1"
21
+ y="1"
22
+ width="100%"
23
+ height="100%"
24
+ fill={`url(#${patternIdFromItem ?? patternIdFromProps})`}
25
+ />
26
+ </Svg>
27
27
  );
28
28
  };
29
29
 
@@ -2,7 +2,7 @@ import React from 'react';
2
2
  import {View} from 'react-native';
3
3
  import {BarDefaults} from 'gifted-charts-core';
4
4
 
5
- const Cap = props => {
5
+ const Cap = (props: any) => {
6
6
  const {
7
7
  capThicknessFromItem,
8
8
  capThicknessFromProps,
@@ -0,0 +1,59 @@
1
+ import React, {useState} from 'react';
2
+ import {View} from 'react-native';
3
+
4
+ interface TooltipProps {
5
+ barHeight: number;
6
+ barWidth: number;
7
+ item: any;
8
+ index: number;
9
+ isLast: boolean;
10
+ leftSpacing: number;
11
+ leftShiftForLastIndexTooltip: number;
12
+ leftShiftForTooltip: number;
13
+ renderTooltip?: Function;
14
+ autoCenterTooltip?: boolean;
15
+ horizontal?: boolean;
16
+ }
17
+
18
+ const Tooltip = (props: TooltipProps) => {
19
+ const {
20
+ barHeight,
21
+ barWidth,
22
+ item,
23
+ index,
24
+ isLast,
25
+ leftSpacing,
26
+ leftShiftForLastIndexTooltip,
27
+ leftShiftForTooltip,
28
+ renderTooltip,
29
+ autoCenterTooltip,
30
+ horizontal,
31
+ } = props;
32
+
33
+ const [leftShiftTooltipForCentering, setLeftShiftTooltipForCentering] =
34
+ useState(0);
35
+
36
+ return (
37
+ <View
38
+ style={{
39
+ position: 'absolute',
40
+ bottom: barHeight + 60,
41
+ left:
42
+ leftSpacing -
43
+ (isLast ? leftShiftForLastIndexTooltip : leftShiftForTooltip) -
44
+ leftShiftTooltipForCentering,
45
+ zIndex: 1000,
46
+ transform: [{rotate: horizontal ? '-90deg' : '0deg'}],
47
+ }}
48
+ onLayout={event => {
49
+ if (!autoCenterTooltip) return;
50
+ const {width} = event.nativeEvent.layout;
51
+ const shift = (width - barWidth) / 2;
52
+ if (shift > 0) setLeftShiftTooltipForCentering(shift);
53
+ }}>
54
+ {renderTooltip?.(item, index)}
55
+ </View>
56
+ );
57
+ };
58
+
59
+ export default Tooltip;
@@ -1,12 +1,12 @@
1
1
  import React from 'react';
2
- import {ViewStyle} from "react-native";
3
2
 
4
3
  type LinearGradientProps = {
5
- style?: ViewStyle;
6
- start?: { x: number, y: number };
7
- end?: { x: number, y: number };
4
+ style?: any;
5
+ start?: {x: number; y: number};
6
+ end?: {x: number; y: number};
8
7
  colors: string[];
9
- }
8
+ children?: any;
9
+ };
10
10
 
11
11
  let LinearGradient: React.FC<LinearGradientProps>;
12
12
 
@@ -19,7 +19,7 @@ try {
19
19
  LinearGradient = require('expo-linear-gradient').LinearGradient;
20
20
  } catch (e) {
21
21
  throw new Error(
22
- 'Gradient package was not found. Make sure "react-native-linear-gradient" or "expo-linear-gradient" is installed'
22
+ 'Gradient package was not found. Make sure "react-native-linear-gradient" or "expo-linear-gradient" is installed',
23
23
  );
24
24
  }
25
25
  }
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import {View} from 'react-native';
3
3
 
4
- export const Pointer = props => {
4
+ export const Pointer = (props: any) => {
5
5
  const {
6
6
  pointerX,
7
7
  pointerYLocal,
@@ -3,7 +3,7 @@ import {View} from 'react-native';
3
3
  import Svg, {Line} from 'react-native-svg';
4
4
  import {getTopAndLeftForStripAndLabel} from 'gifted-charts-core';
5
5
 
6
- export const StripAndLabel = props => {
6
+ export const StripAndLabel = (props: any) => {
7
7
  const {
8
8
  pointerX,
9
9
  pointerLabelWidth,
@@ -191,7 +191,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
191
191
  outputRange: [0, totalWidth],
192
192
  });
193
193
 
194
- const onStripPress = (item, index) => {
194
+ const onStripPress = (item: any, index: number) => {
195
195
  setSelectedIndex(index);
196
196
  if (props.onFocus) {
197
197
  props.onFocus(item, index);
@@ -199,16 +199,16 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
199
199
  };
200
200
 
201
201
  const renderDataPoints = (
202
- dataForRender,
203
- dataPtsShape,
204
- dataPtsWidth,
205
- dataPtsHeight,
206
- dataPtsColor,
207
- dataPtsRadius,
208
- textColor,
209
- textFontSize,
210
- startIndex,
211
- endIndex,
202
+ dataForRender: any,
203
+ dataPtsShape: any,
204
+ dataPtsWidth: any,
205
+ dataPtsHeight: any,
206
+ dataPtsColor: any,
207
+ dataPtsRadius: any,
208
+ textColor: any,
209
+ textFontSize: any,
210
+ startIndex: number,
211
+ endIndex: number,
212
212
  ) => {
213
213
  return dataForRender.map((item: bicolorLineDataItem, index: number) => {
214
214
  if (index < startIndex || index > endIndex) return null;
@@ -496,7 +496,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
496
496
  strokeDashArray.length === 2 &&
497
497
  typeof strokeDashArray[0] === 'number' &&
498
498
  typeof strokeDashArray[1] === 'number'
499
- ? pointsArray.map((points, index) => (
499
+ ? pointsArray.map((points: any, index: number) => (
500
500
  <Path
501
501
  key={index}
502
502
  d={points.points}
@@ -506,7 +506,7 @@ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
506
506
  strokeDasharray={strokeDashArray}
507
507
  />
508
508
  ))
509
- : pointsArray.map((points, index) => {
509
+ : pointsArray.map((points: any, index: number) => {
510
510
  return (
511
511
  <Path
512
512
  key={index}
@@ -66,6 +66,7 @@ export const LineChart = (props: LineChartPropsType) => {
66
66
  arrow4Points,
67
67
  arrow5Points,
68
68
  secondaryArrowPoints,
69
+ pointerIndex,
69
70
  setPointerIndex,
70
71
  pointerX,
71
72
  setPointerX,
@@ -413,10 +414,10 @@ export const LineChart = (props: LineChartPropsType) => {
413
414
  useEffect(() => {
414
415
  decreaseWidth();
415
416
  labelsAppear();
416
- widthValuesFromSet?.forEach((item, index) => {
417
+ widthValuesFromSet?.forEach((item: any, index: number) => {
417
418
  setTimeout(
418
419
  () => {
419
- decreaseWidthsFromSet?.[index]?.();
420
+ decreaseWidthsFromSet();
420
421
  },
421
422
  animateTogether ? 0 : animationDuration * index,
422
423
  );
@@ -554,7 +555,7 @@ export const LineChart = (props: LineChartPropsType) => {
554
555
  outputRange: [0, totalWidth],
555
556
  });
556
557
 
557
- const onStripPress = (item, index) => {
558
+ const onStripPress = (item: any, index: number) => {
558
559
  if (props.focusedDataPointIndex === undefined || !props.onFocus) {
559
560
  setSelectedIndex(index);
560
561
  }
@@ -564,20 +565,20 @@ export const LineChart = (props: LineChartPropsType) => {
564
565
  };
565
566
 
566
567
  const renderDataPoints = (
567
- hideDataPoints,
568
- dataForRender,
569
- originalDataFromProps,
570
- dataPtsShape,
571
- dataPtsWidth,
572
- dataPtsHeight,
573
- dataPtsColor,
574
- dataPtsRadius,
575
- textColor,
576
- textFontSize,
577
- startIndex,
578
- endIndex,
579
- isSecondary,
580
- showValuesAsDataPointsText,
568
+ hideDataPoints: any,
569
+ dataForRender: any,
570
+ originalDataFromProps: any,
571
+ dataPtsShape: any,
572
+ dataPtsWidth: any,
573
+ dataPtsHeight: any,
574
+ dataPtsColor: any,
575
+ dataPtsRadius: any,
576
+ textColor: any,
577
+ textFontSize: any,
578
+ startIndex: any,
579
+ endIndex: any,
580
+ isSecondary: any,
581
+ showValuesAsDataPointsText: any,
581
582
  ) => {
582
583
  const getYOrSecondaryY = isSecondary ? getSecondaryY : getY;
583
584
  return dataForRender.map((item: lineDataItem, index: number) => {
@@ -928,6 +929,7 @@ export const LineChart = (props: LineChartPropsType) => {
928
929
  pointerConfig?.secondaryPointerColor || pointerColor;
929
930
  break;
930
931
  }
932
+ if (!pointerYLocal) return;
931
933
 
932
934
  return Pointer({
933
935
  pointerX,
@@ -944,26 +946,43 @@ export const LineChart = (props: LineChartPropsType) => {
944
946
  const renderStripAndLabel = () => {
945
947
  let pointerItemLocal, pointerYLocal;
946
948
 
947
- pointerItemLocal = [pointerItem];
949
+ pointerItemLocal = [
950
+ {...pointerItem, value: props.data?.[pointerIndex]?.value},
951
+ ];
948
952
  let arr = [pointerY];
949
953
  if (pointerY2 !== 0) {
950
954
  arr.push(pointerY2);
951
- pointerItemLocal.push(pointerItem2);
955
+ pointerItemLocal.push({
956
+ ...pointerItem,
957
+ value: props.data2?.[pointerIndex]?.value,
958
+ });
952
959
  }
953
960
  if (pointerY3 !== 0) {
954
961
  arr.push(pointerY3);
955
- pointerItemLocal.push(pointerItem3);
962
+ pointerItemLocal.push({
963
+ ...pointerItem,
964
+ value: props.data3?.[pointerIndex]?.value,
965
+ });
956
966
  }
957
967
  if (pointerY4 !== 0) {
958
968
  arr.push(pointerY4);
959
- pointerItemLocal.push(pointerItem4);
969
+ pointerItemLocal.push({
970
+ ...pointerItem,
971
+ value: props.data4?.[pointerIndex]?.value,
972
+ });
960
973
  }
961
974
  if (pointerY5 !== 0) {
962
975
  arr.push(pointerY5);
963
- pointerItemLocal.push(pointerItem5);
976
+ pointerItemLocal.push({
977
+ ...pointerItem,
978
+ value: props.data5?.[pointerIndex]?.value,
979
+ });
964
980
  }
965
981
  if (secondaryPointerY !== 0) {
966
- pointerItemLocal.push(secondaryPointerItem);
982
+ pointerItemLocal.push({
983
+ ...pointerItem,
984
+ value: props.secondaryData?.[pointerIndex]?.value,
985
+ });
967
986
  }
968
987
  pointerYLocal = Math.min(...arr);
969
988
 
@@ -1051,11 +1070,11 @@ export const LineChart = (props: LineChartPropsType) => {
1051
1070
  endOpacity: number,
1052
1071
  strokeDashArray: Array<number> | undefined | null,
1053
1072
  showArrow: boolean,
1054
- arrowPoints,
1055
- arrowStrokeWidth,
1056
- arrowStrokeColor,
1057
- arrowFillColor,
1058
- key,
1073
+ arrowPoints: any,
1074
+ arrowStrokeWidth: any,
1075
+ arrowStrokeColor: any,
1076
+ arrowFillColor: any,
1077
+ key: any,
1059
1078
  ) => {
1060
1079
  if (!points) return null;
1061
1080
  const isCurved = points.includes('C');
@@ -1104,7 +1123,7 @@ export const LineChart = (props: LineChartPropsType) => {
1104
1123
  lineSvgPropsOuter.strokeDasharray = strokeDashArray;
1105
1124
  }
1106
1125
  return (
1107
- <Svg>
1126
+ <Svg onPress={props.onBackgroundPress}>
1108
1127
  {lineGradient && getLineGradientComponent()}
1109
1128
  {points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? (
1110
1129
  ar.map((item, index) => {
@@ -1143,6 +1162,7 @@ export const LineChart = (props: LineChartPropsType) => {
1143
1162
  )}
1144
1163
  {isNthAreaChart && (
1145
1164
  <Path
1165
+ onPress={props.onChartAreaPress}
1146
1166
  d={fillPoints}
1147
1167
  fill={
1148
1168
  props.areaGradientId
@@ -1293,7 +1313,7 @@ export const LineChart = (props: LineChartPropsType) => {
1293
1313
  );
1294
1314
  };
1295
1315
 
1296
- const activatePointers = x => {
1316
+ const activatePointers = (x: number) => {
1297
1317
  let factor = (x - initialSpacing) / spacing;
1298
1318
  factor = Math.round(factor);
1299
1319
  factor = Math.min(factor, (data0 ?? data).length - 1);
@@ -1371,6 +1391,7 @@ export const LineChart = (props: LineChartPropsType) => {
1371
1391
  (pointerRadius || pointerHeight / 2) +
1372
1392
  10;
1373
1393
  setSecondaryPointerY(y);
1394
+ // @ts-ignore
1374
1395
  setSecondaryPointerItem(item);
1375
1396
  }
1376
1397
  }
@@ -1378,11 +1399,12 @@ export const LineChart = (props: LineChartPropsType) => {
1378
1399
  if (dataSet[0].data[factor]) {
1379
1400
  const ysForDataSet = dataSet.map(set => {
1380
1401
  const item = set.data[factor];
1381
- const y =
1382
- containerHeight -
1383
- (item.value * containerHeight) / maxValue -
1384
- (pointerRadius || pointerHeight / 2) +
1385
- 10;
1402
+ const y = item
1403
+ ? containerHeight -
1404
+ (item.value * containerHeight) / maxValue -
1405
+ (pointerRadius || pointerHeight / 2) +
1406
+ 10
1407
+ : 0;
1386
1408
  return y;
1387
1409
  });
1388
1410
  setPointerYsForDataSet(ysForDataSet);
@@ -1401,11 +1423,11 @@ export const LineChart = (props: LineChartPropsType) => {
1401
1423
  startOpacity: number,
1402
1424
  endOpacity: number,
1403
1425
  strokeDashArray: Array<number> | undefined | null,
1404
- showArrow,
1405
- arrowPoints,
1406
- arrowStrokeWidth,
1407
- arrowStrokeColor,
1408
- arrowFillColor,
1426
+ showArrow: any,
1427
+ arrowPoints: any,
1428
+ arrowStrokeWidth: any,
1429
+ arrowStrokeColor: any,
1430
+ arrowFillColor: any,
1409
1431
  key?: number,
1410
1432
  ) => {
1411
1433
  return (
@@ -1514,22 +1536,22 @@ export const LineChart = (props: LineChartPropsType) => {
1514
1536
  (pointerRadius || pointerHeight / 2) +
1515
1537
  10;
1516
1538
  setSecondaryPointerY(y);
1539
+ // @ts-ignore
1517
1540
  setSecondaryPointerItem(item);
1518
1541
  }
1519
1542
  }
1520
1543
  if (dataSet?.length) {
1521
- if (dataSet[0].data[factor]) {
1522
- const ysForDataSet = dataSet.map(set => {
1523
- const item = set.data[factor];
1524
- const y =
1525
- containerHeight -
1544
+ const ysForDataSet = dataSet.map(set => {
1545
+ const item = set.data[factor];
1546
+ const y = item
1547
+ ? containerHeight -
1526
1548
  (item.value * containerHeight) / maxValue -
1527
1549
  (pointerRadius || pointerHeight / 2) +
1528
- 10;
1529
- return y;
1530
- });
1531
- setPointerYsForDataSet(ysForDataSet);
1532
- }
1550
+ 10
1551
+ : 0;
1552
+ return y;
1553
+ });
1554
+ setPointerYsForDataSet(ysForDataSet);
1533
1555
  }
1534
1556
  }}
1535
1557
  // onResponderReject={evt => {
@@ -1600,11 +1622,11 @@ export const LineChart = (props: LineChartPropsType) => {
1600
1622
  startOpacity: number,
1601
1623
  endOpacity: number,
1602
1624
  strokeDashArray: Array<number> | undefined | null,
1603
- showArrow,
1604
- arrowPoints,
1605
- arrowStrokeWidth,
1606
- arrowStrokeColor,
1607
- arrowFillColor,
1625
+ showArrow: any,
1626
+ arrowPoints: any,
1627
+ arrowStrokeWidth: any,
1628
+ arrowStrokeColor: any,
1629
+ arrowFillColor: any,
1608
1630
  key?: number,
1609
1631
  ) => {
1610
1632
  return (
@@ -1713,7 +1735,9 @@ export const LineChart = (props: LineChartPropsType) => {
1713
1735
  (item.value * containerHeight) / secondaryMaxValue -
1714
1736
  (pointerRadius || pointerHeight / 2) +
1715
1737
  10;
1738
+
1716
1739
  setSecondaryPointerY(y);
1740
+ // @ts-ignore
1717
1741
  setSecondaryPointerItem(item);
1718
1742
  }
1719
1743
  }
@@ -1721,11 +1745,12 @@ export const LineChart = (props: LineChartPropsType) => {
1721
1745
  if (dataSet[0].data[factor]) {
1722
1746
  const ysForDataSet = dataSet.map(set => {
1723
1747
  const item = set.data[factor];
1724
- const y =
1725
- containerHeight -
1726
- (item.value * containerHeight) / maxValue -
1727
- (pointerRadius || pointerHeight / 2) +
1728
- 10;
1748
+ const y = item
1749
+ ? containerHeight -
1750
+ (item.value * containerHeight) / maxValue -
1751
+ (pointerRadius || pointerHeight / 2) +
1752
+ 10
1753
+ : 0;
1729
1754
  return y;
1730
1755
  });
1731
1756
  setPointerYsForDataSet(ysForDataSet);
@@ -29,7 +29,10 @@ export const PieChart = (props: PieChartPropsType) => {
29
29
  paddingVertical,
30
30
  } = usePieChart(props);
31
31
 
32
- const renderInnerCircle = (innerRadius, innerCircleBorderWidth) => {
32
+ const renderInnerCircle = (
33
+ innerRadius: number,
34
+ innerCircleBorderWidth: number,
35
+ ) => {
33
36
  if (props.centerLabelComponent || (donut && !isDataShifted)) {
34
37
  return (
35
38
  <View
package/src/index.tsx CHANGED
@@ -22,4 +22,5 @@ export {
22
22
  ruleTypes,
23
23
  yAxisSides,
24
24
  EdgePosition,
25
+ DataSet,
25
26
  } from 'gifted-charts-core';