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,381 @@
1
+ import React, {useCallback, useEffect, useMemo, useRef} from 'react';
2
+ import {Animated, Easing, View} from 'react-native';
3
+ import RenderBars from './RenderBars';
4
+ import RenderStackBars from './RenderStackBars';
5
+ import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
6
+ import {BarChartPropsType, useBarChart} from 'gifted-charts-core';
7
+ import {StripAndLabel} from '../Components/common/StripAndLabel';
8
+ import {Pointer} from '../Components/common/Pointer';
9
+ import {screenWidth} from '../utils';
10
+
11
+ export const BarChart = (props: BarChartPropsType) => {
12
+ const heightValue = useMemo(() => new Animated.Value(0), []);
13
+ const opacValue = useMemo(() => new Animated.Value(0), []);
14
+ const widthValue = useMemo(() => new Animated.Value(0), []);
15
+
16
+ const scrollRef = props.scrollRef ?? useRef(null);
17
+ const remainingScrollViewProps = {
18
+ onScroll: (ev: any) => props.onScroll?.(ev),
19
+ onTouchStart: evt => {
20
+ if (props.renderTooltip) {
21
+ setSelectedIndex(-1);
22
+ }
23
+ },
24
+ };
25
+
26
+ const {
27
+ lineConfig,
28
+ hidePointer1,
29
+ pointerItem,
30
+ pointerY,
31
+ pointerConfig,
32
+ pointerColor,
33
+ pointerX,
34
+ pointerComponent,
35
+ pointerHeight,
36
+ pointerRadius,
37
+ pointerWidth,
38
+ autoAdjustPointerLabelPosition,
39
+ pointerLabelWidth,
40
+ activatePointersOnLongPress,
41
+ yAxisLabelWidth,
42
+ shiftPointerLabelX,
43
+ pointerLabelHeight,
44
+ pointerStripUptoDataPoint,
45
+ pointerStripHeight,
46
+ shiftPointerLabelY,
47
+ showPointerStrip,
48
+ pointerStripWidth,
49
+ containerHeight,
50
+ xAxisThickness,
51
+ pointerStripColor,
52
+ pointerEvents,
53
+ setResponderStartTime,
54
+ setPointerY,
55
+ setPointerItem,
56
+ initialSpacing,
57
+ spacing,
58
+ data,
59
+ barWidth,
60
+ setPointerX,
61
+ setPointerIndex,
62
+ maxValue,
63
+ responderStartTime,
64
+ setResponderActive,
65
+ activatePointersDelay,
66
+ persistPointer,
67
+ pointerVanishDelay,
68
+ containerHeightIncludingBelowXAxis,
69
+ extendedContainerHeight,
70
+ totalWidth,
71
+ stripBehindBars,
72
+ noOfSectionsBelowXAxis,
73
+ stepHeight,
74
+ xAxisLabelsVerticalShift,
75
+ labelsExtraHeight,
76
+ stripOverPointer,
77
+ pointerLabelComponent,
78
+ setSelectedIndex,
79
+ isAnimated,
80
+ animationDuration,
81
+ side,
82
+ labelWidth,
83
+ isThreeD,
84
+ animatedHeight,
85
+ appearingOpacity,
86
+ autoShiftLabels,
87
+ getPropsCommonForBarAndStack,
88
+ barAndLineChartsWrapperProps,
89
+ autoShiftLabelsForNegativeStacks,
90
+ } = useBarChart({
91
+ ...props,
92
+ heightValue,
93
+ widthValue,
94
+ opacValue,
95
+ parentWidth: props.parentWidth ?? screenWidth,
96
+ });
97
+
98
+ const labelsAppear = useCallback(() => {
99
+ opacValue.setValue(0);
100
+ Animated.timing(opacValue, {
101
+ toValue: 1,
102
+ duration: 500,
103
+ easing: Easing.ease,
104
+ useNativeDriver: false,
105
+ }).start();
106
+ }, [opacValue]);
107
+
108
+ const decreaseWidth = useCallback(() => {
109
+ widthValue.setValue(0);
110
+ Animated.timing(widthValue, {
111
+ toValue: 1,
112
+ duration: lineConfig.animationDuration,
113
+ easing: Easing.linear,
114
+ useNativeDriver: false,
115
+ }).start();
116
+ }, [lineConfig.animationDuration, widthValue]);
117
+
118
+ useEffect(() => {
119
+ if (lineConfig.isAnimated) {
120
+ setTimeout(() => decreaseWidth(), lineConfig.delay || 0);
121
+ }
122
+ setTimeout(() => labelsAppear(), animationDuration);
123
+ }, [decreaseWidth, labelsAppear, animationDuration]);
124
+
125
+ const renderPointer = (lineNumber: number) => {
126
+ if (lineNumber === 1 && hidePointer1) return;
127
+
128
+ const pointerItemLocal = pointerItem;
129
+ const pointerYLocal = pointerY;
130
+ const pointerColorLocal = pointerConfig?.pointer1Color || pointerColor;
131
+
132
+ return Pointer({
133
+ pointerX,
134
+ pointerYLocal,
135
+ pointerComponent,
136
+ pointerHeight,
137
+ pointerRadius,
138
+ pointerWidth,
139
+ pointerItemLocal,
140
+ pointerColorLocal,
141
+ });
142
+ };
143
+
144
+ const renderStripAndLabel = pointerLabelComponent => {
145
+ let pointerItemLocal,
146
+ pointerYLocal = pointerY;
147
+
148
+ pointerItemLocal = [pointerItem];
149
+ return StripAndLabel({
150
+ autoAdjustPointerLabelPosition,
151
+ pointerX,
152
+ pointerLabelWidth,
153
+ activatePointersOnLongPress,
154
+ yAxisLabelWidth,
155
+ pointerRadius,
156
+ pointerWidth,
157
+ shiftPointerLabelX,
158
+ pointerLabelHeight,
159
+ pointerYLocal,
160
+ pointerStripUptoDataPoint,
161
+ pointerStripHeight,
162
+ shiftPointerLabelY,
163
+ pointerItemLocal,
164
+ showPointerStrip,
165
+ pointerStripWidth,
166
+ containerHeight,
167
+ xAxisThickness,
168
+ pointerStripColor,
169
+ pointerConfig,
170
+ pointerLabelComponent,
171
+ scrollX: 0,
172
+ pointerEvents,
173
+ isBarChart: true,
174
+ });
175
+ };
176
+
177
+ const renderChartContent = () => {
178
+ if (pointerConfig) {
179
+ return (
180
+ <View
181
+ onStartShouldSetResponder={evt => (pointerConfig ? true : false)}
182
+ onMoveShouldSetResponder={evt => (pointerConfig ? true : false)}
183
+ onResponderGrant={evt => {
184
+ if (!pointerConfig) return;
185
+ setResponderStartTime(evt.timeStamp);
186
+ if (activatePointersOnLongPress) {
187
+ return;
188
+ }
189
+ let x = evt.nativeEvent.locationX;
190
+ if (
191
+ !activatePointersOnLongPress &&
192
+ x > (props.width || screenWidth)
193
+ )
194
+ return;
195
+ let factor =
196
+ (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
197
+ factor = Math.round(factor);
198
+ factor = Math.min(factor, data.length - 1);
199
+ factor = Math.max(factor, 0);
200
+ let z =
201
+ initialSpacing +
202
+ (spacing + barWidth) * factor -
203
+ (pointerRadius || pointerWidth / 2) +
204
+ barWidth / 2;
205
+ setPointerX(z);
206
+ setPointerIndex(factor);
207
+ let item, y;
208
+ item = (props.stackData ?? data)[factor];
209
+ const stackSum = item.stacks?.reduce(
210
+ (acc, stack) => acc + (stack.value ?? 0),
211
+ 0,
212
+ );
213
+ y =
214
+ containerHeight -
215
+ ((stackSum ?? item.value) * containerHeight) / maxValue -
216
+ (pointerRadius || pointerHeight / 2) +
217
+ 10;
218
+ setPointerY(y);
219
+ setPointerItem(item);
220
+ }}
221
+ onResponderMove={evt => {
222
+ if (!pointerConfig) return;
223
+ if (
224
+ activatePointersOnLongPress &&
225
+ evt.timeStamp - responderStartTime < activatePointersDelay
226
+ ) {
227
+ return;
228
+ } else {
229
+ setResponderActive(true);
230
+ }
231
+ let x = evt.nativeEvent.locationX;
232
+ if (
233
+ !activatePointersOnLongPress &&
234
+ x > (props.width || screenWidth)
235
+ )
236
+ return;
237
+ let factor =
238
+ (x - initialSpacing - barWidth / 2) / (spacing + barWidth);
239
+ factor = Math.round(factor);
240
+ factor = Math.min(factor, (props.stackData ?? data).length - 1);
241
+ factor = Math.max(factor, 0);
242
+ let z =
243
+ initialSpacing +
244
+ (spacing + barWidth) * factor -
245
+ (pointerRadius || pointerWidth / 2) +
246
+ barWidth / 2;
247
+ let item, y;
248
+ setPointerX(z);
249
+ setPointerIndex(factor);
250
+ item = (props.stackData ?? data)[factor];
251
+ const stackSum = item.stacks?.reduce(
252
+ (acc, stack) => acc + (stack.value ?? 0),
253
+ 0,
254
+ );
255
+ y =
256
+ containerHeight -
257
+ ((stackSum ?? item.value) * containerHeight) / maxValue -
258
+ (pointerRadius || pointerHeight / 2) +
259
+ 10;
260
+ setPointerY(y);
261
+ setPointerItem(item);
262
+ }}
263
+ onResponderEnd={evt => {
264
+ setResponderStartTime(0);
265
+ setPointerIndex(-1);
266
+ setResponderActive(false);
267
+ if (!persistPointer)
268
+ setTimeout(() => setPointerX(0), pointerVanishDelay);
269
+ }}
270
+ onResponderTerminationRequest={evt => false}
271
+ style={{
272
+ position: 'absolute',
273
+ height: containerHeightIncludingBelowXAxis,
274
+ bottom: 60,
275
+ paddingLeft: initialSpacing,
276
+ width: totalWidth,
277
+ flexDirection: 'row',
278
+ }}>
279
+ {pointerX > 0 && stripBehindBars ? (
280
+ <View
281
+ pointerEvents={pointerEvents ?? 'none'}
282
+ style={{
283
+ position: 'absolute',
284
+ height:
285
+ extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
286
+ bottom: xAxisLabelsVerticalShift + labelsExtraHeight,
287
+ width: totalWidth,
288
+ }}>
289
+ {renderStripAndLabel(null)}
290
+ </View>
291
+ ) : null}
292
+ {renderChart()}
293
+ {pointerX > 0 ? (
294
+ <View
295
+ pointerEvents={pointerEvents ?? 'none'}
296
+ style={{
297
+ position: 'absolute',
298
+ height:
299
+ extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
300
+ bottom: xAxisLabelsVerticalShift + labelsExtraHeight,
301
+ width: totalWidth,
302
+ zIndex: 20,
303
+ }}>
304
+ {!stripOverPointer &&
305
+ !stripBehindBars &&
306
+ renderStripAndLabel(null)}
307
+ {renderPointer(1)}
308
+ {stripOverPointer &&
309
+ !stripBehindBars &&
310
+ renderStripAndLabel(null)}
311
+ {
312
+ pointerLabelComponent &&
313
+ renderStripAndLabel(pointerLabelComponent) // no matter what, pointerLabelComponent will be rendered at last -> over the chart content
314
+ }
315
+ </View>
316
+ ) : null}
317
+ </View>
318
+ );
319
+ } else {
320
+ return renderChart();
321
+ }
322
+ };
323
+
324
+ const renderChart = () => {
325
+ if (props.stackData) {
326
+ return props.stackData.map((item, index) => {
327
+ return (
328
+ <RenderStackBars
329
+ stackData={props.stackData || []}
330
+ isAnimated={isAnimated}
331
+ animationDuration={animationDuration}
332
+ stackBorderRadius={props.stackBorderRadius}
333
+ stackBorderTopLeftRadius={props.stackBorderTopLeftRadius}
334
+ stackBorderTopRightRadius={props.stackBorderTopRightRadius}
335
+ stackBorderBottomLeftRadius={props.stackBorderBottomLeftRadius}
336
+ stackBorderBottomRightRadius={props.stackBorderBottomRightRadius}
337
+ autoShiftLabelsForNegativeStacks={autoShiftLabelsForNegativeStacks}
338
+ {...getPropsCommonForBarAndStack(item, index)}
339
+ />
340
+ );
341
+ });
342
+ } else {
343
+ return data.map((item, index) => (
344
+ <RenderBars
345
+ data={data}
346
+ side={side}
347
+ minHeight={props.minHeight ?? (isAnimated && !isThreeD ? 0.1 : 0)}
348
+ sideWidth={props.sideWidth}
349
+ labelWidth={labelWidth}
350
+ isThreeD={isThreeD}
351
+ isAnimated={isAnimated}
352
+ animationDuration={animationDuration}
353
+ animatedHeight={animatedHeight}
354
+ appearingOpacity={appearingOpacity}
355
+ roundedTop={props.roundedTop}
356
+ roundedBottom={props.roundedBottom}
357
+ frontColor={props.frontColor}
358
+ sideColor={props.sideColor}
359
+ topColor={props.topColor}
360
+ cappedBars={props.cappedBars}
361
+ capThickness={props.capThickness}
362
+ capColor={props.capColor}
363
+ capRadius={props.capRadius}
364
+ autoShiftLabels={autoShiftLabels}
365
+ barMarginBottom={props.barMarginBottom}
366
+ barStyle={props.barStyle}
367
+ {...getPropsCommonForBarAndStack(item, index)}
368
+ />
369
+ ));
370
+ }
371
+ };
372
+
373
+ return (
374
+ <BarAndLineChartsWrapper
375
+ {...barAndLineChartsWrapperProps}
376
+ scrollRef={scrollRef}
377
+ renderChartContent={renderChartContent}
378
+ remainingScrollViewProps={remainingScrollViewProps}
379
+ />
380
+ );
381
+ };
@@ -0,0 +1,47 @@
1
+ import {StyleSheet} from 'react-native';
2
+
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ width: '100%',
6
+ marginBottom: 40,
7
+ marginRight: 40,
8
+ },
9
+ horizBar: {
10
+ flexDirection: 'row',
11
+ },
12
+ leftLabel: {
13
+ justifyContent: 'center',
14
+ alignItems: 'center',
15
+ },
16
+ lastLeftLabel: {
17
+ justifyContent: 'center',
18
+ alignItems: 'center',
19
+ },
20
+ leftPart: {
21
+ justifyContent: 'center',
22
+ width: '100%',
23
+ },
24
+ lastLeftPart: {
25
+ justifyContent: 'flex-end',
26
+ width: '100%',
27
+ },
28
+ line: {
29
+ width: '100%',
30
+ height: 1,
31
+ backgroundColor: 'gray',
32
+ opacity: 0.5,
33
+ },
34
+ lastLine: {
35
+ width: '100%',
36
+ height: 1,
37
+ backgroundColor: 'black',
38
+ },
39
+ bottomLabel: {
40
+ width: '100%',
41
+ },
42
+ customDataPointContainer: {
43
+ position: 'absolute',
44
+ justifyContent: 'center',
45
+ alignItems: 'center',
46
+ },
47
+ });
@@ -0,0 +1,258 @@
1
+ import React, {useEffect, useState} from 'react';
2
+ import {
3
+ View,
4
+ StyleSheet,
5
+ LayoutAnimation,
6
+ Platform,
7
+ UIManager,
8
+ Text,
9
+ } from 'react-native';
10
+ import Svg, {Defs, Rect} from 'react-native-svg';
11
+ import {styles} from './styles';
12
+ import LinearGradient from "../common/LinearGradient";
13
+ import {
14
+ useAnimatedThreeDBar,
15
+ animatedBarPropTypes,
16
+ trianglePropTypes,
17
+ } from 'gifted-charts-core';
18
+
19
+ if (Platform.OS === 'android') {
20
+ UIManager.setLayoutAnimationEnabledExperimental &&
21
+ UIManager.setLayoutAnimationEnabledExperimental(true);
22
+ }
23
+
24
+ const TriangleCorner = (props: trianglePropTypes) => {
25
+ return (
26
+ <View
27
+ style={[
28
+ triangleStyles.triangleCorner,
29
+ props.style,
30
+ {
31
+ borderRightWidth: props.width / 2,
32
+ borderTopWidth: props.width / 2,
33
+ borderTopColor: props.color,
34
+ },
35
+ ]}
36
+ />
37
+ );
38
+ };
39
+
40
+ const triangleStyles = StyleSheet.create({
41
+ triangleCorner: {
42
+ width: 0,
43
+ height: 0,
44
+ backgroundColor: 'transparent',
45
+ borderStyle: 'solid',
46
+ borderRightColor: 'transparent',
47
+ transform: [{rotate: '90deg'}],
48
+ },
49
+ });
50
+
51
+ const AnimatedThreeDBar = (props: animatedBarPropTypes) => {
52
+ const heightCopy = props.height;
53
+ const [height, setHeight] = useState(
54
+ props.isAnimated ? (Platform.OS === 'ios' ? 0 : 20) : heightCopy,
55
+ );
56
+
57
+ const {
58
+ isAnimated,
59
+ animationDuration,
60
+ item,
61
+ index,
62
+ barWidth,
63
+ sideWidth,
64
+ barStyle,
65
+ barBackgroundPattern,
66
+ barInnerComponent,
67
+ patternId,
68
+ intactTopLabel,
69
+ showValuesAsTopLabel,
70
+ topLabelContainerStyle,
71
+ topLabelTextStyle,
72
+ } = props;
73
+
74
+ const {
75
+ showGradient,
76
+ gradientColor,
77
+ frontColor,
78
+ sideColor,
79
+ topColor,
80
+ opacity,
81
+ initialRender,
82
+ setInitialRender,
83
+ } = useAnimatedThreeDBar(props);
84
+
85
+ useEffect(() => {
86
+ if (isAnimated) {
87
+ if (initialRender) {
88
+ setTimeout(() => {
89
+ layoutAppear();
90
+ }, 20);
91
+ } else {
92
+ elevate();
93
+ }
94
+ }
95
+ }, [props.height]);
96
+
97
+ const elevate = () => {
98
+ LayoutAnimation.configureNext({
99
+ duration: animationDuration,
100
+ update: {type: 'linear', property: 'scaleY'},
101
+ });
102
+ setHeight(props.height);
103
+ };
104
+
105
+ const layoutAppear = () => {
106
+ LayoutAnimation.configureNext({
107
+ duration: Platform.OS == 'ios' ? animationDuration : 20,
108
+ create: {type: 'linear', property: 'scaleY'},
109
+ // update: { type: 'linear' }
110
+ });
111
+ setInitialRender(false);
112
+ setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
113
+ };
114
+
115
+ return (
116
+ <View style={styles.container}>
117
+ {!initialRender && (
118
+ <View
119
+ style={[
120
+ styles.row,
121
+ {opacity: opacity, position: 'absolute', bottom: 0},
122
+ props.side === 'right' && {transform: [{rotateY: '180deg'}]},
123
+ ]}>
124
+ {/******************* Top View *****************/}
125
+ {props.height ? (
126
+ <>
127
+ <View style={{position: 'absolute', top: sideWidth / -2}}>
128
+ <TriangleCorner
129
+ color={topColor}
130
+ width={sideWidth}
131
+ style={{transform: [{rotate: '90deg'}], opacity: opacity}}
132
+ />
133
+ </View>
134
+ <View style={{position: 'absolute', top: sideWidth / -2}}>
135
+ <View
136
+ style={{
137
+ width: barWidth,
138
+ height: barWidth,
139
+ // left: width / 2,
140
+ backgroundColor: topColor,
141
+ opacity: opacity,
142
+ }}
143
+ />
144
+ </View>
145
+ <View
146
+ style={{
147
+ position: 'absolute',
148
+ top: sideWidth / -2,
149
+ left: barWidth - 1,
150
+ }}>
151
+ <TriangleCorner
152
+ color={topColor}
153
+ width={sideWidth}
154
+ style={{transform: [{rotate: '-90deg'}], opacity: opacity}}
155
+ />
156
+ </View>
157
+ </>
158
+ ) : null}
159
+
160
+ {/*******************************************************************/}
161
+
162
+ <View style={{marginTop: sideWidth / -2 - 1}}>
163
+ <TriangleCorner
164
+ color={height ? sideColor : 'transparent'}
165
+ width={sideWidth}
166
+ style={{transform: [{rotate: '-90deg'}], opacity: opacity}}
167
+ />
168
+ <View
169
+ style={{
170
+ width: sideWidth / 2 + 1,
171
+ height: height - sideWidth / 2, //animatedSideHeight
172
+ backgroundColor: sideColor,
173
+ opacity: opacity,
174
+ }}
175
+ />
176
+ <TriangleCorner
177
+ color={height ? sideColor : 'transparent'}
178
+ width={sideWidth + 1}
179
+ style={{transform: [{rotate: '90deg'}], opacity: opacity}}
180
+ />
181
+ </View>
182
+
183
+ <View
184
+ style={[
185
+ {
186
+ width: barWidth,
187
+ height: height, //animatedHeight
188
+ backgroundColor: frontColor,
189
+ borderLeftWidth: StyleSheet.hairlineWidth,
190
+ borderTopWidth: StyleSheet.hairlineWidth,
191
+ borderColor: 'white',
192
+ opacity: opacity,
193
+ },
194
+ item.barStyle || barStyle,
195
+ ]}>
196
+ {showGradient && (
197
+ <LinearGradient
198
+ style={{position: 'absolute', width: '100%', height: '100%'}}
199
+ start={{x: 0, y: 0}}
200
+ end={{x: 1, y: 1}}
201
+ colors={[gradientColor, frontColor]}
202
+ />
203
+ )}
204
+ {barBackgroundPattern && (
205
+ <Svg>
206
+ <Defs>{barBackgroundPattern()}</Defs>
207
+ <Rect
208
+ stroke="transparent"
209
+ x="1"
210
+ y="1"
211
+ width={barWidth || 30}
212
+ height={height}
213
+ fill={`url(#${patternId})`}
214
+ />
215
+ </Svg>
216
+ )}
217
+ {barInnerComponent ? (
218
+ <View style={{height: '100%', width: '100%'}}>
219
+ {barInnerComponent(item, index)}
220
+ </View>
221
+ ) : null}
222
+ </View>
223
+
224
+ {/******************* Top Label *****************/}
225
+
226
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
227
+ <View
228
+ style={[
229
+ {
230
+ position: 'absolute',
231
+ top: barWidth * -2,
232
+ height: (barWidth * 3) / 2,
233
+ width: (barWidth * 3) / 2,
234
+ justifyContent: 'flex-end',
235
+ alignItems: 'center',
236
+ opacity: opacity,
237
+ },
238
+ props.horizontal &&
239
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
240
+ props.side === 'right' && {transform: [{rotateY: '180deg'}]},
241
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
242
+ ]}>
243
+ {showValuesAsTopLabel ? (
244
+ <Text style={topLabelTextStyle}>{item.value}</Text>
245
+ ) : (
246
+ item.topLabelComponent?.()
247
+ )}
248
+ </View>
249
+ )}
250
+
251
+ {/*******************************************************************/}
252
+ </View>
253
+ )}
254
+ </View>
255
+ );
256
+ };
257
+
258
+ export default AnimatedThreeDBar;
@@ -0,0 +1,14 @@
1
+ import {StyleSheet} from 'react-native';
2
+
3
+ export const styles = StyleSheet.create({
4
+ container: {
5
+ flex: 1,
6
+ // width: '100%',
7
+ // height: '100%',
8
+ justifyContent: 'center',
9
+ alignItems: 'center',
10
+ },
11
+ row: {
12
+ flexDirection: 'row',
13
+ },
14
+ });