react-native-gifted-charts 1.4.10 → 1.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +2 -2
  2. package/dist/BarChart/Animated2DWithGradient.js +1 -0
  3. package/dist/BarChart/RenderBars.js +1 -0
  4. package/dist/BarChart/RenderStackBars.js +1 -0
  5. package/dist/BarChart/index.js +1 -0
  6. package/dist/BarChart/styles.js +1 -0
  7. package/dist/Components/AnimatedThreeDBar/index.js +1 -0
  8. package/dist/Components/AnimatedThreeDBar/styles.js +1 -0
  9. package/dist/Components/BarAndLineChartsWrapper/index.js +1 -0
  10. package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +1 -0
  11. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +1 -0
  12. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +1 -0
  13. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +1 -0
  14. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +1 -0
  15. package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +1 -0
  16. package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +1 -0
  17. package/dist/Components/BarSpecificComponents/cap.js +1 -0
  18. package/dist/Components/common/LinearGradient.js +1 -0
  19. package/dist/Components/common/Pointer.js +1 -0
  20. package/dist/Components/common/StripAndLabel.js +1 -0
  21. package/dist/Components/lineSvg.js +1 -0
  22. package/dist/LineChart/LineChartBicolor.js +1 -0
  23. package/dist/LineChart/index.js +1 -0
  24. package/dist/LineChart/styles.js +1 -0
  25. package/dist/PieChart/index.js +1 -0
  26. package/dist/PieChart/main.js +1 -0
  27. package/dist/PieChartPro/index.js +1 -0
  28. package/dist/PopulationPyramid/index.js +1 -0
  29. package/dist/index.js +1 -0
  30. package/dist/utils/index.js +1 -0
  31. package/package.json +10 -5
  32. package/src/BarChart/Animated2DWithGradient.tsx +0 -197
  33. package/src/BarChart/RenderBars.tsx +0 -454
  34. package/src/BarChart/RenderStackBars.tsx +0 -383
  35. package/src/BarChart/index.tsx +0 -373
  36. package/src/BarChart/styles.tsx +0 -47
  37. package/src/Components/AnimatedThreeDBar/index.tsx +0 -258
  38. package/src/Components/AnimatedThreeDBar/styles.tsx +0 -14
  39. package/src/Components/BarAndLineChartsWrapper/index.tsx +0 -244
  40. package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +0 -590
  41. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +0 -147
  42. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +0 -157
  43. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +0 -86
  44. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +0 -42
  45. package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +0 -131
  46. package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +0 -30
  47. package/src/Components/BarSpecificComponents/cap.tsx +0 -34
  48. package/src/Components/common/LinearGradient.tsx +0 -27
  49. package/src/Components/common/Pointer.tsx +0 -37
  50. package/src/Components/common/StripAndLabel.tsx +0 -98
  51. package/src/Components/lineSvg.tsx +0 -42
  52. package/src/LineChart/LineChartBicolor.tsx +0 -739
  53. package/src/LineChart/index.tsx +0 -2077
  54. package/src/LineChart/styles.tsx +0 -47
  55. package/src/PieChart/index.tsx +0 -165
  56. package/src/PieChart/main.tsx +0 -363
  57. package/src/PieChartPro/index.tsx +0 -267
  58. package/src/PopulationPyramid/index.tsx +0 -603
  59. package/src/index.tsx +0 -25
  60. package/src/todos.md +0 -23
  61. package/src/utils/index.ts +0 -16
@@ -1,2077 +0,0 @@
1
- import React, {Fragment, useCallback, useEffect, useMemo, useRef} from 'react';
2
- import {
3
- View,
4
- Animated,
5
- Easing,
6
- Text,
7
- Dimensions,
8
- Platform,
9
- ColorValue,
10
- I18nManager,
11
- } from 'react-native';
12
- import {styles} from './styles';
13
- import {screenWidth} from '../utils';
14
- import Svg, {
15
- Path,
16
- LinearGradient,
17
- Stop,
18
- Circle,
19
- Rect,
20
- Text as CanvasText,
21
- Line,
22
- } from 'react-native-svg';
23
- import {
24
- getSegmentedPathObjects,
25
- getRegionPathObjects,
26
- RANGE_ENTER,
27
- RANGE_EXIT,
28
- SEGMENT_END,
29
- SEGMENT_START,
30
- STOP,
31
- LineChartPropsType,
32
- lineDataItem,
33
- LineSvgProps,
34
- useLineChart,
35
- adjustToOffset,
36
- LineProperties,
37
- } from 'gifted-charts-core';
38
- import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
39
- import {StripAndLabel} from '../Components/common/StripAndLabel';
40
- import {Pointer} from '../Components/common/Pointer';
41
-
42
- let initialData: Array<lineDataItem> | null = null;
43
- let animations: Array<Animated.Value> = [];
44
-
45
- export const LineChart = (props: LineChartPropsType) => {
46
- const scrollRef = props.scrollRef ?? useRef(null);
47
- const opacValue = useMemo(() => new Animated.Value(0), []);
48
- const heightValue = useMemo(() => new Animated.Value(0), []);
49
- const widthValue = useMemo(() => new Animated.Value(0), []);
50
- const widthValue2 = useMemo(() => new Animated.Value(0), []);
51
- const widthValue3 = useMemo(() => new Animated.Value(0), []);
52
- const widthValue4 = useMemo(() => new Animated.Value(0), []);
53
- const widthValue5 = useMemo(() => new Animated.Value(0), []);
54
-
55
- if (!initialData) {
56
- initialData = props.dataSet?.[0]?.data ?? props.data ?? [];
57
- animations = initialData.map(item => new Animated.Value(item.value));
58
- }
59
-
60
- const {
61
- scrollX,
62
- setScrollX,
63
- arrow1Points,
64
- arrow2Points,
65
- arrow3Points,
66
- arrow4Points,
67
- arrow5Points,
68
- secondaryArrowPoints,
69
- setPointerIndex,
70
- pointerX,
71
- setPointerX,
72
- pointerY,
73
- setPointerY,
74
- pointerItem,
75
- setPointerItem,
76
- pointerY2,
77
- setPointerY2,
78
- pointerItem2,
79
- setPointerItem2,
80
- pointerY3,
81
- setPointerY3,
82
- pointerItem3,
83
- setPointerItem3,
84
- pointerY4,
85
- setPointerY4,
86
- pointerItem4,
87
- setPointerItem4,
88
- pointerY5,
89
- setPointerY5,
90
- pointerItem5,
91
- setPointerItem5,
92
- secondaryPointerY,
93
- setSecondaryPointerY,
94
- secondaryPointerItem,
95
- setSecondaryPointerItem,
96
- responderStartTime,
97
- setResponderStartTime,
98
- setResponderActive,
99
- points,
100
- points2,
101
- points3,
102
- points4,
103
- points5,
104
- secondaryPoints,
105
- fillPoints,
106
- fillPoints2,
107
- fillPoints3,
108
- fillPoints4,
109
- fillPoints5,
110
- secondaryFillPoints,
111
- pointsFromSet,
112
- fillPointsFromSet,
113
- arrowPointsFromSet,
114
- selectedIndex,
115
- setSelectedIndex,
116
- containerHeight,
117
- data,
118
- data2,
119
- data3,
120
- data4,
121
- data5,
122
- secondaryData,
123
- dataSet,
124
- data0,
125
- labelsExtraHeight,
126
- animationDuration,
127
- onDataChangeAnimationDuration,
128
- animateTogether,
129
- animateOnDataChange,
130
- startIndex1,
131
- startIndex2,
132
- endIndex1,
133
- endIndex2,
134
- startIndex3,
135
- endIndex3,
136
- startIndex4,
137
- endIndex4,
138
- startIndex5,
139
- endIndex5,
140
- initialSpacing,
141
- thickness,
142
- yAxisLabelWidth,
143
- spacing,
144
- xAxisThickness,
145
- dataPointsHeight1,
146
- dataPointsWidth1,
147
- dataPointsRadius1,
148
- dataPointsColor1,
149
- dataPointsShape1,
150
- dataPointsHeight2,
151
- dataPointsWidth2,
152
- dataPointsRadius2,
153
- dataPointsColor2,
154
- dataPointsShape2,
155
- dataPointsHeight3,
156
- dataPointsWidth3,
157
- dataPointsRadius3,
158
- dataPointsColor3,
159
- dataPointsShape3,
160
- dataPointsHeight4,
161
- dataPointsWidth4,
162
- dataPointsRadius4,
163
- dataPointsColor4,
164
- dataPointsShape4,
165
- dataPointsHeight5,
166
- dataPointsWidth5,
167
- dataPointsRadius5,
168
- dataPointsColor5,
169
- dataPointsShape5,
170
- getIsNthAreaChart,
171
- textFontSize1,
172
- textFontSize2,
173
- textFontSize3,
174
- textFontSize4,
175
- textFontSize5,
176
- textColor1,
177
- textColor2,
178
- textColor3,
179
- textColor4,
180
- textColor5,
181
- totalWidth,
182
- maxValue,
183
- overflowTop,
184
- extendedContainerHeight,
185
- getX,
186
- getY,
187
- getSecondaryY,
188
- showValuesAsDataPointsText,
189
- thickness1,
190
- thickness2,
191
- thickness3,
192
- thickness4,
193
- thickness5,
194
- zIndex1,
195
- zIndex2,
196
- zIndex3,
197
- zIndex4,
198
- zIndex5,
199
- strokeDashArray1,
200
- strokeDashArray2,
201
- strokeDashArray3,
202
- strokeDashArray4,
203
- strokeDashArray5,
204
- rotateLabel,
205
- isAnimated,
206
- hideDataPoints1,
207
- hideDataPoints2,
208
- hideDataPoints3,
209
- hideDataPoints4,
210
- hideDataPoints5,
211
- color1,
212
- color2,
213
- color3,
214
- color4,
215
- color5,
216
- startFillColor1,
217
- endFillColor1,
218
- startOpacity1,
219
- endOpacity1,
220
- startFillColor2,
221
- endFillColor2,
222
- startOpacity2,
223
- endOpacity2,
224
- startFillColor3,
225
- endFillColor3,
226
- startOpacity3,
227
- endOpacity3,
228
- startFillColor4,
229
- endFillColor4,
230
- startOpacity4,
231
- endOpacity4,
232
- startFillColor5,
233
- endFillColor5,
234
- startOpacity5,
235
- endOpacity5,
236
- arrowStrokeWidth1,
237
- arrowStrokeColor1,
238
- arrowFillColor1,
239
- arrowStrokeWidth2,
240
- arrowStrokeColor2,
241
- arrowFillColor2,
242
- arrowStrokeWidth3,
243
- arrowStrokeColor3,
244
- arrowFillColor3,
245
- arrowStrokeWidth4,
246
- arrowStrokeColor4,
247
- arrowFillColor4,
248
- arrowStrokeWidth5,
249
- arrowStrokeColor5,
250
- arrowFillColor5,
251
- arrowStrokeWidthsFromSet,
252
- arrowStrokeColorsFromSet,
253
- arrowFillColorsFromSet,
254
- secondaryLineConfig,
255
- gradientDirection,
256
- stepHeight,
257
- noOfSectionsBelowXAxis,
258
- xAxisTextNumberOfLines,
259
- xAxisLabelsVerticalShift,
260
- pointerConfig,
261
- pointerHeight,
262
- pointerWidth,
263
- pointerRadius,
264
- pointerColor,
265
- pointerComponent,
266
- showPointerStrip,
267
- pointerStripHeight,
268
- pointerStripWidth,
269
- pointerStripColor,
270
- pointerStripUptoDataPoint,
271
- pointerLabelComponent,
272
- stripOverPointer,
273
- shiftPointerLabelX,
274
- shiftPointerLabelY,
275
- pointerLabelWidth,
276
- pointerLabelHeight,
277
- autoAdjustPointerLabelPosition,
278
- pointerVanishDelay,
279
- activatePointersOnLongPress,
280
- activatePointersDelay,
281
- persistPointer,
282
- hidePointer1,
283
- hidePointer2,
284
- hidePointer3,
285
- hidePointer4,
286
- hidePointer5,
287
- hideSecondaryPointer,
288
- pointerEvents,
289
- focusEnabled,
290
- showDataPointOnFocus,
291
- showStripOnFocus,
292
- showTextOnFocus,
293
- stripHeight,
294
- stripWidth,
295
- stripColor,
296
- stripOpacity,
297
- unFocusOnPressOut,
298
- delayBeforeUnFocus,
299
- containerHeightIncludingBelowXAxis,
300
- lineGradient,
301
- lineGradientDirection,
302
- lineGradientStartColor,
303
- lineGradientEndColor,
304
- barAndLineChartsWrapperProps,
305
- } = useLineChart({...props, animations, screenWidth});
306
-
307
- const widthValuesFromSet = useMemo(
308
- () => dataSet?.map(set => new Animated.Value(0)),
309
- [],
310
- );
311
-
312
- useEffect(() => {
313
- if (animateOnDataChange) {
314
- Animated.parallel(
315
- animations.map((anItem, index) =>
316
- Animated.timing(anItem, {
317
- toValue: data[index]?.value ?? 0,
318
- useNativeDriver: Platform.OS === 'ios', // if useNativeDriver is set to true, animateOnDataChange feature fails for Android, so setting it true only for iOS
319
- duration: onDataChangeAnimationDuration,
320
- }),
321
- ),
322
- ).start();
323
- }
324
- }, [animateOnDataChange, data, onDataChangeAnimationDuration]);
325
-
326
- const labelsAppear = useCallback(() => {
327
- opacValue.setValue(0);
328
- Animated.timing(opacValue, {
329
- toValue: 1,
330
- duration: 500,
331
- easing: Easing.ease,
332
- useNativeDriver: false,
333
- }).start();
334
- }, [opacValue]);
335
-
336
- const appearingOpacity = opacValue.interpolate({
337
- inputRange: [0, 1],
338
- outputRange: [0, 1],
339
- });
340
-
341
- const decreaseWidth = useCallback(() => {
342
- widthValue.setValue(0);
343
- Animated.timing(widthValue, {
344
- toValue: 1,
345
- duration: animationDuration,
346
- easing: Easing.linear,
347
- useNativeDriver: false,
348
- }).start();
349
- }, [animationDuration, widthValue]);
350
-
351
- const decreaseWidth2 = useCallback(() => {
352
- widthValue2.setValue(0);
353
- Animated.timing(widthValue2, {
354
- toValue: 1,
355
- duration: animationDuration,
356
- easing: Easing.linear,
357
- useNativeDriver: false,
358
- }).start();
359
- }, [animationDuration, widthValue2]);
360
-
361
- const decreaseWidth3 = useCallback(() => {
362
- widthValue3.setValue(0);
363
- Animated.timing(widthValue3, {
364
- toValue: 1,
365
- duration: animationDuration,
366
- easing: Easing.linear,
367
- useNativeDriver: false,
368
- }).start();
369
- }, [animationDuration, widthValue3]);
370
-
371
- const decreaseWidth4 = useCallback(() => {
372
- widthValue4.setValue(0);
373
- Animated.timing(widthValue4, {
374
- toValue: 1,
375
- duration: animationDuration,
376
- easing: Easing.linear,
377
- useNativeDriver: false,
378
- }).start();
379
- }, [animationDuration, widthValue4]);
380
-
381
- const decreaseWidth5 = useCallback(() => {
382
- widthValue5.setValue(0);
383
- Animated.timing(widthValue5, {
384
- toValue: 1,
385
- duration: animationDuration,
386
- easing: Easing.linear,
387
- useNativeDriver: false,
388
- }).start();
389
- }, [animationDuration, widthValue5]);
390
-
391
- const decreaseWidthsFromSet = useCallback(() => {
392
- dataSet?.map((set, index) => {
393
- widthValuesFromSet?.[index]?.setValue(0);
394
- if (widthValuesFromSet?.[index]) {
395
- Animated.timing(widthValuesFromSet?.[index], {
396
- toValue: 1,
397
- duration: animationDuration,
398
- easing: Easing.linear,
399
- useNativeDriver: false,
400
- }).start();
401
- }
402
- });
403
- }, [animationDuration, widthValuesFromSet]);
404
-
405
- useEffect(() => {
406
- decreaseWidth();
407
- labelsAppear();
408
- widthValuesFromSet?.forEach((item, index) => {
409
- setTimeout(
410
- () => {
411
- decreaseWidthsFromSet?.[index]?.();
412
- },
413
- animateTogether ? 0 : animationDuration * index,
414
- );
415
- });
416
- setTimeout(
417
- () => {
418
- decreaseWidth2();
419
- },
420
- animateTogether ? 0 : animationDuration,
421
- );
422
- setTimeout(
423
- () => {
424
- decreaseWidth3();
425
- },
426
- animateTogether ? 0 : animationDuration * 2,
427
- );
428
- setTimeout(
429
- () => {
430
- decreaseWidth4();
431
- },
432
- animateTogether ? 0 : animationDuration * 3,
433
- );
434
- setTimeout(
435
- () => {
436
- decreaseWidth5();
437
- },
438
- animateTogether ? 0 : animationDuration * 4,
439
- );
440
- }, [
441
- animateTogether,
442
- animationDuration,
443
- decreaseWidth,
444
- decreaseWidth2,
445
- decreaseWidth3,
446
- decreaseWidth4,
447
- decreaseWidth5,
448
- labelsAppear,
449
- ]);
450
-
451
- const renderLabel = (
452
- index: number,
453
- label: String,
454
- labelTextStyle: any,
455
- labelComponent: Function | undefined,
456
- ) => {
457
- return (
458
- <View
459
- style={[
460
- {
461
- position: 'absolute',
462
- bottom: 54 - xAxisTextNumberOfLines * 18,
463
- zIndex: 10,
464
- width: spacing + labelsExtraHeight,
465
- left:
466
- index === 0 && initialSpacing < 10
467
- ? initialSpacing / 2 + spacing * index - spacing / 2 + 4
468
- : initialSpacing / 2 + spacing * index - spacing / 2 - 10,
469
- height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
470
- },
471
- rotateLabel && {transform: [{rotate: '60deg'}]},
472
- ]}>
473
- {labelComponent ? (
474
- labelComponent()
475
- ) : (
476
- <Text
477
- style={[{textAlign: 'center'}, labelTextStyle]}
478
- numberOfLines={xAxisTextNumberOfLines}>
479
- {label || ''}
480
- </Text>
481
- )}
482
- </View>
483
- );
484
- };
485
-
486
- const renderAnimatedLabel = (
487
- index: number,
488
- label: String,
489
- labelTextStyle: any,
490
- labelComponent: Function | undefined,
491
- ) => {
492
- return (
493
- <Animated.View
494
- style={[
495
- {
496
- height: rotateLabel
497
- ? 40
498
- : props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
499
- position: 'absolute',
500
- bottom: rotateLabel ? 10 : 54 - xAxisTextNumberOfLines * 18,
501
- zIndex: 10,
502
- width: spacing,
503
- left:
504
- index === 0 && initialSpacing < 10
505
- ? initialSpacing / 2 + spacing * index - spacing / 2 + 4
506
- : initialSpacing / 2 + spacing * index - spacing / 2 - 10,
507
- opacity: appearingOpacity,
508
- },
509
- rotateLabel && {transform: [{rotate: '60deg'}]},
510
- ]}>
511
- {labelComponent ? (
512
- labelComponent()
513
- ) : (
514
- <Text
515
- style={[{textAlign: 'center'}, labelTextStyle]}
516
- numberOfLines={xAxisTextNumberOfLines}>
517
- {label || ''}
518
- </Text>
519
- )}
520
- </Animated.View>
521
- );
522
- };
523
-
524
- const animatedWidth = widthValue.interpolate({
525
- inputRange: [0, 1],
526
- outputRange: [0, totalWidth],
527
- });
528
-
529
- const animatedWidth2 = widthValue2.interpolate({
530
- inputRange: [0, 1],
531
- outputRange: [0, totalWidth],
532
- });
533
-
534
- const animatedWidth3 = widthValue3.interpolate({
535
- inputRange: [0, 1],
536
- outputRange: [0, totalWidth],
537
- });
538
-
539
- const animatedWidth4 = widthValue4.interpolate({
540
- inputRange: [0, 1],
541
- outputRange: [0, totalWidth],
542
- });
543
-
544
- const animatedWidth5 = widthValue5.interpolate({
545
- inputRange: [0, 1],
546
- outputRange: [0, totalWidth],
547
- });
548
-
549
- const onStripPress = (item, index) => {
550
- setSelectedIndex(index);
551
- if (props.onFocus) {
552
- props.onFocus(item, index);
553
- }
554
- };
555
-
556
- const renderDataPoints = (
557
- hideDataPoints,
558
- dataForRender,
559
- originalDataFromProps,
560
- dataPtsShape,
561
- dataPtsWidth,
562
- dataPtsHeight,
563
- dataPtsColor,
564
- dataPtsRadius,
565
- textColor,
566
- textFontSize,
567
- startIndex,
568
- endIndex,
569
- isSecondary,
570
- showValuesAsDataPointsText,
571
- ) => {
572
- const getYOrSecondaryY = isSecondary ? getSecondaryY : getY;
573
- return dataForRender.map((item: lineDataItem, index: number) => {
574
- if (index < startIndex || index > endIndex) return null;
575
- if (item.hideDataPoint) {
576
- return null;
577
- }
578
- let dataPointsShape,
579
- dataPointsWidth,
580
- dataPointsHeight,
581
- dataPointsColor,
582
- dataPointsRadius,
583
- text,
584
- customDataPoint,
585
- dataPointLabelComponent;
586
- if (index === selectedIndex) {
587
- dataPointsShape =
588
- item.focusedDataPointShape ||
589
- props.focusedDataPointShape ||
590
- item.dataPointShape ||
591
- dataPtsShape;
592
- dataPointsWidth =
593
- item.focusedDataPointWidth ||
594
- props.focusedDataPointWidth ||
595
- item.dataPointWidth ||
596
- dataPtsWidth;
597
- dataPointsHeight =
598
- item.focusedDataPointHeight ||
599
- props.focusedDataPointHeight ||
600
- item.dataPointHeight ||
601
- dataPtsHeight;
602
- dataPointsColor =
603
- item.focusedDataPointColor || props.focusedDataPointColor || 'orange';
604
- dataPointsRadius =
605
- item.focusedDataPointRadius ||
606
- props.focusedDataPointRadius ||
607
- item.dataPointRadius ||
608
- dataPtsRadius;
609
- if (showTextOnFocus) {
610
- text = item.dataPointText;
611
- }
612
- customDataPoint =
613
- item.focusedCustomDataPoint ||
614
- props.focusedCustomDataPoint ||
615
- item.customDataPoint ||
616
- props.customDataPoint;
617
- dataPointLabelComponent =
618
- item.focusedDataPointLabelComponent || item.dataPointLabelComponent;
619
- } else {
620
- dataPointsShape = item.dataPointShape || dataPtsShape;
621
- dataPointsWidth = item.dataPointWidth || dataPtsWidth;
622
- dataPointsHeight = item.dataPointHeight || dataPtsHeight;
623
- dataPointsColor = item.dataPointColor || dataPtsColor;
624
- dataPointsRadius = item.dataPointRadius || dataPtsRadius;
625
- if (showTextOnFocus) {
626
- text = '';
627
- }
628
- customDataPoint = item.customDataPoint || props.customDataPoint;
629
- dataPointLabelComponent = item.dataPointLabelComponent;
630
- }
631
-
632
- if (showValuesAsDataPointsText) {
633
- text = originalDataFromProps[index].value;
634
- }
635
-
636
- const currentStripHeight = item.stripHeight ?? stripHeight;
637
- const currentStripWidth = item.stripWidth ?? stripWidth;
638
- const currentStripOpacity = item.stripOpacity ?? stripOpacity;
639
- const currentStripColor = item.stripColor || stripColor;
640
- const position = I18nManager.isRTL ? 'right' : 'left';
641
-
642
- return (
643
- <Fragment key={index}>
644
- {focusEnabled ? (
645
- <>
646
- {unFocusOnPressOut ? ( // remove strip on onFocus
647
- <Rect
648
- onPressIn={() => onStripPress(item, index)}
649
- onPressOut={() =>
650
- setTimeout(() => setSelectedIndex(-1), delayBeforeUnFocus)
651
- }
652
- x={initialSpacing + (spacing * index - spacing / 2)}
653
- y={8}
654
- width={spacing}
655
- height={containerHeight - 0}
656
- fill={'none'}
657
- />
658
- ) : (
659
- <Rect
660
- onPress={() => onStripPress(item, index)}
661
- x={initialSpacing + (spacing * index - spacing / 2)}
662
- y={8}
663
- width={spacing}
664
- height={containerHeight}
665
- fill={'none'}
666
- />
667
- )}
668
- </>
669
- ) : null}
670
- {item.showStrip ||
671
- (focusEnabled && index === selectedIndex && showStripOnFocus) ? (
672
- <Rect
673
- x={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
674
- y={
675
- currentStripHeight
676
- ? containerHeight - currentStripHeight + 8
677
- : containerHeight -
678
- dataPointsHeight / 2 +
679
- 14 -
680
- (item.value * containerHeight) / maxValue
681
- }
682
- width={currentStripWidth}
683
- height={
684
- currentStripHeight ||
685
- (item.value * containerHeight) / maxValue - 2 + overflowTop
686
- }
687
- opacity={currentStripOpacity}
688
- fill={currentStripColor}
689
- />
690
- ) : null}
691
- {hideDataPoints ? null : (
692
- <>
693
- {customDataPoint ? (
694
- <View
695
- style={[
696
- styles.customDataPointContainer,
697
- {
698
- height: dataPointsHeight,
699
- width: dataPointsWidth,
700
- top: getYOrSecondaryY(item.value),
701
- [position]:
702
- initialSpacing - dataPointsWidth + spacing * index,
703
- transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
704
- },
705
- ]}>
706
- {customDataPoint(item, index)}
707
- </View>
708
- ) : null}
709
- {dataPointsShape === 'rectangular' ? (
710
- <Fragment key={index}>
711
- {customDataPoint ? null : (
712
- <Rect
713
- x={getX(index) - dataPointsWidth / 2}
714
- y={getYOrSecondaryY(item.value) - dataPointsHeight / 2}
715
- width={dataPointsWidth}
716
- height={dataPointsHeight}
717
- fill={
718
- showDataPointOnFocus
719
- ? index === selectedIndex
720
- ? dataPointsColor
721
- : 'none'
722
- : dataPointsColor
723
- }
724
- onPress={() => {
725
- item.onPress
726
- ? item.onPress(item, index)
727
- : props.onPress
728
- ? props.onPress(item, index)
729
- : null;
730
- }}
731
- />
732
- )}
733
- </Fragment>
734
- ) : (
735
- <Fragment key={index}>
736
- {customDataPoint ? null : (
737
- <Circle
738
- cx={getX(index)}
739
- cy={getYOrSecondaryY(item.value)}
740
- r={dataPointsRadius}
741
- fill={
742
- showDataPointOnFocus
743
- ? index === selectedIndex
744
- ? dataPointsColor
745
- : 'none'
746
- : dataPointsColor
747
- }
748
- onPress={() => {
749
- item.onPress
750
- ? item.onPress(item, index)
751
- : props.onPress
752
- ? props.onPress(item, index)
753
- : null;
754
- }}
755
- />
756
- )}
757
- </Fragment>
758
- )}
759
- {dataPointLabelComponent ? (
760
- !showTextOnFocus || index === selectedIndex ? (
761
- <View
762
- style={[
763
- styles.customDataPointContainer,
764
- {
765
- zIndex: index === selectedIndex ? 1000 : 0,
766
- top:
767
- containerHeight +
768
- (item.dataPointLabelShiftY ||
769
- props.dataPointLabelShiftY ||
770
- 0) -
771
- (item.value * containerHeight) / maxValue,
772
- left:
773
- initialSpacing +
774
- (item.dataPointLabelShiftX ||
775
- props.dataPointLabelShiftX ||
776
- 0) -
777
- (item.dataPointLabelWidth
778
- ? item.dataPointLabelWidth + 20
779
- : props.dataPointLabelWidth
780
- ? props.dataPointLabelWidth + 20
781
- : 50) /
782
- 2 +
783
- spacing * index,
784
- },
785
- ]}>
786
- {dataPointLabelComponent()}
787
- </View>
788
- ) : null
789
- ) : text || item.dataPointText ? (
790
- !showTextOnFocus || index === selectedIndex ? (
791
- <CanvasText
792
- fill={item.textColor || textColor}
793
- fontSize={item.textFontSize || textFontSize}
794
- x={
795
- getX(index) -
796
- dataPointsWidth +
797
- (item.textShiftX || props.textShiftX || 0)
798
- }
799
- y={
800
- getYOrSecondaryY(item.value) -
801
- dataPointsHeight / 2 +
802
- (item.textShiftY || props.textShiftY || 0)
803
- }>
804
- {!showTextOnFocus && !showValuesAsDataPointsText
805
- ? item.dataPointText
806
- : text}
807
- </CanvasText>
808
- ) : null
809
- ) : null}
810
- </>
811
- )}
812
- </Fragment>
813
- );
814
- });
815
- };
816
-
817
- const renderSpecificVerticalLines = (dataForRender: any) => {
818
- return dataForRender.map((item: lineDataItem, index: number) => {
819
- if (item.showVerticalLine) {
820
- const x = getX(index);
821
- return (
822
- <Line
823
- key={index}
824
- x1={x}
825
- y1={extendedContainerHeight}
826
- x2={x}
827
- y2={
828
- item.verticalLineUptoDataPoint ?? props.verticalLinesUptoDataPoint
829
- ? getY(item.value)
830
- : -xAxisThickness
831
- }
832
- stroke={
833
- item.verticalLineColor || props.verticalLinesColor || 'lightgray'
834
- }
835
- strokeWidth={
836
- item.verticalLineThickness || props.verticalLinesThickness || 2
837
- }
838
- strokeDasharray={
839
- item.verticalLineStrokeDashArray ??
840
- props.verticalLinesStrokeDashArray ??
841
- ''
842
- }
843
- />
844
- );
845
- }
846
- return null;
847
- });
848
- };
849
-
850
- const renderPointer = (lineNumber: number) => {
851
- if (lineNumber === 1 && hidePointer1) return;
852
- if (lineNumber === 2 && hidePointer2) return;
853
- if (lineNumber === 3 && hidePointer3) return;
854
- if (lineNumber === 4 && hidePointer4) return;
855
- if (lineNumber === 5 && hidePointer5) return;
856
- // 6 is for secondaryData
857
- if (lineNumber === 6 && hideSecondaryPointer) return;
858
-
859
- let pointerItemLocal, pointerYLocal, pointerColorLocal;
860
- switch (lineNumber) {
861
- case 1:
862
- pointerItemLocal = pointerItem;
863
- pointerYLocal = pointerY;
864
- pointerColorLocal = pointerConfig?.pointer1Color || pointerColor;
865
- break;
866
- case 2:
867
- pointerItemLocal = pointerItem2;
868
- pointerYLocal = pointerY2;
869
- pointerColorLocal = pointerConfig?.pointer2Color || pointerColor;
870
- break;
871
- case 3:
872
- pointerItemLocal = pointerItem3;
873
- pointerYLocal = pointerY3;
874
- pointerColorLocal = pointerConfig?.pointer3Color || pointerColor;
875
- break;
876
- case 4:
877
- pointerItemLocal = pointerItem4;
878
- pointerYLocal = pointerY4;
879
- pointerColorLocal = pointerConfig?.pointer4Color || pointerColor;
880
- break;
881
- case 5:
882
- pointerItemLocal = pointerItem5;
883
- pointerYLocal = pointerY5;
884
- pointerColorLocal = pointerConfig?.pointer5Color || pointerColor;
885
- break;
886
- case 6:
887
- pointerItemLocal = secondaryPointerItem;
888
- pointerYLocal = secondaryPointerY;
889
- pointerColorLocal =
890
- pointerConfig?.secondaryPointerColor || pointerColor;
891
- break;
892
- }
893
-
894
- return Pointer({
895
- pointerX,
896
- pointerYLocal: pointerYLocal + xAxisThickness,
897
- pointerComponent,
898
- pointerHeight,
899
- pointerRadius,
900
- pointerWidth,
901
- pointerItemLocal,
902
- pointerColorLocal,
903
- });
904
- };
905
-
906
- const renderStripAndLabel = () => {
907
- let pointerItemLocal, pointerYLocal;
908
-
909
- pointerItemLocal = [pointerItem];
910
- let arr = [pointerY];
911
- if (pointerY2 !== 0) {
912
- arr.push(pointerY2);
913
- pointerItemLocal.push(pointerItem2);
914
- }
915
- if (pointerY3 !== 0) {
916
- arr.push(pointerY3);
917
- pointerItemLocal.push(pointerItem3);
918
- }
919
- if (pointerY4 !== 0) {
920
- arr.push(pointerY4);
921
- pointerItemLocal.push(pointerItem4);
922
- }
923
- if (pointerY5 !== 0) {
924
- arr.push(pointerY5);
925
- pointerItemLocal.push(pointerItem5);
926
- }
927
- if (secondaryPointerY !== 0) {
928
- pointerItemLocal.push(secondaryPointerItem);
929
- }
930
- pointerYLocal = Math.min(...arr);
931
-
932
- return StripAndLabel({
933
- autoAdjustPointerLabelPosition,
934
- pointerX,
935
- pointerLabelWidth,
936
- activatePointersOnLongPress,
937
- yAxisLabelWidth,
938
- pointerRadius,
939
- pointerWidth,
940
- shiftPointerLabelX,
941
- pointerLabelHeight,
942
- pointerYLocal,
943
- pointerStripUptoDataPoint,
944
- pointerStripHeight,
945
- shiftPointerLabelY,
946
- pointerItemLocal,
947
- showPointerStrip,
948
- pointerStripWidth,
949
- containerHeight,
950
- xAxisThickness,
951
- pointerStripColor,
952
- pointerConfig,
953
- pointerLabelComponent,
954
- secondaryPointerItem,
955
- scrollX,
956
- pointerEvents,
957
- });
958
- };
959
-
960
- const getLineGradientComponent = () => {
961
- return props.lineGradientComponent ? (
962
- props.lineGradientComponent()
963
- ) : (
964
- <LinearGradient
965
- id="lineGradient"
966
- x1="0"
967
- y1="0"
968
- x2={lineGradientDirection === 'horizontal' ? '1' : '0'}
969
- y2={lineGradientDirection === 'vertical' ? '1' : '0'}>
970
- <Stop offset="0" stopColor={lineGradientStartColor} />
971
- <Stop offset="1" stopColor={lineGradientEndColor} />
972
- </LinearGradient>
973
- );
974
- };
975
-
976
- const getAreaGradientComponent = (
977
- startFillColor: string,
978
- endFillColor: string,
979
- startOpacity: number,
980
- endOpacity: number,
981
- ) => {
982
- return props.areaGradientComponent ? (
983
- props.areaGradientComponent()
984
- ) : (
985
- <LinearGradient
986
- id="Gradient"
987
- x1="0"
988
- y1="0"
989
- x2={gradientDirection === 'horizontal' ? '1' : '0'}
990
- y2={gradientDirection === 'vertical' ? '1' : '0'}>
991
- <Stop
992
- offset="0"
993
- stopColor={startFillColor}
994
- stopOpacity={startOpacity.toString()}
995
- />
996
- <Stop
997
- offset="1"
998
- stopColor={endFillColor}
999
- stopOpacity={endOpacity.toString()}
1000
- />
1001
- </LinearGradient>
1002
- );
1003
- };
1004
-
1005
- const lineSvgComponent = (
1006
- points: any,
1007
- currentLineThickness: number | undefined,
1008
- color: ColorValue,
1009
- fillPoints: any,
1010
- startFillColor: string,
1011
- endFillColor: string,
1012
- startOpacity: number,
1013
- endOpacity: number,
1014
- strokeDashArray: Array<number> | undefined | null,
1015
- showArrow: boolean,
1016
- arrowPoints,
1017
- arrowStrokeWidth,
1018
- arrowStrokeColor,
1019
- arrowFillColor,
1020
- key,
1021
- ) => {
1022
- if (!points) return null;
1023
- const isCurved = points.includes('C');
1024
- const isNthAreaChart = getIsNthAreaChart(key ?? 0);
1025
- let ar: LineProperties[] = [{d: '', color: '', strokeWidth: 0}];
1026
- if (points.includes(RANGE_ENTER)) {
1027
- ar = getRegionPathObjects(
1028
- points,
1029
- color,
1030
- currentLineThickness ?? 0,
1031
- thickness,
1032
- strokeDashArray ?? [],
1033
- isCurved,
1034
- RANGE_ENTER,
1035
- STOP,
1036
- RANGE_EXIT,
1037
- );
1038
- } else if (points.includes(SEGMENT_START)) {
1039
- ar = getSegmentedPathObjects(
1040
- points,
1041
- color,
1042
- currentLineThickness ?? 0,
1043
- thickness,
1044
- strokeDashArray ?? [],
1045
- isCurved,
1046
- SEGMENT_START,
1047
- SEGMENT_END,
1048
- );
1049
- }
1050
- const lineSvgPropsOuter: LineSvgProps = {
1051
- d: points,
1052
- fill: 'none',
1053
- stroke: lineGradient
1054
- ? props.lineGradientId
1055
- ? `url(#${props.lineGradientId})`
1056
- : `url(#lineGradient)`
1057
- : color,
1058
- strokeWidth: currentLineThickness || thickness,
1059
- };
1060
- if (
1061
- strokeDashArray &&
1062
- strokeDashArray.length === 2 &&
1063
- typeof strokeDashArray[0] === 'number' &&
1064
- typeof strokeDashArray[1] === 'number'
1065
- ) {
1066
- lineSvgPropsOuter.strokeDasharray = strokeDashArray;
1067
- }
1068
- return (
1069
- <Svg>
1070
- {lineGradient && getLineGradientComponent()}
1071
- {points.includes(SEGMENT_START) || points.includes(RANGE_ENTER) ? (
1072
- ar.map((item, index) => {
1073
- const lineSvgProps: LineSvgProps = {
1074
- d: item.d,
1075
- fill: 'none',
1076
- stroke: lineGradient
1077
- ? props.lineGradientId
1078
- ? `url(#${props.lineGradientId})`
1079
- : `url(#lineGradient)`
1080
- : item.color,
1081
- strokeWidth: item.strokeWidth,
1082
- };
1083
- if (
1084
- item.strokeDashArray &&
1085
- item.strokeDashArray.length === 2 &&
1086
- typeof item.strokeDashArray[0] === 'number' &&
1087
- typeof item.strokeDashArray[1] === 'number'
1088
- ) {
1089
- lineSvgProps.strokeDasharray = item.strokeDashArray;
1090
- }
1091
- return <Path key={index} {...lineSvgProps} />;
1092
- })
1093
- ) : (
1094
- <Path {...lineSvgPropsOuter} />
1095
- )}
1096
-
1097
- {/*********************** For Area Chart ************/}
1098
-
1099
- {isNthAreaChart &&
1100
- getAreaGradientComponent(
1101
- startFillColor,
1102
- endFillColor,
1103
- startOpacity,
1104
- endOpacity,
1105
- )}
1106
- {isNthAreaChart && (
1107
- <Path
1108
- d={fillPoints}
1109
- fill={
1110
- props.areaGradientId
1111
- ? `url(#${props.areaGradientId})`
1112
- : `url(#Gradient)`
1113
- }
1114
- stroke={'transparent'}
1115
- strokeWidth={currentLineThickness || thickness}
1116
- />
1117
- )}
1118
-
1119
- {/******************************************************************/}
1120
-
1121
- {renderSpecificVerticalLines(data)}
1122
- {renderSpecificVerticalLines(data2)}
1123
- {renderSpecificVerticalLines(data3)}
1124
- {renderSpecificVerticalLines(data4)}
1125
- {renderSpecificVerticalLines(data5)}
1126
-
1127
- {dataSet?.map(set => renderSpecificVerticalLines(set?.data)) ?? null}
1128
- {dataSet?.map(set => {
1129
- return renderDataPoints(
1130
- set.hideDataPoints ?? hideDataPoints1,
1131
- set.data,
1132
- adjustToOffset(set.data, -(props.yAxisOffset ?? 0)), // need the actual values passed by user
1133
- set.dataPointsShape ?? dataPointsShape1,
1134
- set.dataPointsWidth ?? dataPointsWidth1,
1135
- set.dataPointsHeight ?? dataPointsHeight1,
1136
- set.dataPointsColor ?? dataPointsColor1,
1137
- set.dataPointsRadius ?? dataPointsRadius1,
1138
- set.textColor ?? textColor1,
1139
- set.textFontSize ?? textFontSize1,
1140
- set.startIndex ?? 0,
1141
- set.endIndex ?? set.data.length - 1,
1142
- false,
1143
- showValuesAsDataPointsText,
1144
- );
1145
- }) ?? null}
1146
-
1147
- {/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
1148
- {renderDataPoints(
1149
- hideDataPoints1,
1150
- data,
1151
- props.data,
1152
- dataPointsShape1,
1153
- dataPointsWidth1,
1154
- dataPointsHeight1,
1155
- dataPointsColor1,
1156
- dataPointsRadius1,
1157
- textColor1,
1158
- textFontSize1,
1159
- startIndex1,
1160
- endIndex1,
1161
- false,
1162
- showValuesAsDataPointsText,
1163
- )}
1164
- {renderDataPoints(
1165
- hideDataPoints2,
1166
- data2,
1167
- props.data2,
1168
- dataPointsShape2,
1169
- dataPointsWidth2,
1170
- dataPointsHeight2,
1171
- dataPointsColor2,
1172
- dataPointsRadius2,
1173
- textColor2,
1174
- textFontSize2,
1175
- startIndex2,
1176
- endIndex2,
1177
- false,
1178
- showValuesAsDataPointsText,
1179
- )}
1180
- {renderDataPoints(
1181
- hideDataPoints3,
1182
- data3,
1183
- props.data3,
1184
- dataPointsShape3,
1185
- dataPointsWidth3,
1186
- dataPointsHeight3,
1187
- dataPointsColor3,
1188
- dataPointsRadius3,
1189
- textColor3,
1190
- textFontSize3,
1191
- startIndex3,
1192
- endIndex3,
1193
- false,
1194
- showValuesAsDataPointsText,
1195
- )}
1196
- {renderDataPoints(
1197
- hideDataPoints4,
1198
- data4,
1199
- props.data4,
1200
- dataPointsShape4,
1201
- dataPointsWidth4,
1202
- dataPointsHeight4,
1203
- dataPointsColor4,
1204
- dataPointsRadius4,
1205
- textColor4,
1206
- textFontSize4,
1207
- startIndex4,
1208
- endIndex4,
1209
- false,
1210
- showValuesAsDataPointsText,
1211
- )}
1212
- {renderDataPoints(
1213
- hideDataPoints5,
1214
- data5,
1215
- props.data5,
1216
- dataPointsShape5,
1217
- dataPointsWidth5,
1218
- dataPointsHeight5,
1219
- dataPointsColor5,
1220
- dataPointsRadius5,
1221
- textColor5,
1222
- textFontSize5,
1223
- startIndex5,
1224
- endIndex5,
1225
- false,
1226
- showValuesAsDataPointsText,
1227
- )}
1228
- {secondaryData?.length
1229
- ? renderDataPoints(
1230
- secondaryLineConfig.hideDataPoints,
1231
- secondaryData,
1232
- props.secondaryData,
1233
- secondaryLineConfig.dataPointsShape,
1234
- secondaryLineConfig.dataPointsWidth,
1235
- secondaryLineConfig.dataPointsHeight,
1236
- secondaryLineConfig.dataPointsColor,
1237
- secondaryLineConfig.dataPointsRadius,
1238
- secondaryLineConfig.textColor,
1239
- secondaryLineConfig.textFontSize,
1240
- secondaryLineConfig.startIndex,
1241
- secondaryLineConfig.endIndex,
1242
- true,
1243
- secondaryLineConfig.showValuesAsDataPointsText,
1244
- )
1245
- : null}
1246
- {showArrow && (
1247
- <Path
1248
- d={arrowPoints}
1249
- fill={arrowFillColor}
1250
- stroke={arrowStrokeColor}
1251
- strokeWidth={arrowStrokeWidth}
1252
- />
1253
- )}
1254
- </Svg>
1255
- );
1256
- };
1257
-
1258
- const activatePointers = x => {
1259
- let factor = (x - initialSpacing) / spacing;
1260
- factor = Math.round(factor);
1261
- factor = Math.min(factor, (data0 ?? data).length - 1);
1262
- factor = Math.max(factor, 0);
1263
- let z =
1264
- initialSpacing +
1265
- spacing * factor -
1266
- (pointerRadius || pointerWidth / 2) -
1267
- 1;
1268
- setPointerX(z);
1269
- setPointerIndex(factor);
1270
- let item, y;
1271
- item = (data0 ?? data)[factor];
1272
- y =
1273
- containerHeight -
1274
- (item.value * containerHeight) / maxValue -
1275
- (pointerRadius || pointerHeight / 2) +
1276
- 10;
1277
- setPointerY(y);
1278
- setPointerItem(item);
1279
- if (data2 && data2.length) {
1280
- item = data2[factor];
1281
- if (item) {
1282
- y =
1283
- containerHeight -
1284
- (item.value * containerHeight) / maxValue -
1285
- (pointerRadius || pointerHeight / 2) +
1286
- 10;
1287
- setPointerY2(y);
1288
- setPointerItem2(item);
1289
- }
1290
- }
1291
- if (data3 && data3.length) {
1292
- item = data3[factor];
1293
- if (item) {
1294
- y =
1295
- containerHeight -
1296
- (item.value * containerHeight) / maxValue -
1297
- (pointerRadius || pointerHeight / 2) +
1298
- 10;
1299
- setPointerY3(y);
1300
- setPointerItem3(item);
1301
- }
1302
- }
1303
- if (data4 && data4.length) {
1304
- item = data4[factor];
1305
- if (item) {
1306
- y =
1307
- containerHeight -
1308
- (item.value * containerHeight) / maxValue -
1309
- (pointerRadius || pointerHeight / 2) +
1310
- 10;
1311
- setPointerY4(y);
1312
- setPointerItem4(item);
1313
- }
1314
- }
1315
- if (data5 && data5.length) {
1316
- item = data5[factor];
1317
- if (item) {
1318
- y =
1319
- containerHeight -
1320
- (item.value * containerHeight) / maxValue -
1321
- (pointerRadius || pointerHeight / 2) +
1322
- 10;
1323
- setPointerY5(y);
1324
- setPointerItem5(item);
1325
- }
1326
- }
1327
- if (secondaryData?.length) {
1328
- item = secondaryData[factor];
1329
- if (item) {
1330
- y =
1331
- containerHeight -
1332
- (item.value * containerHeight) / maxValue -
1333
- (pointerRadius || pointerHeight / 2) +
1334
- 10;
1335
- setSecondaryPointerY(y);
1336
- setSecondaryPointerItem(item);
1337
- }
1338
- }
1339
- };
1340
-
1341
- const renderLine = (
1342
- zIndex: number,
1343
- points: any,
1344
- currentLineThickness: number | undefined,
1345
- color: ColorValue,
1346
- fillPoints: any,
1347
- startFillColor: string,
1348
- endFillColor: string,
1349
- startOpacity: number,
1350
- endOpacity: number,
1351
- strokeDashArray: Array<number> | undefined | null,
1352
- showArrow,
1353
- arrowPoints,
1354
- arrowStrokeWidth,
1355
- arrowStrokeColor,
1356
- arrowFillColor,
1357
- key?: number,
1358
- ) => {
1359
- return (
1360
- <View
1361
- key={key ?? 0}
1362
- onMoveShouldSetResponder={evt => (pointerConfig ? true : false)}
1363
- onResponderGrant={evt => {
1364
- if (!pointerConfig) return;
1365
- setResponderStartTime(evt.timeStamp);
1366
- if (activatePointersOnLongPress) {
1367
- return;
1368
- }
1369
- let x = evt.nativeEvent.locationX;
1370
- activatePointers(x);
1371
- }}
1372
- onResponderMove={evt => {
1373
- if (!pointerConfig) return;
1374
- if (
1375
- activatePointersOnLongPress &&
1376
- evt.timeStamp - responderStartTime < activatePointersDelay
1377
- ) {
1378
- return;
1379
- } else {
1380
- setResponderActive(true);
1381
- }
1382
- let x = evt.nativeEvent.locationX;
1383
- if (
1384
- !activatePointersOnLongPress &&
1385
- x > (props.width || Dimensions.get('window').width)
1386
- )
1387
- return;
1388
- let factor = (x - initialSpacing) / spacing;
1389
- factor = Math.round(factor);
1390
- factor = Math.min(factor, (data0 ?? data).length - 1);
1391
- factor = Math.max(factor, 0);
1392
- let z =
1393
- initialSpacing +
1394
- spacing * factor -
1395
- (pointerRadius || pointerWidth / 2) -
1396
- 1;
1397
- let item, y;
1398
- setPointerX(z);
1399
- setPointerIndex(factor);
1400
- item = (data0 ?? data)[factor];
1401
- y =
1402
- containerHeight -
1403
- (item.value * containerHeight) / maxValue -
1404
- (pointerRadius || pointerHeight / 2) +
1405
- 10;
1406
- setPointerY(y);
1407
- setPointerItem(item);
1408
- if (data2 && data2.length) {
1409
- item = data2[factor];
1410
- if (item) {
1411
- y =
1412
- containerHeight -
1413
- (item.value * containerHeight) / maxValue -
1414
- (pointerRadius || pointerHeight / 2) +
1415
- 10;
1416
- setPointerY2(y);
1417
- setPointerItem2(item);
1418
- }
1419
- }
1420
- if (data3 && data3.length) {
1421
- item = data3[factor];
1422
- if (item) {
1423
- y =
1424
- containerHeight -
1425
- (item.value * containerHeight) / maxValue -
1426
- (pointerRadius || pointerHeight / 2) +
1427
- 10;
1428
- setPointerY3(y);
1429
- setPointerItem3(item);
1430
- }
1431
- }
1432
- if (data4 && data4.length) {
1433
- item = data4[factor];
1434
- if (item) {
1435
- y =
1436
- containerHeight -
1437
- (item.value * containerHeight) / maxValue -
1438
- (pointerRadius || pointerHeight / 2) +
1439
- 10;
1440
- setPointerY4(y);
1441
- setPointerItem4(item);
1442
- }
1443
- }
1444
- if (data5 && data5.length) {
1445
- item = data5[factor];
1446
- if (item) {
1447
- y =
1448
- containerHeight -
1449
- (item.value * containerHeight) / maxValue -
1450
- (pointerRadius || pointerHeight / 2) +
1451
- 10;
1452
- setPointerY5(y);
1453
- setPointerItem5(item);
1454
- }
1455
- }
1456
- if (secondaryData?.length) {
1457
- item = secondaryData[factor];
1458
- if (item) {
1459
- y =
1460
- containerHeight -
1461
- (item.value * containerHeight) / maxValue -
1462
- (pointerRadius || pointerHeight / 2) +
1463
- 10;
1464
- setSecondaryPointerY(y);
1465
- setSecondaryPointerItem(item);
1466
- }
1467
- }
1468
- }}
1469
- // onResponderReject={evt => {
1470
- // console.log('evt...reject.......',evt);
1471
- // }}
1472
- onResponderEnd={evt => {
1473
- // console.log('evt...end.......',evt);
1474
- setResponderStartTime(0);
1475
- setPointerIndex(-1);
1476
- setResponderActive(false);
1477
- if (!persistPointer)
1478
- setTimeout(() => setPointerX(0), pointerVanishDelay);
1479
- }}
1480
- onResponderTerminationRequest={evt => false}
1481
- // onResponderTerminate={evt => {
1482
- // console.log('evt...terminate.......',evt);
1483
- // }}
1484
- // onResponderRelease={evt => {
1485
- // setResponderStartTime(0);
1486
- // setResponderActive(false);
1487
- // setTimeout(() => setPointerX(0), pointerVanishDelay);
1488
- // }}
1489
- style={{
1490
- position: 'absolute',
1491
- height:
1492
- containerHeightIncludingBelowXAxis +
1493
- (props.overflowBottom ?? dataPointsRadius1),
1494
- bottom:
1495
- 60 +
1496
- xAxisLabelsVerticalShift +
1497
- labelsExtraHeight -
1498
- xAxisThickness -
1499
- (props.overflowBottom ?? dataPointsRadius1),
1500
- zIndex: zIndex,
1501
- transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
1502
- width: totalWidth,
1503
- }}>
1504
- {lineSvgComponent(
1505
- points,
1506
- currentLineThickness,
1507
- color,
1508
- fillPoints,
1509
- startFillColor,
1510
- endFillColor,
1511
- startOpacity,
1512
- endOpacity,
1513
- strokeDashArray,
1514
- showArrow,
1515
- arrowPoints,
1516
- arrowStrokeWidth,
1517
- arrowStrokeColor,
1518
- arrowFillColor,
1519
- key,
1520
- )}
1521
- </View>
1522
- );
1523
- };
1524
-
1525
- const renderAnimatedLine = (
1526
- zIndex: number,
1527
- points: any,
1528
- animatedWidth: any,
1529
- currentLineThickness: number | undefined,
1530
- color: ColorValue,
1531
- fillPoints: any,
1532
- startFillColor: string,
1533
- endFillColor: string,
1534
- startOpacity: number,
1535
- endOpacity: number,
1536
- strokeDashArray: Array<number> | undefined | null,
1537
- showArrow,
1538
- arrowPoints,
1539
- arrowStrokeWidth,
1540
- arrowStrokeColor,
1541
- arrowFillColor,
1542
- key?: number,
1543
- ) => {
1544
- return (
1545
- <Animated.View
1546
- key={key ?? 0}
1547
- onStartShouldSetResponder={evt => (pointerConfig ? true : false)}
1548
- onMoveShouldSetResponder={evt => (pointerConfig ? true : false)}
1549
- onResponderGrant={evt => {
1550
- if (!pointerConfig) return;
1551
- setResponderStartTime(evt.timeStamp);
1552
- if (activatePointersOnLongPress) {
1553
- return;
1554
- }
1555
- let x = evt.nativeEvent.locationX;
1556
- activatePointers(x);
1557
- }}
1558
- onResponderMove={evt => {
1559
- if (!pointerConfig) return;
1560
- if (
1561
- activatePointersOnLongPress &&
1562
- evt.timeStamp - responderStartTime < activatePointersDelay
1563
- ) {
1564
- return;
1565
- } else {
1566
- setResponderActive(true);
1567
- }
1568
- let x = evt.nativeEvent.locationX;
1569
- if (
1570
- !activatePointersOnLongPress &&
1571
- x > (props.width || Dimensions.get('window').width)
1572
- )
1573
- return;
1574
- let factor = (x - initialSpacing) / spacing;
1575
- factor = Math.round(factor);
1576
- factor = Math.min(factor, (data0 ?? data).length - 1);
1577
- factor = Math.max(factor, 0);
1578
- let z =
1579
- initialSpacing +
1580
- spacing * factor -
1581
- (pointerRadius || pointerWidth / 2) -
1582
- 1;
1583
- let item, y;
1584
- setPointerX(z);
1585
- setPointerIndex(factor);
1586
- item = (data0 ?? data)[factor];
1587
- y =
1588
- containerHeight -
1589
- (item.value * containerHeight) / maxValue -
1590
- (pointerRadius || pointerHeight / 2) +
1591
- 10;
1592
- setPointerY(y);
1593
- setPointerItem(item);
1594
- if (data2 && data2.length) {
1595
- item = data2[factor];
1596
- if (item) {
1597
- y =
1598
- containerHeight -
1599
- (item.value * containerHeight) / maxValue -
1600
- (pointerRadius || pointerHeight / 2) +
1601
- 10;
1602
- setPointerY2(y);
1603
- setPointerItem2(item);
1604
- }
1605
- }
1606
- if (data3 && data3.length) {
1607
- item = data3[factor];
1608
- if (item) {
1609
- y =
1610
- containerHeight -
1611
- (item.value * containerHeight) / maxValue -
1612
- (pointerRadius || pointerHeight / 2) +
1613
- 10;
1614
- setPointerY3(y);
1615
- setPointerItem3(item);
1616
- }
1617
- }
1618
- if (data4 && data4.length) {
1619
- item = data4[factor];
1620
- if (item) {
1621
- y =
1622
- containerHeight -
1623
- (item.value * containerHeight) / maxValue -
1624
- (pointerRadius || pointerHeight / 2) +
1625
- 10;
1626
- setPointerY4(y);
1627
- setPointerItem4(item);
1628
- }
1629
- }
1630
- if (data5 && data5.length) {
1631
- item = data5[factor];
1632
- if (item) {
1633
- y =
1634
- containerHeight -
1635
- (item.value * containerHeight) / maxValue -
1636
- (pointerRadius || pointerHeight / 2) +
1637
- 10;
1638
- setPointerY5(y);
1639
- setPointerItem5(item);
1640
- }
1641
- }
1642
- if (secondaryData?.length) {
1643
- item = secondaryData[factor];
1644
- if (item) {
1645
- y =
1646
- containerHeight -
1647
- (item.value * containerHeight) / maxValue -
1648
- (pointerRadius || pointerHeight / 2) +
1649
- 10;
1650
- setSecondaryPointerY(y);
1651
- setSecondaryPointerItem(item);
1652
- }
1653
- }
1654
- }}
1655
- // onResponderReject={evt => {
1656
- // console.log('evt...reject.......',evt);
1657
- // }}
1658
- onResponderEnd={evt => {
1659
- // console.log('evt...end.......',evt);
1660
- setResponderStartTime(0);
1661
- setPointerIndex(-1);
1662
- setResponderActive(false);
1663
- if (!persistPointer)
1664
- setTimeout(() => setPointerX(0), pointerVanishDelay);
1665
- }}
1666
- onResponderTerminationRequest={evt => false}
1667
- // onResponderTerminate={evt => {
1668
- // console.log('evt...terminate.......',evt);
1669
- // }}
1670
- // onResponderRelease={evt => {
1671
- // setResponderStartTime(0);
1672
- // setResponderActive(false);
1673
- // setTimeout(() => setPointerX(0), pointerVanishDelay);
1674
- // }}
1675
- style={{
1676
- position: 'absolute',
1677
- height:
1678
- containerHeightIncludingBelowXAxis +
1679
- (props.overflowBottom ?? dataPointsRadius1),
1680
- bottom:
1681
- 60 +
1682
- xAxisLabelsVerticalShift +
1683
- labelsExtraHeight -
1684
- xAxisThickness -
1685
- (props.overflowBottom ?? dataPointsRadius1),
1686
- zIndex: zIndex,
1687
- transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
1688
- width: animatedWidth,
1689
- }}>
1690
- {lineSvgComponent(
1691
- points,
1692
- currentLineThickness,
1693
- color,
1694
- fillPoints,
1695
- startFillColor,
1696
- endFillColor,
1697
- startOpacity,
1698
- endOpacity,
1699
- strokeDashArray,
1700
- showArrow,
1701
- arrowPoints,
1702
- arrowStrokeWidth,
1703
- arrowStrokeColor,
1704
- arrowFillColor,
1705
- key,
1706
- )}
1707
- </Animated.View>
1708
- );
1709
- };
1710
-
1711
- const remainingScrollViewProps = {
1712
- onScroll: (ev: any) => {
1713
- props.onScroll?.(ev);
1714
- if (
1715
- pointerConfig &&
1716
- pointerConfig.activatePointersOnLongPress &&
1717
- pointerConfig.autoAdjustPointerLabelPosition
1718
- ) {
1719
- setScrollX(ev.nativeEvent.contentOffset.x);
1720
- }
1721
- },
1722
- };
1723
-
1724
- const renderChartContent = () => {
1725
- return (
1726
- <>
1727
- {dataSet
1728
- ? pointsFromSet.length
1729
- ? dataSet.map((set, index) => {
1730
- if (isAnimated) {
1731
- return renderAnimatedLine(
1732
- set.zIndex ?? zIndex1,
1733
- pointsFromSet[index],
1734
- animatedWidth,
1735
- set.thickness ?? thickness1,
1736
- set.color ?? color1,
1737
- fillPointsFromSet[index],
1738
- set.startFillColor ?? startFillColor1,
1739
- set.endFillColor ?? endFillColor1,
1740
- set.startOpacity ?? startOpacity1,
1741
- set.endOpacity ?? endOpacity1,
1742
- set.strokeDashArray ?? strokeDashArray1,
1743
- set.showArrow || props.showArrows,
1744
- arrowPointsFromSet[index],
1745
- arrowStrokeWidthsFromSet?.[index],
1746
- arrowStrokeColorsFromSet?.[index],
1747
- arrowFillColorsFromSet?.[index],
1748
- index,
1749
- );
1750
- } else {
1751
- return renderLine(
1752
- set.zIndex ?? zIndex1,
1753
- pointsFromSet[index],
1754
- set.thickness ?? thickness1,
1755
- set.color ?? color1,
1756
- fillPointsFromSet[index],
1757
- set.startFillColor ?? startFillColor1,
1758
- set.endFillColor ?? endFillColor1,
1759
- set.startOpacity ?? startOpacity1,
1760
- set.endOpacity ?? endOpacity1,
1761
- set.strokeDashArray ?? strokeDashArray1,
1762
- set.showArrow || props.showArrows,
1763
- arrowPointsFromSet[index],
1764
- arrowStrokeWidthsFromSet?.[index],
1765
- arrowStrokeColorsFromSet?.[index],
1766
- arrowFillColorsFromSet?.[index],
1767
- index,
1768
- );
1769
- }
1770
- })
1771
- : null
1772
- : isAnimated
1773
- ? renderAnimatedLine(
1774
- zIndex1,
1775
- points,
1776
- animatedWidth,
1777
- thickness1,
1778
- color1,
1779
- fillPoints,
1780
- startFillColor1,
1781
- endFillColor1,
1782
- startOpacity1,
1783
- endOpacity1,
1784
- strokeDashArray1,
1785
- props.showArrow1 || props.showArrows,
1786
- arrow1Points,
1787
- arrowStrokeWidth1,
1788
- arrowStrokeColor1,
1789
- arrowFillColor1,
1790
- 0,
1791
- )
1792
- : renderLine(
1793
- zIndex1,
1794
- points,
1795
- thickness1,
1796
- color1,
1797
- fillPoints,
1798
- startFillColor1,
1799
- endFillColor1,
1800
- startOpacity1,
1801
- endOpacity1,
1802
- strokeDashArray1,
1803
- props.showArrow1 || props.showArrows,
1804
- arrow1Points,
1805
- arrowStrokeWidth1,
1806
- arrowStrokeColor1,
1807
- arrowFillColor1,
1808
- 0,
1809
- )}
1810
- {secondaryPoints
1811
- ? isAnimated
1812
- ? renderAnimatedLine(
1813
- secondaryLineConfig.zIndex,
1814
- secondaryPoints,
1815
- animatedWidth,
1816
- secondaryLineConfig.thickness,
1817
- secondaryLineConfig.color,
1818
- secondaryFillPoints,
1819
- secondaryLineConfig.startFillColor,
1820
- secondaryLineConfig.endFillColor,
1821
- secondaryLineConfig.startOpacity,
1822
- secondaryLineConfig.endOpacity,
1823
- secondaryLineConfig.strokeDashArray,
1824
- secondaryLineConfig.showArrow,
1825
- secondaryArrowPoints,
1826
- secondaryLineConfig.arrowConfig?.strokeWidth,
1827
- secondaryLineConfig.arrowConfig?.strokeColor,
1828
- secondaryLineConfig.arrowConfig?.fillColor,
1829
- 6,
1830
- )
1831
- : renderLine(
1832
- secondaryLineConfig.zIndex,
1833
- secondaryPoints,
1834
- secondaryLineConfig.thickness,
1835
- secondaryLineConfig.color,
1836
- secondaryFillPoints,
1837
- secondaryLineConfig.startFillColor,
1838
- secondaryLineConfig.endFillColor,
1839
- secondaryLineConfig.startOpacity,
1840
- secondaryLineConfig.endOpacity,
1841
- secondaryLineConfig.strokeDashArray,
1842
- secondaryLineConfig.showArrow,
1843
- secondaryArrowPoints,
1844
- secondaryLineConfig.arrowConfig?.strokeWidth,
1845
- secondaryLineConfig.arrowConfig?.strokeColor,
1846
- secondaryLineConfig.arrowConfig?.fillColor,
1847
- 6,
1848
- )
1849
- : null}
1850
- {points2
1851
- ? isAnimated
1852
- ? renderAnimatedLine(
1853
- zIndex2,
1854
- points2,
1855
- animatedWidth2,
1856
- thickness2,
1857
- color2,
1858
- fillPoints2,
1859
- startFillColor2,
1860
- endFillColor2,
1861
- startOpacity2,
1862
- endOpacity2,
1863
- strokeDashArray2,
1864
- props.showArrow2 || props.showArrows,
1865
- arrow2Points,
1866
- arrowStrokeWidth2,
1867
- arrowStrokeColor2,
1868
- arrowFillColor2,
1869
- 1,
1870
- )
1871
- : renderLine(
1872
- zIndex2,
1873
- points2,
1874
- thickness2,
1875
- color2,
1876
- fillPoints2,
1877
- startFillColor2,
1878
- endFillColor2,
1879
- startOpacity2,
1880
- endOpacity2,
1881
- strokeDashArray2,
1882
- props.showArrow2 || props.showArrows,
1883
- arrow2Points,
1884
- arrowStrokeWidth2,
1885
- arrowStrokeColor2,
1886
- arrowFillColor2,
1887
- 1,
1888
- )
1889
- : null}
1890
- {points3
1891
- ? isAnimated
1892
- ? renderAnimatedLine(
1893
- zIndex3,
1894
- points3,
1895
- animatedWidth3,
1896
- thickness3,
1897
- color3,
1898
- fillPoints3,
1899
- startFillColor3,
1900
- endFillColor3,
1901
- startOpacity3,
1902
- endOpacity3,
1903
- strokeDashArray3,
1904
- props.showArrow3 || props.showArrows,
1905
- arrow3Points,
1906
- arrowStrokeWidth3,
1907
- arrowStrokeColor3,
1908
- arrowFillColor3,
1909
- 2,
1910
- )
1911
- : renderLine(
1912
- zIndex3,
1913
- points3,
1914
- thickness3,
1915
- color3,
1916
- fillPoints3,
1917
- startFillColor3,
1918
- endFillColor3,
1919
- startOpacity3,
1920
- endOpacity3,
1921
- strokeDashArray3,
1922
- props.showArrow3 || props.showArrows,
1923
- arrow3Points,
1924
- arrowStrokeWidth3,
1925
- arrowStrokeColor3,
1926
- arrowFillColor3,
1927
- 2,
1928
- )
1929
- : null}
1930
- {points4
1931
- ? isAnimated
1932
- ? renderAnimatedLine(
1933
- zIndex4,
1934
- points4,
1935
- animatedWidth4,
1936
- thickness4,
1937
- color4,
1938
- fillPoints4,
1939
- startFillColor4,
1940
- endFillColor4,
1941
- startOpacity4,
1942
- endOpacity4,
1943
- strokeDashArray4,
1944
- props.showArrow4 || props.showArrows,
1945
- arrow4Points,
1946
- arrowStrokeWidth4,
1947
- arrowStrokeColor4,
1948
- arrowFillColor4,
1949
- 3,
1950
- )
1951
- : renderLine(
1952
- zIndex4,
1953
- points4,
1954
- thickness4,
1955
- color4,
1956
- fillPoints4,
1957
- startFillColor4,
1958
- endFillColor4,
1959
- startOpacity4,
1960
- endOpacity4,
1961
- strokeDashArray4,
1962
- props.showArrow4 || props.showArrows,
1963
- arrow4Points,
1964
- arrowStrokeWidth4,
1965
- arrowStrokeColor4,
1966
- arrowFillColor4,
1967
- 3,
1968
- )
1969
- : null}
1970
- {points5
1971
- ? isAnimated
1972
- ? renderAnimatedLine(
1973
- zIndex5,
1974
- points5,
1975
- animatedWidth5,
1976
- thickness5,
1977
- color5,
1978
- fillPoints5,
1979
- startFillColor5,
1980
- endFillColor5,
1981
- startOpacity5,
1982
- endOpacity5,
1983
- strokeDashArray5,
1984
- props.showArrow5 || props.showArrows,
1985
- arrow5Points,
1986
- arrowStrokeWidth5,
1987
- arrowStrokeColor5,
1988
- arrowFillColor5,
1989
- 4,
1990
- )
1991
- : renderLine(
1992
- zIndex5,
1993
- points5,
1994
- thickness5,
1995
- color5,
1996
- fillPoints5,
1997
- startFillColor5,
1998
- endFillColor5,
1999
- startOpacity5,
2000
- endOpacity5,
2001
- strokeDashArray5,
2002
- props.showArrow5 || props.showArrows,
2003
- arrow5Points,
2004
- arrowStrokeWidth5,
2005
- arrowStrokeColor5,
2006
- arrowFillColor5,
2007
- 4,
2008
- )
2009
- : null}
2010
- {pointerX > 0 ? (
2011
- <View
2012
- pointerEvents={pointerEvents ?? 'none'}
2013
- style={{
2014
- position: 'absolute',
2015
- height:
2016
- extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
2017
- bottom:
2018
- 58 + labelsExtraHeight + xAxisLabelsVerticalShift - overflowTop,
2019
- // width: totalWidth,
2020
- zIndex: 20,
2021
- }}>
2022
- {!stripOverPointer && renderStripAndLabel()}
2023
- {dataSet ? (
2024
- renderPointer(1)
2025
- ) : (
2026
- <>
2027
- {renderPointer(1)}
2028
- {points2 ? renderPointer(2) : null}
2029
- {points3 ? renderPointer(3) : null}
2030
- {points4 ? renderPointer(4) : null}
2031
- {points5 ? renderPointer(5) : null}
2032
- {secondaryPoints ? renderPointer(6) : null}
2033
- {stripOverPointer && renderStripAndLabel()}
2034
- </>
2035
- )}
2036
- </View>
2037
- ) : null}
2038
- {(data0 ?? data).map((item: lineDataItem, index: number) => {
2039
- return (
2040
- <View key={index}>
2041
- {isAnimated
2042
- ? renderAnimatedLabel(
2043
- index,
2044
- item.label ||
2045
- (props.xAxisLabelTexts && props.xAxisLabelTexts[index]
2046
- ? props.xAxisLabelTexts[index]
2047
- : ''),
2048
- item.labelTextStyle || props.xAxisLabelTextStyle,
2049
- item.labelComponent,
2050
- )
2051
- : renderLabel(
2052
- index,
2053
- item.label ||
2054
- (props.xAxisLabelTexts && props.xAxisLabelTexts[index]
2055
- ? props.xAxisLabelTexts[index]
2056
- : ''),
2057
- item.labelTextStyle || props.xAxisLabelTextStyle,
2058
- item.labelComponent,
2059
- )}
2060
- {/* {renderLabel(index, item.label, item.labelTextStyle)} */}
2061
- </View>
2062
- );
2063
- })}
2064
- </>
2065
- );
2066
- };
2067
-
2068
- return (
2069
- <BarAndLineChartsWrapper
2070
- {...barAndLineChartsWrapperProps}
2071
- scrollRef={scrollRef}
2072
- animatedWidth={animatedWidth}
2073
- renderChartContent={renderChartContent}
2074
- remainingScrollViewProps={remainingScrollViewProps}
2075
- />
2076
- );
2077
- };