react-native-gifted-charts 1.3.33 → 1.4.1
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/README.md +9 -2
- package/package.json +2 -1
- package/src/BarChart/Animated2DWithGradient.tsx +13 -154
- package/src/BarChart/RenderBars.tsx +29 -179
- package/src/BarChart/RenderStackBars.tsx +22 -104
- package/src/BarChart/index.tsx +87 -686
- package/src/Components/AnimatedThreeDBar/index.tsx +16 -48
- package/src/Components/BarAndLineChartsWrapper/index.tsx +38 -283
- package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +17 -339
- 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 +1 -1
- package/src/Components/BarSpecificComponents/cap.tsx +1 -1
- package/src/Components/common/StripAndLabel.tsx +3 -56
- package/src/Components/lineSvg.tsx +1 -1
- package/src/LineChart/LineChartBicolor.tsx +80 -516
- package/src/LineChart/index.tsx +266 -1778
- package/src/PieChart/index.tsx +20 -84
- package/src/PieChart/main.tsx +47 -119
- package/src/PopulationPyramid/index.tsx +90 -203
- package/src/index.tsx +7 -12
- package/src/BarChart/types.ts +0 -394
- package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart.tsx +0 -402
- package/src/LineChart/types.ts +0 -575
- package/src/PieChart/types.ts +0 -77
- package/src/PopulationPyramid/types.ts +0 -200
- package/src/utils/constants.ts +0 -333
- package/src/utils/index.tsx +0 -1137
- package/src/utils/types.ts +0 -360
|
@@ -2,18 +2,16 @@ import React from 'react';
|
|
|
2
2
|
import {Text, View} from 'react-native';
|
|
3
3
|
import Rule from '../lineSvg';
|
|
4
4
|
import {styles} from '../../LineChart/styles';
|
|
5
|
-
import {AxesAndRulesDefaults, yAxisSides} from '../../utils/constants';
|
|
6
5
|
import {
|
|
6
|
+
getHorizSectionVals,
|
|
7
|
+
yAxisSides,
|
|
7
8
|
HorizSectionsType,
|
|
8
9
|
horizSectionPropTypes,
|
|
9
|
-
|
|
10
|
-
} from '../../utils/types';
|
|
11
|
-
import {computeMaxAndMinItems, getLabelTextUtil} from '../../utils';
|
|
10
|
+
} from 'gifted-charts-core';
|
|
12
11
|
|
|
13
12
|
export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
14
13
|
const {
|
|
15
14
|
width,
|
|
16
|
-
horizSections: h,
|
|
17
15
|
noOfSectionsBelowXAxis,
|
|
18
16
|
totalWidth,
|
|
19
17
|
endSpacing,
|
|
@@ -25,8 +23,6 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
25
23
|
yAxisLabelContainerStyle,
|
|
26
24
|
yAxisThickness,
|
|
27
25
|
yAxisColor,
|
|
28
|
-
yAxisExtraHeight,
|
|
29
|
-
trimYAxisAtTop,
|
|
30
26
|
xAxisThickness,
|
|
31
27
|
xAxisColor,
|
|
32
28
|
xAxisLength,
|
|
@@ -48,359 +44,41 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
48
44
|
|
|
49
45
|
hideOrigin,
|
|
50
46
|
hideYAxisText,
|
|
51
|
-
showFractionalValues,
|
|
52
47
|
yAxisTextNumberOfLines,
|
|
53
|
-
yAxisLabelPrefix,
|
|
54
|
-
yAxisLabelSuffix,
|
|
55
48
|
yAxisTextStyle,
|
|
56
49
|
rotateYAxisTexts,
|
|
57
50
|
rtl,
|
|
58
51
|
|
|
59
52
|
containerHeight,
|
|
60
53
|
maxValue,
|
|
61
|
-
|
|
62
|
-
referenceLinesConfig,
|
|
63
|
-
|
|
64
|
-
yAxisLabelTexts,
|
|
65
54
|
yAxisOffset,
|
|
66
55
|
|
|
67
56
|
horizontal,
|
|
68
57
|
yAxisAtTop,
|
|
69
|
-
|
|
70
|
-
stepValue,
|
|
71
|
-
roundToDigits,
|
|
72
|
-
|
|
73
|
-
secondaryData,
|
|
74
58
|
secondaryYAxis,
|
|
75
|
-
formatYLabel,
|
|
76
59
|
onlyReferenceLines,
|
|
77
60
|
renderReferenceLines,
|
|
78
61
|
} = props;
|
|
79
62
|
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* *
|
|
86
|
-
***********************************************************************************************************************************/
|
|
87
|
-
|
|
88
|
-
const secondaryYAxisConfig: secondaryYAxisType = {
|
|
89
|
-
noOfSections: secondaryYAxis?.noOfSections ?? noOfSections,
|
|
90
|
-
maxValue: secondaryYAxis?.maxValue,
|
|
91
|
-
mostNegativeValue: secondaryYAxis?.mostNegativeValue,
|
|
92
|
-
stepValue: secondaryYAxis?.stepValue,
|
|
93
|
-
stepHeight: secondaryYAxis?.stepHeight,
|
|
94
|
-
|
|
95
|
-
showFractionalValues:
|
|
96
|
-
secondaryYAxis?.showFractionalValues ?? showFractionalValues,
|
|
97
|
-
roundToDigits: secondaryYAxis?.roundToDigits ?? roundToDigits,
|
|
98
|
-
noOfSectionsBelowXAxis:
|
|
99
|
-
secondaryYAxis?.noOfSectionsBelowXAxis ?? noOfSectionsBelowXAxis,
|
|
100
|
-
|
|
101
|
-
showYAxisIndices: secondaryYAxis?.showYAxisIndices ?? showYAxisIndices,
|
|
102
|
-
yAxisIndicesHeight:
|
|
103
|
-
secondaryYAxis?.yAxisIndicesHeight ?? yAxisIndicesHeight,
|
|
104
|
-
yAxisIndicesWidth: secondaryYAxis?.yAxisIndicesWidth ?? yAxisIndicesWidth,
|
|
105
|
-
yAxisIndicesColor: secondaryYAxis?.yAxisIndicesColor ?? yAxisIndicesColor,
|
|
106
|
-
|
|
107
|
-
yAxisSide: secondaryYAxis?.yAxisSide ?? yAxisSide,
|
|
108
|
-
yAxisOffset: secondaryYAxis?.yAxisOffset,
|
|
109
|
-
yAxisThickness: secondaryYAxis?.yAxisThickness ?? yAxisThickness,
|
|
110
|
-
yAxisColor: secondaryYAxis?.yAxisColor ?? yAxisColor,
|
|
111
|
-
yAxisLabelContainerStyle:
|
|
112
|
-
secondaryYAxis?.yAxisLabelContainerStyle ?? yAxisLabelContainerStyle,
|
|
113
|
-
yAxisLabelTexts: secondaryYAxis?.yAxisLabelTexts ?? yAxisLabelTexts,
|
|
114
|
-
yAxisTextStyle: secondaryYAxis?.yAxisTextStyle ?? yAxisTextStyle,
|
|
115
|
-
yAxisTextNumberOfLines:
|
|
116
|
-
secondaryYAxis?.yAxisTextNumberOfLines ?? yAxisTextNumberOfLines,
|
|
117
|
-
yAxisLabelWidth: secondaryYAxis?.yAxisLabelWidth ?? yAxisLabelWidth,
|
|
118
|
-
hideYAxisText: secondaryYAxis?.hideYAxisText ?? hideYAxisText,
|
|
119
|
-
yAxisLabelPrefix: secondaryYAxis?.yAxisLabelPrefix ?? yAxisLabelPrefix,
|
|
120
|
-
yAxisLabelSuffix: secondaryYAxis?.yAxisLabelSuffix ?? yAxisLabelSuffix,
|
|
121
|
-
hideOrigin: secondaryYAxis?.hideOrigin ?? hideOrigin,
|
|
122
|
-
formatYLabel: secondaryYAxis?.formatYLabel,
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
const {maxItem, minItem} = computeMaxAndMinItems(
|
|
126
|
-
secondaryData,
|
|
127
|
-
secondaryYAxisConfig.roundToDigits,
|
|
128
|
-
secondaryYAxisConfig.showFractionalValues,
|
|
129
|
-
);
|
|
130
|
-
secondaryYAxisConfig.maxValue =
|
|
131
|
-
secondaryYAxisConfig.maxValue ?? (maxItem || maxValue);
|
|
132
|
-
secondaryYAxisConfig.mostNegativeValue =
|
|
133
|
-
secondaryYAxisConfig.mostNegativeValue ?? minItem;
|
|
134
|
-
secondaryYAxisConfig.stepValue =
|
|
135
|
-
secondaryYAxisConfig.stepValue ??
|
|
136
|
-
secondaryYAxisConfig.maxValue /
|
|
137
|
-
(secondaryYAxisConfig.noOfSections ?? noOfSections);
|
|
138
|
-
secondaryYAxisConfig.stepHeight =
|
|
139
|
-
secondaryYAxisConfig.stepHeight ||
|
|
140
|
-
containerHeight / (secondaryYAxisConfig.noOfSections ?? noOfSections);
|
|
141
|
-
|
|
142
|
-
const horizSections: HorizSectionsType = [];
|
|
143
|
-
for (let i = 0; i <= noOfSections; i++) {
|
|
144
|
-
let value = maxValue - stepValue * i;
|
|
145
|
-
if (showFractionalValues || roundToDigits) {
|
|
146
|
-
value = parseFloat(
|
|
147
|
-
value.toFixed(roundToDigits ?? AxesAndRulesDefaults.roundToDigits),
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
horizSections.push({
|
|
152
|
-
value: yAxisLabelTexts?.length
|
|
153
|
-
? yAxisLabelTexts[noOfSections + noOfSectionsBelowXAxis - i] ??
|
|
154
|
-
value.toString()
|
|
155
|
-
: value.toString(),
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const horizSectionsBelow: HorizSectionsType = [];
|
|
160
|
-
if (noOfSectionsBelowXAxis) {
|
|
161
|
-
for (let i = 1; i <= noOfSectionsBelowXAxis; i++) {
|
|
162
|
-
let value = stepValue * -i;
|
|
163
|
-
if (showFractionalValues || roundToDigits) {
|
|
164
|
-
value = parseFloat(
|
|
165
|
-
value.toFixed(roundToDigits ?? AxesAndRulesDefaults.roundToDigits),
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
horizSectionsBelow.push({
|
|
169
|
-
value: props.yAxisLabelTexts
|
|
170
|
-
? props.yAxisLabelTexts[noOfSectionsBelowXAxis - i] ??
|
|
171
|
-
value.toString()
|
|
172
|
-
: value.toString(),
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
const secondaryHorizSections: HorizSectionsType = [];
|
|
178
|
-
if (secondaryYAxis) {
|
|
179
|
-
for (
|
|
180
|
-
let i = 0;
|
|
181
|
-
i <= (secondaryYAxisConfig.noOfSections ?? noOfSections);
|
|
182
|
-
i++
|
|
183
|
-
) {
|
|
184
|
-
let value = secondaryYAxisConfig.stepValue * i;
|
|
185
|
-
if (
|
|
186
|
-
secondaryYAxisConfig.showFractionalValues ||
|
|
187
|
-
secondaryYAxisConfig.roundToDigits
|
|
188
|
-
) {
|
|
189
|
-
value = parseFloat(
|
|
190
|
-
value.toFixed(
|
|
191
|
-
secondaryYAxisConfig.roundToDigits ??
|
|
192
|
-
AxesAndRulesDefaults.roundToDigits,
|
|
193
|
-
),
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
secondaryHorizSections.push({
|
|
197
|
-
value: secondaryYAxisConfig.yAxisLabelTexts?.length
|
|
198
|
-
? secondaryYAxisConfig.yAxisLabelTexts[
|
|
199
|
-
i - noOfSectionsBelowXAxis - 1
|
|
200
|
-
] ?? value.toString()
|
|
201
|
-
: value.toString(),
|
|
202
|
-
});
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
const secondaryHorizSectionsBelow: HorizSectionsType = [];
|
|
207
|
-
if (secondaryYAxisConfig.noOfSectionsBelowXAxis) {
|
|
208
|
-
for (let i = 1; i <= secondaryYAxisConfig.noOfSectionsBelowXAxis; i++) {
|
|
209
|
-
let value =
|
|
210
|
-
secondaryYAxisConfig.stepValue *
|
|
211
|
-
(i - secondaryYAxisConfig.noOfSectionsBelowXAxis - 1);
|
|
212
|
-
if (
|
|
213
|
-
secondaryYAxisConfig.showFractionalValues ||
|
|
214
|
-
secondaryYAxisConfig.roundToDigits
|
|
215
|
-
) {
|
|
216
|
-
value = parseFloat(
|
|
217
|
-
value.toFixed(
|
|
218
|
-
secondaryYAxisConfig.roundToDigits ??
|
|
219
|
-
AxesAndRulesDefaults.roundToDigits,
|
|
220
|
-
),
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
secondaryHorizSectionsBelow.push({
|
|
224
|
-
value: secondaryYAxisConfig.yAxisLabelTexts?.length
|
|
225
|
-
? secondaryYAxisConfig.yAxisLabelTexts[i - 1] ?? value.toString()
|
|
226
|
-
: value.toString(),
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/***********************************************************************************************************************************
|
|
232
|
-
***********************************************************************************************************************************/
|
|
233
|
-
|
|
234
|
-
let {
|
|
63
|
+
const {
|
|
64
|
+
secondaryYAxisConfig,
|
|
65
|
+
horizSections,
|
|
66
|
+
yAxisExtraHeightAtTop,
|
|
67
|
+
secondaryHorizSections,
|
|
235
68
|
showReferenceLine1,
|
|
236
|
-
referenceLine1Position,
|
|
237
69
|
referenceLine1Config,
|
|
238
|
-
|
|
70
|
+
referenceLine1Position,
|
|
239
71
|
showReferenceLine2,
|
|
240
|
-
referenceLine2Position,
|
|
241
72
|
referenceLine2Config,
|
|
242
|
-
|
|
73
|
+
referenceLine2Position,
|
|
243
74
|
showReferenceLine3,
|
|
244
|
-
referenceLine3Position,
|
|
245
75
|
referenceLine3Config,
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
type: rulesType,
|
|
253
|
-
dashWidth: dashWidth,
|
|
254
|
-
dashGap: dashGap,
|
|
255
|
-
labelText: '',
|
|
256
|
-
labelTextStyle: null,
|
|
257
|
-
zIndex: 1,
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
showReferenceLine1 = referenceLinesConfig.showReferenceLine1 || false;
|
|
261
|
-
referenceLine1Position =
|
|
262
|
-
referenceLinesConfig.referenceLine1Position ??
|
|
263
|
-
(referenceLinesConfig.referenceLine1Position || containerHeight / 2);
|
|
264
|
-
referenceLine1Config = referenceLinesConfig.referenceLine1Config
|
|
265
|
-
? {
|
|
266
|
-
thickness:
|
|
267
|
-
referenceLinesConfig.referenceLine1Config.thickness ||
|
|
268
|
-
defaultReferenceConfig.thickness,
|
|
269
|
-
width:
|
|
270
|
-
referenceLinesConfig.referenceLine1Config.width ??
|
|
271
|
-
defaultReferenceConfig.width,
|
|
272
|
-
color:
|
|
273
|
-
referenceLinesConfig.referenceLine1Config.color ||
|
|
274
|
-
defaultReferenceConfig.color,
|
|
275
|
-
type:
|
|
276
|
-
referenceLinesConfig.referenceLine1Config.type ||
|
|
277
|
-
defaultReferenceConfig.type,
|
|
278
|
-
dashWidth:
|
|
279
|
-
referenceLinesConfig.referenceLine1Config.dashWidth ||
|
|
280
|
-
defaultReferenceConfig.dashWidth,
|
|
281
|
-
dashGap:
|
|
282
|
-
referenceLinesConfig.referenceLine1Config.dashGap ||
|
|
283
|
-
defaultReferenceConfig.dashGap,
|
|
284
|
-
labelText:
|
|
285
|
-
referenceLinesConfig.referenceLine1Config.labelText ||
|
|
286
|
-
defaultReferenceConfig.labelText,
|
|
287
|
-
labelTextStyle:
|
|
288
|
-
referenceLinesConfig.referenceLine1Config.labelTextStyle ||
|
|
289
|
-
defaultReferenceConfig.labelTextStyle,
|
|
290
|
-
zIndex:
|
|
291
|
-
referenceLinesConfig.referenceLine1Config.zIndex ??
|
|
292
|
-
defaultReferenceConfig.zIndex,
|
|
293
|
-
}
|
|
294
|
-
: defaultReferenceConfig;
|
|
295
|
-
|
|
296
|
-
showReferenceLine2 = referenceLinesConfig.showReferenceLine2 || false;
|
|
297
|
-
referenceLine2Position =
|
|
298
|
-
referenceLinesConfig.referenceLine2Position ??
|
|
299
|
-
(referenceLinesConfig.referenceLine2Position || (3 * containerHeight) / 2);
|
|
300
|
-
referenceLine2Config = referenceLinesConfig.referenceLine2Config
|
|
301
|
-
? {
|
|
302
|
-
thickness:
|
|
303
|
-
referenceLinesConfig.referenceLine2Config.thickness ||
|
|
304
|
-
defaultReferenceConfig.thickness,
|
|
305
|
-
width:
|
|
306
|
-
referenceLinesConfig.referenceLine2Config.width ??
|
|
307
|
-
defaultReferenceConfig.width,
|
|
308
|
-
color:
|
|
309
|
-
referenceLinesConfig.referenceLine2Config.color ||
|
|
310
|
-
defaultReferenceConfig.color,
|
|
311
|
-
type:
|
|
312
|
-
referenceLinesConfig.referenceLine2Config.type ||
|
|
313
|
-
defaultReferenceConfig.type,
|
|
314
|
-
dashWidth:
|
|
315
|
-
referenceLinesConfig.referenceLine2Config.dashWidth ||
|
|
316
|
-
defaultReferenceConfig.dashWidth,
|
|
317
|
-
dashGap:
|
|
318
|
-
referenceLinesConfig.referenceLine2Config.dashGap ||
|
|
319
|
-
defaultReferenceConfig.dashGap,
|
|
320
|
-
labelText:
|
|
321
|
-
referenceLinesConfig.referenceLine2Config.labelText ||
|
|
322
|
-
defaultReferenceConfig.labelText,
|
|
323
|
-
labelTextStyle:
|
|
324
|
-
referenceLinesConfig.referenceLine2Config.labelTextStyle ||
|
|
325
|
-
defaultReferenceConfig.labelTextStyle,
|
|
326
|
-
zIndex:
|
|
327
|
-
referenceLinesConfig.referenceLine2Config.zIndex ??
|
|
328
|
-
defaultReferenceConfig.zIndex,
|
|
329
|
-
}
|
|
330
|
-
: defaultReferenceConfig;
|
|
331
|
-
|
|
332
|
-
showReferenceLine3 = referenceLinesConfig.showReferenceLine3 || false;
|
|
333
|
-
referenceLine3Position =
|
|
334
|
-
referenceLinesConfig.referenceLine3Position ??
|
|
335
|
-
(referenceLinesConfig.referenceLine3Position || containerHeight / 3);
|
|
336
|
-
referenceLine3Config = referenceLinesConfig.referenceLine3Config
|
|
337
|
-
? {
|
|
338
|
-
thickness:
|
|
339
|
-
referenceLinesConfig.referenceLine3Config.thickness ||
|
|
340
|
-
defaultReferenceConfig.thickness,
|
|
341
|
-
width:
|
|
342
|
-
referenceLinesConfig.referenceLine3Config.width ??
|
|
343
|
-
defaultReferenceConfig.width,
|
|
344
|
-
color:
|
|
345
|
-
referenceLinesConfig.referenceLine3Config.color ||
|
|
346
|
-
defaultReferenceConfig.color,
|
|
347
|
-
type:
|
|
348
|
-
referenceLinesConfig.referenceLine3Config.type ||
|
|
349
|
-
defaultReferenceConfig.type,
|
|
350
|
-
dashWidth:
|
|
351
|
-
referenceLinesConfig.referenceLine3Config.dashWidth ||
|
|
352
|
-
defaultReferenceConfig.dashWidth,
|
|
353
|
-
dashGap:
|
|
354
|
-
referenceLinesConfig.referenceLine3Config.dashGap ||
|
|
355
|
-
defaultReferenceConfig.dashGap,
|
|
356
|
-
labelText:
|
|
357
|
-
referenceLinesConfig.referenceLine3Config.labelText ||
|
|
358
|
-
defaultReferenceConfig.labelText,
|
|
359
|
-
labelTextStyle:
|
|
360
|
-
referenceLinesConfig.referenceLine3Config.labelTextStyle ||
|
|
361
|
-
defaultReferenceConfig.labelTextStyle,
|
|
362
|
-
zIndex:
|
|
363
|
-
referenceLinesConfig.referenceLine3Config.zIndex ??
|
|
364
|
-
defaultReferenceConfig.zIndex,
|
|
365
|
-
}
|
|
366
|
-
: defaultReferenceConfig;
|
|
367
|
-
|
|
368
|
-
const getLabelTexts = (val, index) => {
|
|
369
|
-
return getLabelTextUtil(
|
|
370
|
-
val,
|
|
371
|
-
index,
|
|
372
|
-
showFractionalValues,
|
|
373
|
-
yAxisLabelTexts,
|
|
374
|
-
yAxisOffset,
|
|
375
|
-
yAxisLabelPrefix,
|
|
376
|
-
yAxisLabelSuffix,
|
|
377
|
-
roundToDigits ?? AxesAndRulesDefaults.roundToDigits,
|
|
378
|
-
formatYLabel,
|
|
379
|
-
);
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
const getLabelTextsForSecondaryYAxis = (val, index) => {
|
|
383
|
-
const {
|
|
384
|
-
showFractionalValues,
|
|
385
|
-
yAxisLabelTexts,
|
|
386
|
-
yAxisOffset,
|
|
387
|
-
yAxisLabelPrefix,
|
|
388
|
-
yAxisLabelSuffix,
|
|
389
|
-
roundToDigits,
|
|
390
|
-
formatYLabel,
|
|
391
|
-
} = secondaryYAxisConfig;
|
|
392
|
-
return getLabelTextUtil(
|
|
393
|
-
val,
|
|
394
|
-
index,
|
|
395
|
-
showFractionalValues,
|
|
396
|
-
yAxisLabelTexts,
|
|
397
|
-
yAxisOffset,
|
|
398
|
-
yAxisLabelPrefix,
|
|
399
|
-
yAxisLabelSuffix,
|
|
400
|
-
roundToDigits ?? AxesAndRulesDefaults.roundToDigits,
|
|
401
|
-
formatYLabel,
|
|
402
|
-
);
|
|
403
|
-
};
|
|
76
|
+
referenceLine3Position,
|
|
77
|
+
horizSectionsBelow,
|
|
78
|
+
secondaryHorizSectionsBelow,
|
|
79
|
+
getLabelTexts,
|
|
80
|
+
getLabelTextsForSecondaryYAxis,
|
|
81
|
+
} = getHorizSectionVals(props);
|
|
404
82
|
|
|
405
83
|
const renderAxesAndRules = (index: number) => {
|
|
406
84
|
const invertedIndex = horizSections.length - index - 1;
|
|
@@ -664,7 +342,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
|
|
|
664
342
|
</View>
|
|
665
343
|
) : (
|
|
666
344
|
<View
|
|
667
|
-
pointerEvents=
|
|
345
|
+
pointerEvents="none"
|
|
668
346
|
style={{
|
|
669
347
|
flexDirection: 'row',
|
|
670
348
|
marginTop: stepHeight / -2,
|
|
@@ -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
|
+
};
|