react-native-gifted-charts 1.4.17 → 1.4.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.19",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"registry": "https://registry.npmjs.org/"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"gifted-charts-core": "^0.1.
|
|
28
|
+
"gifted-charts-core": "^0.1.18"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@babel/core": "^7.22.5",
|
|
@@ -2,7 +2,7 @@ import React, {useEffect, useState} from 'react';
|
|
|
2
2
|
import {View, LayoutAnimation, Platform, UIManager, Text} from 'react-native';
|
|
3
3
|
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
4
4
|
import Cap from '../Components/BarSpecificComponents/cap';
|
|
5
|
-
import LinearGradient from
|
|
5
|
+
import LinearGradient from '../Components/common/LinearGradient';
|
|
6
6
|
import {Animated2DWithGradientPropsType} from 'gifted-charts-core';
|
|
7
7
|
|
|
8
8
|
if (Platform.OS === 'android') {
|
|
@@ -22,8 +22,6 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
22
22
|
animationDuration,
|
|
23
23
|
noGradient,
|
|
24
24
|
noAnimation,
|
|
25
|
-
containerHeight,
|
|
26
|
-
maxValue,
|
|
27
25
|
barMarginBottom,
|
|
28
26
|
barInnerComponent,
|
|
29
27
|
intactTopLabel,
|
|
@@ -46,6 +44,8 @@ const Animated2DWithGradient = (props: Animated2DWithGradientPropsType) => {
|
|
|
46
44
|
} else {
|
|
47
45
|
elevate();
|
|
48
46
|
}
|
|
47
|
+
} else {
|
|
48
|
+
setHeight(props.height);
|
|
49
49
|
}
|
|
50
50
|
}, [props.height]);
|
|
51
51
|
|
|
@@ -33,7 +33,9 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
33
33
|
animationDuration,
|
|
34
34
|
autoShiftLabels,
|
|
35
35
|
label,
|
|
36
|
+
secondaryLabel,
|
|
36
37
|
labelTextStyle,
|
|
38
|
+
secondaryLabelTextStyle,
|
|
37
39
|
xAxisTextNumberOfLines,
|
|
38
40
|
xAxisLabelsVerticalShift,
|
|
39
41
|
renderTooltip,
|
|
@@ -59,6 +61,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
59
61
|
negativeStepHeight,
|
|
60
62
|
negativeStepValue,
|
|
61
63
|
autoCenterTooltip,
|
|
64
|
+
secondaryXAxis,
|
|
62
65
|
} = props;
|
|
63
66
|
|
|
64
67
|
const heightFactor =
|
|
@@ -91,7 +94,12 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
91
94
|
? 0
|
|
92
95
|
: item.barMarginBottom || props.barMarginBottom || 0;
|
|
93
96
|
|
|
94
|
-
const renderLabel = (
|
|
97
|
+
const renderLabel = (
|
|
98
|
+
top: boolean,
|
|
99
|
+
label: String,
|
|
100
|
+
labelTextStyle: any,
|
|
101
|
+
value: number,
|
|
102
|
+
) => {
|
|
95
103
|
return (
|
|
96
104
|
<View
|
|
97
105
|
style={[
|
|
@@ -104,12 +112,16 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
104
112
|
left: spacing / -2,
|
|
105
113
|
position: 'absolute',
|
|
106
114
|
height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
107
|
-
bottom:
|
|
108
|
-
(
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
115
|
+
bottom: top
|
|
116
|
+
? (containerHeight || 200) +
|
|
117
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
118
|
+
: (rotateLabel
|
|
119
|
+
? -40
|
|
120
|
+
: -6 -
|
|
121
|
+
xAxisTextNumberOfLines * 18 -
|
|
122
|
+
xAxisLabelsVerticalShift) -
|
|
123
|
+
barMarginBottom -
|
|
124
|
+
labelsDistanceFromXaxis,
|
|
113
125
|
},
|
|
114
126
|
rotateLabel
|
|
115
127
|
? horizontal
|
|
@@ -136,7 +148,21 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
136
148
|
}
|
|
137
149
|
: {},
|
|
138
150
|
]}>
|
|
139
|
-
{
|
|
151
|
+
{top ? (
|
|
152
|
+
item.secondaryLabelComponent ? (
|
|
153
|
+
item.secondaryLabelComponent()
|
|
154
|
+
) : (
|
|
155
|
+
<Text
|
|
156
|
+
style={[
|
|
157
|
+
{textAlign: 'center'},
|
|
158
|
+
rtl && horizontal && {transform: [{rotate: '180deg'}]},
|
|
159
|
+
labelTextStyle,
|
|
160
|
+
]}
|
|
161
|
+
numberOfLines={xAxisTextNumberOfLines}>
|
|
162
|
+
{label}
|
|
163
|
+
</Text>
|
|
164
|
+
)
|
|
165
|
+
) : item.labelComponent ? (
|
|
140
166
|
item.labelComponent()
|
|
141
167
|
) : (
|
|
142
168
|
<Text
|
|
@@ -146,7 +172,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
146
172
|
labelTextStyle,
|
|
147
173
|
]}
|
|
148
174
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
149
|
-
{label
|
|
175
|
+
{label}
|
|
150
176
|
</Text>
|
|
151
177
|
)}
|
|
152
178
|
</View>
|
|
@@ -154,6 +180,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
154
180
|
};
|
|
155
181
|
|
|
156
182
|
const renderAnimatedLabel = (
|
|
183
|
+
top: boolean,
|
|
157
184
|
label: String,
|
|
158
185
|
labelTextStyle: any,
|
|
159
186
|
value: number,
|
|
@@ -170,11 +197,14 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
170
197
|
left: spacing / -2,
|
|
171
198
|
position: 'absolute',
|
|
172
199
|
height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
173
|
-
bottom:
|
|
174
|
-
(
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
200
|
+
bottom: top
|
|
201
|
+
? (containerHeight || 200) +
|
|
202
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
203
|
+
: (rotateLabel
|
|
204
|
+
? -40
|
|
205
|
+
: -6 -
|
|
206
|
+
xAxisTextNumberOfLines * 18 -
|
|
207
|
+
xAxisLabelsVerticalShift) - barMarginBottom,
|
|
178
208
|
opacity: appearingOpacity,
|
|
179
209
|
},
|
|
180
210
|
value < 0 && {transform: [{rotate: '180deg'}]},
|
|
@@ -197,7 +227,21 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
197
227
|
}
|
|
198
228
|
: {},
|
|
199
229
|
]}>
|
|
200
|
-
{
|
|
230
|
+
{top ? (
|
|
231
|
+
item.secondaryLabelComponent ? (
|
|
232
|
+
item.secondaryLabelComponent()
|
|
233
|
+
) : (
|
|
234
|
+
<Text
|
|
235
|
+
style={[
|
|
236
|
+
{textAlign: 'center'},
|
|
237
|
+
rtl && horizontal && {transform: [{rotate: '180deg'}]},
|
|
238
|
+
labelTextStyle,
|
|
239
|
+
]}
|
|
240
|
+
numberOfLines={xAxisTextNumberOfLines}>
|
|
241
|
+
{label}
|
|
242
|
+
</Text>
|
|
243
|
+
)
|
|
244
|
+
) : item.labelComponent ? (
|
|
201
245
|
item.labelComponent()
|
|
202
246
|
) : (
|
|
203
247
|
<Text
|
|
@@ -207,7 +251,7 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
207
251
|
labelTextStyle,
|
|
208
252
|
]}
|
|
209
253
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
210
|
-
{label
|
|
254
|
+
{label}
|
|
211
255
|
</Text>
|
|
212
256
|
)}
|
|
213
257
|
</Animated.View>
|
|
@@ -399,8 +443,23 @@ const RenderBars = (props: RenderBarsPropsType) => {
|
|
|
399
443
|
animated2DWithGradient(true, true)
|
|
400
444
|
)}
|
|
401
445
|
{isAnimated
|
|
402
|
-
? renderAnimatedLabel(label, labelTextStyle, item.value)
|
|
403
|
-
: renderLabel(label, labelTextStyle, item.value)}
|
|
446
|
+
? renderAnimatedLabel(false, label, labelTextStyle, item.value)
|
|
447
|
+
: renderLabel(false, label, labelTextStyle, item.value)}
|
|
448
|
+
{secondaryXAxis
|
|
449
|
+
? isAnimated
|
|
450
|
+
? renderAnimatedLabel(
|
|
451
|
+
true,
|
|
452
|
+
secondaryLabel,
|
|
453
|
+
secondaryLabelTextStyle,
|
|
454
|
+
item.value,
|
|
455
|
+
)
|
|
456
|
+
: renderLabel(
|
|
457
|
+
true,
|
|
458
|
+
secondaryLabel,
|
|
459
|
+
secondaryLabelTextStyle,
|
|
460
|
+
item.value,
|
|
461
|
+
)
|
|
462
|
+
: null}
|
|
404
463
|
</>
|
|
405
464
|
);
|
|
406
465
|
};
|
|
@@ -62,6 +62,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
62
62
|
secondaryYAxis,
|
|
63
63
|
onlyReferenceLines,
|
|
64
64
|
renderReferenceLines,
|
|
65
|
+
secondaryXAxis,
|
|
65
66
|
} = props;
|
|
66
67
|
|
|
67
68
|
const {
|
|
@@ -138,6 +139,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
138
139
|
{showYAxisIndices && index !== noOfSections ? (
|
|
139
140
|
<View
|
|
140
141
|
style={{
|
|
142
|
+
position: 'absolute',
|
|
141
143
|
height: yAxisIndicesHeight,
|
|
142
144
|
width: yAxisIndicesWidth,
|
|
143
145
|
left:
|
|
@@ -183,7 +185,12 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
183
185
|
style={[
|
|
184
186
|
styles.leftPart,
|
|
185
187
|
{
|
|
186
|
-
|
|
188
|
+
borderLeftColor: yAxisColor,
|
|
189
|
+
borderRightColor: yAxisColor,
|
|
190
|
+
borderTopColor: secondaryXAxis?.color ?? xAxisColor,
|
|
191
|
+
borderTopWidth: secondaryXAxis
|
|
192
|
+
? secondaryXAxis.thickness ?? xAxisThickness
|
|
193
|
+
: 0,
|
|
187
194
|
backgroundColor: backgroundColor,
|
|
188
195
|
width: (props.width || totalWidth - spacing) + endSpacing,
|
|
189
196
|
},
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -299,6 +299,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
299
299
|
stripWidth,
|
|
300
300
|
stripColor,
|
|
301
301
|
stripOpacity,
|
|
302
|
+
stripStrokeDashArray,
|
|
302
303
|
unFocusOnPressOut,
|
|
303
304
|
delayBeforeUnFocus,
|
|
304
305
|
containerHeightIncludingBelowXAxis,
|
|
@@ -313,6 +314,8 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
313
314
|
parentWidth: props.parentWidth ?? screenWidth,
|
|
314
315
|
});
|
|
315
316
|
|
|
317
|
+
const {secondaryXAxis} = props;
|
|
318
|
+
|
|
316
319
|
const widthValuesFromSet = useMemo(
|
|
317
320
|
() => dataSet?.map(set => new Animated.Value(0)),
|
|
318
321
|
[],
|
|
@@ -458,6 +461,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
458
461
|
]);
|
|
459
462
|
|
|
460
463
|
const renderLabel = (
|
|
464
|
+
top: boolean,
|
|
461
465
|
index: number,
|
|
462
466
|
label: String,
|
|
463
467
|
labelTextStyle: any,
|
|
@@ -468,7 +472,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
468
472
|
style={[
|
|
469
473
|
{
|
|
470
474
|
position: 'absolute',
|
|
471
|
-
bottom:
|
|
475
|
+
bottom: top
|
|
476
|
+
? containerHeight +
|
|
477
|
+
60 +
|
|
478
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
479
|
+
: 54 - xAxisTextNumberOfLines * 18,
|
|
472
480
|
zIndex: 10,
|
|
473
481
|
width: spacing + labelsExtraHeight,
|
|
474
482
|
left:
|
|
@@ -485,7 +493,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
485
493
|
<Text
|
|
486
494
|
style={[{textAlign: 'center'}, labelTextStyle]}
|
|
487
495
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
488
|
-
{label
|
|
496
|
+
{label}
|
|
489
497
|
</Text>
|
|
490
498
|
)}
|
|
491
499
|
</View>
|
|
@@ -493,6 +501,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
493
501
|
};
|
|
494
502
|
|
|
495
503
|
const renderAnimatedLabel = (
|
|
504
|
+
top: boolean,
|
|
496
505
|
index: number,
|
|
497
506
|
label: String,
|
|
498
507
|
labelTextStyle: any,
|
|
@@ -506,7 +515,13 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
506
515
|
? 40
|
|
507
516
|
: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
|
|
508
517
|
position: 'absolute',
|
|
509
|
-
bottom:
|
|
518
|
+
bottom: top
|
|
519
|
+
? containerHeight +
|
|
520
|
+
60 +
|
|
521
|
+
(secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
|
|
522
|
+
: rotateLabel
|
|
523
|
+
? 10
|
|
524
|
+
: 54 - xAxisTextNumberOfLines * 18,
|
|
510
525
|
zIndex: 10,
|
|
511
526
|
width: spacing,
|
|
512
527
|
left:
|
|
@@ -523,7 +538,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
523
538
|
<Text
|
|
524
539
|
style={[{textAlign: 'center'}, labelTextStyle]}
|
|
525
540
|
numberOfLines={xAxisTextNumberOfLines}>
|
|
526
|
-
{label
|
|
541
|
+
{label}
|
|
527
542
|
</Text>
|
|
528
543
|
)}
|
|
529
544
|
</Animated.View>
|
|
@@ -647,9 +662,22 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
647
662
|
const currentStripHeight = item.stripHeight ?? stripHeight;
|
|
648
663
|
const currentStripWidth = item.stripWidth ?? stripWidth;
|
|
649
664
|
const currentStripOpacity = item.stripOpacity ?? stripOpacity;
|
|
665
|
+
const currentStripStrokeDashArray =
|
|
666
|
+
item.stripStrokeDashArray ?? stripStrokeDashArray ?? '';
|
|
650
667
|
const currentStripColor = item.stripColor || stripColor;
|
|
651
668
|
const position = I18nManager.isRTL ? 'right' : 'left';
|
|
652
669
|
|
|
670
|
+
const y1 = currentStripHeight
|
|
671
|
+
? containerHeight - currentStripHeight + 8
|
|
672
|
+
: containerHeight -
|
|
673
|
+
dataPointsHeight / 2 +
|
|
674
|
+
14 -
|
|
675
|
+
(item.value * containerHeight) / maxValue;
|
|
676
|
+
|
|
677
|
+
const actualStripHeight =
|
|
678
|
+
currentStripHeight ||
|
|
679
|
+
(item.value * containerHeight) / maxValue - 2 + overflowTop;
|
|
680
|
+
|
|
653
681
|
return (
|
|
654
682
|
<Fragment key={index}>
|
|
655
683
|
{focusEnabled ? (
|
|
@@ -680,23 +708,15 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
680
708
|
) : null}
|
|
681
709
|
{item.showStrip ||
|
|
682
710
|
(focusEnabled && index === selectedIndex && showStripOnFocus) ? (
|
|
683
|
-
<
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
(item.value * containerHeight) / maxValue
|
|
692
|
-
}
|
|
693
|
-
width={currentStripWidth}
|
|
694
|
-
height={
|
|
695
|
-
currentStripHeight ||
|
|
696
|
-
(item.value * containerHeight) / maxValue - 2 + overflowTop
|
|
697
|
-
}
|
|
711
|
+
<Line
|
|
712
|
+
x1={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
|
|
713
|
+
y1={y1}
|
|
714
|
+
x2={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
|
|
715
|
+
y2={y1 + actualStripHeight}
|
|
716
|
+
strokeWidth={currentStripWidth}
|
|
717
|
+
stroke={currentStripColor}
|
|
718
|
+
strokeDasharray={currentStripStrokeDashArray}
|
|
698
719
|
opacity={currentStripOpacity}
|
|
699
|
-
fill={currentStripColor}
|
|
700
720
|
/>
|
|
701
721
|
) : null}
|
|
702
722
|
{hideDataPoints ? null : (
|
|
@@ -2142,10 +2162,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2142
2162
|
</View>
|
|
2143
2163
|
) : null}
|
|
2144
2164
|
{(data0 ?? data).map((item: lineDataItem, index: number) => {
|
|
2165
|
+
const secondaryLabel =
|
|
2166
|
+
item.secondaryLabel ?? secondaryXAxis?.labelTexts?.[index] ?? '';
|
|
2167
|
+
const secondaryLabelTextStyle =
|
|
2168
|
+
item.secondaryLabelTextStyle ??
|
|
2169
|
+
secondaryXAxis?.labelsTextStyle ??
|
|
2170
|
+
item.labelTextStyle ??
|
|
2171
|
+
props.xAxisLabelTextStyle;
|
|
2145
2172
|
return (
|
|
2146
2173
|
<View key={index}>
|
|
2147
2174
|
{isAnimated
|
|
2148
2175
|
? renderAnimatedLabel(
|
|
2176
|
+
false,
|
|
2149
2177
|
index,
|
|
2150
2178
|
item.label ||
|
|
2151
2179
|
(props.xAxisLabelTexts && props.xAxisLabelTexts[index]
|
|
@@ -2155,6 +2183,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2155
2183
|
item.labelComponent,
|
|
2156
2184
|
)
|
|
2157
2185
|
: renderLabel(
|
|
2186
|
+
false,
|
|
2158
2187
|
index,
|
|
2159
2188
|
item.label ||
|
|
2160
2189
|
(props.xAxisLabelTexts && props.xAxisLabelTexts[index]
|
|
@@ -2163,7 +2192,23 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2163
2192
|
item.labelTextStyle || props.xAxisLabelTextStyle,
|
|
2164
2193
|
item.labelComponent,
|
|
2165
2194
|
)}
|
|
2166
|
-
{
|
|
2195
|
+
{secondaryXAxis
|
|
2196
|
+
? isAnimated
|
|
2197
|
+
? renderAnimatedLabel(
|
|
2198
|
+
true,
|
|
2199
|
+
index,
|
|
2200
|
+
secondaryLabel,
|
|
2201
|
+
secondaryLabelTextStyle,
|
|
2202
|
+
item.secondaryLabelComponent,
|
|
2203
|
+
)
|
|
2204
|
+
: renderLabel(
|
|
2205
|
+
true,
|
|
2206
|
+
index,
|
|
2207
|
+
secondaryLabel,
|
|
2208
|
+
secondaryLabelTextStyle,
|
|
2209
|
+
item.secondaryLabelComponent,
|
|
2210
|
+
)
|
|
2211
|
+
: null}
|
|
2167
2212
|
</View>
|
|
2168
2213
|
);
|
|
2169
2214
|
})}
|