react-native-gifted-charts 1.4.18 → 1.4.20

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 CHANGED
@@ -23,6 +23,8 @@ The exact same piece of code that you write to render charts in react-native, ca
23
23
 
24
24
  ## [Release notes 🎉](release-notes/release-notes.md)
25
25
 
26
+ See the **[release changes by version here.](release-notes/release-notes.md)**
27
+
26
28
 
27
29
  <img src='/demos/bars.png' alt=''/>
28
30
  <img src='/demos/lineArea.png' alt=''/>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.4.18",
3
+ "version": "1.4.20",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut, Stacked Bar and Population Pyramid charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -25,7 +25,7 @@
25
25
  "registry": "https://registry.npmjs.org/"
26
26
  },
27
27
  "dependencies": {
28
- "gifted-charts-core": "^0.1.16"
28
+ "gifted-charts-core": "^0.1.19"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@babel/core": "^7.22.5",
@@ -139,6 +139,7 @@ export const renderHorizSections = (props: horizSectionPropTypes) => {
139
139
  {showYAxisIndices && index !== noOfSections ? (
140
140
  <View
141
141
  style={{
142
+ position: 'absolute',
142
143
  height: yAxisIndicesHeight,
143
144
  width: yAxisIndicesWidth,
144
145
  left:
@@ -4,8 +4,10 @@ import Svg, {Path} from 'react-native-svg';
4
4
  import {renderSpecificVerticalLines} from './renderSpecificVerticalLines';
5
5
  import {renderDataPoints} from './renderDataPoints';
6
6
  import {renderSpecificDataPoints} from './renderSpecificDataPoints';
7
+ import {LineInBarChartPropsType} from 'gifted-charts-core';
8
+ import {DataPointProps} from 'gifted-charts-core';
7
9
 
8
- const RenderLineInBarChart = (props: any) => {
10
+ const RenderLineInBarChart = (props: LineInBarChartPropsType) => {
9
11
  const {
10
12
  yAxisLabelWidth,
11
13
  initialSpacing,
@@ -22,11 +24,12 @@ const RenderLineInBarChart = (props: any) => {
22
24
  barWidth,
23
25
  labelsExtraHeight,
24
26
  xAxisLabelsVerticalShift,
27
+ selectedIndex,
25
28
  } = props;
26
29
 
27
30
  const firstBarWidth = data[0].barWidth ?? barWidth;
28
31
 
29
- const dataPointsProps = {
32
+ const dataPointsProps: DataPointProps = {
30
33
  data,
31
34
  lineConfig,
32
35
  barWidth,
@@ -35,6 +38,7 @@ const RenderLineInBarChart = (props: any) => {
35
38
  firstBarWidth,
36
39
  yAxisLabelWidth,
37
40
  spacing,
41
+ selectedIndex,
38
42
  };
39
43
 
40
44
  const specificVerticalLinesProps = {
@@ -89,9 +93,9 @@ const RenderLineInBarChart = (props: any) => {
89
93
  {lineConfig.showArrow && (
90
94
  <Path
91
95
  d={arrowPoints}
92
- fill={lineConfig.arrowConfig.fillColor}
93
- stroke={lineConfig.arrowConfig.strokeColor}
94
- strokeWidth={lineConfig.arrowConfig.strokeWidth}
96
+ fill={lineConfig.arrowConfig?.fillColor}
97
+ stroke={lineConfig.arrowConfig?.strokeColor}
98
+ strokeWidth={lineConfig.arrowConfig?.strokeWidth}
95
99
  />
96
100
  )}
97
101
  </Svg>
@@ -127,9 +131,9 @@ const RenderLineInBarChart = (props: any) => {
127
131
  {lineConfig.showArrow && (
128
132
  <Path
129
133
  d={arrowPoints}
130
- fill={lineConfig.arrowConfig.fillColor}
131
- stroke={lineConfig.arrowConfig.strokeColor}
132
- strokeWidth={lineConfig.arrowConfig.strokeWidth}
134
+ fill={lineConfig.arrowConfig?.fillColor}
135
+ stroke={lineConfig.arrowConfig?.strokeColor}
136
+ strokeWidth={lineConfig.arrowConfig?.strokeWidth}
133
137
  />
134
138
  )}
135
139
  </Svg>
@@ -3,8 +3,9 @@ import {styles} from '../../../BarChart/styles';
3
3
  import {View} from 'react-native';
4
4
  import {getXForLineInBar, getYForLineInBar} from 'gifted-charts-core';
5
5
  import {Rect, Text as CanvasText, Circle} from 'react-native-svg';
6
+ import {DataPointProps} from 'gifted-charts-core';
6
7
 
7
- export const renderDataPoints = (props: any) => {
8
+ export const renderDataPoints = (props: DataPointProps) => {
8
9
  const {
9
10
  data,
10
11
  lineConfig,
@@ -14,13 +15,29 @@ export const renderDataPoints = (props: any) => {
14
15
  firstBarWidth,
15
16
  yAxisLabelWidth,
16
17
  spacing,
18
+ selectedIndex,
17
19
  } = props;
18
20
  return data.map((item: any, index: number) => {
19
- if (index < lineConfig.startIndex || index > lineConfig.endIndex || item.hideDataPoint) {
21
+ if (
22
+ index < lineConfig.startIndex ||
23
+ index > lineConfig.endIndex ||
24
+ item.hideDataPoint
25
+ ) {
20
26
  return null;
21
27
  }
22
28
  const currentBarWidth = item.barWidth || barWidth || 30;
23
29
  const customDataPoint = item.customDataPoint || lineConfig.customDataPoint;
30
+ const dataPointColor =
31
+ lineConfig.focusEnabled &&
32
+ index === (lineConfig.focusedDataPointIndex ?? selectedIndex)
33
+ ? lineConfig.focusedDataPointColor
34
+ : lineConfig.dataPointsColor;
35
+
36
+ const dataPointRadius =
37
+ lineConfig.focusEnabled &&
38
+ index === (lineConfig.focusedDataPointIndex ?? selectedIndex)
39
+ ? lineConfig.focusedDataPointRadius
40
+ : lineConfig.dataPointsRadius;
24
41
  const value =
25
42
  item.value ??
26
43
  item.stacks.reduce((total: number, item: any) => total + item.value, 0);
@@ -73,7 +90,7 @@ export const renderDataPoints = (props: any) => {
73
90
  }
74
91
  width={lineConfig.dataPointsWidth}
75
92
  height={lineConfig.dataPointsHeight}
76
- fill={lineConfig.dataPointsColor}
93
+ fill={dataPointColor}
77
94
  />
78
95
  {item.dataPointText && (
79
96
  <CanvasText
@@ -122,8 +139,8 @@ export const renderDataPoints = (props: any) => {
122
139
  containerHeight,
123
140
  maxValue,
124
141
  )}
125
- r={lineConfig.dataPointsRadius}
126
- fill={lineConfig.dataPointsColor}
142
+ r={dataPointRadius}
143
+ fill={dataPointColor}
127
144
  />
128
145
  {item.dataPointText && (
129
146
  <CanvasText
@@ -34,6 +34,7 @@ import {
34
34
  useLineChart,
35
35
  adjustToOffset,
36
36
  LineProperties,
37
+ LineDefaults,
37
38
  } from 'gifted-charts-core';
38
39
  import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
39
40
  import {StripAndLabel} from '../Components/common/StripAndLabel';
@@ -299,6 +300,7 @@ export const LineChart = (props: LineChartPropsType) => {
299
300
  stripWidth,
300
301
  stripColor,
301
302
  stripOpacity,
303
+ stripStrokeDashArray,
302
304
  unFocusOnPressOut,
303
305
  delayBeforeUnFocus,
304
306
  containerHeightIncludingBelowXAxis,
@@ -625,7 +627,9 @@ export const LineChart = (props: LineChartPropsType) => {
625
627
  item.dataPointHeight ||
626
628
  dataPtsHeight;
627
629
  dataPointsColor =
628
- item.focusedDataPointColor || props.focusedDataPointColor || 'orange';
630
+ item.focusedDataPointColor ||
631
+ props.focusedDataPointColor ||
632
+ LineDefaults.focusedDataPointColor;
629
633
  dataPointsRadius =
630
634
  item.focusedDataPointRadius ||
631
635
  props.focusedDataPointRadius ||
@@ -661,9 +665,22 @@ export const LineChart = (props: LineChartPropsType) => {
661
665
  const currentStripHeight = item.stripHeight ?? stripHeight;
662
666
  const currentStripWidth = item.stripWidth ?? stripWidth;
663
667
  const currentStripOpacity = item.stripOpacity ?? stripOpacity;
668
+ const currentStripStrokeDashArray =
669
+ item.stripStrokeDashArray ?? stripStrokeDashArray ?? '';
664
670
  const currentStripColor = item.stripColor || stripColor;
665
671
  const position = I18nManager.isRTL ? 'right' : 'left';
666
672
 
673
+ const y1 = currentStripHeight
674
+ ? containerHeight - currentStripHeight + 8
675
+ : containerHeight -
676
+ dataPointsHeight / 2 +
677
+ 14 -
678
+ (item.value * containerHeight) / maxValue;
679
+
680
+ const actualStripHeight =
681
+ currentStripHeight ||
682
+ (item.value * containerHeight) / maxValue - 2 + overflowTop;
683
+
667
684
  return (
668
685
  <Fragment key={index}>
669
686
  {focusEnabled ? (
@@ -694,23 +711,15 @@ export const LineChart = (props: LineChartPropsType) => {
694
711
  ) : null}
695
712
  {item.showStrip ||
696
713
  (focusEnabled && index === selectedIndex && showStripOnFocus) ? (
697
- <Rect
698
- x={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
699
- y={
700
- currentStripHeight
701
- ? containerHeight - currentStripHeight + 8
702
- : containerHeight -
703
- dataPointsHeight / 2 +
704
- 14 -
705
- (item.value * containerHeight) / maxValue
706
- }
707
- width={currentStripWidth}
708
- height={
709
- currentStripHeight ||
710
- (item.value * containerHeight) / maxValue - 2 + overflowTop
711
- }
714
+ <Line
715
+ x1={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
716
+ y1={y1}
717
+ x2={initialSpacing + spacing * index - currentStripWidth / 2 - 1}
718
+ y2={y1 + actualStripHeight}
719
+ strokeWidth={currentStripWidth}
720
+ stroke={currentStripColor}
721
+ strokeDasharray={currentStripStrokeDashArray}
712
722
  opacity={currentStripOpacity}
713
- fill={currentStripColor}
714
723
  />
715
724
  ) : null}
716
725
  {hideDataPoints ? null : (
@@ -1211,7 +1220,7 @@ export const LineChart = (props: LineChartPropsType) => {
1211
1220
  set.textFontSize ?? textFontSize1,
1212
1221
  set.startIndex ?? 0,
1213
1222
  set.endIndex ?? set.data.length - 1,
1214
- false,
1223
+ set.isSecondary,
1215
1224
  showValuesAsDataPointsText,
1216
1225
  );
1217
1226
  }) ?? null}