react-native-gifted-charts 1.4.20 → 1.4.21

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.
Files changed (63) hide show
  1. package/README.md +4 -3
  2. package/dist/BarChart/Animated2DWithGradient.js +1 -0
  3. package/dist/BarChart/RenderBars.js +1 -0
  4. package/dist/BarChart/RenderStackBars.js +1 -0
  5. package/dist/BarChart/index.js +1 -0
  6. package/dist/BarChart/styles.js +1 -0
  7. package/dist/Components/AnimatedThreeDBar/index.js +1 -0
  8. package/dist/Components/AnimatedThreeDBar/styles.js +1 -0
  9. package/dist/Components/BarAndLineChartsWrapper/index.js +1 -0
  10. package/dist/Components/BarAndLineChartsWrapper/renderHorizSections.js +1 -0
  11. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.js +1 -0
  12. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.js +1 -0
  13. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.js +1 -0
  14. package/dist/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.js +1 -0
  15. package/dist/Components/BarAndLineChartsWrapper/renderVerticalLines.js +1 -0
  16. package/dist/Components/BarSpecificComponents/barBackgroundPattern.js +1 -0
  17. package/dist/Components/BarSpecificComponents/cap.js +1 -0
  18. package/dist/Components/BarSpecificComponents/tooltip.js +1 -0
  19. package/dist/Components/common/LinearGradient.js +1 -0
  20. package/dist/Components/common/Pointer.js +1 -0
  21. package/dist/Components/common/StripAndLabel.js +1 -0
  22. package/dist/Components/lineSvg.js +1 -0
  23. package/dist/LineChart/LineChartBicolor.js +1 -0
  24. package/dist/LineChart/index.js +1 -0
  25. package/dist/LineChart/styles.js +1 -0
  26. package/dist/PieChart/index.js +1 -0
  27. package/dist/PieChart/main.js +1 -0
  28. package/dist/PieChartPro/index.js +1 -0
  29. package/dist/PopulationPyramid/index.js +1 -0
  30. package/dist/index.js +1 -0
  31. package/dist/utils/index.js +1 -0
  32. package/package.json +21 -20
  33. package/src/BarChart/Animated2DWithGradient.tsx +0 -197
  34. package/src/BarChart/RenderBars.tsx +0 -527
  35. package/src/BarChart/RenderStackBars.tsx +0 -359
  36. package/src/BarChart/index.tsx +0 -391
  37. package/src/BarChart/styles.tsx +0 -47
  38. package/src/Components/AnimatedThreeDBar/index.tsx +0 -258
  39. package/src/Components/AnimatedThreeDBar/styles.tsx +0 -14
  40. package/src/Components/BarAndLineChartsWrapper/index.tsx +0 -246
  41. package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +0 -607
  42. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +0 -151
  43. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +0 -175
  44. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +0 -86
  45. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +0 -42
  46. package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +0 -131
  47. package/src/Components/BarSpecificComponents/barBackgroundPattern.tsx +0 -30
  48. package/src/Components/BarSpecificComponents/cap.tsx +0 -34
  49. package/src/Components/BarSpecificComponents/tooltip.tsx +0 -59
  50. package/src/Components/common/LinearGradient.tsx +0 -27
  51. package/src/Components/common/Pointer.tsx +0 -37
  52. package/src/Components/common/StripAndLabel.tsx +0 -98
  53. package/src/Components/lineSvg.tsx +0 -42
  54. package/src/LineChart/LineChartBicolor.tsx +0 -740
  55. package/src/LineChart/index.tsx +0 -2231
  56. package/src/LineChart/styles.tsx +0 -47
  57. package/src/PieChart/index.tsx +0 -168
  58. package/src/PieChart/main.tsx +0 -363
  59. package/src/PieChartPro/index.tsx +0 -267
  60. package/src/PopulationPyramid/index.tsx +0 -603
  61. package/src/index.tsx +0 -26
  62. package/src/todos.md +0 -24
  63. package/src/utils/index.ts +0 -16
@@ -1,527 +0,0 @@
1
- import React from 'react';
2
- import {View, TouchableOpacity, Animated, Text} from 'react-native';
3
- import AnimatedThreeDBar from '../Components/AnimatedThreeDBar';
4
- import Animated2DWithGradient from './Animated2DWithGradient';
5
- import Cap from '../Components/BarSpecificComponents/cap';
6
- import BarBackgroundPattern from '../Components/BarSpecificComponents/barBackgroundPattern';
7
- import LinearGradient from '../Components/common/LinearGradient';
8
- import {
9
- getPropsForAnimated2DWithGradient,
10
- RenderBarsPropsType,
11
- barDataItem,
12
- AxesAndRulesDefaults,
13
- } from 'gifted-charts-core';
14
- import Tooltip from '../Components/BarSpecificComponents/tooltip';
15
-
16
- const RenderBars = (props: RenderBarsPropsType) => {
17
- const {
18
- item,
19
- index,
20
- containerHeight,
21
- maxValue,
22
- minHeight,
23
- spacing,
24
- propSpacing,
25
- side,
26
- data,
27
- barBorderWidth,
28
- barBorderColor,
29
- isThreeD,
30
- isAnimated,
31
- rotateLabel,
32
- appearingOpacity,
33
- animationDuration,
34
- autoShiftLabels,
35
- label,
36
- secondaryLabel,
37
- labelTextStyle,
38
- secondaryLabelTextStyle,
39
- xAxisTextNumberOfLines,
40
- xAxisLabelsVerticalShift,
41
- renderTooltip,
42
- leftShiftForTooltip,
43
- leftShiftForLastIndexTooltip,
44
- initialSpacing,
45
- selectedIndex,
46
- setSelectedIndex,
47
- xAxisThickness = AxesAndRulesDefaults.xAxisThickness,
48
- horizontal,
49
- rtl,
50
- intactTopLabel,
51
- showValuesAsTopLabel,
52
- topLabelContainerStyle,
53
- topLabelTextStyle,
54
- pointerConfig,
55
- noOfSectionsBelowXAxis,
56
- yAxisOffset,
57
- barWidth,
58
- labelsDistanceFromXaxis = 0,
59
- stepHeight,
60
- stepValue,
61
- negativeStepHeight,
62
- negativeStepValue,
63
- autoCenterTooltip,
64
- secondaryXAxis,
65
- } = props;
66
-
67
- const heightFactor =
68
- item.value < 0
69
- ? negativeStepHeight / negativeStepValue
70
- : stepHeight / stepValue;
71
-
72
- const barHeight = Math.max(
73
- minHeight,
74
- Math.abs(item.value) * heightFactor - xAxisThickness,
75
- );
76
-
77
- const {
78
- commonStyleForBar,
79
- barStyleWithBackground,
80
- commonPropsFor2Dand3Dbars,
81
- isFocused,
82
- focusedBarConfig,
83
- localFrontColor,
84
- } = getPropsForAnimated2DWithGradient({...props, barHeight});
85
-
86
- const itemOrPropsBarInnerComponent =
87
- item.barInnerComponent ?? props.barInnerComponent;
88
- const localBarInnerComponent = isFocused
89
- ? focusedBarConfig?.barInnerComponent ?? itemOrPropsBarInnerComponent
90
- : itemOrPropsBarInnerComponent;
91
-
92
- const barMarginBottom =
93
- item.barMarginBottom === 0
94
- ? 0
95
- : item.barMarginBottom || props.barMarginBottom || 0;
96
-
97
- const renderLabel = (
98
- top: boolean,
99
- label: String,
100
- labelTextStyle: any,
101
- value: number,
102
- ) => {
103
- return (
104
- <View
105
- style={[
106
- {
107
- width:
108
- (item.labelWidth ||
109
- props.labelWidth ||
110
- item.barWidth ||
111
- barWidth) + spacing,
112
- left: spacing / -2,
113
- position: 'absolute',
114
- height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
115
- bottom: top
116
- ? (containerHeight || 200) +
117
- (secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
118
- : (rotateLabel
119
- ? -40
120
- : -6 -
121
- xAxisTextNumberOfLines * 18 -
122
- xAxisLabelsVerticalShift) -
123
- barMarginBottom -
124
- labelsDistanceFromXaxis,
125
- },
126
- rotateLabel
127
- ? horizontal
128
- ? {transform: [{rotate: '330deg'}]}
129
- : {
130
- transform: [
131
- {rotate: value < 0 ? '240deg' : '60deg'},
132
- {translateX: value < 0 ? 56 : 0},
133
- {translateY: value < 0 ? 32 : 0},
134
- ],
135
- }
136
- : horizontal
137
- ? {transform: [{rotate: '-90deg'}]}
138
- : value < 0
139
- ? {
140
- transform: [
141
- {rotate: '180deg'},
142
- {
143
- translateY: autoShiftLabels
144
- ? 0
145
- : 16.5 * xAxisTextNumberOfLines + 14,
146
- },
147
- ],
148
- }
149
- : {},
150
- ]}>
151
- {top ? (
152
- item.secondaryLabelComponent ? (
153
- item.secondaryLabelComponent()
154
- ) : (
155
- <Text
156
- style={[
157
- {textAlign: 'center'},
158
- rtl && horizontal && {transform: [{rotate: '180deg'}]},
159
- labelTextStyle,
160
- ]}
161
- numberOfLines={xAxisTextNumberOfLines}>
162
- {label}
163
- </Text>
164
- )
165
- ) : item.labelComponent ? (
166
- item.labelComponent()
167
- ) : (
168
- <Text
169
- style={[
170
- {textAlign: 'center'},
171
- rtl && horizontal && {transform: [{rotate: '180deg'}]},
172
- labelTextStyle,
173
- ]}
174
- numberOfLines={xAxisTextNumberOfLines}>
175
- {label}
176
- </Text>
177
- )}
178
- </View>
179
- );
180
- };
181
-
182
- const renderAnimatedLabel = (
183
- top: boolean,
184
- label: String,
185
- labelTextStyle: any,
186
- value: number,
187
- ) => {
188
- return (
189
- <Animated.View
190
- style={[
191
- {
192
- width:
193
- (item.labelWidth ||
194
- props.labelWidth ||
195
- item.barWidth ||
196
- barWidth) + spacing,
197
- left: spacing / -2,
198
- position: 'absolute',
199
- height: props.xAxisLabelsHeight ?? xAxisTextNumberOfLines * 18,
200
- bottom: top
201
- ? (containerHeight || 200) +
202
- (secondaryXAxis?.labelsDistanceFromXaxis ?? 15)
203
- : (rotateLabel
204
- ? -40
205
- : -6 -
206
- xAxisTextNumberOfLines * 18 -
207
- xAxisLabelsVerticalShift) - barMarginBottom,
208
- opacity: appearingOpacity,
209
- },
210
- value < 0 && {transform: [{rotate: '180deg'}]},
211
- rotateLabel
212
- ? horizontal
213
- ? {transform: [{rotate: '330deg'}]}
214
- : {transform: [{rotate: '60deg'}]}
215
- : horizontal
216
- ? {transform: [{rotate: '-90deg'}]}
217
- : value < 0
218
- ? {
219
- transform: [
220
- {rotate: '180deg'},
221
- {
222
- translateY: autoShiftLabels
223
- ? 0
224
- : 16.5 * xAxisTextNumberOfLines + 14,
225
- },
226
- ],
227
- }
228
- : {},
229
- ]}>
230
- {top ? (
231
- item.secondaryLabelComponent ? (
232
- item.secondaryLabelComponent()
233
- ) : (
234
- <Text
235
- style={[
236
- {textAlign: 'center'},
237
- rtl && horizontal && {transform: [{rotate: '180deg'}]},
238
- labelTextStyle,
239
- ]}
240
- numberOfLines={xAxisTextNumberOfLines}>
241
- {label}
242
- </Text>
243
- )
244
- ) : item.labelComponent ? (
245
- item.labelComponent()
246
- ) : (
247
- <Text
248
- style={[
249
- {textAlign: 'center'},
250
- rtl && horizontal && {transform: [{rotate: '180deg'}]},
251
- labelTextStyle,
252
- ]}
253
- numberOfLines={xAxisTextNumberOfLines}>
254
- {label}
255
- </Text>
256
- )}
257
- </Animated.View>
258
- );
259
- };
260
-
261
- let leftSpacing = initialSpacing;
262
- for (let i = 0; i < index; i++) {
263
- leftSpacing +=
264
- (data[i].spacing ?? propSpacing) + (data[i].barWidth || barWidth);
265
- }
266
-
267
- const static2DWithGradient = (item: barDataItem) => {
268
- const localGradientColor =
269
- item.gradientColor || props.gradientColor || 'white';
270
- return (
271
- <>
272
- <LinearGradient
273
- style={commonStyleForBar}
274
- start={{x: 0, y: 0}}
275
- end={{x: 0, y: 1}}
276
- colors={[
277
- isFocused
278
- ? focusedBarConfig?.gradientColor ?? localGradientColor
279
- : localGradientColor,
280
- localFrontColor,
281
- ]}>
282
- {props.cappedBars && item.value ? (
283
- <Cap
284
- capThicknessFromItem={item.capThickness}
285
- capThicknessFromProps={props.capThickness}
286
- capColorFromItem={item.capColor}
287
- capColorFromProps={props.capColor}
288
- capRadiusFromItem={item.capRadius}
289
- capRadiusFromProps={props.capRadius}
290
- />
291
- ) : null}
292
- </LinearGradient>
293
- {(item.barBackgroundPattern || props.barBackgroundPattern) && (
294
- <BarBackgroundPattern
295
- barBackgroundPatternFromItem={item.barBackgroundPattern}
296
- barBackgroundPatternFromProps={props.barBackgroundPattern}
297
- patternIdFromItem={item.patternId}
298
- patternIdFromProps={props.patternId}
299
- />
300
- )}
301
- {(item.topLabelComponent || showValuesAsTopLabel) && (
302
- <View
303
- style={[
304
- {
305
- position: 'absolute',
306
- top: (item.barWidth || barWidth) * -1,
307
- height: item.barWidth || barWidth,
308
- width: item.barWidth || barWidth,
309
- justifyContent:
310
- (horizontal && !intactTopLabel) || item.value < 0
311
- ? 'center'
312
- : 'flex-end',
313
- alignItems: 'center',
314
- },
315
- item.value < 0 && {transform: [{rotate: '180deg'}]},
316
- horizontal &&
317
- !intactTopLabel && {transform: [{rotate: '270deg'}]},
318
- topLabelContainerStyle ?? item.topLabelContainerStyle,
319
- ]}>
320
- {showValuesAsTopLabel ? (
321
- <Text style={topLabelTextStyle}>{item.value + yAxisOffset}</Text>
322
- ) : (
323
- item.topLabelComponent?.()
324
- )}
325
- </View>
326
- )}
327
- {localBarInnerComponent ? (
328
- <View style={{height: '100%', width: '100%'}}>
329
- {localBarInnerComponent(item, index)}
330
- </View>
331
- ) : null}
332
- </>
333
- );
334
- };
335
-
336
- const barWrapperStyle = [
337
- {
338
- // overflow: 'visible',
339
- marginBottom: 60 + barMarginBottom + xAxisLabelsVerticalShift - 0.5,
340
- width: commonPropsFor2Dand3Dbars.barWidth,
341
- height: barHeight,
342
- marginRight: spacing,
343
- },
344
-
345
- pointerConfig
346
- ? {
347
- transform: [
348
- {
349
- translateY:
350
- (containerHeight || 200) -
351
- (barHeight - 10 + xAxisLabelsVerticalShift) +
352
- (item.value < 0 ? Math.abs(item.value) * heightFactor : 0),
353
- },
354
- ],
355
- }
356
- : item.value < 0
357
- ? {
358
- transform: [
359
- {
360
- translateY: Math.abs(item.value) * heightFactor,
361
- },
362
- {rotateZ: '180deg'},
363
- ],
364
- }
365
- : null,
366
- side !== 'right' && {zIndex: data.length - index},
367
- ];
368
-
369
- const pressDisabled =
370
- item.disablePress ||
371
- props.disablePress ||
372
- (pointerConfig && pointerConfig.barTouchable !== true);
373
-
374
- const barContent = () => {
375
- const isBarBelowXaxisAndInvisible =
376
- item.value < 0 && !noOfSectionsBelowXAxis;
377
- const animated2DWithGradient = (
378
- noGradient: boolean,
379
- noAnimation: boolean,
380
- ) => (
381
- <Animated2DWithGradient
382
- {...commonPropsFor2Dand3Dbars}
383
- animationDuration={animationDuration || 800}
384
- roundedBottom={props.roundedBottom || false}
385
- roundedTop={props.roundedTop || false}
386
- noGradient={noGradient}
387
- noAnimation={noAnimation}
388
- containerHeight={containerHeight}
389
- maxValue={maxValue}
390
- minHeight={minHeight ?? 0}
391
- barMarginBottom={barMarginBottom}
392
- cappedBars={props.cappedBars}
393
- capThickness={props.capThickness}
394
- capColor={props.capColor}
395
- capRadius={props.capRadius}
396
- horizontal={horizontal}
397
- barBorderWidth={barBorderWidth}
398
- barBorderColor={barBorderColor}
399
- commonStyleForBar={commonStyleForBar}
400
- barStyleWithBackground={barStyleWithBackground}
401
- />
402
- );
403
- return (
404
- <>
405
- {(props.showXAxisIndices || item.showXAxisIndex) && (
406
- <View
407
- style={{
408
- zIndex: 2,
409
- position: 'absolute',
410
- height: props.xAxisIndicesHeight,
411
- width: props.xAxisIndicesWidth,
412
- bottom: props.xAxisIndicesHeight / -2,
413
- left: ((item.barWidth || barWidth) - props.xAxisIndicesWidth) / 2,
414
- backgroundColor: props.xAxisIndicesColor,
415
- }}
416
- />
417
- )}
418
- {isBarBelowXaxisAndInvisible ? null : isThreeD ? (
419
- <AnimatedThreeDBar
420
- {...commonPropsFor2Dand3Dbars}
421
- sideWidth={
422
- item.sideWidth ||
423
- props.sideWidth ||
424
- (item.barWidth || barWidth) / 2
425
- }
426
- side={side || 'left'}
427
- sideColor={item.sideColor || props.sideColor || ''}
428
- topColor={item.topColor || props.topColor || ''}
429
- horizontal={horizontal}
430
- isAnimated={isAnimated}
431
- animationDuration={animationDuration || 800}
432
- selectedIndex={selectedIndex}
433
- />
434
- ) : item.showGradient || props.showGradient ? (
435
- isAnimated ? (
436
- animated2DWithGradient(false, false)
437
- ) : (
438
- static2DWithGradient(item)
439
- )
440
- ) : isAnimated ? (
441
- animated2DWithGradient(true, false)
442
- ) : (
443
- animated2DWithGradient(true, true)
444
- )}
445
- {isAnimated
446
- ? renderAnimatedLabel(false, label, labelTextStyle, item.value)
447
- : renderLabel(false, label, labelTextStyle, item.value)}
448
- {secondaryXAxis
449
- ? isAnimated
450
- ? renderAnimatedLabel(
451
- true,
452
- secondaryLabel,
453
- secondaryLabelTextStyle,
454
- item.value,
455
- )
456
- : renderLabel(
457
- true,
458
- secondaryLabel,
459
- secondaryLabelTextStyle,
460
- item.value,
461
- )
462
- : null}
463
- </>
464
- );
465
- };
466
-
467
- const tooltipProps = {
468
- barHeight,
469
- barWidth: item.barWidth || barWidth,
470
- item,
471
- index,
472
- isLast: index === data.length - 1,
473
- leftSpacing,
474
- leftShiftForLastIndexTooltip,
475
- leftShiftForTooltip: item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0,
476
- renderTooltip,
477
- autoCenterTooltip,
478
- horizontal,
479
- };
480
-
481
- return (
482
- <>
483
- {pressDisabled ? (
484
- <View pointerEvents="none" style={barWrapperStyle}>
485
- {barContent()}
486
- </View>
487
- ) : (
488
- <TouchableOpacity
489
- activeOpacity={props.activeOpacity || 0.2}
490
- onPress={() => {
491
- if (renderTooltip || props.focusBarOnPress) {
492
- if (props.focusedBarIndex === undefined || !props.onPress) {
493
- setSelectedIndex(index);
494
- }
495
- }
496
- item.onPress
497
- ? item.onPress()
498
- : props.onPress
499
- ? props.onPress(item, index)
500
- : null;
501
- }}
502
- onLongPress={() => {
503
- item.onLongPress
504
- ? item.onLongPress()
505
- : props.onLongPress
506
- ? props.onLongPress(item, index)
507
- : null;
508
- }}
509
- onPressOut={() => {
510
- item.onPressOut
511
- ? item.onPressOut()
512
- : props.onPressOut
513
- ? props.onPressOut(item, index)
514
- : null;
515
- }}
516
- style={barWrapperStyle}>
517
- {barContent()}
518
- </TouchableOpacity>
519
- )}
520
- {renderTooltip && selectedIndex === index && (
521
- <Tooltip {...tooltipProps} />
522
- )}
523
- </>
524
- );
525
- };
526
-
527
- export default RenderBars;