react-native-gifted-charts 1.4.61 → 1.4.63
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 +22 -6
- package/dist/BarChart/RenderStackBars.js +1 -1
- package/dist/BarChart/index.js +3 -2
- package/dist/LineChart/index.js +61 -7
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -3,12 +3,21 @@
|
|
|
3
3
|
<p align="center">
|
|
4
4
|
<a href="https://gifted-charts.web.app">
|
|
5
5
|
<img src="/demos/favicon.png" height="auto" width="26" height="26" />
|
|
6
|
-
</a>
|
|
6
|
+
</a>
|
|
7
7
|
<a href="https://www.npmjs.com/package/react-native-gifted-charts">
|
|
8
8
|
<img src="/demos/npmIcon.png" height="auto" width="28" height="28" />
|
|
9
|
-
</a>
|
|
9
|
+
</a>
|
|
10
|
+
<a href="https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts">
|
|
11
|
+
<img src="/demos/gitLogo.png" height="auto" width="28" height="28" />
|
|
12
|
+
</a>
|
|
13
|
+
<a href="https://stackoverflow.com/questions/tagged/react-native-gifted-charts?tab=Newest">
|
|
14
|
+
<img src="/demos/stackOverflow.png" height="auto" width="28" height="28" />
|
|
15
|
+
</a>
|
|
10
16
|
<a href="https://discord.gg/FBbu9duJxs">
|
|
11
17
|
<img src="/demos/discord.png" height="auto" width="30" height="30" />
|
|
18
|
+
</a>
|
|
19
|
+
<a href="https://www.reddit.com/r/gifted_charts/">
|
|
20
|
+
<img src="/demos/redditLogo.png" height="auto" width="32" height="32" />
|
|
12
21
|
</a>
|
|
13
22
|
</p>
|
|
14
23
|
The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar, Population Pyramid and Radar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.
|
|
@@ -73,10 +82,12 @@ npx expo install react-native-gifted-charts expo-linear-gradient react-native-sv
|
|
|
73
82
|
Please note that `react-native-svg` and `react-native-linear-gradient`/`expo-linear-gradient` are needed for the library to work, so make sure they are installed in your project. <br />
|
|
74
83
|
**[gifted-charts-core](https://www.npmjs.com/package/gifted-charts-core)** contains the mathematical and logical utilities used by this library.
|
|
75
84
|
|
|
76
|
-
# Docs
|
|
85
|
+
# 📚 Docs & Demos 🎦
|
|
77
86
|
|
|
78
87
|
- [Documentation and gallery](https://gifted-charts.web.app/) <br />
|
|
79
88
|
- [Architecture and working (dev docs)](docs/dev/index.md)
|
|
89
|
+
- [Demo repo and snacks list](https://github.com/Abhinandan-Kushwaha/GiftedChartsDemo?tab=readme-ov-file#gifted-charts-demo)
|
|
90
|
+
- [Demo app on Play Store](https://play.google.com/store/apps/details?id=com.giftedcharts.demo)
|
|
80
91
|
|
|
81
92
|
## Usage
|
|
82
93
|
|
|
@@ -115,7 +126,7 @@ const data=[ {value:50}, {value:80}, {value:90}, {value:70} ]
|
|
|
115
126
|
**4. [Population Pyramid props](docs/PopulationPyramid/PopulationPyramid.md)** \
|
|
116
127
|
**5. [RadarChart props](docs/RadarChart/RadarChartProps.md)**
|
|
117
128
|
|
|
118
|
-
## Contributing
|
|
129
|
+
## 🤝 Contributing
|
|
119
130
|
|
|
120
131
|
This project exists thanks to all the people who contribute.
|
|
121
132
|
|
|
@@ -132,15 +143,20 @@ Sometimes people report issues which don't exist, or request for features which
|
|
|
132
143
|
|
|
133
144
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
|
134
145
|
|
|
135
|
-
[To do list](./src/todos.md)
|
|
146
|
+
📝 [To do list](./src/todos.md)
|
|
136
147
|
|
|
137
|
-
## Test cases
|
|
148
|
+
## 🧐 Test cases
|
|
138
149
|
|
|
139
150
|
- Test strategy and cases are discussed here- [TESTS.md](./TESTS.md) <br />
|
|
140
151
|
- Pixel perfection is assured using [react-native-screenshot-test](https://www.npmjs.com/package/react-native-screenshot-test). <br/>
|
|
141
152
|
- 220+ screenshot tests have been written. See the [Reports here](https://abhinandan-kushwaha.github.io/TestingCharts/ss-test/test.html).
|
|
142
153
|
- Screenshot tests are written in a separate repo named [TestingCharts](https://github.com/Abhinandan-Kushwaha/TestingCharts)
|
|
143
154
|
|
|
155
|
+
## 🏆 Showcase
|
|
156
|
+
|
|
157
|
+
Showcase your dashing charts on [Expo snack](https://snack.expo.dev/) and list them on the [Demo app repo](https://github.com/Abhinandan-Kushwaha/GiftedChartsDemo?tab=readme-ov-file#gifted-charts-demo).<br />
|
|
158
|
+
Your snack might get published in the [Demo app on Play Store!](https://play.google.com/store/apps/details?id=com.giftedcharts.demo)
|
|
159
|
+
|
|
144
160
|
## License
|
|
145
161
|
|
|
146
162
|
MIT
|
|
@@ -160,7 +160,7 @@ var RenderStackBars = function (props) {
|
|
|
160
160
|
] })) : null, stackItem.innerBarComponent && stackItem.innerBarComponent()] }, index));
|
|
161
161
|
}), (item.barBackgroundPattern || barBackgroundPattern) && (_jsxs(Svg, { children: [_jsx(Defs, { children: item.barBackgroundPattern
|
|
162
162
|
? item.barBackgroundPattern()
|
|
163
|
-
: barBackgroundPattern === null || barBackgroundPattern === void 0 ? void 0 : barBackgroundPattern() }), _jsx(Rect, { stroke: "none", x: "
|
|
163
|
+
: barBackgroundPattern === null || barBackgroundPattern === void 0 ? void 0 : barBackgroundPattern() }), _jsx(Rect, { stroke: "none", x: "0", y: "0", width: "100%", height: totalHeight, fill: "url(#".concat(item.patternId || patternId, ")") })] }))] }), localBarInnerComponent ? (_jsx(View, { style: { height: '100%', width: '100%' }, children: localBarInnerComponent(item, index) })) : null, (item.topLabelComponent || showValuesAsTopLabel) && (_jsx(View, { style: [
|
|
164
164
|
{
|
|
165
165
|
position: 'absolute',
|
|
166
166
|
top: containsNegativeValue
|
package/dist/BarChart/index.js
CHANGED
|
@@ -133,9 +133,10 @@ export var BarChart = function (props) {
|
|
|
133
133
|
};
|
|
134
134
|
var activatePointer = function (x) {
|
|
135
135
|
var _a;
|
|
136
|
+
var chartData = stackData !== null && stackData !== void 0 ? stackData : data;
|
|
136
137
|
var factor = (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
|
|
137
138
|
factor = Math.round(factor);
|
|
138
|
-
factor = Math.min(factor,
|
|
139
|
+
factor = Math.min(factor, chartData.length - 1);
|
|
139
140
|
factor = Math.max(factor, 0);
|
|
140
141
|
var z = initialSpacing +
|
|
141
142
|
(spacing + barWidth) * factor -
|
|
@@ -144,7 +145,7 @@ export var BarChart = function (props) {
|
|
|
144
145
|
setPointerX(z);
|
|
145
146
|
setPointerIndex(factor);
|
|
146
147
|
var item, y;
|
|
147
|
-
item =
|
|
148
|
+
item = chartData[factor];
|
|
148
149
|
var stackSum = 0;
|
|
149
150
|
if ('stacks' in item) {
|
|
150
151
|
stackSum = item.stacks.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
|
package/dist/LineChart/index.js
CHANGED
|
@@ -38,8 +38,8 @@ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-run
|
|
|
38
38
|
import { Fragment, useCallback, useEffect, useMemo, useRef } from 'react';
|
|
39
39
|
import { View, Animated, Easing, Text, Dimensions, I18nManager, } from 'react-native';
|
|
40
40
|
import { screenWidth, usePrevious } from '../utils';
|
|
41
|
-
import Svg, { Path, LinearGradient, Stop, Circle, Rect, Text as CanvasText, Line, ClipPath, Use, ForeignObject, } from 'react-native-svg';
|
|
42
|
-
import { getSegmentedPathObjects, getRegionPathObjects, RANGE_ENTER, RANGE_EXIT, SEGMENT_END, SEGMENT_START, STOP, useLineChart, adjustToOffset, LineDefaults, pointsWithPaddedRepititions, } from 'gifted-charts-core';
|
|
41
|
+
import Svg, { Path, LinearGradient, Stop, Circle, Rect, Text as CanvasText, Line, ClipPath, Use, ForeignObject, Defs, } from 'react-native-svg';
|
|
42
|
+
import { getSegmentedPathObjects, getRegionPathObjects, RANGE_ENTER, RANGE_EXIT, SEGMENT_END, SEGMENT_START, STOP, svgPath, useLineChart, adjustToOffset, LineDefaults, pointsWithPaddedRepititions, } from 'gifted-charts-core';
|
|
43
43
|
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
44
44
|
import { StripAndLabel } from '../Components/common/StripAndLabel';
|
|
45
45
|
import { Pointer } from '../Components/common/Pointer';
|
|
@@ -558,8 +558,54 @@ export var LineChart = function (props) {
|
|
|
558
558
|
var getLineGradientComponent = function () {
|
|
559
559
|
return props.lineGradientComponent ? (props.lineGradientComponent()) : (_jsxs(LinearGradient, { id: "lineGradient", x1: "0", y1: "0", x2: lineGradientDirection === 'horizontal' ? '1' : '0', y2: lineGradientDirection === 'vertical' ? '1' : '0', children: [_jsx(Stop, { offset: "0", stopColor: lineGradientStartColor }), _jsx(Stop, { offset: "1", stopColor: lineGradientEndColor })] }));
|
|
560
560
|
};
|
|
561
|
-
var getAreaGradientComponent = function (startFillColor, endFillColor, startOpacity, endOpacity) {
|
|
562
|
-
return props.areaGradientComponent ? (props.areaGradientComponent()) : (_jsxs(LinearGradient, { id:
|
|
561
|
+
var getAreaGradientComponent = function (startFillColor, endFillColor, startOpacity, endOpacity, gradientId) {
|
|
562
|
+
return props.areaGradientComponent ? (props.areaGradientComponent()) : (_jsxs(LinearGradient, { id: gradientId || 'Gradient', x1: "0", y1: "0", x2: gradientDirection === 'horizontal' ? '1' : '0', y2: gradientDirection === 'vertical' ? '1' : '0', children: [_jsx(Stop, { offset: "0", stopColor: startFillColor, stopOpacity: startOpacity.toString() }), _jsx(Stop, { offset: "1", stopColor: endFillColor, stopOpacity: endOpacity.toString() })] }));
|
|
563
|
+
};
|
|
564
|
+
var getSpreadAreaPath = function (spreadAreaData, getX, getY, spacingArray, curvature, curveType) {
|
|
565
|
+
if (!spreadAreaData || spreadAreaData.length === 0)
|
|
566
|
+
return '';
|
|
567
|
+
// Generate points arrays for upper and lower bounds
|
|
568
|
+
var upperPoints = spreadAreaData.map(function (point, index) { return [
|
|
569
|
+
getX(spacingArray, index),
|
|
570
|
+
getY(point.upper),
|
|
571
|
+
]; });
|
|
572
|
+
var lowerPoints = spreadAreaData.map(function (point, index) { return [
|
|
573
|
+
getX(spacingArray, index),
|
|
574
|
+
getY(point.lower),
|
|
575
|
+
]; });
|
|
576
|
+
// Use curve interpolation if curveType is specified
|
|
577
|
+
if (curveType !== undefined && curveType !== 0) {
|
|
578
|
+
var topPath = svgPath(upperPoints, curveType, props.curvature);
|
|
579
|
+
// Reverse the lower points for the path and create curved path
|
|
580
|
+
var reversedLowerPoints = lowerPoints.slice().reverse();
|
|
581
|
+
var bottomPath = svgPath(reversedLowerPoints, curveType, props.curvature);
|
|
582
|
+
// Remove the initial 'M' from bottomPath and prepend 'L' to connect it
|
|
583
|
+
var bottomPathConnected = bottomPath.replace(/^M/, 'L');
|
|
584
|
+
return "".concat(topPath, " ").concat(bottomPathConnected, " Z");
|
|
585
|
+
}
|
|
586
|
+
else {
|
|
587
|
+
// Fallback to straight lines for compatibility
|
|
588
|
+
var topPath = spreadAreaData
|
|
589
|
+
.map(function (point, index) {
|
|
590
|
+
return "L ".concat(getX(spacingArray, index), " ").concat(getY(point.upper));
|
|
591
|
+
})
|
|
592
|
+
.join(' ')
|
|
593
|
+
.replace(/^L/, 'M');
|
|
594
|
+
var bottomPath = spreadAreaData
|
|
595
|
+
.slice()
|
|
596
|
+
.reverse()
|
|
597
|
+
.map(function (point, index) {
|
|
598
|
+
return "L ".concat(getX(spacingArray, spreadAreaData.length - 1 - index), " ").concat(getY(point.lower));
|
|
599
|
+
})
|
|
600
|
+
.join(' ');
|
|
601
|
+
return "".concat(topPath, " ").concat(bottomPath, " Z");
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
var getClipRange = function (startIndex, endIndex, clipRangeId) {
|
|
605
|
+
var startX = startIndex * spacing + initialSpacing;
|
|
606
|
+
var endX = endIndex * spacing + initialSpacing;
|
|
607
|
+
var clipWidth = endX - startX;
|
|
608
|
+
return (_jsx(Defs, { children: _jsx(ClipPath, { id: clipRangeId, children: _jsx(Rect, { x: startX, y: 0, width: clipWidth, height: "100%" }) }) }));
|
|
563
609
|
};
|
|
564
610
|
var renderIntersection = function () {
|
|
565
611
|
var _a;
|
|
@@ -590,9 +636,15 @@ export var LineChart = function (props) {
|
|
|
590
636
|
if (!points)
|
|
591
637
|
return null;
|
|
592
638
|
var isCurved = points.includes('C') || points.includes('Q');
|
|
639
|
+
var clipRangeId = "Clip-range-".concat(key);
|
|
640
|
+
var uniqueId = "Gradient-line-".concat(key);
|
|
593
641
|
var isNthAreaChart = !!dataSet
|
|
594
642
|
? ((_a = dataSet[Number(key)].areaChart) !== null && _a !== void 0 ? _a : areaChart)
|
|
595
643
|
: getIsNthAreaChart(key !== null && key !== void 0 ? key : 0);
|
|
644
|
+
// Add support for spread area data from props
|
|
645
|
+
var spreadAreaData = props.spreadAreaData;
|
|
646
|
+
var spreadAreaColor = props.spreadAreaColor;
|
|
647
|
+
var spreadAreaOpacity = props.spreadAreaOpacity;
|
|
596
648
|
var ar = [{ d: '', color: '', strokeWidth: 0 }];
|
|
597
649
|
if (points.includes(RANGE_ENTER)) {
|
|
598
650
|
ar = getRegionPathObjects(points, color, currentLineThickness !== null && currentLineThickness !== void 0 ? currentLineThickness : 0, thickness, strokeDashArray !== null && strokeDashArray !== void 0 ? strokeDashArray : [], isCurved, RANGE_ENTER, STOP, RANGE_EXIT, curveType);
|
|
@@ -639,12 +691,14 @@ export var LineChart = function (props) {
|
|
|
639
691
|
}
|
|
640
692
|
return _jsx(Path, __assign({}, lineSvgProps), index);
|
|
641
693
|
})) : animateOnDataChange && animatedPath ? (_jsx(AnimatedPath, __assign({}, lineSvgPropsOuter))) : (_jsx(Path, __assign({}, lineSvgPropsOuter))), isNthAreaChart &&
|
|
642
|
-
getAreaGradientComponent(startFillColor, endFillColor, startOpacity, endOpacity), isNthAreaChart
|
|
694
|
+
getAreaGradientComponent(startFillColor, endFillColor, startOpacity, endOpacity, uniqueId), isNthAreaChart &&
|
|
695
|
+
(startIndex !== 0 || endIndex !== data.length - 1) &&
|
|
696
|
+
getClipRange(startIndex, endIndex, clipRangeId), isNthAreaChart ? (props.interpolateMissingValues === false &&
|
|
643
697
|
propsData.some(function (item) { return isNaN(item.value); }) ? null : animateOnDataChange && animatedFillPath ? (_jsx(AnimatedPath, { onPress: props.onChartAreaPress, d: animatedFillPath, fill: props.areaGradientId
|
|
644
698
|
? "url(#".concat(props.areaGradientId, ")")
|
|
645
|
-
: "url(#
|
|
699
|
+
: "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness })) : (_jsx(Path, { onPress: props.onChartAreaPress, d: fillPoints, fill: props.areaGradientId
|
|
646
700
|
? "url(#".concat(props.areaGradientId, ")")
|
|
647
|
-
: "url(#
|
|
701
|
+
: "url(#".concat(uniqueId, ")"), clipPath: "url(#".concat(clipRangeId, ")"), stroke: 'none', strokeWidth: currentLineThickness || thickness }))) : null, spreadAreaData && (_jsx(Path, { d: getSpreadAreaPath(spreadAreaData, getX, getY, spacingArray, props.curvature, curveType), fill: spreadAreaColor || 'rgba(0,0,255,0.2)', stroke: "none", opacity: spreadAreaOpacity !== null && spreadAreaOpacity !== void 0 ? spreadAreaOpacity : 0.3 })), renderSpecificVerticalLines(data, cumulativeSpacing1), renderSpecificVerticalLines(data2, cumulativeSpacing2), renderSpecificVerticalLines(data3, cumulativeSpacing3), renderSpecificVerticalLines(data4, cumulativeSpacing4), renderSpecificVerticalLines(data5, cumulativeSpacing5), (_b = dataSet === null || dataSet === void 0 ? void 0 : dataSet.map(function (set, index) {
|
|
648
702
|
return renderSpecificVerticalLines(set === null || set === void 0 ? void 0 : set.data, cumulativeSpacingForSet[index]);
|
|
649
703
|
})) !== null && _b !== void 0 ? _b : null, isAnimated && !renderDataPointsAfterAnimationEnds // in this condition onPress won't work properly in case of multi-line, so it's suggested to use either renderDataPointsAfterAnimationEnds prop if you want to use onPress for data points
|
|
650
704
|
? renderDataPoints(hideDataPoints, data, propsData, dataPointsShape, dataPointsWidth, dataPointsHeight, dataPointsColor, dataPointsRadius, textColor, textFontSize, startIndex, endIndex, isSecondary, showValuesAsDataPointsText, spacingArray, key)
|
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.63",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar, Population Pyramid and Radar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"files": [
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"registry": "https://registry.npmjs.org/"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"gifted-charts-core": "0.1.
|
|
29
|
+
"gifted-charts-core": "0.1.65"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@babel/cli": "^7.24.8",
|