react-native-gifted-charts 1.4.12 → 1.4.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +6 -10
- package/src/BarChart/Animated2DWithGradient.tsx +197 -0
- package/src/BarChart/RenderBars.tsx +458 -0
- package/src/BarChart/RenderStackBars.tsx +385 -0
- package/src/BarChart/index.tsx +381 -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,603 @@
|
|
|
1
|
+
import React, {Fragment} from 'react';
|
|
2
|
+
import {View} from 'react-native';
|
|
3
|
+
import {
|
|
4
|
+
PopulationPyramidPropsType,
|
|
5
|
+
RulesProps,
|
|
6
|
+
ruleTypes,
|
|
7
|
+
usePopulationPyramid,
|
|
8
|
+
} from 'gifted-charts-core';
|
|
9
|
+
import {
|
|
10
|
+
ClipPath,
|
|
11
|
+
Line,
|
|
12
|
+
Rect,
|
|
13
|
+
Svg,
|
|
14
|
+
Text as SvgText,
|
|
15
|
+
Use,
|
|
16
|
+
} from 'react-native-svg';
|
|
17
|
+
import {screenWidth} from '../utils';
|
|
18
|
+
|
|
19
|
+
export const PopulationPyramid = (props: PopulationPyramidPropsType) => {
|
|
20
|
+
const {
|
|
21
|
+
width,
|
|
22
|
+
verticalMarginBetweenBars,
|
|
23
|
+
barsMapToYAxisSections,
|
|
24
|
+
data,
|
|
25
|
+
hideRules,
|
|
26
|
+
yAxisColor,
|
|
27
|
+
xAxisColor,
|
|
28
|
+
xAxisThickness,
|
|
29
|
+
xAxisType,
|
|
30
|
+
xAxisNoOfSections,
|
|
31
|
+
showXAxisIndices,
|
|
32
|
+
showXAxisLabelTexts,
|
|
33
|
+
xAxisLabelShiftX,
|
|
34
|
+
xAxisLabelPrefix,
|
|
35
|
+
xAxisLabelSuffix,
|
|
36
|
+
formatXAxisLabels,
|
|
37
|
+
showVerticalLines,
|
|
38
|
+
showYAxisIndices,
|
|
39
|
+
yAxisIndicesWidth,
|
|
40
|
+
yAxisIndicesHeight,
|
|
41
|
+
yAxisIndicesColor,
|
|
42
|
+
yAxisLabelFontSize,
|
|
43
|
+
yAxisLabelFontStyle,
|
|
44
|
+
yAxisLabelFontWeight,
|
|
45
|
+
yAxisLabelFontFamily,
|
|
46
|
+
yAxisLabelColor,
|
|
47
|
+
yAxisLabelTextMarginRight,
|
|
48
|
+
yAxisLabelTexts,
|
|
49
|
+
showValuesAsBarLabels,
|
|
50
|
+
rulesThickness,
|
|
51
|
+
rulesColor,
|
|
52
|
+
rulesType,
|
|
53
|
+
dashWidth,
|
|
54
|
+
dashGap,
|
|
55
|
+
leftBarLabelWidth,
|
|
56
|
+
leftBarLabelFontSize,
|
|
57
|
+
leftBarLabelColor,
|
|
58
|
+
leftBarLabelFontStyle,
|
|
59
|
+
leftBarLabelFontWeight,
|
|
60
|
+
leftBarLabelFontFamily,
|
|
61
|
+
leftBarLabelPrefix,
|
|
62
|
+
leftBarLabelSuffix,
|
|
63
|
+
rightBarLabelFontSize,
|
|
64
|
+
rightBarLabelColor,
|
|
65
|
+
rightBarLabelFontStyle,
|
|
66
|
+
rightBarLabelFontWeight,
|
|
67
|
+
rightBarLabelFontFamily,
|
|
68
|
+
rightBarLabelPrefix,
|
|
69
|
+
rightBarLabelSuffix,
|
|
70
|
+
formatBarLabels,
|
|
71
|
+
showMidAxis,
|
|
72
|
+
midAxisLabelFontSize,
|
|
73
|
+
midAxisLabelColor,
|
|
74
|
+
midAxisLabelFontStyle,
|
|
75
|
+
midAxisLabelFontWeight,
|
|
76
|
+
midAxisLabelFontFamily,
|
|
77
|
+
leftBarColor,
|
|
78
|
+
rightBarColor,
|
|
79
|
+
leftBarBorderColor,
|
|
80
|
+
rightBarBorderColor,
|
|
81
|
+
leftBarBorderWidth,
|
|
82
|
+
rightBarBorderWidth,
|
|
83
|
+
leftBarBorderRadius,
|
|
84
|
+
rightBarBorderRadius,
|
|
85
|
+
allCornersRounded,
|
|
86
|
+
showSurplus,
|
|
87
|
+
showSurplusLeft,
|
|
88
|
+
showSurplusRight,
|
|
89
|
+
leftSurplusColor,
|
|
90
|
+
leftSurplusBorderColor,
|
|
91
|
+
rightSurplusColor,
|
|
92
|
+
rightSurplusBorderColor,
|
|
93
|
+
leftSurplusBorderWidth,
|
|
94
|
+
rightSurplusBorderWidth,
|
|
95
|
+
yAxisLabelWidth,
|
|
96
|
+
noOfSections,
|
|
97
|
+
stepHeight,
|
|
98
|
+
containerHeightWithXaxisLabels,
|
|
99
|
+
mid,
|
|
100
|
+
barWidthFactor,
|
|
101
|
+
leftXAfterMid,
|
|
102
|
+
rightXAfterMid,
|
|
103
|
+
yAxisLineProps,
|
|
104
|
+
midAxisLineCommonProps,
|
|
105
|
+
xAxisIndicesCommonProps,
|
|
106
|
+
verticalLinesCommonProps,
|
|
107
|
+
xAxisLabelsCommonProps,
|
|
108
|
+
getXLabel,
|
|
109
|
+
} = usePopulationPyramid({...props, screenWidth});
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<View style={{height: containerHeightWithXaxisLabels, width}}>
|
|
113
|
+
<Svg fill={'none'}>
|
|
114
|
+
{/************** Y-Axis ************/}
|
|
115
|
+
<Line {...yAxisLineProps} />
|
|
116
|
+
|
|
117
|
+
{/************ Rules, X-axis and Y-Axis labels ***********/}
|
|
118
|
+
{Array.from(Array(noOfSections)).map((item, index) => {
|
|
119
|
+
const isLast = index === noOfSections - 1;
|
|
120
|
+
const y = stepHeight * (index + 1);
|
|
121
|
+
const rulesProps: RulesProps = {
|
|
122
|
+
x1: yAxisLabelWidth,
|
|
123
|
+
y1: y,
|
|
124
|
+
x2: width,
|
|
125
|
+
y2: y,
|
|
126
|
+
stroke: isLast ? xAxisColor : rulesColor,
|
|
127
|
+
strokeWidth: isLast ? xAxisThickness : rulesThickness,
|
|
128
|
+
};
|
|
129
|
+
if (
|
|
130
|
+
(isLast && xAxisType !== ruleTypes.SOLID) ||
|
|
131
|
+
(!isLast && rulesType !== ruleTypes.SOLID)
|
|
132
|
+
) {
|
|
133
|
+
rulesProps.strokeDasharray = [dashWidth, dashGap];
|
|
134
|
+
} else {
|
|
135
|
+
delete rulesProps.strokeDasharray;
|
|
136
|
+
}
|
|
137
|
+
return (
|
|
138
|
+
<Fragment key={'rule' + index}>
|
|
139
|
+
{!hideRules || isLast ? <Line {...rulesProps} /> : null}
|
|
140
|
+
{showYAxisIndices ? (
|
|
141
|
+
<Line
|
|
142
|
+
x1={yAxisLabelWidth - yAxisIndicesWidth / 2}
|
|
143
|
+
y1={y}
|
|
144
|
+
x2={yAxisLabelWidth + yAxisIndicesWidth / 2}
|
|
145
|
+
y2={y}
|
|
146
|
+
stroke={yAxisIndicesColor}
|
|
147
|
+
strokeWidth={yAxisIndicesHeight}
|
|
148
|
+
/>
|
|
149
|
+
) : null}
|
|
150
|
+
{/************** Y-Axis Labels ************/}
|
|
151
|
+
{!barsMapToYAxisSections ? (
|
|
152
|
+
<SvgText
|
|
153
|
+
x={yAxisLabelWidth - yAxisLabelTextMarginRight}
|
|
154
|
+
y={stepHeight * (index + 0.5) + yAxisLabelFontSize / 2 - 2}
|
|
155
|
+
stroke={yAxisLabelColor}
|
|
156
|
+
fontSize={yAxisLabelFontSize}
|
|
157
|
+
fontStyle={yAxisLabelFontStyle}
|
|
158
|
+
fontWeight={yAxisLabelFontWeight}
|
|
159
|
+
fontFamily={yAxisLabelFontFamily}
|
|
160
|
+
textAnchor="end">
|
|
161
|
+
{yAxisLabelTexts[index] ?? ''}
|
|
162
|
+
</SvgText>
|
|
163
|
+
) : null}
|
|
164
|
+
</Fragment>
|
|
165
|
+
);
|
|
166
|
+
})}
|
|
167
|
+
|
|
168
|
+
{/************** X-Axis Labels Left ************/}
|
|
169
|
+
{Array.from(Array(xAxisNoOfSections)).map((item, index) => {
|
|
170
|
+
const x = leftXAfterMid - (leftXAfterMid * index) / xAxisNoOfSections;
|
|
171
|
+
const unformattedXLabel = getXLabel(index);
|
|
172
|
+
const xLabel = formatXAxisLabels
|
|
173
|
+
? formatXAxisLabels(unformattedXLabel)
|
|
174
|
+
: unformattedXLabel;
|
|
175
|
+
return (
|
|
176
|
+
<Fragment key={'x-axis' + index}>
|
|
177
|
+
{showVerticalLines ? (
|
|
178
|
+
<Line {...verticalLinesCommonProps} x1={x} x2={x} />
|
|
179
|
+
) : null}
|
|
180
|
+
{showXAxisIndices ? (
|
|
181
|
+
<Line {...xAxisIndicesCommonProps} x1={x} x2={x} />
|
|
182
|
+
) : null}
|
|
183
|
+
{showXAxisLabelTexts ? (
|
|
184
|
+
<SvgText
|
|
185
|
+
{...xAxisLabelsCommonProps}
|
|
186
|
+
x={x + xAxisLabelShiftX}
|
|
187
|
+
textAnchor="middle">
|
|
188
|
+
{xAxisLabelPrefix + xLabel + xAxisLabelSuffix}
|
|
189
|
+
</SvgText>
|
|
190
|
+
) : null}
|
|
191
|
+
</Fragment>
|
|
192
|
+
);
|
|
193
|
+
})}
|
|
194
|
+
|
|
195
|
+
{/************** X-Axis Labels Right ************/}
|
|
196
|
+
{Array.from(Array(xAxisNoOfSections)).map((item, index) => {
|
|
197
|
+
if (!index && !showMidAxis) return null;
|
|
198
|
+
const x = leftXAfterMid + (leftXAfterMid * index) / xAxisNoOfSections;
|
|
199
|
+
const unformattedXLabel = getXLabel(index);
|
|
200
|
+
const xLabel = formatXAxisLabels
|
|
201
|
+
? formatXAxisLabels(unformattedXLabel)
|
|
202
|
+
: unformattedXLabel;
|
|
203
|
+
return (
|
|
204
|
+
<Fragment key={'x-axis' + index}>
|
|
205
|
+
{showVerticalLines ? (
|
|
206
|
+
<Line {...verticalLinesCommonProps} x1={x} x2={x} />
|
|
207
|
+
) : null}
|
|
208
|
+
{showXAxisIndices ? (
|
|
209
|
+
<Line {...xAxisIndicesCommonProps} x1={x} x2={x} />
|
|
210
|
+
) : null}
|
|
211
|
+
{showXAxisLabelTexts ? (
|
|
212
|
+
<SvgText
|
|
213
|
+
{...xAxisLabelsCommonProps}
|
|
214
|
+
x={x + xAxisLabelShiftX}
|
|
215
|
+
textAnchor="middle">
|
|
216
|
+
{xAxisLabelPrefix + xLabel + xAxisLabelSuffix}
|
|
217
|
+
</SvgText>
|
|
218
|
+
) : null}
|
|
219
|
+
</Fragment>
|
|
220
|
+
);
|
|
221
|
+
})}
|
|
222
|
+
|
|
223
|
+
{/************** Bars ************/}
|
|
224
|
+
{data.map((item, index) => {
|
|
225
|
+
const leftWidth = item.left * barWidthFactor;
|
|
226
|
+
const rightWidth = item.right * barWidthFactor;
|
|
227
|
+
const y = stepHeight * index + verticalMarginBetweenBars;
|
|
228
|
+
|
|
229
|
+
const leftSurplusWidth = leftWidth - rightWidth;
|
|
230
|
+
const rightSurplusWidth = rightWidth - leftWidth;
|
|
231
|
+
const leftRadius =
|
|
232
|
+
item.leftBarBorderRadius ??
|
|
233
|
+
item.barBorderRadius ??
|
|
234
|
+
leftBarBorderRadius;
|
|
235
|
+
const rightRadius =
|
|
236
|
+
item.rightBarBorderRadius ??
|
|
237
|
+
item.barBorderRadius ??
|
|
238
|
+
rightBarBorderRadius;
|
|
239
|
+
|
|
240
|
+
const leftBorderWidth =
|
|
241
|
+
item.leftBarBorderWidth ??
|
|
242
|
+
item.barBorderWidth ??
|
|
243
|
+
leftBarBorderWidth;
|
|
244
|
+
const rightBorderWidth =
|
|
245
|
+
item.rightBarBorderWidth ??
|
|
246
|
+
item.barBorderWidth ??
|
|
247
|
+
rightBarBorderWidth;
|
|
248
|
+
|
|
249
|
+
const unFormattedLeftBarLabel =
|
|
250
|
+
item.leftBarLabel ??
|
|
251
|
+
(showValuesAsBarLabels ? item.left.toString() : '');
|
|
252
|
+
const leftBarLabel = formatBarLabels
|
|
253
|
+
? formatBarLabels(unFormattedLeftBarLabel)
|
|
254
|
+
: unFormattedLeftBarLabel;
|
|
255
|
+
|
|
256
|
+
const unFormattedRightBarLabel =
|
|
257
|
+
item.rightBarLabel ??
|
|
258
|
+
(showValuesAsBarLabels ? item.right.toString() : '');
|
|
259
|
+
const rightBarLabel = formatBarLabels
|
|
260
|
+
? formatBarLabels(unFormattedRightBarLabel)
|
|
261
|
+
: unFormattedRightBarLabel;
|
|
262
|
+
|
|
263
|
+
const leftLabelFontSize =
|
|
264
|
+
item.leftBarLabelFontSize ?? leftBarLabelFontSize;
|
|
265
|
+
|
|
266
|
+
const leftLabelX =
|
|
267
|
+
leftXAfterMid -
|
|
268
|
+
leftWidth -
|
|
269
|
+
leftBarBorderWidth / 2 -
|
|
270
|
+
yAxisLabelWidth / 2 -
|
|
271
|
+
leftBarLabelWidth / 2 +
|
|
272
|
+
28 -
|
|
273
|
+
(leftBarLabel.length * leftLabelFontSize) / 2 +
|
|
274
|
+
(item.leftBarLabelShift ?? props.leftBarLabelShift ?? 0);
|
|
275
|
+
|
|
276
|
+
const rightLabelX =
|
|
277
|
+
rightXAfterMid +
|
|
278
|
+
rightBarBorderWidth / 2 +
|
|
279
|
+
rightWidth +
|
|
280
|
+
3 +
|
|
281
|
+
(item.rightBarLabelShift ?? props.rightBarLabelShift ?? 0);
|
|
282
|
+
|
|
283
|
+
const leftBarCommonProps = {
|
|
284
|
+
x: leftXAfterMid - leftWidth - leftBarBorderWidth / 2,
|
|
285
|
+
y: y,
|
|
286
|
+
width: leftWidth,
|
|
287
|
+
height: stepHeight - verticalMarginBetweenBars * 2,
|
|
288
|
+
rx: leftRadius,
|
|
289
|
+
ry: leftRadius,
|
|
290
|
+
};
|
|
291
|
+
const rightBarCommonProps = {
|
|
292
|
+
x: rightXAfterMid + rightBarBorderWidth / 2,
|
|
293
|
+
y: y,
|
|
294
|
+
width: rightWidth,
|
|
295
|
+
height: stepHeight - verticalMarginBetweenBars * 2,
|
|
296
|
+
rx: rightRadius,
|
|
297
|
+
ry: rightRadius,
|
|
298
|
+
};
|
|
299
|
+
return (
|
|
300
|
+
<Fragment key={'bars' + index}>
|
|
301
|
+
{/************** Y-Axis Labels ************/}
|
|
302
|
+
{barsMapToYAxisSections ? (
|
|
303
|
+
<SvgText
|
|
304
|
+
x={yAxisLabelWidth - yAxisLabelTextMarginRight}
|
|
305
|
+
y={stepHeight * (index + 0.5) + yAxisLabelFontSize / 2 - 2}
|
|
306
|
+
stroke={yAxisLabelColor}
|
|
307
|
+
fontSize={yAxisLabelFontSize}
|
|
308
|
+
fontStyle={yAxisLabelFontStyle}
|
|
309
|
+
fontWeight={yAxisLabelFontWeight}
|
|
310
|
+
fontFamily={yAxisLabelFontFamily}
|
|
311
|
+
textAnchor="end">
|
|
312
|
+
{item.yAxisLabel ?? yAxisLabelTexts[index] ?? ''}
|
|
313
|
+
</SvgText>
|
|
314
|
+
) : null}
|
|
315
|
+
|
|
316
|
+
{/************** Left Bars ************/}
|
|
317
|
+
<Rect
|
|
318
|
+
{...leftBarCommonProps}
|
|
319
|
+
fill={item.leftBarColor ?? leftBarColor}
|
|
320
|
+
stroke={item.leftBarBorderColor ?? leftBarBorderColor}
|
|
321
|
+
strokeWidth={leftBorderWidth}
|
|
322
|
+
/>
|
|
323
|
+
<ClipPath id={'cp-left' + index}>
|
|
324
|
+
<Rect {...leftBarCommonProps} />
|
|
325
|
+
</ClipPath>
|
|
326
|
+
{/********* Hide inner border-radius ********/}
|
|
327
|
+
{!allCornersRounded && leftWidth >= leftRadius ? (
|
|
328
|
+
<>
|
|
329
|
+
<Rect
|
|
330
|
+
x={leftXAfterMid - leftRadius}
|
|
331
|
+
y={y}
|
|
332
|
+
width={leftRadius}
|
|
333
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
334
|
+
fill={item.leftBarColor ?? leftBarColor}
|
|
335
|
+
/>
|
|
336
|
+
{/********* work-around for border ********/}
|
|
337
|
+
{leftBorderWidth ? (
|
|
338
|
+
<>
|
|
339
|
+
<Line
|
|
340
|
+
x1={leftXAfterMid - leftRadius}
|
|
341
|
+
y1={y}
|
|
342
|
+
x2={leftXAfterMid}
|
|
343
|
+
y2={y}
|
|
344
|
+
stroke={item.leftBarBorderColor ?? leftBarBorderColor}
|
|
345
|
+
strokeWidth={leftBorderWidth}
|
|
346
|
+
/>
|
|
347
|
+
<Line
|
|
348
|
+
x1={leftXAfterMid - leftRadius}
|
|
349
|
+
y1={y + stepHeight - verticalMarginBetweenBars * 2}
|
|
350
|
+
x2={leftXAfterMid}
|
|
351
|
+
y2={y + stepHeight - verticalMarginBetweenBars * 2}
|
|
352
|
+
stroke={item.leftBarBorderColor ?? leftBarBorderColor}
|
|
353
|
+
strokeWidth={leftBorderWidth}
|
|
354
|
+
/>
|
|
355
|
+
</>
|
|
356
|
+
) : null}
|
|
357
|
+
</>
|
|
358
|
+
) : null}
|
|
359
|
+
|
|
360
|
+
{/************** Left Bar Labels ************/}
|
|
361
|
+
{leftBarLabel !== '' ? (
|
|
362
|
+
<SvgText
|
|
363
|
+
x={leftLabelX}
|
|
364
|
+
y={stepHeight * (index + 0.5) + yAxisLabelFontSize / 2 - 2}
|
|
365
|
+
stroke={item.leftBarLabelColor ?? leftBarLabelColor}
|
|
366
|
+
fontSize={leftLabelFontSize}
|
|
367
|
+
fontStyle={
|
|
368
|
+
item.leftBarLabelFontStyle ?? leftBarLabelFontStyle
|
|
369
|
+
}
|
|
370
|
+
fontWeight={
|
|
371
|
+
item.leftBarLabelFontWeight ?? leftBarLabelFontWeight
|
|
372
|
+
}
|
|
373
|
+
fontFamily={
|
|
374
|
+
item.leftBarLabelFontFamily ?? leftBarLabelFontFamily
|
|
375
|
+
}
|
|
376
|
+
textAnchor="start">
|
|
377
|
+
{leftBarLabelPrefix + leftBarLabel + leftBarLabelSuffix}
|
|
378
|
+
</SvgText>
|
|
379
|
+
) : null}
|
|
380
|
+
|
|
381
|
+
{/************** Right Bars ************/}
|
|
382
|
+
<Rect
|
|
383
|
+
{...rightBarCommonProps}
|
|
384
|
+
fill={item.rightBarColor ?? rightBarColor}
|
|
385
|
+
stroke={item.rightBarBorderColor ?? rightBarBorderColor}
|
|
386
|
+
strokeWidth={rightBorderWidth}
|
|
387
|
+
/>
|
|
388
|
+
<ClipPath id={'cp-right' + index}>
|
|
389
|
+
<Rect {...rightBarCommonProps} />
|
|
390
|
+
</ClipPath>
|
|
391
|
+
{/********* Hide inner border-radius ********/}
|
|
392
|
+
{!allCornersRounded && rightWidth >= rightRadius ? (
|
|
393
|
+
<>
|
|
394
|
+
<Rect
|
|
395
|
+
x={rightXAfterMid}
|
|
396
|
+
y={y}
|
|
397
|
+
width={rightRadius}
|
|
398
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
399
|
+
fill={item.rightBarColor ?? rightBarColor}
|
|
400
|
+
/>
|
|
401
|
+
{/********* work-around for border ********/}
|
|
402
|
+
{rightBorderWidth ? (
|
|
403
|
+
<>
|
|
404
|
+
<Line
|
|
405
|
+
x1={rightXAfterMid}
|
|
406
|
+
y1={y}
|
|
407
|
+
x2={rightXAfterMid + rightRadius}
|
|
408
|
+
y2={y}
|
|
409
|
+
stroke={item.rightBarBorderColor ?? rightBarBorderColor}
|
|
410
|
+
strokeWidth={rightBorderWidth}
|
|
411
|
+
/>
|
|
412
|
+
<Line
|
|
413
|
+
x1={rightXAfterMid}
|
|
414
|
+
y1={y + stepHeight - verticalMarginBetweenBars * 2}
|
|
415
|
+
x2={rightXAfterMid + rightRadius}
|
|
416
|
+
y2={y + stepHeight - verticalMarginBetweenBars * 2}
|
|
417
|
+
stroke={item.rightBarBorderColor ?? rightBarBorderColor}
|
|
418
|
+
strokeWidth={rightBorderWidth}
|
|
419
|
+
/>
|
|
420
|
+
</>
|
|
421
|
+
) : null}
|
|
422
|
+
</>
|
|
423
|
+
) : null}
|
|
424
|
+
|
|
425
|
+
{/************** Right Bar Labels ************/}
|
|
426
|
+
{rightBarLabel !== '' ? (
|
|
427
|
+
<SvgText
|
|
428
|
+
x={rightLabelX}
|
|
429
|
+
y={stepHeight * (index + 0.5) + yAxisLabelFontSize / 2 - 2}
|
|
430
|
+
stroke={item.rightBarLabelColor ?? rightBarLabelColor}
|
|
431
|
+
fontSize={item.rightBarLabelFontSize ?? rightBarLabelFontSize}
|
|
432
|
+
fontStyle={
|
|
433
|
+
item.rightBarLabelFontStyle ?? rightBarLabelFontStyle
|
|
434
|
+
}
|
|
435
|
+
fontWeight={
|
|
436
|
+
item.rightBarLabelFontWeight ?? rightBarLabelFontWeight
|
|
437
|
+
}
|
|
438
|
+
fontFamily={
|
|
439
|
+
item.rightBarLabelFontFamily ?? rightBarLabelFontFamily
|
|
440
|
+
}
|
|
441
|
+
textAnchor="start">
|
|
442
|
+
{rightBarLabelPrefix + rightBarLabel + rightBarLabelSuffix}
|
|
443
|
+
</SvgText>
|
|
444
|
+
) : null}
|
|
445
|
+
|
|
446
|
+
{/************** Left Surplus ************/}
|
|
447
|
+
{(showSurplus ||
|
|
448
|
+
showSurplusLeft ||
|
|
449
|
+
item.showSurplus ||
|
|
450
|
+
item.showSurplusLeft) &&
|
|
451
|
+
leftSurplusWidth > 0 ? (
|
|
452
|
+
<>
|
|
453
|
+
<Rect
|
|
454
|
+
id={'l-spls' + index}
|
|
455
|
+
x={leftXAfterMid - leftWidth - leftBarBorderWidth / 2}
|
|
456
|
+
y={y}
|
|
457
|
+
width={leftSurplusWidth}
|
|
458
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
459
|
+
stroke={
|
|
460
|
+
item.leftSurplusBorderColor ?? leftSurplusBorderColor
|
|
461
|
+
}
|
|
462
|
+
strokeWidth={
|
|
463
|
+
item.leftSurplusBorderWidth ?? leftSurplusBorderWidth
|
|
464
|
+
}
|
|
465
|
+
/>
|
|
466
|
+
<Use
|
|
467
|
+
fill={item.leftSurplusColor ?? leftSurplusColor}
|
|
468
|
+
clipPath={'#cp-left' + index}
|
|
469
|
+
href={'#l-spls' + index}
|
|
470
|
+
/>
|
|
471
|
+
{/********* remove inner curve ********/}
|
|
472
|
+
{leftSurplusWidth >= leftRadius ? (
|
|
473
|
+
<>
|
|
474
|
+
<Rect
|
|
475
|
+
id={'hide-in-left' + index}
|
|
476
|
+
x={
|
|
477
|
+
leftXAfterMid -
|
|
478
|
+
leftWidth -
|
|
479
|
+
leftBarBorderWidth +
|
|
480
|
+
leftSurplusWidth -
|
|
481
|
+
leftRadius
|
|
482
|
+
}
|
|
483
|
+
y={y}
|
|
484
|
+
width={leftRadius}
|
|
485
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
486
|
+
/>
|
|
487
|
+
<Use
|
|
488
|
+
fill={item.leftSurplusColor ?? leftSurplusColor}
|
|
489
|
+
clipPath={`url(#cp-left${index})`}
|
|
490
|
+
href={'#hide-in-left' + index}
|
|
491
|
+
/>
|
|
492
|
+
</>
|
|
493
|
+
) : null}
|
|
494
|
+
</>
|
|
495
|
+
) : null}
|
|
496
|
+
{/************** Right Surplus ************/}
|
|
497
|
+
{(showSurplus ||
|
|
498
|
+
showSurplusRight ||
|
|
499
|
+
item.showSurplus ||
|
|
500
|
+
item.showSurplusRight) &&
|
|
501
|
+
rightSurplusWidth > 0 ? (
|
|
502
|
+
<>
|
|
503
|
+
<Rect
|
|
504
|
+
id={'r-spls' + index}
|
|
505
|
+
x={
|
|
506
|
+
rightXAfterMid +
|
|
507
|
+
rightBarBorderWidth / 2 +
|
|
508
|
+
rightWidth -
|
|
509
|
+
rightSurplusWidth
|
|
510
|
+
}
|
|
511
|
+
y={y}
|
|
512
|
+
width={rightSurplusWidth}
|
|
513
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
514
|
+
stroke={
|
|
515
|
+
item.rightSurplusBorderColor ?? rightSurplusBorderColor
|
|
516
|
+
}
|
|
517
|
+
strokeWidth={
|
|
518
|
+
item.rightSurplusBorderWidth ?? rightSurplusBorderWidth
|
|
519
|
+
}
|
|
520
|
+
/>
|
|
521
|
+
<Use
|
|
522
|
+
fill={item.rightSurplusColor ?? rightSurplusColor}
|
|
523
|
+
clipPath={'#cp-right' + index}
|
|
524
|
+
href={'#r-spls' + index}
|
|
525
|
+
/>
|
|
526
|
+
{/********* remove inner curve ********/}
|
|
527
|
+
{rightSurplusWidth >= rightRadius ? (
|
|
528
|
+
<>
|
|
529
|
+
<Rect
|
|
530
|
+
id={'hide-in-right' + index}
|
|
531
|
+
x={
|
|
532
|
+
rightXAfterMid +
|
|
533
|
+
rightBarBorderWidth / 2 +
|
|
534
|
+
rightWidth -
|
|
535
|
+
rightSurplusWidth
|
|
536
|
+
}
|
|
537
|
+
y={y}
|
|
538
|
+
width={rightRadius}
|
|
539
|
+
height={stepHeight - verticalMarginBetweenBars * 2}
|
|
540
|
+
/>
|
|
541
|
+
<Use
|
|
542
|
+
fill={item.rightSurplusColor ?? rightSurplusColor}
|
|
543
|
+
clipPath={`url(#cp-right${index})`}
|
|
544
|
+
href={'#hide-in-right' + index}
|
|
545
|
+
/>
|
|
546
|
+
</>
|
|
547
|
+
) : null}
|
|
548
|
+
</>
|
|
549
|
+
) : null}
|
|
550
|
+
</Fragment>
|
|
551
|
+
);
|
|
552
|
+
})}
|
|
553
|
+
|
|
554
|
+
{/************** Mid Axis ************/}
|
|
555
|
+
{showMidAxis ? (
|
|
556
|
+
<>
|
|
557
|
+
<Line
|
|
558
|
+
{...midAxisLineCommonProps}
|
|
559
|
+
stroke={
|
|
560
|
+
props.midAxisLeftColor ?? props.midAxisColor ?? yAxisColor
|
|
561
|
+
}
|
|
562
|
+
x1={leftXAfterMid}
|
|
563
|
+
x2={leftXAfterMid}
|
|
564
|
+
/>
|
|
565
|
+
|
|
566
|
+
<Line
|
|
567
|
+
{...midAxisLineCommonProps}
|
|
568
|
+
stroke={
|
|
569
|
+
props.midAxisRightColor ?? props.midAxisColor ?? yAxisColor
|
|
570
|
+
}
|
|
571
|
+
x1={rightXAfterMid}
|
|
572
|
+
x2={rightXAfterMid}
|
|
573
|
+
/>
|
|
574
|
+
|
|
575
|
+
{data.map((item, index) => {
|
|
576
|
+
const y = stepHeight * (index + 0.5);
|
|
577
|
+
return (
|
|
578
|
+
<SvgText
|
|
579
|
+
key={'ml' + index}
|
|
580
|
+
x={mid}
|
|
581
|
+
y={y + midAxisLabelFontSize / 2}
|
|
582
|
+
stroke={item.midAxisLabelColor ?? midAxisLabelColor}
|
|
583
|
+
fontSize={item.midAxisLabelFontSize ?? midAxisLabelFontSize}
|
|
584
|
+
fontStyle={
|
|
585
|
+
item.midAxisLabelFontStyle ?? midAxisLabelFontStyle
|
|
586
|
+
}
|
|
587
|
+
fontWeight={
|
|
588
|
+
item.midAxisLabelFontWeight ?? midAxisLabelFontWeight
|
|
589
|
+
}
|
|
590
|
+
fontFamily={
|
|
591
|
+
item.midAxisLabelFontFamily ?? midAxisLabelFontFamily
|
|
592
|
+
}
|
|
593
|
+
textAnchor="middle">
|
|
594
|
+
{item.midAxisLabel ?? ''}
|
|
595
|
+
</SvgText>
|
|
596
|
+
);
|
|
597
|
+
})}
|
|
598
|
+
</>
|
|
599
|
+
) : null}
|
|
600
|
+
</Svg>
|
|
601
|
+
</View>
|
|
602
|
+
);
|
|
603
|
+
};
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export {BarChart} from './BarChart';
|
|
2
|
+
export {PieChart} from './PieChart';
|
|
3
|
+
export {PieChartPro} from './PieChartPro';
|
|
4
|
+
export {LineChart} from './LineChart';
|
|
5
|
+
export {LineChartBicolor} from './LineChart/LineChartBicolor';
|
|
6
|
+
export {PopulationPyramid} from './PopulationPyramid';
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
barDataItem,
|
|
10
|
+
stackDataItem,
|
|
11
|
+
BarChartPropsType,
|
|
12
|
+
StackedBarChartPropsType,
|
|
13
|
+
pieDataItem,
|
|
14
|
+
PieChartPropsType,
|
|
15
|
+
lineDataItem,
|
|
16
|
+
bicolorLineDataItem,
|
|
17
|
+
LineChartPropsType,
|
|
18
|
+
LineChartBicolorPropsType,
|
|
19
|
+
popnPyramidDataItem,
|
|
20
|
+
PopulationPyramidPropsType,
|
|
21
|
+
chartTypes,
|
|
22
|
+
ruleTypes,
|
|
23
|
+
yAxisSides,
|
|
24
|
+
EdgePosition,
|
|
25
|
+
} from 'gifted-charts-core';
|
package/src/todos.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Features
|
|
2
|
+
|
|
3
|
+
1. Issue with eslint - tsc https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/222
|
|
4
|
+
|
|
5
|
+
## To-dos in documentation-
|
|
6
|
+
|
|
7
|
+
1. Prepare a doc for Line chart with negative values
|
|
8
|
+
2. Prepare a doc for gaps in data values https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/405 and https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/353
|
|
9
|
+
3. Prepare a doc for Line chart with y axis on right side
|
|
10
|
+
4. Prepare a doc for Line chart with gaps in the line https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/100
|
|
11
|
+
5. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
|
|
12
|
+
6. Prepare a doc for Line chart with smoothly scrolling data pointer and strip (along with pointerShiftX)
|
|
13
|
+
7. Prepare a doc for labelsPosition in Pie and Donut charts
|
|
14
|
+
8. Prepare a doc for adjustToWidth in Line and Area charts
|
|
15
|
+
9. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
|
|
16
|
+
10. Prepare a doc for vertical lines to explain noOfVerticalLines and verticalLinesSpacing props. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/205
|
|
17
|
+
11. Prepare a doc for negative marginBottom instead of marginTop for x axis labels. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/190
|
|
18
|
+
12. Add about endSpacing in docs
|
|
19
|
+
|
|
20
|
+
## Architecture Enhancement
|
|
21
|
+
|
|
22
|
+
1. Make it compliant with React js
|
|
23
|
+
2. Write Snapshot tests for more example charts (snapshot tests for some charts are already written)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {Dimensions} from 'react-native';
|
|
2
|
+
|
|
3
|
+
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
4
|
+
const versionString = require('react-native/package.json').version;
|
|
5
|
+
|
|
6
|
+
const versionAr = versionString?.split?.('.') ?? '';
|
|
7
|
+
const msb = Number(versionAr[0]);
|
|
8
|
+
const mid = Number(versionAr[1]);
|
|
9
|
+
const lsb = Number(versionAr[2]);
|
|
10
|
+
|
|
11
|
+
export const rnVersion =
|
|
12
|
+
(!isNaN(msb) ? msb : 0) * 1000000 +
|
|
13
|
+
(!isNaN(mid) ? mid : 0) * 10000 +
|
|
14
|
+
(!isNaN(lsb) ? lsb : 0);
|
|
15
|
+
|
|
16
|
+
export const screenWidth = Dimensions.get('window').width;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireWildcard(require("react"));var _reactNative=require("react-native");var _reactNativeSvg=_interopRequireWildcard(require("react-native-svg"));var _cap=_interopRequireDefault(require("../Components/BarSpecificComponents/cap"));var _LinearGradient=_interopRequireDefault(require("../Components/common/LinearGradient"));var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/Users/abhinandankushwaha/sites/projects/react-native-gifted-charts/src/BarChart/Animated2DWithGradient.tsx";function _getRequireWildcardCache(e){if("function"!=typeof WeakMap)return null;var r=new WeakMap(),t=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(e){return e?t:r;})(e);}function _interopRequireWildcard(e,r){if(!r&&e&&e.__esModule)return e;if(null===e||"object"!=typeof e&&"function"!=typeof e)return{default:e};var t=_getRequireWildcardCache(r);if(t&&t.has(e))return t.get(e);var n={__proto__:null},a=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var u in e)if("default"!==u&&{}.hasOwnProperty.call(e,u)){var i=a?Object.getOwnPropertyDescriptor(e,u):null;i&&(i.get||i.set)?Object.defineProperty(n,u,i):n[u]=e[u];}return n.default=e,t&&t.set(e,n),n;}if(_reactNative.Platform.OS==='android'){_reactNative.UIManager.setLayoutAnimationEnabledExperimental&&_reactNative.UIManager.setLayoutAnimationEnabledExperimental(true);}var Animated2DWithGradient=function Animated2DWithGradient(props){var barBackgroundPattern=props.barBackgroundPattern,patternId=props.patternId,barWidth=props.barWidth,barStyle=props.barStyle,item=props.item,index=props.index,opacity=props.opacity,animationDuration=props.animationDuration,noGradient=props.noGradient,noAnimation=props.noAnimation,containerHeight=props.containerHeight,maxValue=props.maxValue,barMarginBottom=props.barMarginBottom,barInnerComponent=props.barInnerComponent,intactTopLabel=props.intactTopLabel,showValuesAsTopLabel=props.showValuesAsTopLabel,topLabelContainerStyle=props.topLabelContainerStyle,topLabelTextStyle=props.topLabelTextStyle,commonStyleForBar=props.commonStyleForBar,barStyleWithBackground=props.barStyleWithBackground,yAxisOffset=props.yAxisOffset;var _useState=(0,_react.useState)(noAnimation?props.height:0.2),_useState2=(0,_slicedToArray2.default)(_useState,2),height=_useState2[0],setHeight=_useState2[1];var _useState3=(0,_react.useState)(noAnimation?false:true),_useState4=(0,_slicedToArray2.default)(_useState3,2),initialRender=_useState4[0],setInitialRender=_useState4[1];(0,_react.useEffect)(function(){if(!noAnimation){if(initialRender){setTimeout(function(){return layoutAppear();},20);}else{elevate();}}},[props.height]);var elevate=function elevate(){_reactNative.LayoutAnimation.configureNext({duration:animationDuration,update:{type:'linear',property:'scaleXY'}});setHeight(props.height);};var layoutAppear=function layoutAppear(){_reactNative.LayoutAnimation.configureNext({duration:_reactNative.Platform.OS=='ios'?animationDuration:20,create:{type:'linear',property:'opacity'},update:{type:'linear',property:'scaleXY'}});setInitialRender(false);setTimeout(function(){return elevate();},_reactNative.Platform.OS=='ios'?10:100);};return(0,_jsxRuntime.jsxs)(_jsxRuntime.Fragment,{children:[!initialRender&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:'absolute',bottom:-0.5,width:'100%',overflow:'hidden',height:(noAnimation?Math.max(props.minHeight,Math.abs(height)):height)-(barMarginBottom||0)},children:(0,_jsxRuntime.jsxs)(_reactNative.View,{style:[{width:'100%',height:(noAnimation?Math.max(props.minHeight,Math.abs(height)):height)-(barMarginBottom||0)},item.barStyle||barStyle],children:[noGradient?(0,_jsxRuntime.jsx)(_reactNative.View,{style:barStyleWithBackground,children:props.cappedBars&&item.value?(0,_jsxRuntime.jsx)(_cap.default,{capThicknessFromItem:item.capThickness,capThicknessFromProps:props.capThickness,capColorFromItem:item.capColor,capColorFromProps:props.capColor,capRadiusFromItem:item.capRadius,capRadiusFromProps:props.capRadius}):null}):(0,_jsxRuntime.jsx)(_LinearGradient.default,{style:commonStyleForBar,start:{x:0,y:0},end:{x:1,y:1},colors:[item.gradientColor||props.gradientColor||'white',item.frontColor||props.frontColor||'black'],children:props.cappedBars&&(0,_jsxRuntime.jsx)(_reactNative.View,{style:{position:'absolute',width:'100%',height:item.capThickness===0?0:item.capThickness||props.capThickness||6,backgroundColor:item.capColor||props.capColor||'black',borderTopLeftRadius:item.capRadius===0?0:item.capRadius||props.capRadius||0,borderTopRightRadius:item.capRadius===0?0:item.capRadius||props.capRadius||0}})}),(item.barBackgroundPattern||barBackgroundPattern)&&(0,_jsxRuntime.jsxs)(_reactNativeSvg.default,{children:[(0,_jsxRuntime.jsx)(_reactNativeSvg.Defs,{children:item.barBackgroundPattern?item.barBackgroundPattern():barBackgroundPattern==null?void 0:barBackgroundPattern()}),(0,_jsxRuntime.jsx)(_reactNativeSvg.Rect,{stroke:"transparent",x:"1",y:"1",width:item.barWidth||props.barWidth||30,height:noAnimation?Math.abs(height):height,fill:`url(#${item.patternId||patternId})`})]}),barInnerComponent?(0,_jsxRuntime.jsx)(_reactNative.View,{style:{height:'100%',width:'100%'},children:barInnerComponent(item,index)}):null]})}),item.topLabelComponent||showValuesAsTopLabel?(0,_jsxRuntime.jsx)(_reactNative.View,{style:[{position:'absolute',top:(item.barWidth||barWidth||30)*-1,height:item.barWidth||barWidth||30,width:item.barWidth||barWidth||30,justifyContent:props.horizontal&&!intactTopLabel||item.value<0?'center':'flex-end',alignItems:'center',opacity:opacity},item.value<0&&{transform:[{rotate:'180deg'}]},props.horizontal&&!intactTopLabel&&{transform:[{rotate:'270deg'}]},topLabelContainerStyle!=null?topLabelContainerStyle:item.topLabelContainerStyle],children:showValuesAsTopLabel?(0,_jsxRuntime.jsx)(_reactNative.Text,{style:topLabelTextStyle,children:item.value+yAxisOffset}):item.topLabelComponent==null?void 0:item.topLabelComponent()}):null]});};var _default=exports.default=Animated2DWithGradient;
|