react-native-gifted-charts 1.4.12 → 1.4.13

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 (60) hide show
  1. package/package.json +5 -9
  2. package/src/BarChart/Animated2DWithGradient.tsx +197 -0
  3. package/src/BarChart/RenderBars.tsx +454 -0
  4. package/src/BarChart/RenderStackBars.tsx +383 -0
  5. package/src/BarChart/index.tsx +373 -0
  6. package/src/BarChart/styles.tsx +47 -0
  7. package/src/Components/AnimatedThreeDBar/index.tsx +258 -0
  8. package/src/Components/AnimatedThreeDBar/styles.tsx +14 -0
  9. package/src/Components/BarAndLineChartsWrapper/index.tsx +244 -0
  10. package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +590 -0
  11. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
  12. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
  13. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
  14. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
  15. package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +131 -0
  16. package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +30 -0
  17. package/src/Components/BarSpecificComponents/cap.tsx +34 -0
  18. package/src/Components/common/LinearGradient.tsx +27 -0
  19. package/src/Components/common/Pointer.tsx +37 -0
  20. package/src/Components/common/StripAndLabel.tsx +98 -0
  21. package/src/Components/lineSvg.tsx +42 -0
  22. package/src/LineChart/LineChartBicolor.tsx +740 -0
  23. package/src/LineChart/index.tsx +2158 -0
  24. package/src/LineChart/styles.tsx +47 -0
  25. package/src/PieChart/index.tsx +165 -0
  26. package/src/PieChart/main.tsx +363 -0
  27. package/src/PieChartPro/index.tsx +267 -0
  28. package/src/PopulationPyramid/index.tsx +603 -0
  29. package/src/index.tsx +25 -0
  30. package/src/todos.md +23 -0
  31. package/src/utils/index.ts +16 -0
  32. package/dist/BarChart/Animated2DWithGradient.js +0 -1
  33. package/dist/BarChart/RenderBars.js +0 -1
  34. package/dist/BarChart/RenderStackBars.js +0 -1
  35. package/dist/BarChart/index.js +0 -1
  36. package/dist/BarChart/styles.js +0 -1
  37. package/dist/Components/AnimatedThreeDBar/index.js +0 -1
  38. package/dist/Components/AnimatedThreeDBar/styles.js +0 -1
  39. package/dist/Components/BarAndLineChartsWrapper/index.js +0 -1
  40. package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +0 -1
  41. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +0 -1
  42. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +0 -1
  43. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +0 -1
  44. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +0 -1
  45. package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +0 -1
  46. package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +0 -1
  47. package/dist/Components/BarSpecificComponents/cap.js +0 -1
  48. package/dist/Components/common/LinearGradient.js +0 -1
  49. package/dist/Components/common/Pointer.js +0 -1
  50. package/dist/Components/common/StripAndLabel.js +0 -1
  51. package/dist/Components/lineSvg.js +0 -1
  52. package/dist/LineChart/LineChartBicolor.js +0 -1
  53. package/dist/LineChart/index.js +0 -1
  54. package/dist/LineChart/styles.js +0 -1
  55. package/dist/PieChart/index.js +0 -1
  56. package/dist/PieChart/main.js +0 -1
  57. package/dist/PieChartPro/index.js +0 -1
  58. package/dist/PopulationPyramid/index.js +0 -1
  59. package/dist/index.js +0 -1
  60. package/dist/utils/index.js +0 -1
@@ -0,0 +1,740 @@
1
+ import React, {Fragment, useCallback, useEffect, useMemo, useRef} from 'react';
2
+ import {View, Animated, Easing, Text} from 'react-native';
3
+ import {styles} from './styles';
4
+ import Svg, {
5
+ Path,
6
+ LinearGradient,
7
+ Stop,
8
+ Circle,
9
+ Rect,
10
+ Text as CanvasText,
11
+ } from 'react-native-svg';
12
+ import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
13
+ import {
14
+ LineChartBicolorPropsType,
15
+ bicolorLineDataItem,
16
+ useLineChartBiColor,
17
+ } from 'gifted-charts-core';
18
+ import { screenWidth } from '../utils';
19
+
20
+ export const LineChartBicolor = (props: LineChartBicolorPropsType) => {
21
+ const scrollRef = useRef();
22
+ // const heightValue = useMemo(() => new Animated.Value(0), []);
23
+ const widthValue = useMemo(() => new Animated.Value(0), []);
24
+ const opacValue = useMemo(() => new Animated.Value(0), []);
25
+
26
+ const {
27
+ pointsArray,
28
+ fillPointsArray,
29
+ selectedIndex,
30
+ setSelectedIndex,
31
+ containerHeight,
32
+ data,
33
+ labelsExtraHeight,
34
+ animationDuration,
35
+ startIndex1,
36
+ endIndex1,
37
+ initialSpacing,
38
+ thickness,
39
+ spacing,
40
+ xAxisThickness,
41
+ dataPointsHeight1,
42
+ dataPointsWidth1,
43
+ dataPointsRadius1,
44
+ dataPointsColor1,
45
+ dataPointsShape1,
46
+ areaChart,
47
+ textFontSize1,
48
+ textColor1,
49
+ totalWidth,
50
+ maxValue,
51
+ extendedContainerHeight,
52
+ getX,
53
+ getY,
54
+ stepHeight,
55
+ noOfSectionsBelowXAxis,
56
+ thickness1,
57
+ zIndex,
58
+ strokeDashArray1,
59
+ rotateLabel,
60
+ isAnimated,
61
+ hideDataPoints1,
62
+ color,
63
+ colorNegative,
64
+ startFillColor,
65
+ endFillColor,
66
+ startOpacity,
67
+ endOpacity,
68
+ startFillColorNegative,
69
+ endFillColorNegative,
70
+ startOpacityNegative,
71
+ endOpacityNegative,
72
+ gradientDirection,
73
+ xAxisTextNumberOfLines,
74
+ focusEnabled,
75
+ showDataPointOnFocus,
76
+ showStripOnFocus,
77
+ showTextOnFocus,
78
+ stripHeight,
79
+ stripWidth,
80
+ stripColor,
81
+ stripOpacity,
82
+ unFocusOnPressOut,
83
+ delayBeforeUnFocus,
84
+ barAndLineChartsWrapperProps,
85
+ } = useLineChartBiColor({...props, parentWidth: props.parentWidth ?? screenWidth});
86
+
87
+ const labelsAppear = useCallback(() => {
88
+ opacValue.setValue(0);
89
+ Animated.timing(opacValue, {
90
+ toValue: 1,
91
+ duration: 500,
92
+ easing: Easing.ease,
93
+ useNativeDriver: false,
94
+ }).start();
95
+ }, [opacValue]);
96
+
97
+ const appearingOpacity = opacValue.interpolate({
98
+ inputRange: [0, 1],
99
+ outputRange: [0, 1],
100
+ });
101
+
102
+ const decreaseWidth = useCallback(() => {
103
+ widthValue.setValue(0);
104
+ Animated.timing(widthValue, {
105
+ toValue: 1,
106
+ duration: animationDuration,
107
+ easing: Easing.linear,
108
+ useNativeDriver: false,
109
+ }).start();
110
+ }, [animationDuration, widthValue]);
111
+
112
+ useEffect(() => {
113
+ decreaseWidth();
114
+ labelsAppear();
115
+ }, [animationDuration, decreaseWidth, labelsAppear]);
116
+
117
+ const renderLabel = (
118
+ index: number,
119
+ label: String,
120
+ labelTextStyle: any,
121
+ labelComponent?: Function,
122
+ ) => {
123
+ return (
124
+ <View
125
+ style={[
126
+ {
127
+ position: 'absolute',
128
+ bottom: 30,
129
+ zIndex: 10,
130
+ width: spacing + labelsExtraHeight,
131
+ left:
132
+ index === 0 && initialSpacing < 10
133
+ ? getX(index) - spacing / 2 + 8
134
+ : getX(index) - spacing / 2,
135
+ justifyContent: 'center',
136
+ },
137
+ rotateLabel && {transform: [{rotate: '60deg'}]},
138
+ ]}>
139
+ {labelComponent ? (
140
+ labelComponent()
141
+ ) : (
142
+ <Text
143
+ style={labelTextStyle || {textAlign: 'center'}}
144
+ numberOfLines={xAxisTextNumberOfLines}>
145
+ {label || ''}
146
+ </Text>
147
+ )}
148
+ </View>
149
+ );
150
+ };
151
+
152
+ const renderAnimatedLabel = (
153
+ index: number,
154
+ label: String,
155
+ labelTextStyle: any,
156
+ labelComponent?: Function,
157
+ ) => {
158
+ return (
159
+ <Animated.View
160
+ style={[
161
+ {
162
+ height: rotateLabel ? 40 : 20,
163
+ // backgroundColor: 'yellow',
164
+ position: 'absolute',
165
+ bottom: rotateLabel ? 10 : 30,
166
+ zIndex: 10,
167
+ width: spacing,
168
+ left:
169
+ index === 0 && initialSpacing < 10
170
+ ? getX(index) - spacing / 2 + 8
171
+ : getX(index) - spacing / 2,
172
+ opacity: appearingOpacity,
173
+ },
174
+ rotateLabel && {transform: [{rotate: '60deg'}]},
175
+ ]}>
176
+ {labelComponent ? (
177
+ labelComponent()
178
+ ) : (
179
+ <Text
180
+ style={labelTextStyle || {textAlign: 'center'}}
181
+ numberOfLines={xAxisTextNumberOfLines}>
182
+ {label || ''}
183
+ </Text>
184
+ )}
185
+ </Animated.View>
186
+ );
187
+ };
188
+
189
+ const animatedWidth = widthValue.interpolate({
190
+ inputRange: [0, 1],
191
+ outputRange: [0, totalWidth],
192
+ });
193
+
194
+ const onStripPress = (item, index) => {
195
+ setSelectedIndex(index);
196
+ if (props.onFocus) {
197
+ props.onFocus(item, index);
198
+ }
199
+ };
200
+
201
+ const renderDataPoints = (
202
+ dataForRender,
203
+ dataPtsShape,
204
+ dataPtsWidth,
205
+ dataPtsHeight,
206
+ dataPtsColor,
207
+ dataPtsRadius,
208
+ textColor,
209
+ textFontSize,
210
+ startIndex,
211
+ endIndex,
212
+ ) => {
213
+ return dataForRender.map((item: bicolorLineDataItem, index: number) => {
214
+ if (index < startIndex || index > endIndex) return null;
215
+ if (item.hideDataPoint) {
216
+ return null;
217
+ }
218
+ let dataPointsShape,
219
+ dataPointsWidth,
220
+ dataPointsHeight,
221
+ dataPointsColor,
222
+ dataPointsRadius,
223
+ text,
224
+ customDataPoint,
225
+ dataPointLabelComponent;
226
+ if (index === selectedIndex) {
227
+ dataPointsShape =
228
+ item.focusedDataPointShape ||
229
+ props.focusedDataPointShape ||
230
+ item.dataPointShape ||
231
+ dataPtsShape;
232
+ dataPointsWidth =
233
+ item.focusedDataPointWidth ||
234
+ props.focusedDataPointWidth ||
235
+ item.dataPointWidth ||
236
+ dataPtsWidth;
237
+ dataPointsHeight =
238
+ item.focusedDataPointHeight ||
239
+ props.focusedDataPointHeight ||
240
+ item.dataPointHeight ||
241
+ dataPtsHeight;
242
+ dataPointsColor =
243
+ item.focusedDataPointColor || props.focusedDataPointColor || 'orange';
244
+ dataPointsRadius =
245
+ item.focusedDataPointRadius ||
246
+ props.focusedDataPointRadius ||
247
+ item.dataPointRadius ||
248
+ dataPtsRadius;
249
+ if (showTextOnFocus) {
250
+ text = item.dataPointText;
251
+ }
252
+ customDataPoint =
253
+ item.focusedCustomDataPoint ||
254
+ props.focusedCustomDataPoint ||
255
+ item.customDataPoint ||
256
+ props.customDataPoint;
257
+ dataPointLabelComponent =
258
+ item.focusedDataPointLabelComponent || item.dataPointLabelComponent;
259
+ } else {
260
+ dataPointsShape = item.dataPointShape || dataPtsShape;
261
+ dataPointsWidth = item.dataPointWidth || dataPtsWidth;
262
+ dataPointsHeight = item.dataPointHeight || dataPtsHeight;
263
+ dataPointsColor = item.dataPointColor || dataPtsColor;
264
+ dataPointsRadius = item.dataPointRadius || dataPtsRadius;
265
+ if (showTextOnFocus) {
266
+ text = '';
267
+ }
268
+ customDataPoint = item.customDataPoint || props.customDataPoint;
269
+ dataPointLabelComponent = item.dataPointLabelComponent;
270
+ }
271
+
272
+ const currentStripHeight = item.stripHeight ?? stripHeight;
273
+ const currentStripWidth = item.stripWidth ?? stripWidth;
274
+ const currentStripOpacity = item.stripOpacity ?? stripOpacity;
275
+ const currentStripColor = item.stripColor || stripColor;
276
+
277
+ return (
278
+ <Fragment key={index}>
279
+ {focusEnabled ? (
280
+ <>
281
+ {unFocusOnPressOut ? (
282
+ <Rect
283
+ onPressIn={() => onStripPress(item, index)}
284
+ onPressOut={() =>
285
+ setTimeout(() => setSelectedIndex(-1), delayBeforeUnFocus)
286
+ }
287
+ x={initialSpacing + (spacing * index - spacing / 2)}
288
+ y={8}
289
+ width={spacing}
290
+ height={containerHeight}
291
+ fill={'none'}
292
+ />
293
+ ) : (
294
+ <Rect
295
+ onPress={() => onStripPress(item, index)}
296
+ x={initialSpacing + (spacing * index - spacing / 2)}
297
+ y={8}
298
+ width={spacing}
299
+ height={containerHeight}
300
+ fill={'none'}
301
+ />
302
+ )}
303
+ </>
304
+ ) : null}
305
+ {item.showStrip ||
306
+ (focusEnabled && index === selectedIndex && showStripOnFocus) ? (
307
+ <Rect
308
+ x={initialSpacing + (spacing * index - dataPointsWidth / 2)}
309
+ y={
310
+ currentStripHeight
311
+ ? containerHeight - currentStripHeight + 8
312
+ : containerHeight -
313
+ dataPointsHeight / 2 +
314
+ 20 -
315
+ (item.value * containerHeight) / maxValue
316
+ }
317
+ width={currentStripWidth}
318
+ height={
319
+ currentStripHeight ||
320
+ containerHeight - dataPointsHeight / 2 + 20
321
+ }
322
+ opacity={currentStripOpacity}
323
+ fill={currentStripColor}
324
+ />
325
+ ) : null}
326
+ {customDataPoint ? (
327
+ <View
328
+ style={[
329
+ styles.customDataPointContainer,
330
+ {
331
+ height: dataPointsHeight,
332
+ width: dataPointsWidth,
333
+ top:
334
+ containerHeight - (item.value * containerHeight) / maxValue,
335
+ left: getX(index) - dataPointsWidth,
336
+ },
337
+ ]}>
338
+ {customDataPoint()}
339
+ </View>
340
+ ) : null}
341
+ {dataPointsShape === 'rectangular' ? (
342
+ <Fragment key={index}>
343
+ {customDataPoint ? null : (
344
+ <Rect
345
+ x={getX(index) - dataPointsWidth}
346
+ y={
347
+ extendedContainerHeight +
348
+ dataPointsHeight / 2 -
349
+ (item.value * containerHeight) / maxValue
350
+ }
351
+ width={dataPointsWidth}
352
+ height={dataPointsHeight}
353
+ fill={
354
+ showDataPointOnFocus
355
+ ? index === selectedIndex
356
+ ? dataPointsColor
357
+ : 'none'
358
+ : dataPointsColor
359
+ }
360
+ onPress={() => {
361
+ item.onPress
362
+ ? item.onPress(item, index)
363
+ : props.onPress
364
+ ? props.onPress(item, index)
365
+ : null;
366
+ }}
367
+ />
368
+ )}
369
+ </Fragment>
370
+ ) : (
371
+ <Fragment key={index}>
372
+ {customDataPoint ? null : (
373
+ <Circle
374
+ cx={getX(index)}
375
+ cy={getY(index)}
376
+ r={dataPointsRadius}
377
+ fill={
378
+ showDataPointOnFocus
379
+ ? index === selectedIndex
380
+ ? dataPointsColor
381
+ : 'none'
382
+ : dataPointsColor
383
+ }
384
+ onPress={() => {
385
+ item.onPress
386
+ ? item.onPress(item, index)
387
+ : props.onPress
388
+ ? props.onPress(item, index)
389
+ : null;
390
+ }}
391
+ />
392
+ )}
393
+ </Fragment>
394
+ )}
395
+ {dataPointLabelComponent ? (
396
+ !showTextOnFocus || index === selectedIndex ? (
397
+ <View
398
+ style={[
399
+ styles.customDataPointContainer,
400
+ {
401
+ top:
402
+ containerHeight +
403
+ (item.dataPointLabelShiftY ||
404
+ props.dataPointLabelShiftY ||
405
+ 0) -
406
+ (item.value * containerHeight) / maxValue,
407
+ left:
408
+ initialSpacing +
409
+ (item.dataPointLabelShiftX ||
410
+ props.dataPointLabelShiftX ||
411
+ 0) -
412
+ (item.dataPointLabelWidth
413
+ ? item.dataPointLabelWidth + 20
414
+ : props.dataPointLabelWidth
415
+ ? props.dataPointLabelWidth + 20
416
+ : 50) /
417
+ 2 +
418
+ spacing * index,
419
+ },
420
+ ]}>
421
+ {dataPointLabelComponent()}
422
+ </View>
423
+ ) : null
424
+ ) : text || item.dataPointText ? (
425
+ !showTextOnFocus || index === selectedIndex ? (
426
+ <CanvasText
427
+ fill={item.textColor || textColor}
428
+ fontSize={item.textFontSize || textFontSize}
429
+ x={
430
+ initialSpacing -
431
+ dataPointsWidth +
432
+ spacing * index +
433
+ (item.textShiftX || props.textShiftX || 0)
434
+ }
435
+ y={
436
+ extendedContainerHeight -
437
+ dataPointsHeight / 2 -
438
+ (item.value * containerHeight) / maxValue +
439
+ (item.textShiftY || props.textShiftY || 0)
440
+ }>
441
+ {!showTextOnFocus ? item.dataPointText : text}
442
+ </CanvasText>
443
+ ) : null
444
+ ) : null}
445
+ </Fragment>
446
+ );
447
+ });
448
+ };
449
+
450
+ const renderSpecificVerticalLines = (dataForRender: any) => {
451
+ return dataForRender.map((item: bicolorLineDataItem, index: number) => {
452
+ if (item.showVerticalLine) {
453
+ return (
454
+ <Rect
455
+ key={index}
456
+ x={
457
+ initialSpacing -
458
+ (item.verticalLineThickness || 1) / 2 -
459
+ 1 +
460
+ spacing * index
461
+ }
462
+ y={
463
+ item.verticalLineUptoDataPoint
464
+ ? containerHeight -
465
+ (item.value * containerHeight) / maxValue +
466
+ 10
467
+ : -xAxisThickness
468
+ }
469
+ width={item.verticalLineThickness || 1}
470
+ height={
471
+ item.verticalLineUptoDataPoint
472
+ ? (item.value * containerHeight) / maxValue - xAxisThickness
473
+ : containerHeight + 10 - xAxisThickness
474
+ }
475
+ fill={item.verticalLineColor || 'lightgray'}
476
+ />
477
+ );
478
+ }
479
+ return null;
480
+ });
481
+ };
482
+
483
+ const lineSvgComponent = (
484
+ pointsArray: any,
485
+ currentLineThickness: number | undefined,
486
+ color: string,
487
+ startFillColor: string,
488
+ endFillColor: string,
489
+ startOpacity: number,
490
+ endOpacity: number,
491
+ strokeDashArray: Array<number> | undefined | null,
492
+ ) => {
493
+ return (
494
+ <Svg>
495
+ {strokeDashArray &&
496
+ strokeDashArray.length === 2 &&
497
+ typeof strokeDashArray[0] === 'number' &&
498
+ typeof strokeDashArray[1] === 'number'
499
+ ? pointsArray.map((points, index) => (
500
+ <Path
501
+ key={index}
502
+ d={points.points}
503
+ fill="none"
504
+ stroke={points.color === 'green' ? color : colorNegative}
505
+ strokeWidth={currentLineThickness || thickness}
506
+ strokeDasharray={strokeDashArray}
507
+ />
508
+ ))
509
+ : pointsArray.map((points, index) => {
510
+ return (
511
+ <Path
512
+ key={index}
513
+ d={points.points}
514
+ fill="none"
515
+ stroke={points.color === 'green' ? color : colorNegative}
516
+ strokeWidth={currentLineThickness || thickness}
517
+ />
518
+ );
519
+ })}
520
+
521
+ {/*********************** For Area Chart ************/}
522
+
523
+ {areaChart && (
524
+ <>
525
+ <LinearGradient
526
+ id="Gradient"
527
+ x1="0"
528
+ y1="0"
529
+ x2={gradientDirection === 'horizontal' ? '1' : '0'}
530
+ y2={gradientDirection === 'vertical' ? '1' : '0'}>
531
+ <Stop
532
+ offset="0"
533
+ stopColor={startFillColor}
534
+ stopOpacity={startOpacity.toString()}
535
+ />
536
+ <Stop
537
+ offset="1"
538
+ stopColor={endFillColor}
539
+ stopOpacity={endOpacity.toString()}
540
+ />
541
+ </LinearGradient>
542
+ <LinearGradient
543
+ id="GradientNegative"
544
+ x1="0"
545
+ y1="0"
546
+ x2={gradientDirection === 'horizontal' ? '1' : '0'}
547
+ y2={gradientDirection === 'vertical' ? '1' : '0'}>
548
+ <Stop
549
+ offset="1"
550
+ stopColor={startFillColorNegative}
551
+ stopOpacity={startOpacityNegative.toString()}
552
+ />
553
+ <Stop
554
+ offset="0"
555
+ stopColor={endFillColorNegative}
556
+ stopOpacity={endOpacityNegative.toString()}
557
+ />
558
+ </LinearGradient>
559
+ </>
560
+ )}
561
+ {areaChart
562
+ ? fillPointsArray.map((item, index) => {
563
+ return (
564
+ <Path
565
+ key={index}
566
+ d={item.points}
567
+ fill={
568
+ item.color === 'green'
569
+ ? 'url(#Gradient)'
570
+ : 'url(#GradientNegative)'
571
+ }
572
+ stroke={'transparent'}
573
+ strokeWidth={currentLineThickness || thickness}
574
+ />
575
+ );
576
+ })
577
+ : null}
578
+
579
+ {/******************************************************************/}
580
+
581
+ {renderSpecificVerticalLines(data)}
582
+
583
+ {/*** !!! Here it's done thrice intentionally, trying to make it to only 1 breaks things !!! ***/}
584
+ {!hideDataPoints1
585
+ ? renderDataPoints(
586
+ data,
587
+ dataPointsShape1,
588
+ dataPointsWidth1,
589
+ dataPointsHeight1,
590
+ dataPointsColor1,
591
+ dataPointsRadius1,
592
+ textColor1,
593
+ textFontSize1,
594
+ startIndex1,
595
+ endIndex1,
596
+ )
597
+ : null}
598
+ </Svg>
599
+ );
600
+ };
601
+
602
+ const renderLine = (
603
+ zIndex: number,
604
+ pointsArray: any,
605
+ currentLineThickness: number | undefined,
606
+ color: string,
607
+ startFillColor: string,
608
+ endFillColor: string,
609
+ startOpacity: number,
610
+ endOpacity: number,
611
+ strokeDashArray: Array<number> | undefined | null,
612
+ ) => {
613
+ return (
614
+ <View
615
+ style={{
616
+ position: 'absolute',
617
+ height: extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
618
+ bottom: 60 + labelsExtraHeight,
619
+ width: totalWidth,
620
+ zIndex: zIndex,
621
+ }}>
622
+ {pointsArray.length
623
+ ? lineSvgComponent(
624
+ pointsArray,
625
+ currentLineThickness,
626
+ color,
627
+ startFillColor,
628
+ endFillColor,
629
+ startOpacity,
630
+ endOpacity,
631
+ strokeDashArray,
632
+ )
633
+ : null}
634
+ </View>
635
+ );
636
+ };
637
+
638
+ const renderAnimatedLine = (
639
+ zIndex: number,
640
+ points: any,
641
+ animatedWidth: any,
642
+ currentLineThickness: number | undefined,
643
+ color: string,
644
+ startFillColor: string,
645
+ endFillColor: string,
646
+ startOpacity: number,
647
+ endOpacity: number,
648
+ strokeDashArray: Array<number> | undefined | null,
649
+ ) => {
650
+ return (
651
+ <Animated.View
652
+ style={{
653
+ position: 'absolute',
654
+ height: extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
655
+ bottom: 60, //stepHeight * -0.5 + xAxisThickness,
656
+ width: animatedWidth,
657
+ zIndex: zIndex,
658
+ // backgroundColor: 'wheat',
659
+ }}>
660
+ {lineSvgComponent(
661
+ points,
662
+ currentLineThickness,
663
+ color,
664
+ startFillColor,
665
+ endFillColor,
666
+ startOpacity,
667
+ endOpacity,
668
+ strokeDashArray,
669
+ )}
670
+ </Animated.View>
671
+ );
672
+ };
673
+
674
+ const renderChartContent = () => {
675
+ return (
676
+ <>
677
+ {isAnimated
678
+ ? renderAnimatedLine(
679
+ zIndex,
680
+ pointsArray,
681
+ animatedWidth,
682
+ thickness1,
683
+ color,
684
+ startFillColor,
685
+ endFillColor,
686
+ startOpacity,
687
+ endOpacity,
688
+ strokeDashArray1,
689
+ )
690
+ : renderLine(
691
+ zIndex,
692
+ pointsArray,
693
+ thickness1,
694
+ color,
695
+ startFillColor,
696
+ endFillColor,
697
+ startOpacity,
698
+ endOpacity,
699
+ strokeDashArray1,
700
+ )}
701
+ {data.map((item: bicolorLineDataItem, index: number) => {
702
+ return (
703
+ <View key={index}>
704
+ {isAnimated
705
+ ? renderAnimatedLabel(
706
+ index,
707
+ item.label ||
708
+ (props.xAxisLabelTexts && props.xAxisLabelTexts[index]
709
+ ? props.xAxisLabelTexts[index]
710
+ : ''),
711
+ item.labelTextStyle || props.xAxisLabelTextStyle,
712
+ item.labelComponent,
713
+ )
714
+ : renderLabel(
715
+ index,
716
+ item.label ||
717
+ (props.xAxisLabelTexts && props.xAxisLabelTexts[index]
718
+ ? props.xAxisLabelTexts[index]
719
+ : ''),
720
+ item.labelTextStyle || props.xAxisLabelTextStyle,
721
+ item.labelComponent,
722
+ )}
723
+ {/* {renderLabel(index, item.label, item.labelTextStyle)} */}
724
+ </View>
725
+ );
726
+ })}
727
+ </>
728
+ );
729
+ };
730
+
731
+ return (
732
+ <BarAndLineChartsWrapper
733
+ {...barAndLineChartsWrapperProps}
734
+ scrollRef={scrollRef}
735
+ animatedWidth={animatedWidth}
736
+ renderChartContent={renderChartContent}
737
+ remainingScrollViewProps={{onScroll: (ev: any) => props.onScroll?.(ev)}}
738
+ />
739
+ );
740
+ };