react-native-gifted-charts 0.2.0 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/package.json +2 -2
- package/src/BarChart/index.tsx +1 -1
- package/src/LineChart/index.tsx +445 -190
- package/src/LineChart/styles.tsx +5 -0
package/README.md
CHANGED
|
@@ -19,12 +19,13 @@ The most complete library for Bar, Line, Area, Pie, and Donut charts in React Na
|
|
|
19
19
|
|
|
20
20
|

|
|
21
21
|

|
|
22
|
+
<img src='/demos/animatedDataLineChart.gif' alt='' width=300/>
|
|
23
|
+
<img src='/demos/pielabbelled.svg' alt='' height=280 width=270/>
|
|
22
24
|
<img src='/demos/movingBars.gif' alt='' width=300/>
|
|
23
25
|
<img src='/demos/lineLabelled.png' alt='' height=370 width=360/>
|
|
24
26
|

|
|
25
27
|
<img src='/demos/cappedCombined.png' alt='' height=280 width=280/>
|
|
26
|
-
<img src='/demos/line.gif' alt='' height=
|
|
27
|
-
<img src='/demos/pielabbelled.svg' alt='' height=280 width=270/>
|
|
28
|
+
<img src='/demos/line.gif' alt='' height=300 width=290/>
|
|
28
29
|
|
|
29
30
|
---
|
|
30
31
|
|
|
@@ -98,6 +99,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
|
|
|
98
99
|
| Issue | Solution |
|
|
99
100
|
| ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
|
|
100
101
|
| [BarChart - Value and section line don't match](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35) | [Comment by the owner](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35#issuecomment-972673281) |
|
|
102
|
+
| **Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.** | install `react-native-webview` |
|
|
101
103
|
|
|
102
104
|
## License
|
|
103
105
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"bugs": {
|
|
20
20
|
"url": "https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues"
|
|
21
21
|
},
|
|
22
|
-
"homepage": "https://
|
|
22
|
+
"homepage": "https://gifted-charts.web.app/",
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"registry": "https://registry.npmjs.org/"
|
|
25
25
|
},
|
package/src/BarChart/index.tsx
CHANGED
package/src/LineChart/index.tsx
CHANGED
|
@@ -25,6 +25,9 @@ import Svg, {
|
|
|
25
25
|
import {svgPath, bezierCommand} from '../utils';
|
|
26
26
|
import Rule from '../Components/lineSvg';
|
|
27
27
|
|
|
28
|
+
let initialData = null;
|
|
29
|
+
let animations = [];
|
|
30
|
+
|
|
28
31
|
type propTypes = {
|
|
29
32
|
height?: number;
|
|
30
33
|
noOfSections?: number;
|
|
@@ -42,7 +45,9 @@ type propTypes = {
|
|
|
42
45
|
thickness3?: number;
|
|
43
46
|
rotateLabel?: Boolean;
|
|
44
47
|
isAnimated?: Boolean;
|
|
48
|
+
animateOnDataChange?: Boolean;
|
|
45
49
|
animationDuration?: number;
|
|
50
|
+
onDataChangeAnimationDuration?: number;
|
|
46
51
|
animationEasing?: any;
|
|
47
52
|
animateTogether?: boolean;
|
|
48
53
|
xAxisThickness?: number;
|
|
@@ -50,6 +55,17 @@ type propTypes = {
|
|
|
50
55
|
hideRules?: Boolean;
|
|
51
56
|
rulesColor?: ColorValue;
|
|
52
57
|
rulesThickness?: number;
|
|
58
|
+
pressEnabled?: Boolean;
|
|
59
|
+
showDataPointOnPress?: Boolean;
|
|
60
|
+
showStripOnPress?: Boolean;
|
|
61
|
+
showTextOnPress?: Boolean;
|
|
62
|
+
stripHeight?: number;
|
|
63
|
+
stripWidth?: number;
|
|
64
|
+
stripColor?: ColorValue | String | any;
|
|
65
|
+
stripOpacity?: number;
|
|
66
|
+
onPress?: Function;
|
|
67
|
+
unFocusOnPressOut?: Boolean;
|
|
68
|
+
delayBeforeUnFocus?: number;
|
|
53
69
|
|
|
54
70
|
rulesType?: String;
|
|
55
71
|
dashWidth?: number;
|
|
@@ -127,6 +143,17 @@ type propTypes = {
|
|
|
127
143
|
dataPointsRadius3?: number;
|
|
128
144
|
dataPointsColor3?: string;
|
|
129
145
|
dataPointsShape3?: string;
|
|
146
|
+
customDataPoint?: Function;
|
|
147
|
+
|
|
148
|
+
focusedDataPointShape?: String;
|
|
149
|
+
focusedDataPointWidth?: number;
|
|
150
|
+
focusedDataPointHeight?: number;
|
|
151
|
+
focusedDataPointColor?: ColorValue | String | any;
|
|
152
|
+
focusedDataPointRadius?: number;
|
|
153
|
+
focusedCustomDataPoint?: Function;
|
|
154
|
+
dataPointLabelWidth?: number;
|
|
155
|
+
dataPointLabelShiftX?: number;
|
|
156
|
+
dataPointLabelShiftY?: number;
|
|
130
157
|
|
|
131
158
|
startFillColor?: string;
|
|
132
159
|
endFillColor?: string;
|
|
@@ -171,6 +198,7 @@ type referenceConfigType = {
|
|
|
171
198
|
type itemType = {
|
|
172
199
|
value?: number;
|
|
173
200
|
label: String;
|
|
201
|
+
labelComponent: Function;
|
|
174
202
|
labelTextStyle?: any;
|
|
175
203
|
dataPointText?: string;
|
|
176
204
|
textShiftX?: number;
|
|
@@ -178,12 +206,32 @@ type itemType = {
|
|
|
178
206
|
textColor?: string;
|
|
179
207
|
textFontSize?: number;
|
|
180
208
|
|
|
181
|
-
|
|
209
|
+
hideDataPoint?: Boolean;
|
|
182
210
|
dataPointHeight?: number;
|
|
183
211
|
dataPointWidth?: number;
|
|
184
212
|
dataPointRadius?: number;
|
|
185
213
|
dataPointColor?: string;
|
|
186
214
|
dataPointShape?: string;
|
|
215
|
+
customDataPoint?: Function;
|
|
216
|
+
|
|
217
|
+
stripHeight?: number;
|
|
218
|
+
stripWidth?: number;
|
|
219
|
+
stripColor?: ColorValue | String | any;
|
|
220
|
+
stripOpacity?: number;
|
|
221
|
+
|
|
222
|
+
focusedDataPointShape?: String;
|
|
223
|
+
focusedDataPointWidth?: number;
|
|
224
|
+
focusedDataPointHeight?: number;
|
|
225
|
+
focusedDataPointColor?: ColorValue | String | any;
|
|
226
|
+
focusedDataPointRadius?: number;
|
|
227
|
+
focusedCustomDataPoint?: Function;
|
|
228
|
+
|
|
229
|
+
dataPointLabelComponent?: Function;
|
|
230
|
+
focusedDataPointLabelComponent?: Function;
|
|
231
|
+
dataPointLabelWidth?: number;
|
|
232
|
+
dataPointLabelShiftX?: number;
|
|
233
|
+
dataPointLabelShiftY?: number;
|
|
234
|
+
showStrip?: Boolean;
|
|
187
235
|
|
|
188
236
|
showVerticalLine?: Boolean;
|
|
189
237
|
verticalLineColor?: string;
|
|
@@ -201,9 +249,10 @@ export const LineChart = (props: propTypes) => {
|
|
|
201
249
|
const [fillPoints, setFillPoints] = useState('');
|
|
202
250
|
const [fillPoints2, setFillPoints2] = useState('');
|
|
203
251
|
const [fillPoints3, setFillPoints3] = useState('');
|
|
252
|
+
const [selectedIndex, setSelectedIndex] = useState(-1);
|
|
204
253
|
const containerHeight = props.height || 200;
|
|
205
254
|
const noOfSections = props.noOfSections || 10;
|
|
206
|
-
|
|
255
|
+
let data = useMemo(() => props.data || [], [props.data]);
|
|
207
256
|
const data2 = useMemo(() => props.data2 || [], [props.data2]);
|
|
208
257
|
const data3 = useMemo(() => props.data3 || [], [props.data3]);
|
|
209
258
|
|
|
@@ -213,7 +262,93 @@ export const LineChart = (props: propTypes) => {
|
|
|
213
262
|
const widthValue3 = useMemo(() => new Animated.Value(0), []);
|
|
214
263
|
|
|
215
264
|
const animationDuration = props.animationDuration || 800;
|
|
265
|
+
const onDataChangeAnimationDuration =
|
|
266
|
+
props.onDataChangeAnimationDuration || 400;
|
|
216
267
|
const animateTogether = props.animateTogether || false;
|
|
268
|
+
const animateOnDataChange = props.animateOnDataChange || false;
|
|
269
|
+
|
|
270
|
+
if (!initialData) {
|
|
271
|
+
initialData = [...data];
|
|
272
|
+
animations = initialData.map(item => new Animated.Value(item.value));
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
let newPoints = '',
|
|
276
|
+
newFillPoints = '';
|
|
277
|
+
let counter = 0;
|
|
278
|
+
|
|
279
|
+
if (animateOnDataChange) {
|
|
280
|
+
animations.forEach((item, index) => {
|
|
281
|
+
item.addListener(val => {
|
|
282
|
+
data[index].value = val.value;
|
|
283
|
+
let pp = '',
|
|
284
|
+
ppp = '';
|
|
285
|
+
if (!props.curved) {
|
|
286
|
+
for (let i = 0; i < data.length; i++) {
|
|
287
|
+
pp +=
|
|
288
|
+
'L' +
|
|
289
|
+
(initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
|
|
290
|
+
' ' +
|
|
291
|
+
(containerHeight +
|
|
292
|
+
10 -
|
|
293
|
+
(data[i].value * containerHeight) / maxValue) +
|
|
294
|
+
' ';
|
|
295
|
+
}
|
|
296
|
+
if (areaChart) {
|
|
297
|
+
ppp =
|
|
298
|
+
'L' +
|
|
299
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
300
|
+
' ' +
|
|
301
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
302
|
+
' ';
|
|
303
|
+
ppp += pp;
|
|
304
|
+
ppp +=
|
|
305
|
+
'L' +
|
|
306
|
+
(initialSpacing -
|
|
307
|
+
dataPointsWidth1 / 2 +
|
|
308
|
+
spacing * (data.length - 1)) +
|
|
309
|
+
' ' +
|
|
310
|
+
(containerHeight + 10 - xAxisThickness);
|
|
311
|
+
ppp +=
|
|
312
|
+
'L' +
|
|
313
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
314
|
+
' ' +
|
|
315
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
316
|
+
' ';
|
|
317
|
+
}
|
|
318
|
+
newPoints = pp;
|
|
319
|
+
newFillPoints = ppp;
|
|
320
|
+
setPointsOnChange();
|
|
321
|
+
}
|
|
322
|
+
counter++;
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const setPointsOnChange = () => {
|
|
328
|
+
if (counter === data.length) {
|
|
329
|
+
// console.log('here.......');
|
|
330
|
+
if (!props.curved) {
|
|
331
|
+
setPoints(newPoints.replace('L', 'M'));
|
|
332
|
+
if (areaChart) {
|
|
333
|
+
setFillPoints(newFillPoints.replace('L', 'M'));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
useEffect(() => {
|
|
340
|
+
if (animateOnDataChange) {
|
|
341
|
+
Animated.parallel(
|
|
342
|
+
animations.map((anItem, index) =>
|
|
343
|
+
Animated.timing(anItem, {
|
|
344
|
+
toValue: data[index].value,
|
|
345
|
+
useNativeDriver: true,
|
|
346
|
+
duration: onDataChangeAnimationDuration,
|
|
347
|
+
}),
|
|
348
|
+
),
|
|
349
|
+
).start();
|
|
350
|
+
}
|
|
351
|
+
}, [animateOnDataChange, data, onDataChangeAnimationDuration]);
|
|
217
352
|
|
|
218
353
|
const labelsAppear = useCallback(() => {
|
|
219
354
|
opacValue.setValue(0);
|
|
@@ -348,14 +483,17 @@ export const LineChart = (props: propTypes) => {
|
|
|
348
483
|
pp3 = '';
|
|
349
484
|
if (!props.curved) {
|
|
350
485
|
for (let i = 0; i < data.length; i++) {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
486
|
+
if (!animateOnDataChange) {
|
|
487
|
+
pp +=
|
|
488
|
+
'L' +
|
|
489
|
+
(initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
|
|
490
|
+
' ' +
|
|
491
|
+
(containerHeight +
|
|
492
|
+
10 -
|
|
493
|
+
(data[i].value * containerHeight) / maxValue) +
|
|
494
|
+
' ';
|
|
495
|
+
setPoints(pp.replace('L', 'M'));
|
|
496
|
+
}
|
|
359
497
|
if (data2.length) {
|
|
360
498
|
pp2 +=
|
|
361
499
|
'L' +
|
|
@@ -377,7 +515,6 @@ export const LineChart = (props: propTypes) => {
|
|
|
377
515
|
' ';
|
|
378
516
|
}
|
|
379
517
|
}
|
|
380
|
-
setPoints(pp.replace('L', 'M'));
|
|
381
518
|
setPoints2(pp2.replace('L', 'M'));
|
|
382
519
|
setPoints3(pp3.replace('L', 'M'));
|
|
383
520
|
|
|
@@ -387,26 +524,29 @@ export const LineChart = (props: propTypes) => {
|
|
|
387
524
|
ppp2 = '',
|
|
388
525
|
ppp3 = '';
|
|
389
526
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
527
|
+
if (!animateOnDataChange) {
|
|
528
|
+
ppp =
|
|
529
|
+
'L' +
|
|
530
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
531
|
+
' ' +
|
|
532
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
533
|
+
' ';
|
|
534
|
+
ppp += pp;
|
|
535
|
+
ppp +=
|
|
536
|
+
'L' +
|
|
537
|
+
(initialSpacing -
|
|
538
|
+
dataPointsWidth1 / 2 +
|
|
539
|
+
spacing * (data.length - 1)) +
|
|
540
|
+
' ' +
|
|
541
|
+
(containerHeight + 10 - xAxisThickness);
|
|
542
|
+
ppp +=
|
|
543
|
+
'L' +
|
|
544
|
+
(initialSpacing - dataPointsWidth1 / 2) +
|
|
545
|
+
' ' +
|
|
546
|
+
(containerHeight + 10 - xAxisThickness) +
|
|
547
|
+
' ';
|
|
548
|
+
setFillPoints(ppp.replace('L', 'M'));
|
|
549
|
+
}
|
|
410
550
|
|
|
411
551
|
if (data2.length) {
|
|
412
552
|
ppp2 =
|
|
@@ -455,8 +595,6 @@ export const LineChart = (props: propTypes) => {
|
|
|
455
595
|
' ';
|
|
456
596
|
setFillPoints3(ppp3.replace('L', 'M'));
|
|
457
597
|
}
|
|
458
|
-
|
|
459
|
-
setFillPoints(ppp.replace('L', 'M'));
|
|
460
598
|
}
|
|
461
599
|
|
|
462
600
|
// console.log('pp-------->', pp);
|
|
@@ -599,6 +737,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
599
737
|
/*************************************************************************************/
|
|
600
738
|
}
|
|
601
739
|
}, [
|
|
740
|
+
animateOnDataChange,
|
|
602
741
|
areaChart,
|
|
603
742
|
containerHeight,
|
|
604
743
|
data,
|
|
@@ -701,6 +840,18 @@ export const LineChart = (props: propTypes) => {
|
|
|
701
840
|
const dashWidth = props.dashWidth === 0 ? 0 : props.dashWidth || 4;
|
|
702
841
|
const dashGap = props.dashGap === 0 ? 0 : props.dashGap || 8;
|
|
703
842
|
|
|
843
|
+
const pressEnabled = props.pressEnabled || false;
|
|
844
|
+
const showDataPointOnPress = props.showDataPointOnPress || false;
|
|
845
|
+
const showStripOnPress = props.showStripOnPress || false;
|
|
846
|
+
const showTextOnPress = props.showTextOnPress || false;
|
|
847
|
+
const stripHeight = props.stripHeight;
|
|
848
|
+
const stripWidth = props.stripWidth === 0 ? 0 : props.stripWidth || 2;
|
|
849
|
+
const stripColor = props.stripColor || color1;
|
|
850
|
+
const stripOpacity = props.stripOpacity || (startOpacity1 + endOpacity1) / 2;
|
|
851
|
+
const unFocusOnPressOut = props.unFocusOnPressOut === false ? false : true;
|
|
852
|
+
const delayBeforeUnFocus =
|
|
853
|
+
props.delayBeforeUnFocus === 0 ? 0 : props.delayBeforeUnFocus || 300;
|
|
854
|
+
|
|
704
855
|
const defaultReferenceConfig = {
|
|
705
856
|
thickness: rulesThickness,
|
|
706
857
|
width: (props.width || totalWidth) + 11,
|
|
@@ -775,7 +926,12 @@ export const LineChart = (props: propTypes) => {
|
|
|
775
926
|
});
|
|
776
927
|
}
|
|
777
928
|
|
|
778
|
-
const renderLabel = (
|
|
929
|
+
const renderLabel = (
|
|
930
|
+
index: number,
|
|
931
|
+
label: String,
|
|
932
|
+
labelTextStyle: any,
|
|
933
|
+
labelComponent: Function,
|
|
934
|
+
) => {
|
|
779
935
|
return (
|
|
780
936
|
<View
|
|
781
937
|
style={[
|
|
@@ -792,9 +948,15 @@ export const LineChart = (props: propTypes) => {
|
|
|
792
948
|
},
|
|
793
949
|
rotateLabel && {transform: [{rotate: '60deg'}]},
|
|
794
950
|
]}>
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
951
|
+
{labelComponent ? (
|
|
952
|
+
labelComponent()
|
|
953
|
+
) : (
|
|
954
|
+
<Text
|
|
955
|
+
style={[labelTextStyle, {textAlign: 'center'}]}
|
|
956
|
+
numberOfLines={1}>
|
|
957
|
+
{label || ''}
|
|
958
|
+
</Text>
|
|
959
|
+
)}
|
|
798
960
|
</View>
|
|
799
961
|
);
|
|
800
962
|
};
|
|
@@ -803,6 +965,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
803
965
|
index: number,
|
|
804
966
|
label: String,
|
|
805
967
|
labelTextStyle: any,
|
|
968
|
+
labelComponent: Function,
|
|
806
969
|
) => {
|
|
807
970
|
// console.log('label', label);
|
|
808
971
|
return (
|
|
@@ -823,9 +986,15 @@ export const LineChart = (props: propTypes) => {
|
|
|
823
986
|
},
|
|
824
987
|
rotateLabel && {transform: [{rotate: '60deg'}]},
|
|
825
988
|
]}>
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
989
|
+
{labelComponent ? (
|
|
990
|
+
labelComponent()
|
|
991
|
+
) : (
|
|
992
|
+
<Text
|
|
993
|
+
style={[labelTextStyle, {textAlign: 'center'}]}
|
|
994
|
+
numberOfLines={1}>
|
|
995
|
+
{label || ''}
|
|
996
|
+
</Text>
|
|
997
|
+
)}
|
|
829
998
|
</Animated.View>
|
|
830
999
|
);
|
|
831
1000
|
};
|
|
@@ -996,124 +1165,232 @@ export const LineChart = (props: propTypes) => {
|
|
|
996
1165
|
);
|
|
997
1166
|
};
|
|
998
1167
|
|
|
999
|
-
const
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
<Fragment key={index}>
|
|
1005
|
-
<Rect
|
|
1006
|
-
x={
|
|
1007
|
-
initialSpacing -
|
|
1008
|
-
(item.dataPointWidth || 2) / 2 -
|
|
1009
|
-
1 +
|
|
1010
|
-
spacing * index
|
|
1011
|
-
}
|
|
1012
|
-
y={
|
|
1013
|
-
containerHeight -
|
|
1014
|
-
(item.dataPointHeight || 2) / 2 +
|
|
1015
|
-
10 -
|
|
1016
|
-
(item.value * containerHeight) / maxValue
|
|
1017
|
-
}
|
|
1018
|
-
width={item.dataPointWidth || 2}
|
|
1019
|
-
height={item.dataPointHeight || 2}
|
|
1020
|
-
fill={item.dataPointColor || 'black'}
|
|
1021
|
-
/>
|
|
1022
|
-
{item.dataPointText && (
|
|
1023
|
-
<CanvasText
|
|
1024
|
-
fill={item.textColor || 'black'}
|
|
1025
|
-
fontSize={item.textFontSize || 10}
|
|
1026
|
-
x={
|
|
1027
|
-
initialSpacing -
|
|
1028
|
-
(item.dataPointWidth || 2) +
|
|
1029
|
-
spacing * index +
|
|
1030
|
-
(item.textShiftX || props.textShiftX || 0)
|
|
1031
|
-
}
|
|
1032
|
-
y={
|
|
1033
|
-
containerHeight -
|
|
1034
|
-
(item.dataPointHeight || 2) / 2 +
|
|
1035
|
-
10 -
|
|
1036
|
-
(item.value * containerHeight) / maxValue +
|
|
1037
|
-
(item.textShiftY || props.textShiftY || 0)
|
|
1038
|
-
}>
|
|
1039
|
-
{item.dataPointText}
|
|
1040
|
-
</CanvasText>
|
|
1041
|
-
)}
|
|
1042
|
-
</Fragment>
|
|
1043
|
-
);
|
|
1044
|
-
} else {
|
|
1045
|
-
return (
|
|
1046
|
-
<Fragment key={index}>
|
|
1047
|
-
<Circle
|
|
1048
|
-
cx={
|
|
1049
|
-
initialSpacing -
|
|
1050
|
-
(item.dataPointWidth || 2) / 2 +
|
|
1051
|
-
spacing * index
|
|
1052
|
-
}
|
|
1053
|
-
cy={
|
|
1054
|
-
containerHeight +
|
|
1055
|
-
10 -
|
|
1056
|
-
(item.value * containerHeight) / maxValue
|
|
1057
|
-
}
|
|
1058
|
-
r={item.dataPointRadius || 3}
|
|
1059
|
-
fill={item.dataPointColor || 'black'}
|
|
1060
|
-
/>
|
|
1061
|
-
{item.dataPointText && (
|
|
1062
|
-
<CanvasText
|
|
1063
|
-
fill={item.textColor || 'black'}
|
|
1064
|
-
fontSize={item.textFontSize || 10}
|
|
1065
|
-
x={
|
|
1066
|
-
initialSpacing -
|
|
1067
|
-
(item.dataPointWidth || 2) +
|
|
1068
|
-
spacing * index +
|
|
1069
|
-
(item.textShiftX || props.textShiftX || 0)
|
|
1070
|
-
}
|
|
1071
|
-
y={
|
|
1072
|
-
containerHeight -
|
|
1073
|
-
(item.dataPointHeight || 2) / 2 +
|
|
1074
|
-
10 -
|
|
1075
|
-
(item.value * containerHeight) / maxValue +
|
|
1076
|
-
(item.textShiftY || props.textShiftY || 0)
|
|
1077
|
-
}>
|
|
1078
|
-
{item.dataPointText}
|
|
1079
|
-
</CanvasText>
|
|
1080
|
-
)}
|
|
1081
|
-
</Fragment>
|
|
1082
|
-
);
|
|
1083
|
-
}
|
|
1084
|
-
}
|
|
1085
|
-
return null;
|
|
1086
|
-
});
|
|
1168
|
+
const onStripPress = (item, index) => {
|
|
1169
|
+
setSelectedIndex(index);
|
|
1170
|
+
if (props.onPress) {
|
|
1171
|
+
props.onPress(item, index);
|
|
1172
|
+
}
|
|
1087
1173
|
};
|
|
1088
1174
|
|
|
1089
1175
|
const renderDataPoints = (
|
|
1090
1176
|
dataForRender,
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1177
|
+
dataPtsShape,
|
|
1178
|
+
dataPtsWidth,
|
|
1179
|
+
dataPtsHeight,
|
|
1180
|
+
dataPtsColor,
|
|
1181
|
+
dataPtsRadius,
|
|
1096
1182
|
textColor,
|
|
1097
1183
|
textFontSize,
|
|
1098
1184
|
) => {
|
|
1099
1185
|
return dataForRender.map((item: itemType, index: number) => {
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1186
|
+
if (item.hideDataPoint) {
|
|
1187
|
+
return null;
|
|
1188
|
+
}
|
|
1189
|
+
let dataPointsShape,
|
|
1190
|
+
dataPointsWidth,
|
|
1191
|
+
dataPointsHeight,
|
|
1192
|
+
dataPointsColor,
|
|
1193
|
+
dataPointsRadius,
|
|
1194
|
+
text,
|
|
1195
|
+
customDataPoint,
|
|
1196
|
+
dataPointLabelComponent;
|
|
1197
|
+
if (index === selectedIndex) {
|
|
1198
|
+
dataPointsShape =
|
|
1199
|
+
item.focusedDataPointShape ||
|
|
1200
|
+
props.focusedDataPointShape ||
|
|
1201
|
+
item.dataPointShape ||
|
|
1202
|
+
dataPtsShape;
|
|
1203
|
+
dataPointsWidth =
|
|
1204
|
+
item.focusedDataPointWidth ||
|
|
1205
|
+
props.focusedDataPointWidth ||
|
|
1206
|
+
item.dataPointWidth ||
|
|
1207
|
+
dataPtsWidth;
|
|
1208
|
+
dataPointsHeight =
|
|
1209
|
+
item.focusedDataPointHeight ||
|
|
1210
|
+
props.focusedDataPointHeight ||
|
|
1211
|
+
item.dataPointHeight ||
|
|
1212
|
+
dataPtsHeight;
|
|
1213
|
+
dataPointsColor =
|
|
1214
|
+
item.focusedDataPointColor ||
|
|
1215
|
+
props.focusedDataPointColor ||
|
|
1216
|
+
item.dataPointColor ||
|
|
1217
|
+
dataPtsColor;
|
|
1218
|
+
dataPointsRadius =
|
|
1219
|
+
item.focusedDataPointRadius ||
|
|
1220
|
+
props.focusedDataPointRadius ||
|
|
1221
|
+
item.dataPointRadius ||
|
|
1222
|
+
dataPtsRadius;
|
|
1223
|
+
if (showTextOnPress) {
|
|
1224
|
+
text = item.dataPointText;
|
|
1225
|
+
}
|
|
1226
|
+
customDataPoint =
|
|
1227
|
+
item.focusedCustomDataPoint ||
|
|
1228
|
+
props.focusedCustomDataPoint ||
|
|
1229
|
+
item.customDataPoint ||
|
|
1230
|
+
props.customDataPoint;
|
|
1231
|
+
dataPointLabelComponent =
|
|
1232
|
+
item.focusedDataPointLabelComponent || item.dataPointLabelComponent;
|
|
1233
|
+
} else {
|
|
1234
|
+
dataPointsShape = item.dataPointShape || dataPtsShape;
|
|
1235
|
+
dataPointsWidth = item.dataPointWidth || dataPtsWidth;
|
|
1236
|
+
dataPointsHeight = item.dataPointHeight || dataPtsHeight;
|
|
1237
|
+
dataPointsColor = item.dataPointColor || dataPtsColor;
|
|
1238
|
+
dataPointsRadius = item.dataPointRadius || dataPtsRadius;
|
|
1239
|
+
if (showTextOnPress) {
|
|
1240
|
+
text = '';
|
|
1241
|
+
}
|
|
1242
|
+
customDataPoint = item.customDataPoint || props.customDataPoint;
|
|
1243
|
+
dataPointLabelComponent = item.dataPointLabelComponent;
|
|
1244
|
+
}
|
|
1245
|
+
|
|
1246
|
+
const currentStripHeight =
|
|
1247
|
+
item.stripHeight === 0 ? 0 : item.stripHeight || stripHeight;
|
|
1248
|
+
const currentStripWidth =
|
|
1249
|
+
item.stripWidth === 0 ? 0 : item.stripWidth || stripWidth;
|
|
1250
|
+
const currentStripOpacity =
|
|
1251
|
+
item.stripOpacity === 0 ? 0 : item.stripOpacity || stripOpacity;
|
|
1252
|
+
const currentStripColor = item.stripColor || stripColor;
|
|
1253
|
+
|
|
1254
|
+
return (
|
|
1255
|
+
<Fragment key={index}>
|
|
1256
|
+
{pressEnabled ? (
|
|
1257
|
+
<>
|
|
1258
|
+
{unFocusOnPressOut ? (
|
|
1259
|
+
<Rect
|
|
1260
|
+
onPressIn={() => onStripPress(item, index)}
|
|
1261
|
+
onPressOut={() =>
|
|
1262
|
+
setTimeout(() => setSelectedIndex(-1), delayBeforeUnFocus)
|
|
1263
|
+
}
|
|
1264
|
+
x={initialSpacing + (spacing * index - spacing / 2)}
|
|
1265
|
+
y={8}
|
|
1266
|
+
width={spacing}
|
|
1267
|
+
height={containerHeight - 0}
|
|
1268
|
+
fill={'none'}
|
|
1269
|
+
/>
|
|
1270
|
+
) : (
|
|
1271
|
+
<Rect
|
|
1272
|
+
onPress={() => onStripPress(item, index)}
|
|
1273
|
+
x={initialSpacing + (spacing * index - spacing / 2)}
|
|
1274
|
+
y={8}
|
|
1275
|
+
width={spacing}
|
|
1276
|
+
height={containerHeight - 0}
|
|
1277
|
+
fill={'none'}
|
|
1278
|
+
/>
|
|
1279
|
+
)}
|
|
1280
|
+
</>
|
|
1281
|
+
) : null}
|
|
1282
|
+
{item.showStrip ||
|
|
1283
|
+
(pressEnabled && index === selectedIndex && showStripOnPress) ? (
|
|
1104
1284
|
<Rect
|
|
1105
|
-
x={initialSpacing
|
|
1285
|
+
x={initialSpacing + (spacing * index - dataPointsWidth / 2)}
|
|
1106
1286
|
y={
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1287
|
+
currentStripHeight
|
|
1288
|
+
? containerHeight - currentStripHeight + 8
|
|
1289
|
+
: containerHeight -
|
|
1290
|
+
dataPointsHeight / 2 +
|
|
1291
|
+
20 -
|
|
1292
|
+
(item.value * containerHeight) / maxValue
|
|
1111
1293
|
}
|
|
1112
|
-
width={
|
|
1113
|
-
height={
|
|
1114
|
-
|
|
1294
|
+
width={currentStripWidth}
|
|
1295
|
+
height={
|
|
1296
|
+
currentStripHeight ||
|
|
1297
|
+
containerHeight - dataPointsHeight / 2 + 20
|
|
1298
|
+
}
|
|
1299
|
+
opacity={currentStripOpacity}
|
|
1300
|
+
fill={currentStripColor}
|
|
1115
1301
|
/>
|
|
1116
|
-
|
|
1302
|
+
) : null}
|
|
1303
|
+
{customDataPoint ? (
|
|
1304
|
+
<View
|
|
1305
|
+
style={[
|
|
1306
|
+
styles.customDataPointContainer,
|
|
1307
|
+
{
|
|
1308
|
+
height: dataPointsHeight,
|
|
1309
|
+
width: dataPointsWidth,
|
|
1310
|
+
top:
|
|
1311
|
+
containerHeight - (item.value * containerHeight) / maxValue,
|
|
1312
|
+
left: initialSpacing - dataPointsWidth + spacing * index,
|
|
1313
|
+
},
|
|
1314
|
+
]}>
|
|
1315
|
+
{customDataPoint()}
|
|
1316
|
+
</View>
|
|
1317
|
+
) : null}
|
|
1318
|
+
{dataPointsShape === 'rectangular' ? (
|
|
1319
|
+
<Fragment key={index}>
|
|
1320
|
+
{customDataPoint ? null : (
|
|
1321
|
+
<Rect
|
|
1322
|
+
x={initialSpacing - dataPointsWidth + spacing * index}
|
|
1323
|
+
y={
|
|
1324
|
+
containerHeight -
|
|
1325
|
+
dataPointsHeight / 2 +
|
|
1326
|
+
10 -
|
|
1327
|
+
(item.value * containerHeight) / maxValue
|
|
1328
|
+
}
|
|
1329
|
+
width={dataPointsWidth}
|
|
1330
|
+
height={dataPointsHeight}
|
|
1331
|
+
fill={
|
|
1332
|
+
showDataPointOnPress
|
|
1333
|
+
? index === selectedIndex
|
|
1334
|
+
? dataPointsColor
|
|
1335
|
+
: 'none'
|
|
1336
|
+
: dataPointsColor
|
|
1337
|
+
}
|
|
1338
|
+
/>
|
|
1339
|
+
)}
|
|
1340
|
+
</Fragment>
|
|
1341
|
+
) : (
|
|
1342
|
+
<Fragment key={index}>
|
|
1343
|
+
{customDataPoint ? null : (
|
|
1344
|
+
<Circle
|
|
1345
|
+
cx={initialSpacing - dataPointsWidth / 2 + spacing * index}
|
|
1346
|
+
cy={
|
|
1347
|
+
containerHeight +
|
|
1348
|
+
10 -
|
|
1349
|
+
(item.value * containerHeight) / maxValue
|
|
1350
|
+
}
|
|
1351
|
+
r={dataPointsRadius}
|
|
1352
|
+
fill={
|
|
1353
|
+
showDataPointOnPress
|
|
1354
|
+
? index === selectedIndex
|
|
1355
|
+
? dataPointsColor
|
|
1356
|
+
: 'none'
|
|
1357
|
+
: dataPointsColor
|
|
1358
|
+
}
|
|
1359
|
+
/>
|
|
1360
|
+
)}
|
|
1361
|
+
</Fragment>
|
|
1362
|
+
)}
|
|
1363
|
+
{dataPointLabelComponent ? (
|
|
1364
|
+
!showTextOnPress || index === selectedIndex ? (
|
|
1365
|
+
<View
|
|
1366
|
+
style={[
|
|
1367
|
+
styles.customDataPointContainer,
|
|
1368
|
+
{
|
|
1369
|
+
top:
|
|
1370
|
+
containerHeight +
|
|
1371
|
+
(item.dataPointLabelShiftY ||
|
|
1372
|
+
props.dataPointLabelShiftY ||
|
|
1373
|
+
0) -
|
|
1374
|
+
(item.value * containerHeight) / maxValue,
|
|
1375
|
+
left:
|
|
1376
|
+
initialSpacing +
|
|
1377
|
+
(item.dataPointLabelShiftX ||
|
|
1378
|
+
props.dataPointLabelShiftX ||
|
|
1379
|
+
0) -
|
|
1380
|
+
(item.dataPointLabelWidth
|
|
1381
|
+
? item.dataPointLabelWidth + 20
|
|
1382
|
+
: props.dataPointLabelWidth
|
|
1383
|
+
? props.dataPointLabelWidth + 20
|
|
1384
|
+
: 50) /
|
|
1385
|
+
2 +
|
|
1386
|
+
spacing * index,
|
|
1387
|
+
},
|
|
1388
|
+
]}>
|
|
1389
|
+
{dataPointLabelComponent()}
|
|
1390
|
+
</View>
|
|
1391
|
+
) : null
|
|
1392
|
+
) : text ? (
|
|
1393
|
+
!showTextOnPress || index === selectedIndex ? (
|
|
1117
1394
|
<CanvasText
|
|
1118
1395
|
fill={item.textColor || textColor}
|
|
1119
1396
|
fontSize={item.textFontSize || textFontSize}
|
|
@@ -1121,7 +1398,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1121
1398
|
initialSpacing -
|
|
1122
1399
|
dataPointsWidth +
|
|
1123
1400
|
spacing * index +
|
|
1124
|
-
(item.textShiftX || props.textShiftX ||
|
|
1401
|
+
(item.textShiftX || props.textShiftX || 0)
|
|
1125
1402
|
}
|
|
1126
1403
|
y={
|
|
1127
1404
|
containerHeight -
|
|
@@ -1130,42 +1407,10 @@ export const LineChart = (props: propTypes) => {
|
|
|
1130
1407
|
(item.value * containerHeight) / maxValue +
|
|
1131
1408
|
(item.textShiftY || props.textShiftY || 0)
|
|
1132
1409
|
}>
|
|
1133
|
-
{
|
|
1410
|
+
{text}
|
|
1134
1411
|
</CanvasText>
|
|
1135
|
-
)
|
|
1136
|
-
|
|
1137
|
-
);
|
|
1138
|
-
}
|
|
1139
|
-
return (
|
|
1140
|
-
<Fragment key={index}>
|
|
1141
|
-
<Circle
|
|
1142
|
-
cx={initialSpacing - dataPointsWidth / 2 + spacing * index}
|
|
1143
|
-
cy={
|
|
1144
|
-
containerHeight + 10 - (item.value * containerHeight) / maxValue
|
|
1145
|
-
}
|
|
1146
|
-
r={dataPointsRadius}
|
|
1147
|
-
fill={dataPointsColor}
|
|
1148
|
-
/>
|
|
1149
|
-
{item.dataPointText && (
|
|
1150
|
-
<CanvasText
|
|
1151
|
-
fill={item.textColor || textColor}
|
|
1152
|
-
fontSize={item.textFontSize || textFontSize}
|
|
1153
|
-
x={
|
|
1154
|
-
initialSpacing -
|
|
1155
|
-
dataPointsWidth +
|
|
1156
|
-
spacing * index +
|
|
1157
|
-
(item.textShiftX || props.textShiftX || 0)
|
|
1158
|
-
}
|
|
1159
|
-
y={
|
|
1160
|
-
containerHeight -
|
|
1161
|
-
dataPointsHeight / 2 +
|
|
1162
|
-
10 -
|
|
1163
|
-
(item.value * containerHeight) / maxValue +
|
|
1164
|
-
(item.textShiftY || props.textShiftY || 0)
|
|
1165
|
-
}>
|
|
1166
|
-
{item.dataPointText}
|
|
1167
|
-
</CanvasText>
|
|
1168
|
-
)}
|
|
1412
|
+
) : null
|
|
1413
|
+
) : null}
|
|
1169
1414
|
</Fragment>
|
|
1170
1415
|
);
|
|
1171
1416
|
});
|
|
@@ -1267,7 +1512,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1267
1512
|
textColor1,
|
|
1268
1513
|
textFontSize1,
|
|
1269
1514
|
)
|
|
1270
|
-
:
|
|
1515
|
+
: null}
|
|
1271
1516
|
{!hideDataPoints2
|
|
1272
1517
|
? renderDataPoints(
|
|
1273
1518
|
data2,
|
|
@@ -1279,7 +1524,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1279
1524
|
textColor2,
|
|
1280
1525
|
textFontSize2,
|
|
1281
1526
|
)
|
|
1282
|
-
:
|
|
1527
|
+
: null}
|
|
1283
1528
|
{!hideDataPoints3
|
|
1284
1529
|
? renderDataPoints(
|
|
1285
1530
|
data3,
|
|
@@ -1291,7 +1536,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1291
1536
|
textColor3,
|
|
1292
1537
|
textFontSize3,
|
|
1293
1538
|
)
|
|
1294
|
-
:
|
|
1539
|
+
: null}
|
|
1295
1540
|
</Svg>
|
|
1296
1541
|
</View>
|
|
1297
1542
|
);
|
|
@@ -1374,7 +1619,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1374
1619
|
textColor1,
|
|
1375
1620
|
textFontSize1,
|
|
1376
1621
|
)
|
|
1377
|
-
:
|
|
1622
|
+
: null}
|
|
1378
1623
|
{!hideDataPoints2
|
|
1379
1624
|
? renderDataPoints(
|
|
1380
1625
|
data2,
|
|
@@ -1386,7 +1631,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1386
1631
|
textColor2,
|
|
1387
1632
|
textFontSize2,
|
|
1388
1633
|
)
|
|
1389
|
-
:
|
|
1634
|
+
: null}
|
|
1390
1635
|
{!hideDataPoints3
|
|
1391
1636
|
? renderDataPoints(
|
|
1392
1637
|
data3,
|
|
@@ -1398,7 +1643,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1398
1643
|
textColor3,
|
|
1399
1644
|
textFontSize3,
|
|
1400
1645
|
)
|
|
1401
|
-
:
|
|
1646
|
+
: null}
|
|
1402
1647
|
</Svg>
|
|
1403
1648
|
</Animated.View>
|
|
1404
1649
|
);
|
|
@@ -1543,8 +1788,18 @@ export const LineChart = (props: propTypes) => {
|
|
|
1543
1788
|
return (
|
|
1544
1789
|
<View key={index}>
|
|
1545
1790
|
{isAnimated
|
|
1546
|
-
? renderAnimatedLabel(
|
|
1547
|
-
|
|
1791
|
+
? renderAnimatedLabel(
|
|
1792
|
+
index,
|
|
1793
|
+
item.label,
|
|
1794
|
+
item.labelTextStyle,
|
|
1795
|
+
item.labelComponent,
|
|
1796
|
+
)
|
|
1797
|
+
: renderLabel(
|
|
1798
|
+
index,
|
|
1799
|
+
item.label,
|
|
1800
|
+
item.labelTextStyle,
|
|
1801
|
+
item.labelComponent,
|
|
1802
|
+
)}
|
|
1548
1803
|
{/* {renderLabel(index, item.label, item.labelTextStyle)} */}
|
|
1549
1804
|
</View>
|
|
1550
1805
|
);
|