react-native-gifted-charts 1.0.0 → 1.0.4
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 +2 -1
- package/src/BarChart/Animated2DWithGradient.tsx +3 -2
- package/src/BarChart/RenderBars.tsx +25 -16
- package/src/BarChart/RenderStackBars.tsx +15 -14
- package/src/BarChart/index.tsx +137 -7
- package/src/Components/AnimatedBar/index.tsx +3 -3
- package/src/Components/ThreeDBar/index.tsx +5 -2
- package/src/LineChart/index.tsx +23 -6
- package/src/PieChart/index.tsx +4 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-gifted-charts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
|
|
5
5
|
"main": "src/index.tsx",
|
|
6
6
|
"files": [
|
|
@@ -51,6 +51,7 @@
|
|
|
51
51
|
"react-native": "*"
|
|
52
52
|
},
|
|
53
53
|
"keywords": [
|
|
54
|
+
"react-native",
|
|
54
55
|
"chart",
|
|
55
56
|
"charts",
|
|
56
57
|
"graph",
|
|
@@ -223,12 +223,13 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
223
223
|
height: item.barWidth || 30,
|
|
224
224
|
width: item.barWidth || 30,
|
|
225
225
|
justifyContent:
|
|
226
|
-
props.horizontal && !props.intactTopLabel
|
|
226
|
+
(props.horizontal && !props.intactTopLabel) || item.value < 0
|
|
227
227
|
? 'center'
|
|
228
228
|
: 'flex-end',
|
|
229
229
|
alignItems: 'center',
|
|
230
230
|
opacity: opacity,
|
|
231
231
|
},
|
|
232
|
+
item.value < 0 && {transform:[{rotate:'180deg'}]},
|
|
232
233
|
props.horizontal &&
|
|
233
234
|
!props.intactTopLabel && {transform: [{rotate: '270deg'}]},
|
|
234
235
|
item.topLabelContainerStyle,
|
|
@@ -242,4 +243,4 @@ const Animated2DWithGradient = (props: propTypes) => {
|
|
|
242
243
|
);
|
|
243
244
|
};
|
|
244
245
|
|
|
245
|
-
export default Animated2DWithGradient;
|
|
246
|
+
export default Animated2DWithGradient;
|
|
@@ -57,6 +57,7 @@ type Props = {
|
|
|
57
57
|
horizontal: Boolean;
|
|
58
58
|
intactTopLabel: Boolean;
|
|
59
59
|
barBorderRadius?: number;
|
|
60
|
+
autoShiftLabels?: Boolean;
|
|
60
61
|
};
|
|
61
62
|
type itemType = {
|
|
62
63
|
value?: number;
|
|
@@ -99,8 +100,9 @@ const RenderBars = (props: Props) => {
|
|
|
99
100
|
appearingOpacity,
|
|
100
101
|
opacity,
|
|
101
102
|
animationDuration,
|
|
103
|
+
autoShiftLabels,
|
|
102
104
|
} = props;
|
|
103
|
-
const renderLabel = (label: String, labelTextStyle: any) => {
|
|
105
|
+
const renderLabel = (label: String, labelTextStyle: any, value: number) => {
|
|
104
106
|
return (
|
|
105
107
|
<View
|
|
106
108
|
style={[
|
|
@@ -119,10 +121,12 @@ const RenderBars = (props: Props) => {
|
|
|
119
121
|
rotateLabel
|
|
120
122
|
? props.horizontal
|
|
121
123
|
? {transform: [{rotate: '330deg'}]}
|
|
122
|
-
: {transform: [{rotate: '60deg'}]}
|
|
124
|
+
: {transform: [{rotate: value < 0 ? '240deg' : '60deg'}, {translateX: value < 0 ? 56 : 0}, {translateY: value < 0 ? 32 : 0}]}
|
|
123
125
|
: props.horizontal
|
|
124
126
|
? {transform: [{rotate: '-90deg'}]}
|
|
125
|
-
:
|
|
127
|
+
: value < 0
|
|
128
|
+
?{transform:[{rotate:'180deg'},{translateY:autoShiftLabels?0:32}]}
|
|
129
|
+
:{},
|
|
126
130
|
]}>
|
|
127
131
|
{item.labelComponent ? (
|
|
128
132
|
item.labelComponent()
|
|
@@ -137,7 +141,7 @@ const RenderBars = (props: Props) => {
|
|
|
137
141
|
);
|
|
138
142
|
};
|
|
139
143
|
|
|
140
|
-
const renderAnimatedLabel = (label: String, labelTextStyle: any) => {
|
|
144
|
+
const renderAnimatedLabel = (label: String, labelTextStyle: any, value: number) => {
|
|
141
145
|
return (
|
|
142
146
|
<Animated.View
|
|
143
147
|
style={[
|
|
@@ -150,9 +154,11 @@ const RenderBars = (props: Props) => {
|
|
|
150
154
|
30) +
|
|
151
155
|
spacing / 2,
|
|
152
156
|
position: 'absolute',
|
|
157
|
+
left: -4,
|
|
153
158
|
bottom: rotateLabel ? -40 : -25,
|
|
154
159
|
opacity: appearingOpacity,
|
|
155
160
|
},
|
|
161
|
+
value < 0 && {transform:[{rotate:'180deg'}]},
|
|
156
162
|
rotateLabel
|
|
157
163
|
? props.horizontal
|
|
158
164
|
? {transform: [{rotate: '330deg'}]}
|
|
@@ -244,11 +250,12 @@ const RenderBars = (props: Props) => {
|
|
|
244
250
|
height: item.barWidth || props.barWidth || 30,
|
|
245
251
|
width: item.barWidth || props.barWidth || 30,
|
|
246
252
|
justifyContent:
|
|
247
|
-
props.horizontal && !props.intactTopLabel
|
|
253
|
+
(props.horizontal && !props.intactTopLabel) || item.value < 0
|
|
248
254
|
? 'center'
|
|
249
255
|
: 'flex-end',
|
|
250
256
|
alignItems: 'center',
|
|
251
257
|
},
|
|
258
|
+
item.value < 0 && {transform:[{rotate:'180deg'}]},
|
|
252
259
|
props.horizontal &&
|
|
253
260
|
!props.intactTopLabel && {transform: [{rotate: '270deg'}]},
|
|
254
261
|
item.topLabelContainerStyle,
|
|
@@ -270,12 +277,13 @@ const RenderBars = (props: Props) => {
|
|
|
270
277
|
// overflow: 'visible',
|
|
271
278
|
marginBottom: 60,
|
|
272
279
|
width: item.barWidth || props.barWidth || 30,
|
|
273
|
-
height: item.topLabelComponent
|
|
280
|
+
height: item.value>=0 &&(!isThreeD || isAnimated) && item.topLabelComponent
|
|
274
281
|
? (item.topLabelComponentHeight || 30) +
|
|
275
|
-
(item.value * (containerHeight || 200)) / (maxValue || 200)
|
|
276
|
-
: (item.value * (containerHeight || 200)) / (maxValue || 200),
|
|
282
|
+
(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)
|
|
283
|
+
: (Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200),
|
|
277
284
|
marginRight: spacing,
|
|
278
285
|
},
|
|
286
|
+
item.value < 0 && {transform:[{translateY:(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)},{rotateZ:'180deg'}]},
|
|
279
287
|
// !isThreeD && !item.showGradient && !props.showGradient &&
|
|
280
288
|
// { backgroundColor: item.frontColor || props.frontColor || 'black' },
|
|
281
289
|
side !== 'right' && {zIndex: data.length - index},
|
|
@@ -325,7 +333,7 @@ const RenderBars = (props: Props) => {
|
|
|
325
333
|
topLabelComponent={item.topLabelComponent}
|
|
326
334
|
opacity={opacity || 1}
|
|
327
335
|
animationDuration={animationDuration || 800}
|
|
328
|
-
height={(item.value * (containerHeight || 200)) / (maxValue || 200)}
|
|
336
|
+
height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
|
|
329
337
|
intactTopLabel={props.intactTopLabel}
|
|
330
338
|
horizontal={props.horizontal}
|
|
331
339
|
/>
|
|
@@ -350,7 +358,8 @@ const RenderBars = (props: Props) => {
|
|
|
350
358
|
opacity={opacity || 1}
|
|
351
359
|
horizontal={props.horizontal}
|
|
352
360
|
intactTopLabel={props.intactTopLabel}
|
|
353
|
-
height={(item.value * (containerHeight || 200)) / (maxValue || 200)}
|
|
361
|
+
height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
|
|
362
|
+
value={item.value}
|
|
354
363
|
/>
|
|
355
364
|
)
|
|
356
365
|
) : item.showGradient || props.showGradient ? (
|
|
@@ -364,7 +373,7 @@ const RenderBars = (props: Props) => {
|
|
|
364
373
|
roundedTop={props.roundedTop || false}
|
|
365
374
|
gradientColor={props.gradientColor}
|
|
366
375
|
frontColor={props.frontColor || 'black'}
|
|
367
|
-
height={(item.value * (containerHeight || 200)) / (maxValue || 200)}
|
|
376
|
+
height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
|
|
368
377
|
cappedBars={props.cappedBars}
|
|
369
378
|
capThickness={props.capThickness}
|
|
370
379
|
capColor={props.capColor}
|
|
@@ -387,7 +396,7 @@ const RenderBars = (props: Props) => {
|
|
|
387
396
|
gradientColor={props.gradientColor}
|
|
388
397
|
noGradient
|
|
389
398
|
frontColor={props.frontColor || 'black'}
|
|
390
|
-
height={(item.value * (containerHeight || 200)) / (maxValue || 200)}
|
|
399
|
+
height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
|
|
391
400
|
cappedBars={props.cappedBars}
|
|
392
401
|
capThickness={props.capThickness}
|
|
393
402
|
capColor={props.capColor}
|
|
@@ -408,7 +417,7 @@ const RenderBars = (props: Props) => {
|
|
|
408
417
|
noGradient
|
|
409
418
|
noAnimation
|
|
410
419
|
frontColor={props.frontColor || 'black'}
|
|
411
|
-
height={(item.value * (containerHeight || 200)) / (maxValue || 200)}
|
|
420
|
+
height={(Math.abs(item.value) * (containerHeight || 200)) / (maxValue || 200)}
|
|
412
421
|
cappedBars={props.cappedBars}
|
|
413
422
|
capThickness={props.capThickness}
|
|
414
423
|
capColor={props.capColor}
|
|
@@ -419,10 +428,10 @@ const RenderBars = (props: Props) => {
|
|
|
419
428
|
/>
|
|
420
429
|
)}
|
|
421
430
|
{isAnimated
|
|
422
|
-
? renderAnimatedLabel(item.label || '', item.labelTextStyle)
|
|
423
|
-
: renderLabel(item.label || '', item.labelTextStyle)}
|
|
431
|
+
? renderAnimatedLabel(item.label || '', item.labelTextStyle,item.value)
|
|
432
|
+
: renderLabel(item.label || '', item.labelTextStyle,item.value)}
|
|
424
433
|
</TouchableOpacity>
|
|
425
434
|
);
|
|
426
435
|
};
|
|
427
436
|
|
|
428
|
-
export default RenderBars;
|
|
437
|
+
export default RenderBars;
|
|
@@ -33,6 +33,7 @@ type Props = {
|
|
|
33
33
|
horizontal: Boolean;
|
|
34
34
|
intactTopLabel: Boolean;
|
|
35
35
|
barBorderRadius?: number;
|
|
36
|
+
xAxisThickness: number;
|
|
36
37
|
};
|
|
37
38
|
type itemType = {
|
|
38
39
|
value?: number;
|
|
@@ -51,7 +52,7 @@ type itemType = {
|
|
|
51
52
|
stacks?: Array<any>;
|
|
52
53
|
};
|
|
53
54
|
const RenderStackBars = (props: Props) => {
|
|
54
|
-
const {item, containerHeight, maxValue, spacing, rotateLabel} = props;
|
|
55
|
+
const {item, containerHeight, maxValue, spacing, rotateLabel,xAxisThickness} = props;
|
|
55
56
|
const disablePress = props.disablePress || false;
|
|
56
57
|
const renderLabel = (label: String, labelTextStyle: any) => {
|
|
57
58
|
return (
|
|
@@ -60,7 +61,6 @@ const RenderStackBars = (props: Props) => {
|
|
|
60
61
|
{
|
|
61
62
|
width:
|
|
62
63
|
(item.stacks[0].barWidth || props.barWidth || 30) + spacing / 2,
|
|
63
|
-
left: -6,
|
|
64
64
|
position: 'absolute',
|
|
65
65
|
bottom: rotateLabel ? -40 : -25,
|
|
66
66
|
},
|
|
@@ -87,18 +87,16 @@ const RenderStackBars = (props: Props) => {
|
|
|
87
87
|
let position = 0;
|
|
88
88
|
for (let i = 0; i < index; i++) {
|
|
89
89
|
position +=
|
|
90
|
-
(props.item.stacks[i].value * (containerHeight || 200)) /
|
|
90
|
+
(Math.abs(props.item.stacks[i].value) * (containerHeight || 200)) /
|
|
91
91
|
(maxValue || 200);
|
|
92
92
|
}
|
|
93
93
|
return position;
|
|
94
94
|
};
|
|
95
95
|
|
|
96
|
-
const
|
|
97
|
-
return props.item.stacks.reduce((acc, stack) => acc + stack.value, 0);
|
|
98
|
-
};
|
|
96
|
+
const totalHeight = props.item.stacks.reduce((acc, stack) => acc + Math.abs(stack.value) * (containerHeight || 200) / (maxValue || 200), 0)
|
|
99
97
|
|
|
100
98
|
const static2DSimple = (item: itemType) => {
|
|
101
|
-
|
|
99
|
+
const cotainsNegative = item.stacks.some(item => item.value < 0)
|
|
102
100
|
return (
|
|
103
101
|
<>
|
|
104
102
|
<View
|
|
@@ -108,6 +106,11 @@ const RenderStackBars = (props: Props) => {
|
|
|
108
106
|
width: item.stacks[0].barWidth || props.barWidth || 30,
|
|
109
107
|
height: '100%',
|
|
110
108
|
},
|
|
109
|
+
cotainsNegative && {
|
|
110
|
+
transform: [
|
|
111
|
+
{translateY: totalHeight + xAxisThickness / 2},
|
|
112
|
+
{rotate:'180deg'}
|
|
113
|
+
]}
|
|
111
114
|
]}>
|
|
112
115
|
{item.stacks.map((stackItem, index) => {
|
|
113
116
|
return (
|
|
@@ -121,7 +124,7 @@ const RenderStackBars = (props: Props) => {
|
|
|
121
124
|
bottom: getPosition(index) + (stackItem.marginBottom || 0),
|
|
122
125
|
width: '100%',
|
|
123
126
|
height:
|
|
124
|
-
(stackItem.value * (containerHeight || 200)) /
|
|
127
|
+
(Math.abs(stackItem.value) * (containerHeight || 200)) /
|
|
125
128
|
(maxValue || 200) -
|
|
126
129
|
(stackItem.marginBottom || 0),
|
|
127
130
|
backgroundColor: stackItem.color || 'black',
|
|
@@ -147,15 +150,13 @@ const RenderStackBars = (props: Props) => {
|
|
|
147
150
|
style={[
|
|
148
151
|
{
|
|
149
152
|
position: 'absolute',
|
|
150
|
-
top: (item.barWidth || props.barWidth || 30) * -1,
|
|
153
|
+
top: cotainsNegative ? 0 : (item.barWidth || props.barWidth || 30) * -1,
|
|
151
154
|
height: item.barWidth || props.barWidth || 30,
|
|
152
155
|
width: item.barWidth || props.barWidth || 30,
|
|
153
|
-
justifyContent:
|
|
154
|
-
props.horizontal && !props.intactTopLabel
|
|
155
|
-
? 'center'
|
|
156
|
-
: 'flex-end',
|
|
156
|
+
justifyContent: 'center',
|
|
157
157
|
alignItems: 'center',
|
|
158
158
|
},
|
|
159
|
+
cotainsNegative && {transform: [{translateY: totalHeight * 2}]},
|
|
159
160
|
props.horizontal &&
|
|
160
161
|
!props.intactTopLabel && {transform: [{rotate: '270deg'}]},
|
|
161
162
|
item.topLabelContainerStyle,
|
|
@@ -174,7 +175,7 @@ const RenderStackBars = (props: Props) => {
|
|
|
174
175
|
// overflow: 'visible',
|
|
175
176
|
marginBottom: 60,
|
|
176
177
|
width: item.stacks[0].barWidth || props.barWidth || 30,
|
|
177
|
-
height:
|
|
178
|
+
height: totalHeight,
|
|
178
179
|
marginRight: spacing,
|
|
179
180
|
},
|
|
180
181
|
]}>
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import React, {
|
|
|
4
4
|
useEffect,
|
|
5
5
|
useMemo,
|
|
6
6
|
useState,
|
|
7
|
+
useRef,
|
|
7
8
|
} from 'react';
|
|
8
9
|
import {
|
|
9
10
|
View,
|
|
@@ -24,7 +25,9 @@ type PropTypes = {
|
|
|
24
25
|
width?: number;
|
|
25
26
|
height?: number;
|
|
26
27
|
noOfSections?: number;
|
|
28
|
+
noOfSectionsBelowXAxis?: number;
|
|
27
29
|
maxValue?: number;
|
|
30
|
+
minValue?: number;
|
|
28
31
|
stepHeight?: number;
|
|
29
32
|
stepValue?: number;
|
|
30
33
|
spacing?: number;
|
|
@@ -44,6 +47,7 @@ type PropTypes = {
|
|
|
44
47
|
yAxisTextStyle?: any;
|
|
45
48
|
yAxisLabelWidth?: number;
|
|
46
49
|
hideYAxisText?: Boolean;
|
|
50
|
+
yAxisSide?: string;
|
|
47
51
|
initialSpacing?: number;
|
|
48
52
|
barWidth?: number;
|
|
49
53
|
sideWidth?: number;
|
|
@@ -114,6 +118,9 @@ type PropTypes = {
|
|
|
114
118
|
yAxisLabelTexts?: Array<string>;
|
|
115
119
|
yAxisLabelPrefix?: String;
|
|
116
120
|
yAxisLabelSuffix?: String;
|
|
121
|
+
autoShiftLabels?: Boolean;
|
|
122
|
+
scrollToEnd?: Boolean;
|
|
123
|
+
scrollAnimation?: Boolean;
|
|
117
124
|
};
|
|
118
125
|
type lineConfigType = {
|
|
119
126
|
curved?: Boolean;
|
|
@@ -164,6 +171,7 @@ type itemType = {
|
|
|
164
171
|
};
|
|
165
172
|
|
|
166
173
|
export const BarChart = (props: PropTypes) => {
|
|
174
|
+
const scrollRef = useRef();
|
|
167
175
|
const [points, setPoints] = useState('');
|
|
168
176
|
const showLine = props.showLine || false;
|
|
169
177
|
const defaultLineConfig = {
|
|
@@ -216,13 +224,16 @@ export const BarChart = (props: PropTypes) => {
|
|
|
216
224
|
const containerHeight = props.height || 200;
|
|
217
225
|
const noOfSections = props.noOfSections || 10;
|
|
218
226
|
const horizSections = [{value: '0'}];
|
|
227
|
+
const horizSectionsBelow = [];
|
|
219
228
|
const stepHeight = props.stepHeight || containerHeight / noOfSections;
|
|
220
229
|
const data = useMemo(() => props.data || [], [props.data]);
|
|
221
230
|
const spacing = props.spacing === 0 ? 0 : props.spacing ? props.spacing : 20;
|
|
222
231
|
const labelWidth = props.labelWidth || 0;
|
|
232
|
+
const scrollToEnd = props.scrollToEnd || false;
|
|
233
|
+
const scrollAnimation = props.scrollAnimation === false ? false : true;
|
|
223
234
|
|
|
224
235
|
let totalWidth = spacing;
|
|
225
|
-
let maxItem = 0;
|
|
236
|
+
let maxItem = 0, minItem = 0;
|
|
226
237
|
if (props.stackData) {
|
|
227
238
|
props.stackData.forEach(stackItem => {
|
|
228
239
|
// console.log('stackItem', stackItem);
|
|
@@ -234,6 +245,9 @@ export const BarChart = (props: PropTypes) => {
|
|
|
234
245
|
if (stackSum > maxItem) {
|
|
235
246
|
maxItem = stackSum;
|
|
236
247
|
}
|
|
248
|
+
if(stackSum < minItem){
|
|
249
|
+
minItem = stackSum;
|
|
250
|
+
}
|
|
237
251
|
totalWidth +=
|
|
238
252
|
(stackItem.stacks[0].barWidth || props.barWidth || 30) + spacing;
|
|
239
253
|
// console.log('totalWidth for stack===', totalWidth);
|
|
@@ -243,6 +257,9 @@ export const BarChart = (props: PropTypes) => {
|
|
|
243
257
|
if (item.value > maxItem) {
|
|
244
258
|
maxItem = item.value;
|
|
245
259
|
}
|
|
260
|
+
if(item.value < minItem){
|
|
261
|
+
minItem = item.value;
|
|
262
|
+
}
|
|
246
263
|
totalWidth +=
|
|
247
264
|
(item.barWidth || props.barWidth || 30) +
|
|
248
265
|
(item.spacing === 0 ? 0 : item.spacing || spacing);
|
|
@@ -254,13 +271,24 @@ export const BarChart = (props: PropTypes) => {
|
|
|
254
271
|
maxItem = maxItem + (10 - (maxItem % 10));
|
|
255
272
|
maxItem /= 10 * (props.roundToDigits || 1);
|
|
256
273
|
maxItem = parseFloat(maxItem.toFixed(props.roundToDigits || 1));
|
|
274
|
+
if(minItem !== 0){
|
|
275
|
+
minItem *= 10 * (props.roundToDigits || 1);
|
|
276
|
+
minItem = minItem - (10 + (minItem % 10));
|
|
277
|
+
minItem /= 10 * (props.roundToDigits || 1);
|
|
278
|
+
minItem = parseFloat(minItem.toFixed(props.roundToDigits || 1));
|
|
279
|
+
}
|
|
257
280
|
} else {
|
|
258
281
|
maxItem = maxItem + (10 - (maxItem % 10));
|
|
282
|
+
if(minItem !== 0){
|
|
283
|
+
minItem = minItem - (10 + (minItem % 10))
|
|
284
|
+
}
|
|
259
285
|
}
|
|
260
286
|
|
|
261
287
|
const maxValue = props.maxValue || maxItem;
|
|
288
|
+
const minValue = props.minValue || minItem;
|
|
262
289
|
|
|
263
290
|
const stepValue = props.stepValue || maxValue / noOfSections;
|
|
291
|
+
const noOfSectionsBelowXAxis = props.noOfSectionsBelowXAxis || (-minValue / stepValue);
|
|
264
292
|
const disableScroll = props.disableScroll || false;
|
|
265
293
|
const showScrollIndicator = props.showScrollIndicator || false;
|
|
266
294
|
const initialSpacing =
|
|
@@ -294,6 +322,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
294
322
|
|
|
295
323
|
const yAxisLabelPrefix = props.yAxisLabelPrefix || '';
|
|
296
324
|
const yAxisLabelSuffix = props.yAxisLabelSuffix || '';
|
|
325
|
+
const yAxisSide = props.yAxisSide || 'left';
|
|
297
326
|
|
|
298
327
|
const xAxisThickness =
|
|
299
328
|
props.xAxisThickness === 0
|
|
@@ -326,6 +355,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
326
355
|
const heightValue = useMemo(() => new Animated.Value(0), []);
|
|
327
356
|
const opacValue = useMemo(() => new Animated.Value(0), []);
|
|
328
357
|
const widthValue = useMemo(() => new Animated.Value(0), []);
|
|
358
|
+
const autoShiftLabels = props.autoShiftLabels || false;
|
|
329
359
|
|
|
330
360
|
const labelsAppear = useCallback(() => {
|
|
331
361
|
opacValue.setValue(0);
|
|
@@ -505,6 +535,19 @@ export const BarChart = (props: PropTypes) => {
|
|
|
505
535
|
: value.toString(),
|
|
506
536
|
});
|
|
507
537
|
}
|
|
538
|
+
if(noOfSectionsBelowXAxis){
|
|
539
|
+
for (let i = 1; i <= noOfSectionsBelowXAxis; i++) {
|
|
540
|
+
let value = stepValue * -i;
|
|
541
|
+
if (props.showFractionalValues || props.roundToDigits) {
|
|
542
|
+
value = parseFloat(value.toFixed(props.roundToDigits || 1));
|
|
543
|
+
}
|
|
544
|
+
horizSectionsBelow.push({
|
|
545
|
+
value: props.yAxisLabelTexts
|
|
546
|
+
? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ?? value.toString()
|
|
547
|
+
: value.toString(),
|
|
548
|
+
})
|
|
549
|
+
}
|
|
550
|
+
}
|
|
508
551
|
|
|
509
552
|
const animatedHeight = heightValue.interpolate({
|
|
510
553
|
inputRange: [0, 1],
|
|
@@ -557,6 +600,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
557
600
|
? props.width || totalWidth
|
|
558
601
|
: props.width || totalWidth + 11,
|
|
559
602
|
},
|
|
603
|
+
yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
|
|
560
604
|
]}>
|
|
561
605
|
<View
|
|
562
606
|
style={[
|
|
@@ -582,12 +626,13 @@ export const BarChart = (props: PropTypes) => {
|
|
|
582
626
|
style={[
|
|
583
627
|
yAxisTextStyle,
|
|
584
628
|
index === noOfSections && {marginBottom: stepHeight / -2},
|
|
585
|
-
horizontal
|
|
629
|
+
horizontal ? {
|
|
586
630
|
transform: [
|
|
587
631
|
{rotate: '270deg'},
|
|
588
632
|
{translateY: yAxisAtTop ? 0 : 50},
|
|
589
633
|
],
|
|
590
|
-
}
|
|
634
|
+
}:
|
|
635
|
+
yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
|
|
591
636
|
]}>
|
|
592
637
|
{label}
|
|
593
638
|
</Text>
|
|
@@ -683,6 +728,81 @@ export const BarChart = (props: PropTypes) => {
|
|
|
683
728
|
</View>
|
|
684
729
|
);
|
|
685
730
|
})}
|
|
731
|
+
{horizSectionsBelow.map((sectionItems, index) => {
|
|
732
|
+
let label = getLabel(sectionItems.value);
|
|
733
|
+
if (hideOrigin && index === horizSections.length - 1) {
|
|
734
|
+
label = '';
|
|
735
|
+
}
|
|
736
|
+
return (
|
|
737
|
+
<View
|
|
738
|
+
key={index}
|
|
739
|
+
style={[
|
|
740
|
+
styles.horizBar,
|
|
741
|
+
{
|
|
742
|
+
width: horizontal
|
|
743
|
+
? props.width || totalWidth
|
|
744
|
+
: props.width || totalWidth + 11,
|
|
745
|
+
},
|
|
746
|
+
index===0&&{marginTop:stepHeight/2}
|
|
747
|
+
]}>
|
|
748
|
+
<View
|
|
749
|
+
style={[
|
|
750
|
+
styles.leftLabel,
|
|
751
|
+
{
|
|
752
|
+
borderRightWidth: yAxisThickness,
|
|
753
|
+
borderColor: yAxisColor,
|
|
754
|
+
},
|
|
755
|
+
horizontal &&
|
|
756
|
+
!yAxisAtTop && {
|
|
757
|
+
transform: [{translateX: totalWidth + yAxisThickness}],
|
|
758
|
+
},
|
|
759
|
+
{
|
|
760
|
+
height: index===0?stepHeight*1.5:stepHeight,
|
|
761
|
+
width: yAxisLabelWidth,
|
|
762
|
+
},
|
|
763
|
+
index===0&&{marginTop:-stepHeight/2}
|
|
764
|
+
]}>
|
|
765
|
+
{!hideYAxisText ? (
|
|
766
|
+
<Text
|
|
767
|
+
numberOfLines={1}
|
|
768
|
+
ellipsizeMode={'clip'}
|
|
769
|
+
style={[
|
|
770
|
+
yAxisTextStyle,
|
|
771
|
+
index === 0 && {marginBottom: stepHeight / -2},
|
|
772
|
+
horizontal && {
|
|
773
|
+
transform: [
|
|
774
|
+
{rotate: '270deg'},
|
|
775
|
+
{translateY: yAxisAtTop ? 0 : 50},
|
|
776
|
+
],
|
|
777
|
+
},
|
|
778
|
+
]}>
|
|
779
|
+
{label}
|
|
780
|
+
</Text>
|
|
781
|
+
) : null}
|
|
782
|
+
</View>
|
|
783
|
+
<View
|
|
784
|
+
style={[
|
|
785
|
+
styles.leftPart,
|
|
786
|
+
{backgroundColor: backgroundColor},
|
|
787
|
+
]}>
|
|
788
|
+
{hideRules ? null : (
|
|
789
|
+
<Rule
|
|
790
|
+
config={{
|
|
791
|
+
thickness: rulesThickness,
|
|
792
|
+
color: rulesColor,
|
|
793
|
+
width: horizontal
|
|
794
|
+
? props.width || totalWidth
|
|
795
|
+
: (props.width || totalWidth) + 11,
|
|
796
|
+
dashWidth: dashWidth,
|
|
797
|
+
dashGap: dashGap,
|
|
798
|
+
type: rulesType,
|
|
799
|
+
}}
|
|
800
|
+
/>
|
|
801
|
+
)}
|
|
802
|
+
</View>
|
|
803
|
+
</View>
|
|
804
|
+
)
|
|
805
|
+
})}
|
|
686
806
|
</>
|
|
687
807
|
);
|
|
688
808
|
};
|
|
@@ -975,16 +1095,23 @@ export const BarChart = (props: PropTypes) => {
|
|
|
975
1095
|
style={[
|
|
976
1096
|
styles.container,
|
|
977
1097
|
{
|
|
978
|
-
height: containerHeight,
|
|
1098
|
+
height: containerHeight + horizSectionsBelow.length * stepHeight,
|
|
979
1099
|
},
|
|
1100
|
+
yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness },
|
|
980
1101
|
props.width && {width: props.width},
|
|
981
1102
|
horizontal && {transform: [{rotate: '90deg'}, {translateY: -15}]},
|
|
982
1103
|
]}>
|
|
983
1104
|
{props.hideAxesAndRules !== true && renderHorizSections()}
|
|
984
1105
|
<ScrollView
|
|
1106
|
+
ref={scrollRef}
|
|
1107
|
+
onContentSizeChange={()=>{
|
|
1108
|
+
if(scrollRef.current && scrollToEnd){
|
|
1109
|
+
scrollRef.current.scrollToEnd({animated: scrollAnimation});
|
|
1110
|
+
}
|
|
1111
|
+
}}
|
|
985
1112
|
style={[
|
|
986
1113
|
{
|
|
987
|
-
marginLeft: yAxisLabelWidth,
|
|
1114
|
+
marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth+10 : yAxisLabelWidth,
|
|
988
1115
|
position: 'absolute',
|
|
989
1116
|
bottom: stepHeight * -0.5 - 60 + xAxisThickness,
|
|
990
1117
|
},
|
|
@@ -995,8 +1122,9 @@ export const BarChart = (props: PropTypes) => {
|
|
|
995
1122
|
contentContainerStyle={[
|
|
996
1123
|
{
|
|
997
1124
|
// backgroundColor: 'yellow',
|
|
998
|
-
height: containerHeight + 130,
|
|
1125
|
+
height: containerHeight + 130 + horizSectionsBelow.length * stepHeight,
|
|
999
1126
|
paddingLeft: initialSpacing,
|
|
1127
|
+
paddingBottom:horizSectionsBelow.length * stepHeight,
|
|
1000
1128
|
alignItems: 'flex-end',
|
|
1001
1129
|
},
|
|
1002
1130
|
!props.width && {width: totalWidth},
|
|
@@ -1021,6 +1149,7 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1021
1149
|
containerHeight={containerHeight}
|
|
1022
1150
|
maxValue={maxValue}
|
|
1023
1151
|
spacing={spacing}
|
|
1152
|
+
xAxisThickness={xAxisThickness}
|
|
1024
1153
|
barWidth={props.barWidth}
|
|
1025
1154
|
opacity={opacity}
|
|
1026
1155
|
disablePress={props.disablePress}
|
|
@@ -1083,10 +1212,11 @@ export const BarChart = (props: PropTypes) => {
|
|
|
1083
1212
|
horizontal={horizontal}
|
|
1084
1213
|
intactTopLabel={intactTopLabel}
|
|
1085
1214
|
barBorderRadius={props.barBorderRadius}
|
|
1215
|
+
autoShiftLabels={autoShiftLabels}
|
|
1086
1216
|
/>
|
|
1087
1217
|
))}
|
|
1088
1218
|
</Fragment>
|
|
1089
1219
|
</ScrollView>
|
|
1090
1220
|
</View>
|
|
1091
1221
|
);
|
|
1092
|
-
};
|
|
1222
|
+
};
|
|
@@ -87,7 +87,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
|
|
|
87
87
|
const elevate = () => {
|
|
88
88
|
LayoutAnimation.configureNext({
|
|
89
89
|
duration: animationDuration,
|
|
90
|
-
update: {type: 'linear', property: '
|
|
90
|
+
update: {type: 'linear', property: 'scaleY'},
|
|
91
91
|
});
|
|
92
92
|
setHeight(props.height);
|
|
93
93
|
};
|
|
@@ -95,7 +95,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
|
|
|
95
95
|
const layoutAppear = () => {
|
|
96
96
|
LayoutAnimation.configureNext({
|
|
97
97
|
duration: Platform.OS == 'ios' ? animationDuration : 20,
|
|
98
|
-
create: {type: 'linear', property: '
|
|
98
|
+
create: {type: 'linear', property: 'scaleY'},
|
|
99
99
|
// update: { type: 'linear' }
|
|
100
100
|
});
|
|
101
101
|
setInitialRender(false);
|
|
@@ -237,4 +237,4 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
|
|
|
237
237
|
);
|
|
238
238
|
};
|
|
239
239
|
|
|
240
|
-
export default AnimatedBar;
|
|
240
|
+
export default AnimatedBar;
|
|
@@ -20,6 +20,7 @@ type PropTypes = {
|
|
|
20
20
|
side: String;
|
|
21
21
|
horizontal: Boolean;
|
|
22
22
|
intactTopLabel: Boolean;
|
|
23
|
+
value: number;
|
|
23
24
|
};
|
|
24
25
|
|
|
25
26
|
type TriangleProps = {
|
|
@@ -59,6 +60,7 @@ const ThreeDBar = (props: PropTypes) => {
|
|
|
59
60
|
const width = props.width;
|
|
60
61
|
const sideWidth = props.sideWidth;
|
|
61
62
|
const height = props.height;
|
|
63
|
+
const value = props.value;
|
|
62
64
|
|
|
63
65
|
const showGradient = props.showGradient || false;
|
|
64
66
|
const gradientColor = props.gradientColor || 'white';
|
|
@@ -160,12 +162,13 @@ const ThreeDBar = (props: PropTypes) => {
|
|
|
160
162
|
style={[
|
|
161
163
|
{
|
|
162
164
|
position: 'absolute',
|
|
163
|
-
top: width * -2,
|
|
165
|
+
top: value < 0 ? width * -1 : width * -2,
|
|
164
166
|
height: (width * 3) / 2,
|
|
165
167
|
width: width,
|
|
166
168
|
justifyContent: 'flex-end',
|
|
167
169
|
alignItems: 'center',
|
|
168
170
|
},
|
|
171
|
+
value < 0 && {transform:[{rotate:'180deg'}]},
|
|
169
172
|
props.horizontal &&
|
|
170
173
|
!props.intactTopLabel && {transform: [{rotate: '270deg'}]},
|
|
171
174
|
props.side === 'right'
|
|
@@ -182,4 +185,4 @@ const ThreeDBar = (props: PropTypes) => {
|
|
|
182
185
|
);
|
|
183
186
|
};
|
|
184
187
|
|
|
185
|
-
export default ThreeDBar;
|
|
188
|
+
export default ThreeDBar;
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import React, {
|
|
|
4
4
|
useEffect,
|
|
5
5
|
useMemo,
|
|
6
6
|
useState,
|
|
7
|
+
useRef,
|
|
7
8
|
} from 'react';
|
|
8
9
|
import {
|
|
9
10
|
View,
|
|
@@ -100,6 +101,7 @@ type propTypes = {
|
|
|
100
101
|
xAxisIndicesWidth?: number;
|
|
101
102
|
xAxisIndicesColor?: ColorValue;
|
|
102
103
|
yAxisIndicesColor?: ColorValue;
|
|
104
|
+
yAxisSide?: string;
|
|
103
105
|
|
|
104
106
|
color?: string;
|
|
105
107
|
color1?: string;
|
|
@@ -188,6 +190,8 @@ type propTypes = {
|
|
|
188
190
|
width?: number;
|
|
189
191
|
yAxisLabelPrefix?: String;
|
|
190
192
|
yAxisLabelSuffix?: String;
|
|
193
|
+
scrollToEnd?: Boolean;
|
|
194
|
+
scrollAnimation?: Boolean;
|
|
191
195
|
};
|
|
192
196
|
type referenceConfigType = {
|
|
193
197
|
thickness: number;
|
|
@@ -245,6 +249,7 @@ type sectionType = {
|
|
|
245
249
|
};
|
|
246
250
|
|
|
247
251
|
export const LineChart = (props: propTypes) => {
|
|
252
|
+
const scrollRef = useRef();
|
|
248
253
|
const [points, setPoints] = useState('');
|
|
249
254
|
const [points2, setPoints2] = useState('');
|
|
250
255
|
const [points3, setPoints3] = useState('');
|
|
@@ -257,6 +262,8 @@ export const LineChart = (props: propTypes) => {
|
|
|
257
262
|
let data = useMemo(() => props.data || [], [props.data]);
|
|
258
263
|
const data2 = useMemo(() => props.data2 || [], [props.data2]);
|
|
259
264
|
const data3 = useMemo(() => props.data3 || [], [props.data3]);
|
|
265
|
+
const scrollToEnd = props.scrollToEnd || false;
|
|
266
|
+
const scrollAnimation = props.scrollAnimation === false ? false : true;
|
|
260
267
|
|
|
261
268
|
const opacValue = useMemo(() => new Animated.Value(0), []);
|
|
262
269
|
const widthValue = useMemo(() => new Animated.Value(0), []);
|
|
@@ -271,6 +278,8 @@ export const LineChart = (props: propTypes) => {
|
|
|
271
278
|
|
|
272
279
|
const yAxisLabelPrefix = props.yAxisLabelPrefix || '';
|
|
273
280
|
const yAxisLabelSuffix = props.yAxisLabelSuffix || '';
|
|
281
|
+
const yAxisSide = props.yAxisSide || 'left';
|
|
282
|
+
|
|
274
283
|
|
|
275
284
|
if (!initialData) {
|
|
276
285
|
initialData = [...data];
|
|
@@ -446,7 +455,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
446
455
|
const xAxisThickness = props.xAxisThickness || 1;
|
|
447
456
|
const xAxisColor = props.xAxisColor || 'black';
|
|
448
457
|
|
|
449
|
-
let totalWidth =
|
|
458
|
+
let totalWidth = initialSpacing;
|
|
450
459
|
let maxItem = 0;
|
|
451
460
|
data.forEach((item: itemType) => {
|
|
452
461
|
if (item.value > maxItem) {
|
|
@@ -1067,8 +1076,9 @@ export const LineChart = (props: propTypes) => {
|
|
|
1067
1076
|
style={[
|
|
1068
1077
|
styles.horizBar,
|
|
1069
1078
|
{
|
|
1070
|
-
width: props.width ? props.width + 15
|
|
1079
|
+
width: (props.width ? props.width : totalWidth) + 15,
|
|
1071
1080
|
},
|
|
1081
|
+
yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]}
|
|
1072
1082
|
]}>
|
|
1073
1083
|
<View
|
|
1074
1084
|
style={[
|
|
@@ -1085,6 +1095,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1085
1095
|
ellipsizeMode={'clip'}
|
|
1086
1096
|
style={[
|
|
1087
1097
|
yAxisTextStyle,
|
|
1098
|
+
yAxisSide === 'right' && {transform:[{rotateY:'180deg'}]},
|
|
1088
1099
|
index === noOfSections && {
|
|
1089
1100
|
marginBottom: stepHeight / -2,
|
|
1090
1101
|
},
|
|
@@ -1668,7 +1679,7 @@ export const LineChart = (props: propTypes) => {
|
|
|
1668
1679
|
};
|
|
1669
1680
|
|
|
1670
1681
|
return (
|
|
1671
|
-
<View style={[styles.container, {height: containerHeight}]}>
|
|
1682
|
+
<View style={[styles.container, {height: containerHeight}, yAxisSide === 'right' && {marginLeft: yAxisLabelWidth + yAxisThickness }]}>
|
|
1672
1683
|
{props.hideAxesAndRules !== true && renderHorizSections()}
|
|
1673
1684
|
{/* {sectionsOverlay()} */}
|
|
1674
1685
|
<ScrollView
|
|
@@ -1676,16 +1687,22 @@ export const LineChart = (props: propTypes) => {
|
|
|
1676
1687
|
contentContainerStyle={[
|
|
1677
1688
|
{
|
|
1678
1689
|
height: containerHeight + 130,
|
|
1679
|
-
width: totalWidth,
|
|
1690
|
+
width: totalWidth -20,
|
|
1680
1691
|
// backgroundColor: 'yellow'
|
|
1681
1692
|
},
|
|
1682
|
-
!props.width && {width: totalWidth},
|
|
1693
|
+
!props.width && {width: totalWidth -20},
|
|
1683
1694
|
]}
|
|
1684
1695
|
scrollEnabled={!disableScroll}
|
|
1696
|
+
ref={scrollRef}
|
|
1697
|
+
onContentSizeChange={()=>{
|
|
1698
|
+
if(scrollRef.current && scrollToEnd){
|
|
1699
|
+
scrollRef.current.scrollToEnd({animated: scrollAnimation});
|
|
1700
|
+
}
|
|
1701
|
+
}}
|
|
1685
1702
|
showsHorizontalScrollIndicator={showScrollIndicator}
|
|
1686
1703
|
style={[
|
|
1687
1704
|
{
|
|
1688
|
-
marginLeft: yAxisLabelWidth + yAxisThickness,
|
|
1705
|
+
marginLeft: yAxisSide === 'right' ? -yAxisLabelWidth - yAxisThickness + 6 : yAxisLabelWidth + yAxisThickness,
|
|
1689
1706
|
position: 'absolute',
|
|
1690
1707
|
bottom: stepHeight * -0.5 - 60, //stepHeight * -0.5 + xAxisThickness,
|
|
1691
1708
|
paddingRight: 100,
|
package/src/PieChart/index.tsx
CHANGED
|
@@ -420,9 +420,11 @@ export const PieChart = (props: propTypes) => {
|
|
|
420
420
|
borderTopWidth: isThreeD
|
|
421
421
|
? innerCircleBorderWidth * 5
|
|
422
422
|
: innerCircleBorderWidth,
|
|
423
|
-
borderLeftWidth: 0.
|
|
423
|
+
borderLeftWidth: 0.5,
|
|
424
|
+
borderLeftColor:innerCircleColor,
|
|
424
425
|
borderBottomWidth: 0,
|
|
425
|
-
borderRightWidth: 0.
|
|
426
|
+
borderRightWidth: 0.5,
|
|
427
|
+
borderRightColor:innerCircleColor,
|
|
426
428
|
},
|
|
427
429
|
]}>
|
|
428
430
|
{props.centerLabelComponent ? props.centerLabelComponent() : null}
|