react-native-gifted-charts 1.3.13 → 1.3.14
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 +1 -1
- package/src/BarChart/RenderBars.tsx +67 -51
- package/src/LineChart/index.tsx +85 -27
- package/src/LineChart/types.ts +9 -0
- package/src/utils/constants.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.14",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -341,57 +341,47 @@ const RenderBars = (props: Props) => {
|
|
|
341
341
|
(data[i].barWidth || props.barWidth || 30);
|
|
342
342
|
}
|
|
343
343
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
344
|
+
const barWrapperStyle = [
|
|
345
|
+
{
|
|
346
|
+
// overflow: 'visible',
|
|
347
|
+
marginBottom: 60 + barMarginBottom,
|
|
348
|
+
width: item.barWidth || props.barWidth || 30,
|
|
349
|
+
height: barHeight,
|
|
350
|
+
marginRight: spacing,
|
|
351
|
+
},
|
|
352
|
+
item.value < 0
|
|
353
|
+
? {
|
|
354
|
+
transform: [
|
|
355
|
+
{
|
|
356
|
+
translateY:
|
|
357
|
+
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
358
|
+
(maxValue || 200),
|
|
359
|
+
},
|
|
360
|
+
{rotateZ: '180deg'},
|
|
361
|
+
],
|
|
351
362
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
{
|
|
375
|
-
translateY:
|
|
376
|
-
(Math.abs(item.value) * (containerHeight || 200)) /
|
|
377
|
-
(maxValue || 200),
|
|
378
|
-
},
|
|
379
|
-
{rotateZ: '180deg'},
|
|
380
|
-
],
|
|
381
|
-
}
|
|
382
|
-
: pointerConfig
|
|
383
|
-
? {
|
|
384
|
-
transform: [
|
|
385
|
-
{
|
|
386
|
-
translateY: (containerHeight || 200) - (barHeight - 10),
|
|
387
|
-
},
|
|
388
|
-
],
|
|
389
|
-
}
|
|
390
|
-
: null,
|
|
391
|
-
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
392
|
-
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
393
|
-
side !== 'right' && {zIndex: data.length - index},
|
|
394
|
-
]}>
|
|
363
|
+
: pointerConfig
|
|
364
|
+
? {
|
|
365
|
+
transform: [
|
|
366
|
+
{
|
|
367
|
+
translateY: (containerHeight || 200) - (barHeight - 10),
|
|
368
|
+
},
|
|
369
|
+
],
|
|
370
|
+
}
|
|
371
|
+
: null,
|
|
372
|
+
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
373
|
+
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
374
|
+
side !== 'right' && {zIndex: data.length - index},
|
|
375
|
+
];
|
|
376
|
+
|
|
377
|
+
const pressDisabled =
|
|
378
|
+
item.disablePress ||
|
|
379
|
+
props.disablePress ||
|
|
380
|
+
(pointerConfig && pointerConfig.barTouchable !== true);
|
|
381
|
+
|
|
382
|
+
const barContent = () => {
|
|
383
|
+
return (
|
|
384
|
+
<>
|
|
395
385
|
{(props.showXAxisIndices || item.showXAxisIndex) && (
|
|
396
386
|
<View
|
|
397
387
|
style={{
|
|
@@ -569,7 +559,33 @@ const RenderBars = (props: Props) => {
|
|
|
569
559
|
{isAnimated
|
|
570
560
|
? renderAnimatedLabel(label, labelTextStyle, item.value)
|
|
571
561
|
: renderLabel(label, labelTextStyle, item.value)}
|
|
572
|
-
|
|
562
|
+
</>
|
|
563
|
+
);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
return (
|
|
567
|
+
<>
|
|
568
|
+
{pressDisabled ? (
|
|
569
|
+
<View pointerEvents="none" style={barWrapperStyle}>
|
|
570
|
+
{barContent()}
|
|
571
|
+
</View>
|
|
572
|
+
) : (
|
|
573
|
+
<TouchableOpacity
|
|
574
|
+
activeOpacity={props.activeOpacity || 0.2}
|
|
575
|
+
onPress={() => {
|
|
576
|
+
if (renderTooltip) {
|
|
577
|
+
setSelectedIndex(index);
|
|
578
|
+
}
|
|
579
|
+
item.onPress
|
|
580
|
+
? item.onPress()
|
|
581
|
+
: props.onPress
|
|
582
|
+
? props.onPress(item, index)
|
|
583
|
+
: null;
|
|
584
|
+
}}
|
|
585
|
+
style={barWrapperStyle}>
|
|
586
|
+
{barContent()}
|
|
587
|
+
</TouchableOpacity>
|
|
588
|
+
)}
|
|
573
589
|
{renderTooltip && selectedIndex === index && (
|
|
574
590
|
<View
|
|
575
591
|
style={{
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -1450,6 +1450,13 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1450
1450
|
const containerHeightIncludingBelowXAxis =
|
|
1451
1451
|
extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
|
|
1452
1452
|
|
|
1453
|
+
const lineGradient = props.lineGradient ?? LineDefaults.lineGradient;
|
|
1454
|
+
const lineGradientDirection = props.lineGradientDirection ?? 'vertical';
|
|
1455
|
+
const lineGradientStartColor =
|
|
1456
|
+
props.lineGradientStartColor ?? LineDefaults.lineGradientStartColor;
|
|
1457
|
+
const lineGradientEndColor =
|
|
1458
|
+
props.lineGradientEndColor ?? LineDefaults.lineGradientEndColor;
|
|
1459
|
+
|
|
1453
1460
|
const renderLabel = (
|
|
1454
1461
|
index: number,
|
|
1455
1462
|
label: String,
|
|
@@ -1637,7 +1644,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1637
1644
|
const currentStripWidth = item.stripWidth ?? stripWidth;
|
|
1638
1645
|
const currentStripOpacity = item.stripOpacity ?? stripOpacity;
|
|
1639
1646
|
const currentStripColor = item.stripColor || stripColor;
|
|
1640
|
-
const position= I18nManager.isRTL ?
|
|
1647
|
+
const position = I18nManager.isRTL ? 'right' : 'left';
|
|
1641
1648
|
|
|
1642
1649
|
return (
|
|
1643
1650
|
<Fragment key={index}>
|
|
@@ -1698,8 +1705,9 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1698
1705
|
height: dataPointsHeight,
|
|
1699
1706
|
width: dataPointsWidth,
|
|
1700
1707
|
top: getYOrSecondaryY(item.value),
|
|
1701
|
-
[position]:
|
|
1702
|
-
|
|
1708
|
+
[position]:
|
|
1709
|
+
initialSpacing - dataPointsWidth + spacing * index,
|
|
1710
|
+
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
|
|
1703
1711
|
},
|
|
1704
1712
|
]}>
|
|
1705
1713
|
{customDataPoint()}
|
|
@@ -1980,6 +1988,51 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1980
1988
|
});
|
|
1981
1989
|
};
|
|
1982
1990
|
|
|
1991
|
+
const getLineGradientComponent = () => {
|
|
1992
|
+
return props.lineGradientComponent ? (
|
|
1993
|
+
props.lineGradientComponent()
|
|
1994
|
+
) : (
|
|
1995
|
+
<LinearGradient
|
|
1996
|
+
id="lineGradient"
|
|
1997
|
+
x1="0"
|
|
1998
|
+
y1="0"
|
|
1999
|
+
x2={lineGradientDirection === 'horizontal' ? '1' : '0'}
|
|
2000
|
+
y2={lineGradientDirection === 'vertical' ? '1' : '0'}>
|
|
2001
|
+
<Stop offset="0" stopColor={lineGradientStartColor} />
|
|
2002
|
+
<Stop offset="1" stopColor={lineGradientEndColor} />
|
|
2003
|
+
</LinearGradient>
|
|
2004
|
+
);
|
|
2005
|
+
};
|
|
2006
|
+
|
|
2007
|
+
const getAreaGradientComponent = (
|
|
2008
|
+
startFillColor: string,
|
|
2009
|
+
endFillColor: string,
|
|
2010
|
+
startOpacity: number,
|
|
2011
|
+
endOpacity: number,
|
|
2012
|
+
) => {
|
|
2013
|
+
return props.areaGradientComponent ? (
|
|
2014
|
+
props.areaGradientComponent()
|
|
2015
|
+
) : (
|
|
2016
|
+
<LinearGradient
|
|
2017
|
+
id="Gradient"
|
|
2018
|
+
x1="0"
|
|
2019
|
+
y1="0"
|
|
2020
|
+
x2={gradientDirection === 'horizontal' ? '1' : '0'}
|
|
2021
|
+
y2={gradientDirection === 'vertical' ? '1' : '0'}>
|
|
2022
|
+
<Stop
|
|
2023
|
+
offset="0"
|
|
2024
|
+
stopColor={startFillColor}
|
|
2025
|
+
stopOpacity={startOpacity.toString()}
|
|
2026
|
+
/>
|
|
2027
|
+
<Stop
|
|
2028
|
+
offset="1"
|
|
2029
|
+
stopColor={endFillColor}
|
|
2030
|
+
stopOpacity={endOpacity.toString()}
|
|
2031
|
+
/>
|
|
2032
|
+
</LinearGradient>
|
|
2033
|
+
);
|
|
2034
|
+
};
|
|
2035
|
+
|
|
1983
2036
|
const lineSvgComponent = (
|
|
1984
2037
|
points: any,
|
|
1985
2038
|
currentLineThickness: number | undefined,
|
|
@@ -1998,6 +2051,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1998
2051
|
) => {
|
|
1999
2052
|
return (
|
|
2000
2053
|
<Svg>
|
|
2054
|
+
{lineGradient && getLineGradientComponent()}
|
|
2001
2055
|
{strokeDashArray &&
|
|
2002
2056
|
strokeDashArray.length === 2 &&
|
|
2003
2057
|
typeof strokeDashArray[0] === 'number' &&
|
|
@@ -2005,7 +2059,13 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2005
2059
|
<Path
|
|
2006
2060
|
d={points}
|
|
2007
2061
|
fill="none"
|
|
2008
|
-
stroke={
|
|
2062
|
+
stroke={
|
|
2063
|
+
lineGradient
|
|
2064
|
+
? props.lineGradientId
|
|
2065
|
+
? `url(#${props.lineGradientId})`
|
|
2066
|
+
: `url(#lineGradient)`
|
|
2067
|
+
: color
|
|
2068
|
+
}
|
|
2009
2069
|
strokeWidth={currentLineThickness || thickness}
|
|
2010
2070
|
strokeDasharray={strokeDashArray}
|
|
2011
2071
|
/>
|
|
@@ -2013,36 +2073,34 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2013
2073
|
<Path
|
|
2014
2074
|
d={points}
|
|
2015
2075
|
fill="none"
|
|
2016
|
-
stroke={
|
|
2076
|
+
stroke={
|
|
2077
|
+
lineGradient
|
|
2078
|
+
? props.lineGradientId
|
|
2079
|
+
? `url(#${props.lineGradientId})`
|
|
2080
|
+
: `url(#lineGradient)`
|
|
2081
|
+
: color
|
|
2082
|
+
}
|
|
2017
2083
|
strokeWidth={currentLineThickness || thickness}
|
|
2018
2084
|
/>
|
|
2019
2085
|
)}
|
|
2020
2086
|
|
|
2021
2087
|
{/*********************** For Area Chart ************/}
|
|
2022
2088
|
|
|
2023
|
-
{atLeastOneAreaChart &&
|
|
2024
|
-
|
|
2025
|
-
|
|
2026
|
-
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2030
|
-
<Stop
|
|
2031
|
-
offset="0"
|
|
2032
|
-
stopColor={startFillColor}
|
|
2033
|
-
stopOpacity={startOpacity.toString()}
|
|
2034
|
-
/>
|
|
2035
|
-
<Stop
|
|
2036
|
-
offset="1"
|
|
2037
|
-
stopColor={endFillColor}
|
|
2038
|
-
stopOpacity={endOpacity.toString()}
|
|
2039
|
-
/>
|
|
2040
|
-
</LinearGradient>
|
|
2041
|
-
)}
|
|
2089
|
+
{atLeastOneAreaChart &&
|
|
2090
|
+
getAreaGradientComponent(
|
|
2091
|
+
startFillColor,
|
|
2092
|
+
endFillColor,
|
|
2093
|
+
startOpacity,
|
|
2094
|
+
endOpacity,
|
|
2095
|
+
)}
|
|
2042
2096
|
{atLeastOneAreaChart && (
|
|
2043
2097
|
<Path
|
|
2044
2098
|
d={fillPoints}
|
|
2045
|
-
fill=
|
|
2099
|
+
fill={
|
|
2100
|
+
props.areaGradientId
|
|
2101
|
+
? `url(#${props.areaGradientId})`
|
|
2102
|
+
: `url(#Gradient)`
|
|
2103
|
+
}
|
|
2046
2104
|
stroke={'transparent'}
|
|
2047
2105
|
strokeWidth={currentLineThickness || thickness}
|
|
2048
2106
|
/>
|
|
@@ -2408,7 +2466,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2408
2466
|
(props.overflowBottom ?? dataPointsRadius1),
|
|
2409
2467
|
width: totalWidth,
|
|
2410
2468
|
zIndex: zIndex,
|
|
2411
|
-
transform: [{
|
|
2469
|
+
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
|
|
2412
2470
|
}}>
|
|
2413
2471
|
{lineSvgComponent(
|
|
2414
2472
|
points,
|
|
@@ -2673,7 +2731,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2673
2731
|
(props.overflowBottom ?? dataPointsRadius1),
|
|
2674
2732
|
width: animatedWidth,
|
|
2675
2733
|
zIndex: zIndex,
|
|
2676
|
-
transform: [{
|
|
2734
|
+
transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
|
|
2677
2735
|
// backgroundColor: 'wheat',
|
|
2678
2736
|
}}>
|
|
2679
2737
|
{lineSvgComponent(
|
package/src/LineChart/types.ts
CHANGED
|
@@ -234,6 +234,9 @@ export type LineChartPropsType = {
|
|
|
234
234
|
endOpacity5?: number;
|
|
235
235
|
gradientDirection?: string;
|
|
236
236
|
|
|
237
|
+
areaGradientComponent?: () => any;
|
|
238
|
+
areaGradientId?: string;
|
|
239
|
+
|
|
237
240
|
textFontSize?: number;
|
|
238
241
|
textColor?: string;
|
|
239
242
|
textFontSize1?: number;
|
|
@@ -281,6 +284,12 @@ export type LineChartPropsType = {
|
|
|
281
284
|
secondaryYAxis?: secondaryYAxisType;
|
|
282
285
|
secondaryLineConfig?: secondaryLineConfigType;
|
|
283
286
|
formatYLabel?: (label: string) => string;
|
|
287
|
+
lineGradient?: boolean;
|
|
288
|
+
lineGradientComponent?: () => any;
|
|
289
|
+
lineGradientId?: string;
|
|
290
|
+
lineGradientDirection?: string;
|
|
291
|
+
lineGradientStartColor?: string;
|
|
292
|
+
lineGradientEndColor?: string;
|
|
284
293
|
};
|
|
285
294
|
|
|
286
295
|
type referenceConfigType = {
|
package/src/utils/constants.ts
CHANGED