react-native-gifted-charts 1.4.12 → 1.4.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.
Files changed (60) hide show
  1. package/package.json +6 -10
  2. package/src/BarChart/Animated2DWithGradient.tsx +197 -0
  3. package/src/BarChart/RenderBars.tsx +458 -0
  4. package/src/BarChart/RenderStackBars.tsx +385 -0
  5. package/src/BarChart/index.tsx +381 -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,244 @@
1
+ import React, {Fragment, useEffect} from 'react';
2
+ import {View, ScrollView, StyleSheet, I18nManager} from 'react-native';
3
+ import {renderHorizSections} from './renderHorizSections';
4
+ import RenderLineInBarChart from './renderLineInBarChart';
5
+ import RenderVerticalLines from './renderVerticalLines';
6
+ import {
7
+ chartTypes,
8
+ yAxisSides,
9
+ BarAndLineChartsWrapperTypes,
10
+ useBarAndLineChartsWrapper,
11
+ } from 'gifted-charts-core';
12
+
13
+ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
14
+ const {
15
+ chartType,
16
+ containerHeight,
17
+ noOfSectionsBelowXAxis,
18
+ stepHeight,
19
+ labelsExtraHeight,
20
+ yAxisLabelWidth,
21
+ horizontal,
22
+ scrollRef,
23
+ initialSpacing,
24
+ data,
25
+ barWidth,
26
+ xAxisThickness,
27
+ totalWidth,
28
+ disableScroll,
29
+ showScrollIndicator,
30
+ scrollToEnd,
31
+ scrollToIndex,
32
+ scrollAnimation,
33
+ indicatorColor,
34
+ spacing,
35
+ showLine,
36
+ points2,
37
+ renderChartContent,
38
+ remainingScrollViewProps,
39
+ endSpacing,
40
+ hideAxesAndRules,
41
+
42
+ showXAxisIndices,
43
+ xAxisIndicesHeight,
44
+ xAxisIndicesWidth,
45
+ xAxisIndicesColor,
46
+
47
+ pointerConfig,
48
+ getPointerProps,
49
+ pointerIndex,
50
+ pointerX,
51
+ pointerY,
52
+
53
+ onEndReached,
54
+ onStartReached,
55
+ onMomentumScrollEnd,
56
+ extraWidthDueToDataPoint = 0, // extraWidthDueToDataPoint will be receved from props onlhy in case of LineCharts, for other charts it will be undefined and will default to 0
57
+ } = props;
58
+
59
+ const {
60
+ containerHeightIncludingBelowXAxis,
61
+ xAxisLabelsVerticalShift,
62
+ trimYAxisAtTop,
63
+ yAxisExtraHeight,
64
+ overflowTop,
65
+ xAxisLabelsHeight,
66
+ xAxisTextNumberOfLines,
67
+ actualContainerWidth,
68
+ transformForHorizontal,
69
+ horizSectionProps,
70
+ referenceLinesOverChartContent,
71
+ setCanMomentum,
72
+ isCloseToStart,
73
+ isCloseToEnd,
74
+ canMomentum,
75
+ yAxisAtTop,
76
+ yAxisThickness,
77
+ yAxisSide,
78
+ showVerticalLines,
79
+ verticalLinesProps,
80
+ lineInBarChartProps,
81
+ lineInBarChartProps2,
82
+ } = useBarAndLineChartsWrapper({...props, isRTL: I18nManager.isRTL});
83
+
84
+ useEffect(() => {
85
+ if (pointerConfig && getPointerProps) {
86
+ getPointerProps({pointerIndex, pointerX, pointerY});
87
+ }
88
+ }, [pointerIndex, pointerX, pointerY]);
89
+
90
+ /*******************************************************************************************************************************************/
91
+ /*******************************************************************************************************************************************/
92
+
93
+ const styles = StyleSheet.create({
94
+ container: {
95
+ width: '100%',
96
+ height:
97
+ containerHeightIncludingBelowXAxis +
98
+ labelsExtraHeight +
99
+ xAxisLabelsVerticalShift +
100
+ (trimYAxisAtTop ? 0 : yAxisExtraHeight) +
101
+ 50 -
102
+ overflowTop,
103
+ marginTop: trimYAxisAtTop ? containerHeight / 20 : 0,
104
+ marginBottom: (xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18) - 55, //This is to not let the Things that should be rendered below the chart overlap with it
105
+ },
106
+ });
107
+
108
+ return (
109
+ <View
110
+ style={[
111
+ styles.container,
112
+ horizontal && {
113
+ width: actualContainerWidth,
114
+ transform: transformForHorizontal,
115
+ },
116
+ ]}>
117
+ {hideAxesAndRules !== true
118
+ ? renderHorizSections({
119
+ ...horizSectionProps,
120
+ onlyReferenceLines: false,
121
+ renderReferenceLines: !referenceLinesOverChartContent,
122
+ })
123
+ : null}
124
+ <ScrollView
125
+ onScrollBeginDrag={() => {
126
+ setCanMomentum(true);
127
+ }}
128
+ onMomentumScrollEnd={({nativeEvent}) => {
129
+ if (onMomentumScrollEnd) {
130
+ onMomentumScrollEnd();
131
+ }
132
+ if (isCloseToEnd(nativeEvent) && canMomentum) {
133
+ onEndReached ? onEndReached() : null;
134
+ setCanMomentum(false);
135
+ }
136
+ if (isCloseToStart(nativeEvent) && canMomentum) {
137
+ onStartReached ? onStartReached() : null;
138
+ setCanMomentum(false);
139
+ }
140
+ }}
141
+ scrollEventThrottle={
142
+ props.scrollEventThrottle ? props.scrollEventThrottle : 16
143
+ }
144
+ horizontal
145
+ ref={scrollRef}
146
+ style={[
147
+ {
148
+ marginLeft:
149
+ horizontal && !yAxisAtTop
150
+ ? -yAxisThickness -
151
+ (props.width ? 20 : 0) -
152
+ (data[data.length - 1]?.barWidth ?? barWidth ?? 0) / 2
153
+ : yAxisSide === yAxisSides.RIGHT
154
+ ? 0
155
+ : yAxisLabelWidth + yAxisThickness,
156
+ position: 'absolute',
157
+ bottom: chartType === chartTypes.LINE_BI_COLOR ? 0 : xAxisThickness,
158
+ },
159
+ !!props.width && {width: props.width + extraWidthDueToDataPoint},
160
+ horizontal && {
161
+ width:
162
+ (props.width ?? totalWidth) + (props.width ? endSpacing : -20),
163
+ },
164
+ ]}
165
+ contentContainerStyle={[
166
+ {
167
+ height:
168
+ containerHeightIncludingBelowXAxis +
169
+ yAxisExtraHeight +
170
+ labelsExtraHeight +
171
+ (50 + xAxisLabelsVerticalShift),
172
+ width:
173
+ Math.max(props.width ?? 0, totalWidth - spacing + endSpacing) +
174
+ extraWidthDueToDataPoint,
175
+ paddingLeft: initialSpacing,
176
+ paddingBottom:
177
+ noOfSectionsBelowXAxis * stepHeight + labelsExtraHeight,
178
+ alignItems: 'flex-end',
179
+ },
180
+ !props.width && {width: totalWidth},
181
+ ]}
182
+ scrollEnabled={!disableScroll}
183
+ showsHorizontalScrollIndicator={showScrollIndicator}
184
+ indicatorStyle={indicatorColor}
185
+ onContentSizeChange={() => {
186
+ if (scrollRef.current && scrollToEnd) {
187
+ scrollRef.current.scrollToEnd({animated: scrollAnimation});
188
+ } else if (scrollRef.current && scrollToIndex) {
189
+ scrollRef.current.scrollTo({
190
+ x:
191
+ initialSpacing +
192
+ ((barWidth ?? 0) + spacing) * scrollToIndex -
193
+ spacing,
194
+ });
195
+ }
196
+ }}
197
+ {...remainingScrollViewProps}>
198
+ <Fragment>
199
+ {showVerticalLines ? (
200
+ <RenderVerticalLines {...verticalLinesProps} />
201
+ ) : null}
202
+ {
203
+ // Only For Bar Charts-
204
+ showLine ? <RenderLineInBarChart {...lineInBarChartProps} /> : null
205
+ }
206
+ {
207
+ // Only For Bar Charts-
208
+ showLine && points2?.length ? (
209
+ <RenderLineInBarChart {...lineInBarChartProps2} />
210
+ ) : null
211
+ }
212
+ {
213
+ // Only For Line Charts-
214
+ chartType === chartTypes.LINE &&
215
+ data.map((item: any, index: number) => {
216
+ return showXAxisIndices || item.showXAxisIndex ? (
217
+ <View
218
+ key={index + '' + item.value}
219
+ style={{
220
+ position: 'absolute',
221
+ height: xAxisIndicesHeight,
222
+ width: xAxisIndicesWidth,
223
+ backgroundColor: xAxisIndicesColor,
224
+ bottom: 60 - xAxisIndicesHeight / 2,
225
+ left:
226
+ index * spacing +
227
+ (initialSpacing - xAxisIndicesWidth / 2) -
228
+ 3,
229
+ }}
230
+ />
231
+ ) : null;
232
+ })
233
+ }
234
+ {renderChartContent()}
235
+ </Fragment>
236
+ </ScrollView>
237
+ {referenceLinesOverChartContent
238
+ ? renderHorizSections({...horizSectionProps, onlyReferenceLines: true})
239
+ : null}
240
+ </View>
241
+ );
242
+ };
243
+
244
+ export default BarAndLineChartsWrapper;