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.
Files changed (31) hide show
  1. package/README.md +9 -2
  2. package/package.json +2 -1
  3. package/src/BarChart/Animated2DWithGradient.tsx +13 -154
  4. package/src/BarChart/RenderBars.tsx +29 -179
  5. package/src/BarChart/RenderStackBars.tsx +22 -104
  6. package/src/BarChart/index.tsx +87 -686
  7. package/src/Components/AnimatedThreeDBar/index.tsx +16 -48
  8. package/src/Components/BarAndLineChartsWrapper/index.tsx +38 -283
  9. package/src/Components/BarAndLineChartsWrapper/renderHorizSections.tsx +17 -339
  10. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/index.tsx +147 -0
  11. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderDataPoints.tsx +157 -0
  12. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificDataPoints.tsx +86 -0
  13. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart/renderSpecificVerticalLines.tsx +42 -0
  14. package/src/Components/BarAndLineChartsWrapper/renderVerticalLines.tsx +1 -1
  15. package/src/Components/BarSpecificComponents/cap.tsx +1 -1
  16. package/src/Components/common/StripAndLabel.tsx +3 -56
  17. package/src/Components/lineSvg.tsx +1 -1
  18. package/src/LineChart/LineChartBicolor.tsx +80 -516
  19. package/src/LineChart/index.tsx +266 -1778
  20. package/src/PieChart/index.tsx +20 -84
  21. package/src/PieChart/main.tsx +47 -119
  22. package/src/PopulationPyramid/index.tsx +90 -203
  23. package/src/index.tsx +7 -12
  24. package/src/BarChart/types.ts +0 -394
  25. package/src/Components/BarAndLineChartsWrapper/renderLineInBarChart.tsx +0 -402
  26. package/src/LineChart/types.ts +0 -575
  27. package/src/PieChart/types.ts +0 -77
  28. package/src/PopulationPyramid/types.ts +0 -200
  29. package/src/utils/constants.ts +0 -333
  30. package/src/utils/index.tsx +0 -1137
  31. package/src/utils/types.ts +0 -360
@@ -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
+ };
@@ -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
+ };
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {View} from 'react-native';
3
- import {chartTypes} from '../../utils/constants';
3
+ import {chartTypes} from 'gifted-charts-core';
4
4
  import {Line, Svg} from 'react-native-svg';
5
5
 
6
6
  const RenderVerticalLines = props => {
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import {View} from 'react-native';
3
- import {BarDefaults} from '../../utils/constants';
3
+ import {BarDefaults} from 'gifted-charts-core';
4
4
 
5
5
  const Cap = props => {
6
6
  const {
@@ -1,22 +1,17 @@
1
1
  import React from 'react';
2
- import {View, Dimensions} from 'react-native';
2
+ import {View} from 'react-native';
3
3
  import Svg, {Line} from 'react-native-svg';
4
+ import {getTopAndLeftForStripAndLabel} from 'gifted-charts-core';
4
5
 
5
6
  export const StripAndLabel = props => {
6
7
  const {
7
- autoAdjustPointerLabelPosition,
8
8
  pointerX,
9
9
  pointerLabelWidth,
10
- activatePointersOnLongPress,
11
- yAxisLabelWidth,
12
10
  pointerRadius,
13
11
  pointerWidth,
14
- shiftPointerLabelX,
15
- pointerLabelHeight,
16
12
  pointerYLocal,
17
13
  pointerStripUptoDataPoint,
18
14
  pointerStripHeight,
19
- shiftPointerLabelY,
20
15
  pointerItemLocal,
21
16
  showPointerStrip,
22
17
  pointerStripWidth,
@@ -26,59 +21,11 @@ export const StripAndLabel = props => {
26
21
  pointerConfig,
27
22
  pointerLabelComponent,
28
23
  secondaryPointerItem,
29
- scrollX,
30
24
  pointerEvents,
31
25
  isBarChart,
32
26
  } = props;
33
- let left = 0,
34
- top = 0;
35
- if (autoAdjustPointerLabelPosition) {
36
- if (pointerX < pointerLabelWidth / 2) {
37
- left = 7;
38
- } else if (
39
- activatePointersOnLongPress &&
40
- pointerX - scrollX < pointerLabelWidth / 2 - 10
41
- ) {
42
- left = 7;
43
- } else {
44
- if (
45
- !activatePointersOnLongPress &&
46
- pointerX >
47
- (props.width ||
48
- Dimensions.get('window').width - yAxisLabelWidth - 15) -
49
- pointerLabelWidth / 2
50
- ) {
51
- left = -pointerLabelWidth - 4;
52
- } else if (
53
- activatePointersOnLongPress &&
54
- pointerX - scrollX >
55
- ((props.width ?? 0) + 10 ||
56
- Dimensions.get('window').width - yAxisLabelWidth - 15) -
57
- pointerLabelWidth / 2
58
- ) {
59
- left = -pointerLabelWidth - 4;
60
- } else {
61
- left = -pointerLabelWidth / 2 + 5;
62
- }
63
- }
64
- } else {
65
- left = (pointerRadius || pointerWidth / 2) - 10 + shiftPointerLabelX;
66
- }
67
27
 
68
- if (autoAdjustPointerLabelPosition) {
69
- if (pointerLabelHeight - pointerYLocal > 10) {
70
- top = 10;
71
- } else {
72
- top = -pointerLabelHeight;
73
- }
74
- } else {
75
- top =
76
- (pointerStripUptoDataPoint
77
- ? pointerRadius || pointerStripHeight / 2
78
- : -pointerYLocal + 8) -
79
- pointerLabelWidth / 2 +
80
- shiftPointerLabelY;
81
- }
28
+ const {top, left} = getTopAndLeftForStripAndLabel(props);
82
29
 
83
30
  return (
84
31
  <View
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import {ColorValue} from 'react-native';
3
3
  import Svg, {G, Path} from 'react-native-svg';
4
- import { ruleTypes } from '../utils/constants';
4
+ import { ruleTypes } from 'gifted-charts-core';
5
5
 
6
6
  type ruleProps = {
7
7
  thickness: number;