react-native-gifted-charts 1.4.12 → 1.4.13
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 +5 -9
- package/src/BarChart/Animated2DWithGradient.tsx +197 -0
- package/src/BarChart/RenderBars.tsx +454 -0
- package/src/BarChart/RenderStackBars.tsx +383 -0
- package/src/BarChart/index.tsx +373 -0
- package/src/BarChart/styles.tsx +47 -0
- package/src/Components/AnimatedThreeDBar/index.tsx +258 -0
- package/src/Components/AnimatedThreeDBar/styles.tsx +14 -0
- package/src/Components/BarAndLineChartsWrapper/index.tsx +244 -0
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +590 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
- package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +131 -0
- package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +30 -0
- package/src/Components/BarSpecificComponents/cap.tsx +34 -0
- package/src/Components/common/LinearGradient.tsx +27 -0
- package/src/Components/common/Pointer.tsx +37 -0
- package/src/Components/common/StripAndLabel.tsx +98 -0
- package/src/Components/lineSvg.tsx +42 -0
- package/src/LineChart/LineChartBicolor.tsx +740 -0
- package/src/LineChart/index.tsx +2158 -0
- package/src/LineChart/styles.tsx +47 -0
- package/src/PieChart/index.tsx +165 -0
- package/src/PieChart/main.tsx +363 -0
- package/src/PieChartPro/index.tsx +267 -0
- package/src/PopulationPyramid/index.tsx +603 -0
- package/src/index.tsx +25 -0
- package/src/todos.md +23 -0
- package/src/utils/index.ts +16 -0
- package/dist/BarChart/Animated2DWithGradient.js +0 -1
- package/dist/BarChart/RenderBars.js +0 -1
- package/dist/BarChart/RenderStackBars.js +0 -1
- package/dist/BarChart/index.js +0 -1
- package/dist/BarChart/styles.js +0 -1
- package/dist/Components/AnimatedThreeDBar/index.js +0 -1
- package/dist/Components/AnimatedThreeDBar/styles.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/index.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +0 -1
- package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +0 -1
- package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +0 -1
- package/dist/Components/BarSpecificComponents/cap.js +0 -1
- package/dist/Components/common/LinearGradient.js +0 -1
- package/dist/Components/common/Pointer.js +0 -1
- package/dist/Components/common/StripAndLabel.js +0 -1
- package/dist/Components/lineSvg.js +0 -1
- package/dist/LineChart/LineChartBicolor.js +0 -1
- package/dist/LineChart/index.js +0 -1
- package/dist/LineChart/styles.js +0 -1
- package/dist/PieChart/index.js +0 -1
- package/dist/PieChart/main.js +0 -1
- package/dist/PieChartPro/index.js +0 -1
- package/dist/PopulationPyramid/index.js +0 -1
- package/dist/index.js +0 -1
- package/dist/utils/index.js +0 -1
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View, Animated} from 'react-native';
|
|
3
|
+
import Svg, {Path} from 'react-native-svg';
|
|
4
|
+
import {renderSpecificVerticalLines} from './renderSpecificVerticalLines';
|
|
5
|
+
import {renderDataPoints} from './renderDataPoints';
|
|
6
|
+
import {renderSpecificDataPoints} from './renderSpecificDataPoints';
|
|
7
|
+
|
|
8
|
+
const RenderLineInBarChart = props => {
|
|
9
|
+
const {
|
|
10
|
+
yAxisLabelWidth,
|
|
11
|
+
initialSpacing,
|
|
12
|
+
spacing,
|
|
13
|
+
containerHeight,
|
|
14
|
+
lineConfig,
|
|
15
|
+
maxValue,
|
|
16
|
+
animatedWidth,
|
|
17
|
+
lineBehindBars,
|
|
18
|
+
points,
|
|
19
|
+
arrowPoints,
|
|
20
|
+
data,
|
|
21
|
+
totalWidth,
|
|
22
|
+
barWidth,
|
|
23
|
+
labelsExtraHeight,
|
|
24
|
+
xAxisLabelsVerticalShift,
|
|
25
|
+
} = props;
|
|
26
|
+
|
|
27
|
+
const firstBarWidth = data[0].barWidth ?? barWidth;
|
|
28
|
+
|
|
29
|
+
const dataPointsProps = {
|
|
30
|
+
data,
|
|
31
|
+
lineConfig,
|
|
32
|
+
barWidth,
|
|
33
|
+
containerHeight,
|
|
34
|
+
maxValue,
|
|
35
|
+
firstBarWidth,
|
|
36
|
+
yAxisLabelWidth,
|
|
37
|
+
spacing,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const specificVerticalLinesProps = {
|
|
41
|
+
data,
|
|
42
|
+
barWidth,
|
|
43
|
+
yAxisLabelWidth,
|
|
44
|
+
initialSpacing,
|
|
45
|
+
spacing,
|
|
46
|
+
containerHeight,
|
|
47
|
+
lineConfig,
|
|
48
|
+
maxValue,
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const specificDataPointsProps = {
|
|
52
|
+
data,
|
|
53
|
+
barWidth,
|
|
54
|
+
firstBarWidth,
|
|
55
|
+
yAxisLabelWidth,
|
|
56
|
+
lineConfig,
|
|
57
|
+
spacing,
|
|
58
|
+
containerHeight,
|
|
59
|
+
maxValue,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const renderAnimatedLine = () => {
|
|
63
|
+
// console.log('animatedWidth is-------->', animatedWidth);
|
|
64
|
+
return (
|
|
65
|
+
<Animated.View
|
|
66
|
+
pointerEvents="none"
|
|
67
|
+
style={{
|
|
68
|
+
position: 'absolute',
|
|
69
|
+
height: containerHeight + 10,
|
|
70
|
+
left: 6 - yAxisLabelWidth,
|
|
71
|
+
bottom: 50 + xAxisLabelsVerticalShift, //stepHeight * -0.5 + xAxisThickness,
|
|
72
|
+
width: animatedWidth,
|
|
73
|
+
zIndex: lineBehindBars ? -1 : 100000,
|
|
74
|
+
// backgroundColor: 'wheat',
|
|
75
|
+
}}>
|
|
76
|
+
<Svg>
|
|
77
|
+
<Path
|
|
78
|
+
d={points}
|
|
79
|
+
fill="none"
|
|
80
|
+
stroke={lineConfig.color}
|
|
81
|
+
strokeWidth={lineConfig.thickness}
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
{renderSpecificVerticalLines(specificVerticalLinesProps)}
|
|
85
|
+
|
|
86
|
+
{!lineConfig.hideDataPoints
|
|
87
|
+
? renderDataPoints(dataPointsProps)
|
|
88
|
+
: renderSpecificDataPoints(specificDataPointsProps)}
|
|
89
|
+
{lineConfig.showArrow && (
|
|
90
|
+
<Path
|
|
91
|
+
d={arrowPoints}
|
|
92
|
+
fill={lineConfig.arrowConfig.fillColor}
|
|
93
|
+
stroke={lineConfig.arrowConfig.strokeColor}
|
|
94
|
+
strokeWidth={lineConfig.arrowConfig.strokeWidth}
|
|
95
|
+
/>
|
|
96
|
+
)}
|
|
97
|
+
</Svg>
|
|
98
|
+
</Animated.View>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const renderLine = () => {
|
|
103
|
+
return (
|
|
104
|
+
<View
|
|
105
|
+
pointerEvents="none"
|
|
106
|
+
style={{
|
|
107
|
+
position: 'absolute',
|
|
108
|
+
height: containerHeight + 10 + labelsExtraHeight,
|
|
109
|
+
left: 6 - yAxisLabelWidth,
|
|
110
|
+
bottom: 50 + xAxisLabelsVerticalShift, //stepHeight * -0.5 + xAxisThickness,
|
|
111
|
+
width: totalWidth,
|
|
112
|
+
zIndex: lineBehindBars ? -1 : 100000,
|
|
113
|
+
// backgroundColor: 'rgba(200,150,150,0.1)'
|
|
114
|
+
}}>
|
|
115
|
+
<Svg>
|
|
116
|
+
<Path
|
|
117
|
+
d={points}
|
|
118
|
+
fill="none"
|
|
119
|
+
stroke={lineConfig.color}
|
|
120
|
+
strokeWidth={lineConfig.thickness}
|
|
121
|
+
/>
|
|
122
|
+
{renderSpecificVerticalLines(specificVerticalLinesProps)}
|
|
123
|
+
|
|
124
|
+
{!lineConfig.hideDataPoints
|
|
125
|
+
? renderDataPoints(dataPointsProps)
|
|
126
|
+
: renderSpecificDataPoints(specificDataPointsProps)}
|
|
127
|
+
{lineConfig.showArrow && (
|
|
128
|
+
<Path
|
|
129
|
+
d={arrowPoints}
|
|
130
|
+
fill={lineConfig.arrowConfig.fillColor}
|
|
131
|
+
stroke={lineConfig.arrowConfig.strokeColor}
|
|
132
|
+
strokeWidth={lineConfig.arrowConfig.strokeWidth}
|
|
133
|
+
/>
|
|
134
|
+
)}
|
|
135
|
+
</Svg>
|
|
136
|
+
</View>
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
if (lineConfig.isAnimated) {
|
|
141
|
+
return renderAnimatedLine();
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return renderLine();
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
export default RenderLineInBarChart;
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import React, {Fragment} from 'react';
|
|
2
|
+
import {styles} from '../../../BarChart/styles';
|
|
3
|
+
import {View} from 'react-native';
|
|
4
|
+
import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
|
|
5
|
+
import {Rect, Text as CanvasText, Circle} from 'react-native-svg';
|
|
6
|
+
|
|
7
|
+
export const renderDataPoints = props => {
|
|
8
|
+
const {
|
|
9
|
+
data,
|
|
10
|
+
lineConfig,
|
|
11
|
+
barWidth,
|
|
12
|
+
containerHeight,
|
|
13
|
+
maxValue,
|
|
14
|
+
firstBarWidth,
|
|
15
|
+
yAxisLabelWidth,
|
|
16
|
+
spacing,
|
|
17
|
+
} = props;
|
|
18
|
+
return data.map((item: any, index: number) => {
|
|
19
|
+
if (index < lineConfig.startIndex || index > lineConfig.endIndex) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
const currentBarWidth = item.barWidth || barWidth || 30;
|
|
23
|
+
const customDataPoint = item.customDataPoint || lineConfig.customDataPoint;
|
|
24
|
+
const value =
|
|
25
|
+
item.value ?? item.stacks.reduce((total, item) => total + item.value, 0);
|
|
26
|
+
if (customDataPoint) {
|
|
27
|
+
return (
|
|
28
|
+
<View
|
|
29
|
+
style={[
|
|
30
|
+
styles.customDataPointContainer,
|
|
31
|
+
{
|
|
32
|
+
height: lineConfig.dataPointsHeight,
|
|
33
|
+
width: lineConfig.dataPointsWidth,
|
|
34
|
+
top:
|
|
35
|
+
containerHeight -
|
|
36
|
+
(value * containerHeight) / maxValue -
|
|
37
|
+
(item.shiftY ?? lineConfig.shiftY ?? 0),
|
|
38
|
+
left: getXForLineInBar(
|
|
39
|
+
index,
|
|
40
|
+
firstBarWidth,
|
|
41
|
+
currentBarWidth,
|
|
42
|
+
yAxisLabelWidth,
|
|
43
|
+
lineConfig,
|
|
44
|
+
spacing,
|
|
45
|
+
),
|
|
46
|
+
},
|
|
47
|
+
]}>
|
|
48
|
+
{customDataPoint(item, index)}
|
|
49
|
+
</View>
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
if (lineConfig.dataPointsShape === 'rectangular') {
|
|
53
|
+
return (
|
|
54
|
+
<Fragment key={index}>
|
|
55
|
+
<Rect
|
|
56
|
+
x={getXForLineInBar(
|
|
57
|
+
index,
|
|
58
|
+
firstBarWidth,
|
|
59
|
+
currentBarWidth,
|
|
60
|
+
yAxisLabelWidth,
|
|
61
|
+
lineConfig,
|
|
62
|
+
spacing,
|
|
63
|
+
)}
|
|
64
|
+
y={
|
|
65
|
+
getYForLineInBar(
|
|
66
|
+
value,
|
|
67
|
+
lineConfig.shiftY,
|
|
68
|
+
containerHeight,
|
|
69
|
+
maxValue,
|
|
70
|
+
) -
|
|
71
|
+
lineConfig.dataPointsHeight / 2
|
|
72
|
+
}
|
|
73
|
+
width={lineConfig.dataPointsWidth}
|
|
74
|
+
height={lineConfig.dataPointsHeight}
|
|
75
|
+
fill={lineConfig.dataPointsColor}
|
|
76
|
+
/>
|
|
77
|
+
{item.dataPointText && (
|
|
78
|
+
<CanvasText
|
|
79
|
+
fill={item.textColor || lineConfig.textColor}
|
|
80
|
+
fontSize={item.textFontSize || lineConfig.textFontSize}
|
|
81
|
+
x={
|
|
82
|
+
getXForLineInBar(
|
|
83
|
+
index,
|
|
84
|
+
firstBarWidth,
|
|
85
|
+
currentBarWidth,
|
|
86
|
+
yAxisLabelWidth,
|
|
87
|
+
lineConfig,
|
|
88
|
+
spacing,
|
|
89
|
+
) + (item.textShiftX || lineConfig.textShiftX || 0)
|
|
90
|
+
}
|
|
91
|
+
y={
|
|
92
|
+
getYForLineInBar(
|
|
93
|
+
value,
|
|
94
|
+
lineConfig.shiftY,
|
|
95
|
+
containerHeight,
|
|
96
|
+
maxValue,
|
|
97
|
+
) -
|
|
98
|
+
lineConfig.dataPointsHeight / 2 +
|
|
99
|
+
(item.textShiftY || lineConfig.textShiftY || 0)
|
|
100
|
+
}>
|
|
101
|
+
{item.dataPointText}
|
|
102
|
+
</CanvasText>
|
|
103
|
+
)}
|
|
104
|
+
</Fragment>
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return (
|
|
108
|
+
<Fragment key={index}>
|
|
109
|
+
<Circle
|
|
110
|
+
cx={getXForLineInBar(
|
|
111
|
+
index,
|
|
112
|
+
firstBarWidth,
|
|
113
|
+
currentBarWidth,
|
|
114
|
+
yAxisLabelWidth,
|
|
115
|
+
lineConfig,
|
|
116
|
+
spacing,
|
|
117
|
+
)}
|
|
118
|
+
cy={getYForLineInBar(
|
|
119
|
+
value,
|
|
120
|
+
lineConfig.shiftY,
|
|
121
|
+
containerHeight,
|
|
122
|
+
maxValue,
|
|
123
|
+
)}
|
|
124
|
+
r={lineConfig.dataPointsRadius}
|
|
125
|
+
fill={lineConfig.dataPointsColor}
|
|
126
|
+
/>
|
|
127
|
+
{item.dataPointText && (
|
|
128
|
+
<CanvasText
|
|
129
|
+
fill={item.textColor || lineConfig.textColor}
|
|
130
|
+
fontSize={item.textFontSize || lineConfig.textFontSize}
|
|
131
|
+
x={
|
|
132
|
+
getXForLineInBar(
|
|
133
|
+
index,
|
|
134
|
+
firstBarWidth,
|
|
135
|
+
currentBarWidth,
|
|
136
|
+
yAxisLabelWidth,
|
|
137
|
+
lineConfig,
|
|
138
|
+
spacing,
|
|
139
|
+
) + (item.textShiftX || lineConfig.textShiftX || 0)
|
|
140
|
+
}
|
|
141
|
+
y={
|
|
142
|
+
getYForLineInBar(
|
|
143
|
+
value,
|
|
144
|
+
lineConfig.shiftY,
|
|
145
|
+
containerHeight,
|
|
146
|
+
maxValue,
|
|
147
|
+
) -
|
|
148
|
+
lineConfig.dataPointsHeight / 2 +
|
|
149
|
+
(item.textShiftY || lineConfig.textShiftY || 0)
|
|
150
|
+
}>
|
|
151
|
+
{item.dataPointText}
|
|
152
|
+
</CanvasText>
|
|
153
|
+
)}
|
|
154
|
+
</Fragment>
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
|
+
};
|
package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import React, {Fragment} from 'react';
|
|
2
|
+
import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
|
|
3
|
+
import {Circle, Rect, Text as CanvasText} from 'react-native-svg';
|
|
4
|
+
|
|
5
|
+
export const renderSpecificDataPoints = props => {
|
|
6
|
+
const {
|
|
7
|
+
data,
|
|
8
|
+
barWidth,
|
|
9
|
+
firstBarWidth,
|
|
10
|
+
yAxisLabelWidth,
|
|
11
|
+
lineConfig,
|
|
12
|
+
spacing,
|
|
13
|
+
containerHeight,
|
|
14
|
+
maxValue,
|
|
15
|
+
} = props;
|
|
16
|
+
return data.map((item: any, index: number) => {
|
|
17
|
+
const currentBarWidth = item.barWidth || barWidth || 30;
|
|
18
|
+
const x = getXForLineInBar(
|
|
19
|
+
index,
|
|
20
|
+
firstBarWidth,
|
|
21
|
+
currentBarWidth,
|
|
22
|
+
yAxisLabelWidth,
|
|
23
|
+
lineConfig,
|
|
24
|
+
spacing,
|
|
25
|
+
);
|
|
26
|
+
const y = getYForLineInBar(
|
|
27
|
+
item.value,
|
|
28
|
+
lineConfig.shiftY,
|
|
29
|
+
containerHeight,
|
|
30
|
+
maxValue,
|
|
31
|
+
);
|
|
32
|
+
if (item.showDataPoint) {
|
|
33
|
+
if (item.dataPointShape === 'rectangular') {
|
|
34
|
+
return (
|
|
35
|
+
<Fragment key={index}>
|
|
36
|
+
<Rect
|
|
37
|
+
x={x}
|
|
38
|
+
y={y - item.dataPointsHeight / 2}
|
|
39
|
+
width={item.dataPointWidth || lineConfig.dataPointsWidth}
|
|
40
|
+
height={item.dataPointHeight || 2}
|
|
41
|
+
fill={item.dataPointColor || 'black'}
|
|
42
|
+
/>
|
|
43
|
+
{item.dataPointText && (
|
|
44
|
+
<CanvasText
|
|
45
|
+
fill={item.textColor || 'black'}
|
|
46
|
+
fontSize={item.textFontSize || 10}
|
|
47
|
+
x={x + (item.textShiftX || lineConfig.textShiftX || 0)}
|
|
48
|
+
y={
|
|
49
|
+
y -
|
|
50
|
+
(item.dataPointHeight || lineConfig.dataPointsHeight) / 2 +
|
|
51
|
+
(item.textShiftY || lineConfig.textShiftY || 0)
|
|
52
|
+
}>
|
|
53
|
+
{item.dataPointText}
|
|
54
|
+
</CanvasText>
|
|
55
|
+
)}
|
|
56
|
+
</Fragment>
|
|
57
|
+
);
|
|
58
|
+
} else {
|
|
59
|
+
return (
|
|
60
|
+
<Fragment key={index}>
|
|
61
|
+
<Circle
|
|
62
|
+
cx={x}
|
|
63
|
+
cy={y}
|
|
64
|
+
r={item.dataPointRadius || 3}
|
|
65
|
+
fill={item.dataPointColor || 'black'}
|
|
66
|
+
/>
|
|
67
|
+
{item.dataPointText && (
|
|
68
|
+
<CanvasText
|
|
69
|
+
fill={item.textColor || 'black'}
|
|
70
|
+
fontSize={item.textFontSize || 10}
|
|
71
|
+
x={x + (item.textShiftX || lineConfig.textShiftX || 0)}
|
|
72
|
+
y={
|
|
73
|
+
y -
|
|
74
|
+
(item.dataPointHeight || lineConfig.dataPointsHeight) / 2 +
|
|
75
|
+
(item.textShiftY || lineConfig.textShiftY || 0)
|
|
76
|
+
}>
|
|
77
|
+
{item.dataPointText}
|
|
78
|
+
</CanvasText>
|
|
79
|
+
)}
|
|
80
|
+
</Fragment>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
});
|
|
86
|
+
};
|
package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {Rect} from 'react-native-svg';
|
|
3
|
+
|
|
4
|
+
export const renderSpecificVerticalLines = props => {
|
|
5
|
+
const {
|
|
6
|
+
data,
|
|
7
|
+
barWidth,
|
|
8
|
+
yAxisLabelWidth,
|
|
9
|
+
initialSpacing,
|
|
10
|
+
spacing,
|
|
11
|
+
containerHeight,
|
|
12
|
+
lineConfig,
|
|
13
|
+
maxValue,
|
|
14
|
+
} = props;
|
|
15
|
+
return data.map((item: any, index: number) => {
|
|
16
|
+
if (item.showVerticalLine) {
|
|
17
|
+
const currentBarWidth = item.barWidth || barWidth || 30;
|
|
18
|
+
return (
|
|
19
|
+
<Rect
|
|
20
|
+
x={
|
|
21
|
+
yAxisLabelWidth +
|
|
22
|
+
6 -
|
|
23
|
+
(item.verticalLineThickness || 1) / 2 -
|
|
24
|
+
1 -
|
|
25
|
+
(initialSpacing - currentBarWidth / 2) +
|
|
26
|
+
(currentBarWidth + spacing) * index
|
|
27
|
+
}
|
|
28
|
+
y={
|
|
29
|
+
containerHeight -
|
|
30
|
+
lineConfig.shiftY -
|
|
31
|
+
(item.value * containerHeight) / maxValue +
|
|
32
|
+
9
|
|
33
|
+
}
|
|
34
|
+
width={item.verticalLineThickness || 1}
|
|
35
|
+
height={(item.value * containerHeight) / maxValue + lineConfig.shiftY}
|
|
36
|
+
fill={item.verticalLineColor || 'lightgray'}
|
|
37
|
+
/>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {chartTypes} from 'gifted-charts-core';
|
|
4
|
+
import {Line, Svg} from 'react-native-svg';
|
|
5
|
+
|
|
6
|
+
const RenderVerticalLines = props => {
|
|
7
|
+
const {
|
|
8
|
+
verticalLinesAr,
|
|
9
|
+
verticalLinesSpacing,
|
|
10
|
+
spacing,
|
|
11
|
+
initialSpacing,
|
|
12
|
+
verticalLinesZIndex,
|
|
13
|
+
verticalLinesHeight,
|
|
14
|
+
verticalLinesThickness,
|
|
15
|
+
verticalLinesColor,
|
|
16
|
+
verticalLinesStrokeDashArray,
|
|
17
|
+
verticalLinesShift,
|
|
18
|
+
verticalLinesUptoDataPoint,
|
|
19
|
+
xAxisThickness,
|
|
20
|
+
labelsExtraHeight,
|
|
21
|
+
containerHeight,
|
|
22
|
+
data,
|
|
23
|
+
stackData,
|
|
24
|
+
barWidth,
|
|
25
|
+
maxValue,
|
|
26
|
+
chartType,
|
|
27
|
+
containerHeightIncludingBelowXAxis,
|
|
28
|
+
totalWidth,
|
|
29
|
+
xAxisLabelsVerticalShift,
|
|
30
|
+
} = props;
|
|
31
|
+
|
|
32
|
+
const getHeightOfVerticalLine = index => {
|
|
33
|
+
if (verticalLinesUptoDataPoint) {
|
|
34
|
+
if (index < data.length) {
|
|
35
|
+
return (
|
|
36
|
+
(data[index].value * containerHeight) / maxValue - xAxisThickness
|
|
37
|
+
);
|
|
38
|
+
} else {
|
|
39
|
+
return verticalLinesHeight ?? 0;
|
|
40
|
+
}
|
|
41
|
+
} else {
|
|
42
|
+
return (
|
|
43
|
+
verticalLinesHeight ||
|
|
44
|
+
containerHeightIncludingBelowXAxis - xAxisThickness
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const extendedContainerHeight = containerHeight + 10 + labelsExtraHeight;
|
|
50
|
+
|
|
51
|
+
return (
|
|
52
|
+
<View
|
|
53
|
+
style={{
|
|
54
|
+
position: 'absolute',
|
|
55
|
+
height: extendedContainerHeight,
|
|
56
|
+
bottom: 60 + xAxisLabelsVerticalShift, //stepHeight * -0.5 + xAxisThickness,
|
|
57
|
+
width: totalWidth,
|
|
58
|
+
zIndex: verticalLinesZIndex || -1,
|
|
59
|
+
}}>
|
|
60
|
+
<Svg>
|
|
61
|
+
{verticalLinesAr.map((item: any, index: number) => {
|
|
62
|
+
let totalSpacing = initialSpacing;
|
|
63
|
+
if (verticalLinesSpacing) {
|
|
64
|
+
totalSpacing = verticalLinesSpacing * (index + 1);
|
|
65
|
+
} else {
|
|
66
|
+
if (stackData) {
|
|
67
|
+
totalSpacing += (stackData[0].barWidth || barWidth || 30) / 2;
|
|
68
|
+
} else {
|
|
69
|
+
totalSpacing += (data[0].barWidth || barWidth || 30) / 2;
|
|
70
|
+
}
|
|
71
|
+
for (let i = 0; i < index; i++) {
|
|
72
|
+
let actualSpacing = spacing;
|
|
73
|
+
if (stackData) {
|
|
74
|
+
if (i >= stackData.length - 1) {
|
|
75
|
+
actualSpacing += (barWidth || 30) / 2;
|
|
76
|
+
} else {
|
|
77
|
+
if (stackData[i].spacing || stackData[i].spacing === 0) {
|
|
78
|
+
actualSpacing = stackData[i].spacing;
|
|
79
|
+
}
|
|
80
|
+
if (stackData[i + 1].barWidth) {
|
|
81
|
+
actualSpacing += stackData[i + 1].barWidth;
|
|
82
|
+
} else {
|
|
83
|
+
actualSpacing += barWidth || 30;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
if (i >= data.length - 1) {
|
|
88
|
+
actualSpacing += (barWidth || 30) / 2;
|
|
89
|
+
} else {
|
|
90
|
+
if (data[i].spacing || data[i].spacing === 0) {
|
|
91
|
+
actualSpacing = data[i].spacing;
|
|
92
|
+
}
|
|
93
|
+
if (data[i + 1].barWidth) {
|
|
94
|
+
actualSpacing += data[i + 1].barWidth;
|
|
95
|
+
} else {
|
|
96
|
+
actualSpacing += barWidth || 30;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
totalSpacing += actualSpacing;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const x =
|
|
105
|
+
verticalLinesShift +
|
|
106
|
+
1 +
|
|
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
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export default RenderVerticalLines;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Svg, {Defs, Rect} from 'react-native-svg';
|
|
3
|
+
|
|
4
|
+
const BarBackgroundPattern = props => {
|
|
5
|
+
const {
|
|
6
|
+
barBackgroundPatternFromItem,
|
|
7
|
+
barBackgroundPatternFromProps,
|
|
8
|
+
patternIdFromItem,
|
|
9
|
+
patternIdFromProps,
|
|
10
|
+
} = props;
|
|
11
|
+
return (
|
|
12
|
+
<Svg>
|
|
13
|
+
<Defs>
|
|
14
|
+
{barBackgroundPatternFromItem
|
|
15
|
+
? barBackgroundPatternFromItem()
|
|
16
|
+
: barBackgroundPatternFromProps()}
|
|
17
|
+
</Defs>
|
|
18
|
+
<Rect
|
|
19
|
+
stroke="transparent"
|
|
20
|
+
x="1"
|
|
21
|
+
y="1"
|
|
22
|
+
width="100%"
|
|
23
|
+
height="100%"
|
|
24
|
+
fill={`url(#${patternIdFromItem ?? patternIdFromProps})`}
|
|
25
|
+
/>
|
|
26
|
+
</Svg>
|
|
27
|
+
);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export default BarBackgroundPattern;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {BarDefaults} from 'gifted-charts-core';
|
|
4
|
+
|
|
5
|
+
const Cap = props => {
|
|
6
|
+
const {
|
|
7
|
+
capThicknessFromItem,
|
|
8
|
+
capThicknessFromProps,
|
|
9
|
+
capColorFromItem,
|
|
10
|
+
capColorFromProps,
|
|
11
|
+
capRadiusFromItem,
|
|
12
|
+
capRadiusFromProps,
|
|
13
|
+
} = props;
|
|
14
|
+
return (
|
|
15
|
+
<View
|
|
16
|
+
style={{
|
|
17
|
+
position: 'absolute',
|
|
18
|
+
width: '100%',
|
|
19
|
+
height:
|
|
20
|
+
capThicknessFromItem ??
|
|
21
|
+
capThicknessFromProps ??
|
|
22
|
+
BarDefaults.capThickness,
|
|
23
|
+
backgroundColor:
|
|
24
|
+
capColorFromItem ?? capColorFromProps ?? BarDefaults.capColor,
|
|
25
|
+
borderTopLeftRadius:
|
|
26
|
+
capRadiusFromItem ?? capRadiusFromProps ?? BarDefaults.capRadius,
|
|
27
|
+
borderTopRightRadius:
|
|
28
|
+
capRadiusFromItem ?? capRadiusFromProps ?? BarDefaults.capRadius,
|
|
29
|
+
}}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default Cap;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {ViewStyle} from "react-native";
|
|
3
|
+
|
|
4
|
+
type LinearGradientProps = {
|
|
5
|
+
style?: ViewStyle;
|
|
6
|
+
start?: { x: number, y: number };
|
|
7
|
+
end?: { x: number, y: number };
|
|
8
|
+
colors: string[];
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let LinearGradient: React.FC<LinearGradientProps>;
|
|
12
|
+
|
|
13
|
+
try {
|
|
14
|
+
// for bare react-native projects
|
|
15
|
+
LinearGradient = require('react-native-linear-gradient').LinearGradient;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
try {
|
|
18
|
+
// for expo-based projects
|
|
19
|
+
LinearGradient = require('expo-linear-gradient').LinearGradient;
|
|
20
|
+
} catch (e) {
|
|
21
|
+
throw new Error(
|
|
22
|
+
'Gradient package was not found. Make sure "react-native-linear-gradient" or "expo-linear-gradient" is installed'
|
|
23
|
+
);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export default LinearGradient;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
|
|
4
|
+
export const Pointer = props => {
|
|
5
|
+
const {
|
|
6
|
+
pointerX,
|
|
7
|
+
pointerYLocal,
|
|
8
|
+
pointerComponent,
|
|
9
|
+
pointerHeight,
|
|
10
|
+
pointerRadius,
|
|
11
|
+
pointerWidth,
|
|
12
|
+
pointerItemLocal,
|
|
13
|
+
pointerColorLocal,
|
|
14
|
+
} = props;
|
|
15
|
+
return (
|
|
16
|
+
<View
|
|
17
|
+
style={{
|
|
18
|
+
position: 'absolute',
|
|
19
|
+
left: pointerX + (pointerX.pointerShiftX || 0),
|
|
20
|
+
top: pointerYLocal - 2,
|
|
21
|
+
}}>
|
|
22
|
+
{pointerComponent ? (
|
|
23
|
+
pointerComponent()
|
|
24
|
+
) : (
|
|
25
|
+
<View
|
|
26
|
+
style={{
|
|
27
|
+
height: pointerHeight || pointerRadius * 2,
|
|
28
|
+
width: pointerWidth || pointerRadius * 2,
|
|
29
|
+
marginTop: pointerItemLocal?.pointerShiftY || 0,
|
|
30
|
+
backgroundColor: pointerColorLocal,
|
|
31
|
+
borderRadius: pointerRadius || 0,
|
|
32
|
+
}}
|
|
33
|
+
/>
|
|
34
|
+
)}
|
|
35
|
+
</View>
|
|
36
|
+
);
|
|
37
|
+
};
|