react-native-gifted-charts 1.3.6 → 1.3.8
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/index.tsx +36 -3
- package/src/BarChart/types.ts +4 -1
- package/src/Components/BarAndLineChartsWrapper/index.tsx +20 -10
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +6 -6
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +79 -72
- package/src/LineChart/LineChartBicolor.tsx +10 -6
- package/src/LineChart/index.tsx +180 -84
- package/src/LineChart/styles.tsx +2 -2
- package/src/LineChart/types.ts +5 -1
- package/src/utils/constants.ts +11 -3
- package/src/utils/index.tsx +7 -3
- package/src/utils/types.ts +10 -1
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.8",
|
|
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": [
|
package/src/BarChart/index.tsx
CHANGED
|
@@ -149,6 +149,8 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
149
149
|
defaultLineConfig.arrowConfig?.showArrowBase,
|
|
150
150
|
},
|
|
151
151
|
customDataPoint: props.lineConfig.customDataPoint,
|
|
152
|
+
isSecondary:
|
|
153
|
+
props.lineConfig.isSecondary ?? defaultLineConfig.isSecondary,
|
|
152
154
|
}
|
|
153
155
|
: defaultLineConfig;
|
|
154
156
|
const noOfSections = props.noOfSections ?? AxesAndRulesDefaults.noOfSections;
|
|
@@ -161,6 +163,8 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
161
163
|
const labelWidth = props.labelWidth ?? AxesAndRulesDefaults.labelWidth;
|
|
162
164
|
const scrollToEnd = props.scrollToEnd ?? BarDefaults.scrollToEnd;
|
|
163
165
|
const scrollAnimation = props.scrollAnimation ?? BarDefaults.scrollAnimation;
|
|
166
|
+
const scrollEventThrottle =
|
|
167
|
+
props.scrollEventThrottle ?? BarDefaults.scrollEventThrottle;
|
|
164
168
|
const labelsExtraHeight =
|
|
165
169
|
props.labelsExtraHeight ?? AxesAndRulesDefaults.labelsExtraHeight;
|
|
166
170
|
|
|
@@ -198,6 +202,20 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
198
202
|
});
|
|
199
203
|
}
|
|
200
204
|
|
|
205
|
+
let secondaryMaxItem = 0,
|
|
206
|
+
secondaryMinItem = 0;
|
|
207
|
+
|
|
208
|
+
if (lineConfig.isSecondary) {
|
|
209
|
+
lineData.forEach((item: itemType) => {
|
|
210
|
+
if (item.value > secondaryMaxItem) {
|
|
211
|
+
secondaryMaxItem = item.value;
|
|
212
|
+
}
|
|
213
|
+
if (item.value < secondaryMinItem) {
|
|
214
|
+
secondaryMinItem = item.value;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
201
219
|
const maxAndMin = maxAndMinUtil(
|
|
202
220
|
maxItem,
|
|
203
221
|
minItem,
|
|
@@ -205,7 +223,17 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
205
223
|
props.showFractionalValues,
|
|
206
224
|
);
|
|
207
225
|
|
|
226
|
+
const secondaryMaxAndMin = maxAndMinUtil(
|
|
227
|
+
secondaryMaxItem,
|
|
228
|
+
secondaryMinItem,
|
|
229
|
+
props.roundToDigits,
|
|
230
|
+
props.showFractionalValues,
|
|
231
|
+
);
|
|
232
|
+
|
|
208
233
|
const maxValue = props.maxValue ?? maxAndMin.maxItem;
|
|
234
|
+
const secondaryMaxValue = lineConfig.isSecondary
|
|
235
|
+
? secondaryMaxAndMin.maxItem
|
|
236
|
+
: maxValue;
|
|
209
237
|
const mostNegativeValue = props.mostNegativeValue ?? maxAndMin.minItem;
|
|
210
238
|
|
|
211
239
|
const stepValue = props.stepValue ?? maxValue / noOfSections;
|
|
@@ -298,7 +326,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
298
326
|
currentValue,
|
|
299
327
|
lineConfig.shiftY,
|
|
300
328
|
containerHeight,
|
|
301
|
-
maxValue,
|
|
329
|
+
lineConfig.isSecondary ? secondaryMaxValue : maxValue,
|
|
302
330
|
) +
|
|
303
331
|
' ';
|
|
304
332
|
}
|
|
@@ -351,7 +379,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
351
379
|
currentValue,
|
|
352
380
|
lineConfig.shiftY,
|
|
353
381
|
containerHeight,
|
|
354
|
-
maxValue,
|
|
382
|
+
lineConfig.isSecondary ? secondaryMaxValue : maxValue,
|
|
355
383
|
),
|
|
356
384
|
]);
|
|
357
385
|
let xx = svgPath(p1Array, lineConfig.curveType, lineConfig.curvature);
|
|
@@ -529,6 +557,7 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
529
557
|
scrollToEnd,
|
|
530
558
|
scrollToIndex: props.scrollToIndex,
|
|
531
559
|
scrollAnimation,
|
|
560
|
+
scrollEventThrottle,
|
|
532
561
|
indicatorColor: props.indicatorColor,
|
|
533
562
|
setSelectedIndex,
|
|
534
563
|
spacing,
|
|
@@ -551,7 +580,11 @@ export const BarChart = (props: BarChartPropsType) => {
|
|
|
551
580
|
noOfSections,
|
|
552
581
|
showFractionalValues,
|
|
553
582
|
|
|
554
|
-
axesAndRulesProps: getAxesAndRulesProps(
|
|
583
|
+
axesAndRulesProps: getAxesAndRulesProps(
|
|
584
|
+
props,
|
|
585
|
+
stepValue,
|
|
586
|
+
secondaryMaxValue,
|
|
587
|
+
),
|
|
555
588
|
|
|
556
589
|
yAxisLabelTexts: props.yAxisLabelTexts,
|
|
557
590
|
yAxisOffset: props.yAxisOffset,
|
package/src/BarChart/types.ts
CHANGED
|
@@ -74,7 +74,7 @@ export type BarChartPropsType = {
|
|
|
74
74
|
verticalLinesThickness?: number;
|
|
75
75
|
verticalLinesHeight?: number;
|
|
76
76
|
verticalLinesColor?: ColorValue;
|
|
77
|
-
|
|
77
|
+
verticalLinesStrokeDashArray?: Array<number>;
|
|
78
78
|
verticalLinesShift?: number;
|
|
79
79
|
verticalLinesZIndex?: number;
|
|
80
80
|
noOfVerticalLines?: number;
|
|
@@ -134,6 +134,7 @@ export type BarChartPropsType = {
|
|
|
134
134
|
scrollToEnd?: boolean;
|
|
135
135
|
scrollToIndex?: number;
|
|
136
136
|
scrollAnimation?: boolean;
|
|
137
|
+
scrollEventThrottle?: number;
|
|
137
138
|
labelsExtraHeight?: number;
|
|
138
139
|
barBackgroundPattern?: Function;
|
|
139
140
|
patternId?: String;
|
|
@@ -174,6 +175,7 @@ type lineConfigType = {
|
|
|
174
175
|
showArrow?: boolean;
|
|
175
176
|
arrowConfig?: arrowType;
|
|
176
177
|
customDataPoint?: Function;
|
|
178
|
+
isSecondary?: boolean;
|
|
177
179
|
};
|
|
178
180
|
export type defaultLineConfigType = {
|
|
179
181
|
initialSpacing: number;
|
|
@@ -202,6 +204,7 @@ export type defaultLineConfigType = {
|
|
|
202
204
|
showArrow: boolean;
|
|
203
205
|
arrowConfig: arrowType;
|
|
204
206
|
customDataPoint?: Function;
|
|
207
|
+
isSecondary: boolean;
|
|
205
208
|
};
|
|
206
209
|
type arrowType = {
|
|
207
210
|
length?: number;
|
|
@@ -76,6 +76,8 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
76
76
|
pointerIndex,
|
|
77
77
|
pointerX,
|
|
78
78
|
pointerY,
|
|
79
|
+
|
|
80
|
+
scrollEventThrottle,
|
|
79
81
|
} = props;
|
|
80
82
|
|
|
81
83
|
let yAxisAtTop = rtl ? !props.yAxisAtTop : props.yAxisAtTop;
|
|
@@ -143,9 +145,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
143
145
|
const verticalLinesColor =
|
|
144
146
|
axesAndRulesProps.verticalLinesColor ??
|
|
145
147
|
AxesAndRulesDefaults.verticalLinesColor;
|
|
146
|
-
const
|
|
147
|
-
axesAndRulesProps.
|
|
148
|
-
AxesAndRulesDefaults.
|
|
148
|
+
const verticalLinesStrokeDashArray =
|
|
149
|
+
axesAndRulesProps.verticalLinesStrokeDashArray ??
|
|
150
|
+
AxesAndRulesDefaults.verticalLinesStrokeDashArray;
|
|
149
151
|
const verticalLinesShift =
|
|
150
152
|
axesAndRulesProps.verticalLinesShift ??
|
|
151
153
|
AxesAndRulesDefaults.verticalLinesShift;
|
|
@@ -231,7 +233,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
231
233
|
spacing,
|
|
232
234
|
containerHeight,
|
|
233
235
|
lineConfig,
|
|
234
|
-
maxValue,
|
|
236
|
+
maxValue: secondaryYAxis?.maxValue ?? maxValue,
|
|
235
237
|
animatedWidth,
|
|
236
238
|
lineBehindBars,
|
|
237
239
|
points,
|
|
@@ -240,6 +242,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
240
242
|
totalWidth,
|
|
241
243
|
barWidth,
|
|
242
244
|
labelsExtraHeight,
|
|
245
|
+
scrollEventThrottle,
|
|
243
246
|
};
|
|
244
247
|
const extendedContainerHeight = containerHeight + 10;
|
|
245
248
|
const containerHeightIncludingBelowXAxis =
|
|
@@ -253,7 +256,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
253
256
|
verticalLinesHeight,
|
|
254
257
|
verticalLinesThickness,
|
|
255
258
|
verticalLinesColor,
|
|
256
|
-
|
|
259
|
+
verticalLinesStrokeDashArray,
|
|
257
260
|
verticalLinesShift,
|
|
258
261
|
verticalLinesUptoDataPoint,
|
|
259
262
|
xAxisThickness,
|
|
@@ -265,6 +268,8 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
265
268
|
maxValue,
|
|
266
269
|
chartType,
|
|
267
270
|
containerHeightIncludingBelowXAxis,
|
|
271
|
+
yAxisLabelWidth,
|
|
272
|
+
totalWidth,
|
|
268
273
|
};
|
|
269
274
|
|
|
270
275
|
const actualContainerHeight =
|
|
@@ -322,6 +327,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
322
327
|
? renderHorizSections(horizSectionProps)
|
|
323
328
|
: null}
|
|
324
329
|
<ScrollView
|
|
330
|
+
scrollEventThrottle={
|
|
331
|
+
props.scrollEventThrottle ? props.scrollEventThrottle : 16
|
|
332
|
+
}
|
|
325
333
|
horizontal
|
|
326
334
|
ref={scrollRef}
|
|
327
335
|
style={[
|
|
@@ -340,7 +348,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
340
348
|
60 +
|
|
341
349
|
(chartType === chartTypes.LINE_BI_COLOR ? 0 : xAxisThickness),
|
|
342
350
|
},
|
|
343
|
-
!!props.width && {width: props.width
|
|
351
|
+
!!props.width && {width: props.width},
|
|
344
352
|
horizontal && {
|
|
345
353
|
width:
|
|
346
354
|
(props.width ?? totalWidth) + (props.width ? endSpacing : -20),
|
|
@@ -378,7 +386,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
378
386
|
}}
|
|
379
387
|
{...remainingScrollViewProps}>
|
|
380
388
|
<Fragment>
|
|
381
|
-
{showVerticalLines
|
|
389
|
+
{showVerticalLines ? (
|
|
390
|
+
<RenderVerticalLines {...verticalLinesProps} />
|
|
391
|
+
) : null}
|
|
382
392
|
{
|
|
383
393
|
// Only For Bar Charts-
|
|
384
394
|
showLine ? <RenderLineInBarChart {...lineInBarChartProps} /> : null
|
|
@@ -410,9 +420,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
|
|
|
410
420
|
</ScrollView>
|
|
411
421
|
{
|
|
412
422
|
// Only For Line Charts-
|
|
413
|
-
pointerConfig &&
|
|
414
|
-
getPointerProps
|
|
415
|
-
|
|
423
|
+
pointerConfig && getPointerProps
|
|
424
|
+
? getPointerProps({pointerIndex, pointerX, pointerY})
|
|
425
|
+
: null
|
|
416
426
|
}
|
|
417
427
|
</View>
|
|
418
428
|
);
|
|
@@ -125,7 +125,8 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
125
125
|
);
|
|
126
126
|
secondaryYAxisConfig.maxValue =
|
|
127
127
|
secondaryYAxisConfig.maxValue ?? (maxItem || maxValue);
|
|
128
|
-
secondaryYAxisConfig.mostNegativeValue =
|
|
128
|
+
secondaryYAxisConfig.mostNegativeValue =
|
|
129
|
+
secondaryYAxisConfig.mostNegativeValue ?? minItem;
|
|
129
130
|
secondaryYAxisConfig.stepValue =
|
|
130
131
|
secondaryYAxisConfig.stepValue ??
|
|
131
132
|
secondaryYAxisConfig.maxValue /
|
|
@@ -391,6 +392,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
391
392
|
{
|
|
392
393
|
borderColor: yAxisColor,
|
|
393
394
|
backgroundColor: backgroundColor,
|
|
395
|
+
width: (props.width || totalWidth - spacing) + endSpacing,
|
|
394
396
|
},
|
|
395
397
|
yAxisSide === yAxisSides.RIGHT
|
|
396
398
|
? {borderRightWidth: yAxisThickness}
|
|
@@ -798,13 +800,11 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
798
800
|
/***********************************************************************************************/
|
|
799
801
|
/************************* Render the secondary Y Axis *********************/
|
|
800
802
|
/***********************************************************************************************/
|
|
801
|
-
secondaryYAxis
|
|
803
|
+
secondaryYAxis ? (
|
|
802
804
|
<View
|
|
803
805
|
style={{
|
|
804
806
|
width: secondaryYAxisConfig.yAxisLabelWidth,
|
|
805
|
-
left: width
|
|
806
|
-
? yAxisLabelWidth
|
|
807
|
-
: yAxisLabelWidth - (chartType === chartTypes.BAR ? 4 : 16),
|
|
807
|
+
left: width ? yAxisLabelWidth : yAxisLabelWidth - spacing,
|
|
808
808
|
borderColor: secondaryYAxisConfig.yAxisColor,
|
|
809
809
|
borderLeftWidth: secondaryYAxisConfig.yAxisThickness,
|
|
810
810
|
}}>
|
|
@@ -815,7 +815,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
815
815
|
? renderSecondaryYaxisLabels(secondaryHorizSectionsBelow, true)
|
|
816
816
|
: null}
|
|
817
817
|
</View>
|
|
818
|
-
)
|
|
818
|
+
) : null
|
|
819
819
|
}
|
|
820
820
|
</View>
|
|
821
821
|
);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import {View} from 'react-native';
|
|
3
|
-
import {chartTypes
|
|
3
|
+
import {chartTypes} from '../../utils/constants';
|
|
4
|
+
import {Line, Svg} from 'react-native-svg';
|
|
4
5
|
|
|
5
6
|
const RenderVerticalLines = props => {
|
|
6
7
|
const {
|
|
@@ -12,7 +13,7 @@ const RenderVerticalLines = props => {
|
|
|
12
13
|
verticalLinesHeight,
|
|
13
14
|
verticalLinesThickness,
|
|
14
15
|
verticalLinesColor,
|
|
15
|
-
|
|
16
|
+
verticalLinesStrokeDashArray,
|
|
16
17
|
verticalLinesShift,
|
|
17
18
|
verticalLinesUptoDataPoint,
|
|
18
19
|
xAxisThickness,
|
|
@@ -24,6 +25,8 @@ const RenderVerticalLines = props => {
|
|
|
24
25
|
maxValue,
|
|
25
26
|
chartType,
|
|
26
27
|
containerHeightIncludingBelowXAxis,
|
|
28
|
+
yAxisLabelWidth,
|
|
29
|
+
totalWidth,
|
|
27
30
|
} = props;
|
|
28
31
|
|
|
29
32
|
const getHeightOfVerticalLine = index => {
|
|
@@ -43,82 +46,86 @@ const RenderVerticalLines = props => {
|
|
|
43
46
|
}
|
|
44
47
|
};
|
|
45
48
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
49
|
+
const extendedContainerHeight = containerHeight + 10 + labelsExtraHeight;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View
|
|
53
|
+
style={{
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
height: extendedContainerHeight,
|
|
56
|
+
left: 36 - yAxisLabelWidth,
|
|
57
|
+
bottom: 60, //stepHeight * -0.5 + xAxisThickness,
|
|
58
|
+
width: totalWidth,
|
|
59
|
+
zIndex: verticalLinesZIndex || -1,
|
|
60
|
+
}}>
|
|
61
|
+
<Svg>
|
|
62
|
+
{verticalLinesAr.map((item: any, index: number) => {
|
|
63
|
+
let totalSpacing = initialSpacing;
|
|
64
|
+
if (verticalLinesSpacing) {
|
|
65
|
+
totalSpacing = verticalLinesSpacing * (index + 1);
|
|
61
66
|
} else {
|
|
62
|
-
if (stackData
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
if (stackData[i + 1].barWidth) {
|
|
66
|
-
actualSpacing += stackData[i + 1].barWidth;
|
|
67
|
+
if (stackData) {
|
|
68
|
+
totalSpacing += (stackData[0].barWidth || barWidth || 30) / 2;
|
|
67
69
|
} else {
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
} else {
|
|
72
|
-
if (i >= data.length - 1) {
|
|
73
|
-
actualSpacing += (barWidth || 30) / 2;
|
|
74
|
-
} else {
|
|
75
|
-
if (data[i].spacing || data[i].spacing === 0) {
|
|
76
|
-
actualSpacing = data[i].spacing;
|
|
70
|
+
totalSpacing += (data[0].barWidth || barWidth || 30) / 2;
|
|
77
71
|
}
|
|
78
|
-
|
|
79
|
-
actualSpacing
|
|
80
|
-
|
|
81
|
-
|
|
72
|
+
for (let i = 0; i < index; i++) {
|
|
73
|
+
let actualSpacing = spacing;
|
|
74
|
+
if (stackData) {
|
|
75
|
+
if (i >= stackData.length - 1) {
|
|
76
|
+
actualSpacing += (barWidth || 30) / 2;
|
|
77
|
+
} else {
|
|
78
|
+
if (stackData[i].spacing || stackData[i].spacing === 0) {
|
|
79
|
+
actualSpacing = stackData[i].spacing;
|
|
80
|
+
}
|
|
81
|
+
if (stackData[i + 1].barWidth) {
|
|
82
|
+
actualSpacing += stackData[i + 1].barWidth;
|
|
83
|
+
} else {
|
|
84
|
+
actualSpacing += barWidth || 30;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
if (i >= data.length - 1) {
|
|
89
|
+
actualSpacing += (barWidth || 30) / 2;
|
|
90
|
+
} else {
|
|
91
|
+
if (data[i].spacing || data[i].spacing === 0) {
|
|
92
|
+
actualSpacing = data[i].spacing;
|
|
93
|
+
}
|
|
94
|
+
if (data[i + 1].barWidth) {
|
|
95
|
+
actualSpacing += data[i + 1].barWidth;
|
|
96
|
+
} else {
|
|
97
|
+
actualSpacing += barWidth || 30;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
totalSpacing += actualSpacing;
|
|
82
102
|
}
|
|
83
103
|
}
|
|
84
|
-
}
|
|
85
|
-
totalSpacing += actualSpacing;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
104
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
borderColor: verticalLinesColor,
|
|
114
|
-
}
|
|
115
|
-
: {
|
|
116
|
-
backgroundColor: verticalLinesColor,
|
|
117
|
-
},
|
|
118
|
-
]}
|
|
119
|
-
/>
|
|
120
|
-
);
|
|
121
|
-
});
|
|
105
|
+
const x =
|
|
106
|
+
verticalLinesShift +
|
|
107
|
+
(chartType === chartTypes.BAR
|
|
108
|
+
? totalSpacing - 1
|
|
109
|
+
: verticalLinesSpacing
|
|
110
|
+
? verticalLinesSpacing * (index + 1)
|
|
111
|
+
: index * spacing + (initialSpacing - 2));
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<Line
|
|
115
|
+
key={index}
|
|
116
|
+
x1={x}
|
|
117
|
+
y1={extendedContainerHeight - getHeightOfVerticalLine(index)}
|
|
118
|
+
x2={x}
|
|
119
|
+
y2={extendedContainerHeight}
|
|
120
|
+
stroke={verticalLinesColor || 'lightgray'}
|
|
121
|
+
strokeWidth={verticalLinesThickness || 2}
|
|
122
|
+
strokeDasharray={verticalLinesStrokeDashArray ?? ''}
|
|
123
|
+
/>
|
|
124
|
+
);
|
|
125
|
+
})}
|
|
126
|
+
</Svg>
|
|
127
|
+
</View>
|
|
128
|
+
);
|
|
122
129
|
};
|
|
123
130
|
|
|
124
131
|
export default RenderVerticalLines;
|
|
@@ -90,7 +90,7 @@ type propTypes = {
|
|
|
90
90
|
verticalLinesThickness?: number;
|
|
91
91
|
verticalLinesHeight?: number;
|
|
92
92
|
verticalLinesColor?: ColorValue;
|
|
93
|
-
|
|
93
|
+
verticalLinesStrokeDashArray?: Array<number>;
|
|
94
94
|
verticalLinesShift?: number;
|
|
95
95
|
verticalLinesZIndex?: number;
|
|
96
96
|
noOfVerticalLines?: number;
|
|
@@ -180,6 +180,7 @@ type propTypes = {
|
|
|
180
180
|
scrollToEnd?: boolean;
|
|
181
181
|
scrollToIndex?: number;
|
|
182
182
|
scrollAnimation?: boolean;
|
|
183
|
+
scrollEventThrottle?: number;
|
|
183
184
|
noOfSectionsBelowXAxis?: number;
|
|
184
185
|
labelsExtraHeight?: number;
|
|
185
186
|
adjustToWidth?: boolean;
|
|
@@ -197,8 +198,8 @@ type referenceConfigType = {
|
|
|
197
198
|
};
|
|
198
199
|
type itemType = {
|
|
199
200
|
value: number;
|
|
200
|
-
label
|
|
201
|
-
labelComponent
|
|
201
|
+
label?: String;
|
|
202
|
+
labelComponent?: Function;
|
|
202
203
|
labelTextStyle?: any;
|
|
203
204
|
dataPointText?: string;
|
|
204
205
|
textShiftX?: number;
|
|
@@ -274,6 +275,8 @@ export const LineChartBicolor = (props: propTypes) => {
|
|
|
274
275
|
|
|
275
276
|
const scrollToEnd = props.scrollToEnd ?? LineDefaults.scrollToEnd;
|
|
276
277
|
const scrollAnimation = props.scrollAnimation ?? LineDefaults.scrollAnimation;
|
|
278
|
+
const scrollEventThrottle =
|
|
279
|
+
props.scrollEventThrottle ?? LineDefaults.scrollEventThrottle;
|
|
277
280
|
|
|
278
281
|
const opacValue = useMemo(() => new Animated.Value(0), []);
|
|
279
282
|
const widthValue = useMemo(() => new Animated.Value(0), []);
|
|
@@ -700,7 +703,7 @@ export const LineChartBicolor = (props: propTypes) => {
|
|
|
700
703
|
index: number,
|
|
701
704
|
label: String,
|
|
702
705
|
labelTextStyle: any,
|
|
703
|
-
labelComponent
|
|
706
|
+
labelComponent?: Function,
|
|
704
707
|
) => {
|
|
705
708
|
return (
|
|
706
709
|
<View
|
|
@@ -735,7 +738,7 @@ export const LineChartBicolor = (props: propTypes) => {
|
|
|
735
738
|
index: number,
|
|
736
739
|
label: String,
|
|
737
740
|
labelTextStyle: any,
|
|
738
|
-
labelComponent
|
|
741
|
+
labelComponent?: Function,
|
|
739
742
|
) => {
|
|
740
743
|
return (
|
|
741
744
|
<Animated.View
|
|
@@ -1335,6 +1338,7 @@ export const LineChartBicolor = (props: propTypes) => {
|
|
|
1335
1338
|
scrollToEnd,
|
|
1336
1339
|
scrollToIndex: props.scrollToIndex,
|
|
1337
1340
|
scrollAnimation,
|
|
1341
|
+
scrollEventThrottle,
|
|
1338
1342
|
indicatorColor: props.indicatorColor,
|
|
1339
1343
|
setSelectedIndex,
|
|
1340
1344
|
spacing,
|
|
@@ -1357,7 +1361,7 @@ export const LineChartBicolor = (props: propTypes) => {
|
|
|
1357
1361
|
noOfSections,
|
|
1358
1362
|
showFractionalValues,
|
|
1359
1363
|
|
|
1360
|
-
axesAndRulesProps: getAxesAndRulesProps(props, stepValue),
|
|
1364
|
+
axesAndRulesProps: getAxesAndRulesProps(props, stepValue, undefined),
|
|
1361
1365
|
|
|
1362
1366
|
yAxisLabelTexts: props.yAxisLabelTexts,
|
|
1363
1367
|
yAxisOffset: props.yAxisOffset,
|
package/src/LineChart/index.tsx
CHANGED
|
@@ -6,7 +6,15 @@ import React, {
|
|
|
6
6
|
useState,
|
|
7
7
|
useRef,
|
|
8
8
|
} from 'react';
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
View,
|
|
11
|
+
Animated,
|
|
12
|
+
Easing,
|
|
13
|
+
Text,
|
|
14
|
+
Dimensions,
|
|
15
|
+
Platform,
|
|
16
|
+
ColorValue,
|
|
17
|
+
} from 'react-native';
|
|
10
18
|
import {styles} from './styles';
|
|
11
19
|
import Svg, {
|
|
12
20
|
Path,
|
|
@@ -32,6 +40,7 @@ import {
|
|
|
32
40
|
chartTypes,
|
|
33
41
|
defaultArrowConfig,
|
|
34
42
|
defaultPointerConfig,
|
|
43
|
+
screenWidth,
|
|
35
44
|
} from '../utils/constants';
|
|
36
45
|
import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
|
|
37
46
|
import {LineChartPropsType, itemType} from './types';
|
|
@@ -78,6 +87,11 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
78
87
|
pointerShiftX: 0,
|
|
79
88
|
pointerShiftY: 0,
|
|
80
89
|
});
|
|
90
|
+
const [secondaryPointerY, setSecondaryPointerY] = useState(0);
|
|
91
|
+
const [secondaryPointerItem, setSecondaryPointerItem] = useState({
|
|
92
|
+
pointerShiftX: 0,
|
|
93
|
+
pointerShiftY: 0,
|
|
94
|
+
});
|
|
81
95
|
const [responderStartTime, setResponderStartTime] = useState(0);
|
|
82
96
|
const [responderActive, setResponderActive] = useState(false);
|
|
83
97
|
const [points, setPoints] = useState('');
|
|
@@ -167,6 +181,8 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
167
181
|
|
|
168
182
|
const scrollToEnd = props.scrollToEnd || LineDefaults.scrollToEnd;
|
|
169
183
|
const scrollAnimation = props.scrollAnimation ?? LineDefaults.scrollAnimation;
|
|
184
|
+
const scrollEventThrottle =
|
|
185
|
+
props.scrollEventThrottle ?? LineDefaults.scrollEventThrottle;
|
|
170
186
|
|
|
171
187
|
const opacValue = useMemo(() => new Animated.Value(0), []);
|
|
172
188
|
const widthValue = useMemo(() => new Animated.Value(0), []);
|
|
@@ -225,10 +241,16 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
225
241
|
|
|
226
242
|
const thickness = props.thickness || LineDefaults.thickness;
|
|
227
243
|
|
|
244
|
+
const yAxisLabelWidth =
|
|
245
|
+
props.yAxisLabelWidth ??
|
|
246
|
+
(props.hideYAxisText
|
|
247
|
+
? AxesAndRulesDefaults.yAxisEmptyLabelWidth
|
|
248
|
+
: AxesAndRulesDefaults.yAxisLabelWidth);
|
|
249
|
+
|
|
228
250
|
const spacing =
|
|
229
251
|
props.spacing ??
|
|
230
252
|
(adjustToWidth
|
|
231
|
-
? ((props.width ??
|
|
253
|
+
? ((props.width ?? screenWidth - yAxisLabelWidth) - initialSpacing) /
|
|
232
254
|
(data.length - 1)
|
|
233
255
|
: LineDefaults.spacing);
|
|
234
256
|
|
|
@@ -1323,11 +1345,6 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1323
1345
|
const horizontalRulesStyle = props.horizontalRulesStyle;
|
|
1324
1346
|
const showFractionalValues =
|
|
1325
1347
|
props.showFractionalValues ?? AxesAndRulesDefaults.showFractionalValues;
|
|
1326
|
-
const yAxisLabelWidth =
|
|
1327
|
-
props.yAxisLabelWidth ??
|
|
1328
|
-
(props.hideYAxisText
|
|
1329
|
-
? AxesAndRulesDefaults.yAxisEmptyLabelWidth
|
|
1330
|
-
: AxesAndRulesDefaults.yAxisLabelWidth);
|
|
1331
1348
|
|
|
1332
1349
|
const horizontal = false;
|
|
1333
1350
|
const yAxisAtTop = false;
|
|
@@ -1336,83 +1353,69 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1336
1353
|
|
|
1337
1354
|
const pointerConfig = props.pointerConfig || null;
|
|
1338
1355
|
const getPointerProps = props.getPointerProps || null;
|
|
1339
|
-
const pointerHeight = pointerConfig?.height
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
const
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
? pointerConfig.radius
|
|
1347
|
-
: defaultPointerConfig.radius;
|
|
1348
|
-
const pointerColor = pointerConfig?.pointerColor
|
|
1349
|
-
? pointerConfig.pointerColor
|
|
1350
|
-
: defaultPointerConfig.pointerColor;
|
|
1351
|
-
const pointerComponent = pointerConfig?.pointerComponent
|
|
1352
|
-
? pointerConfig.pointerComponent
|
|
1353
|
-
: defaultPointerConfig.pointerComponent;
|
|
1356
|
+
const pointerHeight = pointerConfig?.height ?? defaultPointerConfig.height;
|
|
1357
|
+
const pointerWidth = pointerConfig?.width ?? defaultPointerConfig.width;
|
|
1358
|
+
const pointerRadius = pointerConfig?.radius ?? defaultPointerConfig.radius;
|
|
1359
|
+
const pointerColor =
|
|
1360
|
+
pointerConfig?.pointerColor ?? defaultPointerConfig.pointerColor;
|
|
1361
|
+
const pointerComponent =
|
|
1362
|
+
pointerConfig?.pointerComponent ?? defaultPointerConfig.pointerComponent;
|
|
1354
1363
|
|
|
1355
1364
|
const showPointerStrip =
|
|
1356
1365
|
pointerConfig?.showPointerStrip === false
|
|
1357
1366
|
? false
|
|
1358
1367
|
: defaultPointerConfig.showPointerStrip;
|
|
1359
|
-
const pointerStripHeight =
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
const pointerStripWidth =
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
const
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
const
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
const
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
|
|
1385
|
-
: defaultPointerConfig.pointerLabelWidth;
|
|
1386
|
-
const pointerLabelHeight = pointerConfig?.pointerLabelHeight
|
|
1387
|
-
? pointerConfig.pointerLabelHeight
|
|
1388
|
-
: defaultPointerConfig.pointerLabelHeight;
|
|
1368
|
+
const pointerStripHeight =
|
|
1369
|
+
pointerConfig?.pointerStripHeight ??
|
|
1370
|
+
defaultPointerConfig.pointerStripHeight;
|
|
1371
|
+
const pointerStripWidth =
|
|
1372
|
+
pointerConfig?.pointerStripWidth ?? defaultPointerConfig.pointerStripWidth;
|
|
1373
|
+
const pointerStripColor =
|
|
1374
|
+
pointerConfig?.pointerStripColor ?? defaultPointerConfig.pointerStripColor;
|
|
1375
|
+
const pointerStripUptoDataPoint =
|
|
1376
|
+
pointerConfig?.pointerStripUptoDataPoint ??
|
|
1377
|
+
defaultPointerConfig.pointerStripUptoDataPoint;
|
|
1378
|
+
const pointerLabelComponent =
|
|
1379
|
+
pointerConfig?.pointerLabelComponent ??
|
|
1380
|
+
defaultPointerConfig.pointerLabelComponent;
|
|
1381
|
+
const stripOverPointer =
|
|
1382
|
+
pointerConfig?.stripOverPointer ?? defaultPointerConfig.stripOverPointer;
|
|
1383
|
+
const shiftPointerLabelX =
|
|
1384
|
+
pointerConfig?.shiftPointerLabelX ??
|
|
1385
|
+
defaultPointerConfig.shiftPointerLabelX;
|
|
1386
|
+
const shiftPointerLabelY =
|
|
1387
|
+
pointerConfig?.shiftPointerLabelY ??
|
|
1388
|
+
defaultPointerConfig.shiftPointerLabelY;
|
|
1389
|
+
const pointerLabelWidth =
|
|
1390
|
+
pointerConfig?.pointerLabelWidth ?? defaultPointerConfig.pointerLabelWidth;
|
|
1391
|
+
const pointerLabelHeight =
|
|
1392
|
+
pointerConfig?.pointerLabelHeight ??
|
|
1393
|
+
defaultPointerConfig.pointerLabelHeight;
|
|
1389
1394
|
const autoAdjustPointerLabelPosition =
|
|
1390
1395
|
pointerConfig?.autoAdjustPointerLabelPosition ??
|
|
1391
1396
|
defaultPointerConfig.autoAdjustPointerLabelPosition;
|
|
1392
|
-
const pointerVanishDelay =
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
const activatePointersOnLongPress =
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
const activatePointersDelay =
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
const hidePointer1 =
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
const
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
? pointerConfig.hidePointer5
|
|
1415
|
-
: defaultPointerConfig.hidePointer5;
|
|
1397
|
+
const pointerVanishDelay =
|
|
1398
|
+
pointerConfig?.pointerVanishDelay ??
|
|
1399
|
+
defaultPointerConfig.pointerVanishDelay;
|
|
1400
|
+
const activatePointersOnLongPress =
|
|
1401
|
+
pointerConfig?.activatePointersOnLongPress ??
|
|
1402
|
+
defaultPointerConfig.activatePointersOnLongPress;
|
|
1403
|
+
const activatePointersDelay =
|
|
1404
|
+
pointerConfig?.activatePointersDelay ??
|
|
1405
|
+
defaultPointerConfig.activatePointersDelay;
|
|
1406
|
+
const hidePointer1 =
|
|
1407
|
+
pointerConfig?.hidePointer1 ?? defaultPointerConfig.hidePointer1;
|
|
1408
|
+
const hidePointer2 =
|
|
1409
|
+
pointerConfig?.hidePointer2 ?? defaultPointerConfig.hidePointer2;
|
|
1410
|
+
const hidePointer3 =
|
|
1411
|
+
pointerConfig?.hidePointer3 ?? defaultPointerConfig.hidePointer3;
|
|
1412
|
+
const hidePointer4 =
|
|
1413
|
+
pointerConfig?.hidePointer4 ?? defaultPointerConfig.hidePointer4;
|
|
1414
|
+
const hidePointer5 =
|
|
1415
|
+
pointerConfig?.hidePointer5 ?? defaultPointerConfig.hidePointer5;
|
|
1416
|
+
const hideSecondaryPointer =
|
|
1417
|
+
pointerConfig?.hideSecondaryPointer ??
|
|
1418
|
+
defaultPointerConfig.hideSecondaryPointer;
|
|
1416
1419
|
const disableScroll =
|
|
1417
1420
|
props.disableScroll ||
|
|
1418
1421
|
(pointerConfig
|
|
@@ -1806,6 +1809,31 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1806
1809
|
const renderSpecificVerticalLines = (dataForRender: any) => {
|
|
1807
1810
|
return dataForRender.map((item: itemType, index: number) => {
|
|
1808
1811
|
if (item.showVerticalLine) {
|
|
1812
|
+
const x = getX(index);
|
|
1813
|
+
return (
|
|
1814
|
+
<Line
|
|
1815
|
+
key={index}
|
|
1816
|
+
x1={x}
|
|
1817
|
+
y1={extendedContainerHeight}
|
|
1818
|
+
x2={x}
|
|
1819
|
+
y2={
|
|
1820
|
+
item.verticalLineUptoDataPoint ?? props.verticalLinesUptoDataPoint
|
|
1821
|
+
? getY(item.value)
|
|
1822
|
+
: -xAxisThickness
|
|
1823
|
+
}
|
|
1824
|
+
stroke={
|
|
1825
|
+
item.verticalLineColor || props.verticalLinesColor || 'lightgray'
|
|
1826
|
+
}
|
|
1827
|
+
strokeWidth={
|
|
1828
|
+
item.verticalLineThickness || props.verticalLinesThickness || 2
|
|
1829
|
+
}
|
|
1830
|
+
strokeDasharray={
|
|
1831
|
+
item.verticalLineStrokeDashArray ??
|
|
1832
|
+
props.verticalLinesStrokeDashArray ??
|
|
1833
|
+
''
|
|
1834
|
+
}
|
|
1835
|
+
/>
|
|
1836
|
+
);
|
|
1809
1837
|
return (
|
|
1810
1838
|
<Rect
|
|
1811
1839
|
key={index}
|
|
@@ -1821,13 +1849,15 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1821
1849
|
? getY(item.value)
|
|
1822
1850
|
: -xAxisThickness
|
|
1823
1851
|
}
|
|
1824
|
-
width={item.verticalLineThickness ||
|
|
1852
|
+
width={item.verticalLineThickness || 10}
|
|
1825
1853
|
height={
|
|
1826
1854
|
item.verticalLineUptoDataPoint
|
|
1827
1855
|
? (item.value * containerHeight) / maxValue - xAxisThickness
|
|
1828
1856
|
: extendedContainerHeight - xAxisThickness
|
|
1829
1857
|
}
|
|
1830
|
-
fill={
|
|
1858
|
+
fill={
|
|
1859
|
+
item.verticalLineColor || props.verticalLinesColor || 'lightgray'
|
|
1860
|
+
}
|
|
1831
1861
|
/>
|
|
1832
1862
|
);
|
|
1833
1863
|
}
|
|
@@ -1841,6 +1871,9 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1841
1871
|
if (lineNumber === 3 && hidePointer3) return;
|
|
1842
1872
|
if (lineNumber === 4 && hidePointer4) return;
|
|
1843
1873
|
if (lineNumber === 5 && hidePointer5) return;
|
|
1874
|
+
// 6 is for secondaryData
|
|
1875
|
+
if (lineNumber === 6 && hideSecondaryPointer) return;
|
|
1876
|
+
|
|
1844
1877
|
let pointerItemLocal, pointerYLocal, pointerColorLocal;
|
|
1845
1878
|
switch (lineNumber) {
|
|
1846
1879
|
case 1:
|
|
@@ -1868,6 +1901,12 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1868
1901
|
pointerYLocal = pointerY5;
|
|
1869
1902
|
pointerColorLocal = pointerConfig?.pointer5Color || pointerColor;
|
|
1870
1903
|
break;
|
|
1904
|
+
case 6:
|
|
1905
|
+
pointerItemLocal = secondaryPointerItem;
|
|
1906
|
+
pointerYLocal = secondaryPointerY;
|
|
1907
|
+
pointerColorLocal =
|
|
1908
|
+
pointerConfig?.secondaryPointerColor || pointerColor;
|
|
1909
|
+
break;
|
|
1871
1910
|
}
|
|
1872
1911
|
|
|
1873
1912
|
return (
|
|
@@ -1915,6 +1954,9 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
1915
1954
|
arr.push(pointerY5);
|
|
1916
1955
|
pointerItemLocal.push(pointerItem5);
|
|
1917
1956
|
}
|
|
1957
|
+
if (secondaryPointerY !== 0) {
|
|
1958
|
+
pointerItemLocal.push(secondaryPointerItem);
|
|
1959
|
+
}
|
|
1918
1960
|
pointerYLocal = Math.min(...arr);
|
|
1919
1961
|
|
|
1920
1962
|
let left = 0,
|
|
@@ -2025,7 +2067,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2025
2067
|
width: pointerLabelWidth,
|
|
2026
2068
|
},
|
|
2027
2069
|
]}>
|
|
2028
|
-
{pointerLabelComponent(pointerItemLocal)}
|
|
2070
|
+
{pointerLabelComponent(pointerItemLocal, secondaryPointerItem)}
|
|
2029
2071
|
</View>
|
|
2030
2072
|
)}
|
|
2031
2073
|
</View>
|
|
@@ -2320,6 +2362,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2320
2362
|
setPointerItem5(item);
|
|
2321
2363
|
}
|
|
2322
2364
|
}
|
|
2365
|
+
if (secondaryData?.length) {
|
|
2366
|
+
item = secondaryData[factor];
|
|
2367
|
+
if (item) {
|
|
2368
|
+
y =
|
|
2369
|
+
containerHeight -
|
|
2370
|
+
(item.value * containerHeight) / maxValue -
|
|
2371
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2372
|
+
10;
|
|
2373
|
+
setSecondaryPointerY(y);
|
|
2374
|
+
setSecondaryPointerItem(item);
|
|
2375
|
+
}
|
|
2376
|
+
}
|
|
2323
2377
|
}}
|
|
2324
2378
|
onResponderMove={evt => {
|
|
2325
2379
|
if (!pointerConfig) return;
|
|
@@ -2405,6 +2459,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2405
2459
|
setPointerItem5(item);
|
|
2406
2460
|
}
|
|
2407
2461
|
}
|
|
2462
|
+
if (secondaryData?.length) {
|
|
2463
|
+
item = secondaryData[factor];
|
|
2464
|
+
if (item) {
|
|
2465
|
+
y =
|
|
2466
|
+
containerHeight -
|
|
2467
|
+
(item.value * containerHeight) / maxValue -
|
|
2468
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2469
|
+
10;
|
|
2470
|
+
setSecondaryPointerY(y);
|
|
2471
|
+
setSecondaryPointerItem(item);
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2408
2474
|
}}
|
|
2409
2475
|
// onResponderReject={evt => {
|
|
2410
2476
|
// console.log('evt...reject.......',evt);
|
|
@@ -2560,6 +2626,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2560
2626
|
setPointerItem5(item);
|
|
2561
2627
|
}
|
|
2562
2628
|
}
|
|
2629
|
+
if (secondaryData?.length) {
|
|
2630
|
+
item = secondaryData[factor];
|
|
2631
|
+
if (item) {
|
|
2632
|
+
y =
|
|
2633
|
+
containerHeight -
|
|
2634
|
+
(item.value * containerHeight) / maxValue -
|
|
2635
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2636
|
+
10;
|
|
2637
|
+
setSecondaryPointerY(y);
|
|
2638
|
+
setSecondaryPointerItem(item);
|
|
2639
|
+
}
|
|
2640
|
+
}
|
|
2563
2641
|
}}
|
|
2564
2642
|
onResponderMove={evt => {
|
|
2565
2643
|
if (!pointerConfig) return;
|
|
@@ -2645,6 +2723,18 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2645
2723
|
setPointerItem5(item);
|
|
2646
2724
|
}
|
|
2647
2725
|
}
|
|
2726
|
+
if (secondaryData?.length) {
|
|
2727
|
+
item = secondaryData[factor];
|
|
2728
|
+
if (item) {
|
|
2729
|
+
y =
|
|
2730
|
+
containerHeight -
|
|
2731
|
+
(item.value * containerHeight) / maxValue -
|
|
2732
|
+
(pointerRadius || pointerHeight / 2) +
|
|
2733
|
+
10;
|
|
2734
|
+
setSecondaryPointerY(y);
|
|
2735
|
+
setSecondaryPointerItem(item);
|
|
2736
|
+
}
|
|
2737
|
+
}
|
|
2648
2738
|
}}
|
|
2649
2739
|
// onResponderReject={evt => {
|
|
2650
2740
|
// console.log('evt...reject.......',evt);
|
|
@@ -2667,8 +2757,13 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2667
2757
|
// }}
|
|
2668
2758
|
style={{
|
|
2669
2759
|
position: 'absolute',
|
|
2670
|
-
height:
|
|
2671
|
-
|
|
2760
|
+
height:
|
|
2761
|
+
containerHeightIncludingBelowXAxis +
|
|
2762
|
+
(props.overflowBottom ?? dataPointsRadius1),
|
|
2763
|
+
bottom:
|
|
2764
|
+
60 +
|
|
2765
|
+
labelsExtraHeight -
|
|
2766
|
+
(props.overflowBottom ?? dataPointsRadius1),
|
|
2672
2767
|
width: animatedWidth,
|
|
2673
2768
|
zIndex: zIndex,
|
|
2674
2769
|
// backgroundColor: 'wheat',
|
|
@@ -2939,8 +3034,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2939
3034
|
style={{
|
|
2940
3035
|
position: 'absolute',
|
|
2941
3036
|
height:
|
|
2942
|
-
extendedContainerHeight +
|
|
2943
|
-
noOfSectionsBelowXAxis * stepHeight,
|
|
3037
|
+
extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
|
|
2944
3038
|
bottom: 60 + labelsExtraHeight,
|
|
2945
3039
|
width: totalWidth,
|
|
2946
3040
|
zIndex: 20,
|
|
@@ -2951,6 +3045,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
2951
3045
|
{points3 ? renderPointer(3) : null}
|
|
2952
3046
|
{points4 ? renderPointer(4) : null}
|
|
2953
3047
|
{points5 ? renderPointer(5) : null}
|
|
3048
|
+
{secondaryPoints ? renderPointer(6) : null}
|
|
2954
3049
|
{stripOverPointer && renderStripAndLabel()}
|
|
2955
3050
|
</View>
|
|
2956
3051
|
) : null}
|
|
@@ -3010,6 +3105,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
3010
3105
|
scrollToEnd,
|
|
3011
3106
|
scrollToIndex: props.scrollToIndex,
|
|
3012
3107
|
scrollAnimation,
|
|
3108
|
+
scrollEventThrottle,
|
|
3013
3109
|
indicatorColor: props.indicatorColor,
|
|
3014
3110
|
setSelectedIndex,
|
|
3015
3111
|
spacing,
|
|
@@ -3032,7 +3128,7 @@ export const LineChart = (props: LineChartPropsType) => {
|
|
|
3032
3128
|
noOfSections,
|
|
3033
3129
|
showFractionalValues,
|
|
3034
3130
|
|
|
3035
|
-
axesAndRulesProps: getAxesAndRulesProps(props, stepValue),
|
|
3131
|
+
axesAndRulesProps: getAxesAndRulesProps(props, stepValue, undefined),
|
|
3036
3132
|
|
|
3037
3133
|
yAxisLabelTexts: props.yAxisLabelTexts,
|
|
3038
3134
|
yAxisOffset: props.yAxisOffset,
|
package/src/LineChart/styles.tsx
CHANGED
|
@@ -19,11 +19,11 @@ export const styles = StyleSheet.create({
|
|
|
19
19
|
},
|
|
20
20
|
leftPart: {
|
|
21
21
|
justifyContent: 'center',
|
|
22
|
-
width: '100%',
|
|
22
|
+
// width: '100%',
|
|
23
23
|
},
|
|
24
24
|
lastLeftPart: {
|
|
25
25
|
justifyContent: 'flex-end',
|
|
26
|
-
width: '100%',
|
|
26
|
+
// width: '100%',
|
|
27
27
|
},
|
|
28
28
|
line: {
|
|
29
29
|
width: '100%',
|
package/src/LineChart/types.ts
CHANGED
|
@@ -89,7 +89,7 @@ export type LineChartPropsType = {
|
|
|
89
89
|
verticalLinesThickness?: number;
|
|
90
90
|
verticalLinesHeight?: number;
|
|
91
91
|
verticalLinesColor?: ColorValue;
|
|
92
|
-
|
|
92
|
+
verticalLinesStrokeDashArray?: Array<number>;
|
|
93
93
|
verticalLinesShift?: number;
|
|
94
94
|
verticalLinesZIndex?: number;
|
|
95
95
|
noOfVerticalLines?: number;
|
|
@@ -258,6 +258,7 @@ export type LineChartPropsType = {
|
|
|
258
258
|
scrollToEnd?: boolean;
|
|
259
259
|
scrollToIndex?: number;
|
|
260
260
|
scrollAnimation?: boolean;
|
|
261
|
+
scrollEventThrottle?: number;
|
|
261
262
|
noOfSectionsBelowXAxis?: number;
|
|
262
263
|
labelsExtraHeight?: number;
|
|
263
264
|
adjustToWidth?: boolean;
|
|
@@ -332,6 +333,7 @@ export type itemType = {
|
|
|
332
333
|
verticalLineUptoDataPoint?: boolean;
|
|
333
334
|
verticalLineColor?: string;
|
|
334
335
|
verticalLineThickness?: number;
|
|
336
|
+
verticalLineStrokeDashArray?: Array<number>;
|
|
335
337
|
pointerShiftX?: number;
|
|
336
338
|
pointerShiftY?: number;
|
|
337
339
|
onPress?: Function;
|
|
@@ -352,6 +354,7 @@ type Pointer = {
|
|
|
352
354
|
pointer3Color?: ColorValue;
|
|
353
355
|
pointer4Color?: ColorValue;
|
|
354
356
|
pointer5Color?: ColorValue;
|
|
357
|
+
secondaryPointerColor?: ColorValue;
|
|
355
358
|
pointerComponent?: Function;
|
|
356
359
|
showPointerStrip?: boolean;
|
|
357
360
|
pointerStripWidth?: number;
|
|
@@ -373,5 +376,6 @@ type Pointer = {
|
|
|
373
376
|
hidePointer3?: boolean;
|
|
374
377
|
hidePointer4?: boolean;
|
|
375
378
|
hidePointer5?: boolean;
|
|
379
|
+
hideSecondaryPointer?: boolean;
|
|
376
380
|
strokeDashArray?: Array<number>;
|
|
377
381
|
};
|
package/src/utils/constants.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {defaultLineConfigType} from '../BarChart/types';
|
|
2
|
-
import {CurveType} from './types';
|
|
2
|
+
import {CurveType, RuleTypes} from './types';
|
|
3
|
+
import {Dimensions} from 'react-native';
|
|
3
4
|
|
|
4
5
|
// Global
|
|
5
6
|
|
|
@@ -9,9 +10,12 @@ export enum chartTypes {
|
|
|
9
10
|
LINE_BI_COLOR,
|
|
10
11
|
}
|
|
11
12
|
|
|
13
|
+
export const screenWidth = Dimensions.get('window').width;
|
|
14
|
+
|
|
12
15
|
const defaultCurvature = 0.2;
|
|
13
16
|
const defaultCurveType = CurveType.CUBIC;
|
|
14
17
|
const defaultAnimationDuration = 800;
|
|
18
|
+
const defaultScrollEventThrottle = 0;
|
|
15
19
|
|
|
16
20
|
// Bar and Line chart Specific
|
|
17
21
|
|
|
@@ -20,7 +24,7 @@ export enum yAxisSides {
|
|
|
20
24
|
RIGHT,
|
|
21
25
|
}
|
|
22
26
|
|
|
23
|
-
export const ruleTypes = {
|
|
27
|
+
export const ruleTypes: RuleTypes = {
|
|
24
28
|
SOLID: 'solid',
|
|
25
29
|
DASHED: 'dashed',
|
|
26
30
|
DOTTED: 'dotted',
|
|
@@ -62,7 +66,7 @@ export const AxesAndRulesDefaults = {
|
|
|
62
66
|
showVerticalLines: false,
|
|
63
67
|
verticalLinesThickness: 1,
|
|
64
68
|
verticalLinesColor: 'lightgray',
|
|
65
|
-
|
|
69
|
+
verticalLinesStrokeDashArray: '',
|
|
66
70
|
verticalLinesShift: 0,
|
|
67
71
|
verticalLinesZIndex: -1,
|
|
68
72
|
verticalLinesSpacing: 0,
|
|
@@ -114,6 +118,7 @@ export const BarDefaults = {
|
|
|
114
118
|
scrollToEnd: false,
|
|
115
119
|
scrollAnimation: true,
|
|
116
120
|
showScrollIndicator: false,
|
|
121
|
+
scrollEventThrottle: defaultScrollEventThrottle,
|
|
117
122
|
|
|
118
123
|
side: '',
|
|
119
124
|
isAnimated: false,
|
|
@@ -148,6 +153,7 @@ export const defaultLineConfig: defaultLineConfigType = {
|
|
|
148
153
|
endIndex: 0, // gets updated to lineData.length - 1
|
|
149
154
|
showArrow: false,
|
|
150
155
|
arrowConfig: defaultArrowConfig,
|
|
156
|
+
isSecondary: false,
|
|
151
157
|
};
|
|
152
158
|
|
|
153
159
|
// Line chart specific
|
|
@@ -168,6 +174,7 @@ export const LineDefaults = {
|
|
|
168
174
|
scrollToEnd: false,
|
|
169
175
|
scrollAnimation: true,
|
|
170
176
|
showScrollIndicator: false,
|
|
177
|
+
scrollEventThrottle: defaultScrollEventThrottle,
|
|
171
178
|
showValuesAsDataPointsText: false,
|
|
172
179
|
|
|
173
180
|
dataPointsHeight: 4,
|
|
@@ -221,6 +228,7 @@ export const defaultPointerConfig = {
|
|
|
221
228
|
hidePointer3: false,
|
|
222
229
|
hidePointer4: false,
|
|
223
230
|
hidePointer5: false,
|
|
231
|
+
hideSecondaryPointer: false,
|
|
224
232
|
};
|
|
225
233
|
|
|
226
234
|
// Pie chart specific
|
package/src/utils/index.tsx
CHANGED
|
@@ -211,8 +211,8 @@ export const getArrowPoints = (
|
|
|
211
211
|
return arrowPoints;
|
|
212
212
|
};
|
|
213
213
|
|
|
214
|
-
export const getAxesAndRulesProps = (props, stepValue) => {
|
|
215
|
-
|
|
214
|
+
export const getAxesAndRulesProps = (props, stepValue, maxValue) => {
|
|
215
|
+
const axesAndRulesProps = {
|
|
216
216
|
yAxisSide: props.yAxisSide,
|
|
217
217
|
yAxisLabelContainerStyle: props.yAxisLabelContainerStyle,
|
|
218
218
|
yAxisColor: props.yAxisColor,
|
|
@@ -255,7 +255,6 @@ export const getAxesAndRulesProps = (props, stepValue) => {
|
|
|
255
255
|
verticalLinesThickness: props.verticalLinesThickness,
|
|
256
256
|
verticalLinesHeight: props.verticalLinesHeight,
|
|
257
257
|
verticalLinesColor: props.verticalLinesColor,
|
|
258
|
-
verticalLinesType: props.verticalLinesType,
|
|
259
258
|
verticalLinesShift: props.verticalLinesShift,
|
|
260
259
|
verticalLinesZIndex: props.verticalLinesZIndex,
|
|
261
260
|
verticalLinesSpacing: props.verticalLinesSpacing,
|
|
@@ -269,6 +268,11 @@ export const getAxesAndRulesProps = (props, stepValue) => {
|
|
|
269
268
|
|
|
270
269
|
secondaryYAxis: props.secondaryYAxis,
|
|
271
270
|
};
|
|
271
|
+
if (props.secondaryYAxis && maxValue !== undefined) {
|
|
272
|
+
axesAndRulesProps.secondaryYAxis = {...props.secondaryYAxis, maxValue};
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
return axesAndRulesProps;
|
|
272
276
|
};
|
|
273
277
|
|
|
274
278
|
export const getExtendedContainerHeightWithPadding = (
|
package/src/utils/types.ts
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import {ColorValue} from 'react-native';
|
|
2
2
|
import {chartTypes, yAxisSides} from './constants';
|
|
3
3
|
|
|
4
|
-
export type RuleType = 'solid' | 'dashed' | 'dotted';
|
|
4
|
+
export type RuleType = 'solid' | 'dashed' | 'dotted' | string;
|
|
5
|
+
|
|
6
|
+
export type RuleTypes = {
|
|
7
|
+
SOLID: RuleType;
|
|
8
|
+
DASHED: RuleType;
|
|
9
|
+
DOTTED: RuleType;
|
|
10
|
+
};
|
|
5
11
|
|
|
6
12
|
export enum CurveType {
|
|
7
13
|
CUBIC,
|
|
@@ -65,6 +71,7 @@ export type secondaryLineConfigType = {
|
|
|
65
71
|
textColor?: string;
|
|
66
72
|
showArrow?: boolean;
|
|
67
73
|
arrowConfig?: arrowConfigType;
|
|
74
|
+
isSecondary?: boolean;
|
|
68
75
|
};
|
|
69
76
|
|
|
70
77
|
export type arrowConfigType = {
|
|
@@ -205,4 +212,6 @@ export type BarAndLineChartsWrapperTypes = {
|
|
|
205
212
|
pointerIndex: number;
|
|
206
213
|
pointerX: number;
|
|
207
214
|
pointerY: number;
|
|
215
|
+
|
|
216
|
+
scrollEventThrottle: number;
|
|
208
217
|
};
|