react-native-gifted-charts 1.2.28 → 1.2.31

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "1.2.28",
3
+ "version": "1.2.31",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie, Donut and Stacked Bar charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -44,6 +44,7 @@ type PropTypes = {
44
44
  xAxisColor?: ColorValue;
45
45
  yAxisThickness?: number;
46
46
  yAxisColor?: ColorValue;
47
+ xAxisType?: String;
47
48
  yAxisLabelContainerStyle?: any;
48
49
  horizontalRulesStyle?: any;
49
50
  yAxisTextStyle?: any;
@@ -103,6 +104,7 @@ type PropTypes = {
103
104
 
104
105
  disableScroll?: Boolean;
105
106
  showScrollIndicator?: Boolean;
107
+ indicatorColor?: 'black' | 'default' | 'white';
106
108
  roundedTop?: Boolean;
107
109
  roundedBottom?: Boolean;
108
110
  disablePress?: boolean;
@@ -402,6 +404,7 @@ export const BarChart = (props: PropTypes) => {
402
404
  const hideOrigin = props.hideOrigin || false;
403
405
 
404
406
  const rulesType = props.rulesType || 'line';
407
+ const xAxisType = props.xAxisType || 'solid';
405
408
  const dashWidth = props.dashWidth === 0 ? 0 : props.dashWidth || 4;
406
409
  const dashGap = props.dashGap === 0 ? 0 : props.dashGap || 8;
407
410
 
@@ -715,11 +718,17 @@ export const BarChart = (props: PropTypes) => {
715
718
  {backgroundColor: backgroundColor},
716
719
  ]}>
717
720
  {index === noOfSections ? (
718
- <View
719
- style={[
720
- styles.lastLine,
721
- {height: xAxisThickness, backgroundColor: xAxisColor},
722
- ]}
721
+ <Rule
722
+ config={{
723
+ thickness: xAxisThickness,
724
+ color: xAxisColor,
725
+ width: horizontal
726
+ ? props.width || Math.min(300, totalWidth)
727
+ : (props.width || totalWidth) + 11,
728
+ dashWidth: dashWidth,
729
+ dashGap: dashGap,
730
+ type: xAxisType,
731
+ }}
723
732
  />
724
733
  ) : hideRules ? null : (
725
734
  <Rule
@@ -1379,6 +1388,7 @@ export const BarChart = (props: PropTypes) => {
1379
1388
  !props.width && {width: totalWidth},
1380
1389
  ]}
1381
1390
  showsHorizontalScrollIndicator={showScrollIndicator}
1391
+ indicatorStyle={props.indicatorColor}
1382
1392
  horizontal
1383
1393
  // data={props.stackData || data}
1384
1394
  keyExtractor={(item, index) => index.toString()}>
@@ -71,6 +71,7 @@ type propTypes = {
71
71
  animateTogether?: boolean;
72
72
  xAxisThickness?: number;
73
73
  xAxisColor?: ColorValue;
74
+ xAxisType?: String;
74
75
  hideRules?: Boolean;
75
76
  rulesColor?: ColorValue;
76
77
  rulesThickness?: number;
@@ -119,6 +120,7 @@ type propTypes = {
119
120
  disableScroll?: Boolean;
120
121
  pointerConfig?: Pointer;
121
122
  showScrollIndicator?: Boolean;
123
+ indicatorColor?: 'black' | 'default' | 'white';
122
124
 
123
125
  //Indices
124
126
 
@@ -369,6 +371,7 @@ type Pointer = {
369
371
 
370
372
  export const LineChart = (props: propTypes) => {
371
373
  const scrollRef = useRef();
374
+ const [scrollX, setScrollX] = useState(0);
372
375
  const [pointerIndex, setPointerIndex] = useState(-1);
373
376
  const [pointerX, setPointerX] = useState(0);
374
377
  const [pointerY, setPointerY] = useState(0);
@@ -1554,6 +1557,7 @@ export const LineChart = (props: propTypes) => {
1554
1557
  const hideOrigin = props.hideOrigin || false;
1555
1558
 
1556
1559
  const rulesType = props.rulesType || 'line';
1560
+ const xAxisType = props.xAxisType || 'solid';
1557
1561
  const dashWidth = props.dashWidth === 0 ? 0 : props.dashWidth || 4;
1558
1562
  const dashGap = props.dashGap === 0 ? 0 : props.dashGap || 8;
1559
1563
 
@@ -1855,11 +1859,15 @@ export const LineChart = (props: propTypes) => {
1855
1859
  },
1856
1860
  ]}>
1857
1861
  {index === noOfSections ? (
1858
- <View
1859
- style={[
1860
- styles.lastLine,
1861
- {height: xAxisThickness, backgroundColor: xAxisColor},
1862
- ]}
1862
+ <Rule
1863
+ config={{
1864
+ thickness: xAxisThickness,
1865
+ color: xAxisColor,
1866
+ width: (props.width || totalWidth) + 11,
1867
+ dashWidth: dashWidth,
1868
+ dashGap: dashGap,
1869
+ type: xAxisType,
1870
+ }}
1863
1871
  />
1864
1872
  ) : hideRules ? null : (
1865
1873
  <Rule
@@ -2550,6 +2558,11 @@ export const LineChart = (props: propTypes) => {
2550
2558
  if (autoAdjustPointerLabelPosition) {
2551
2559
  if (pointerX < pointerLabelWidth / 2) {
2552
2560
  left = 7;
2561
+ } else if (
2562
+ activatePointersOnLongPress &&
2563
+ pointerX - scrollX < pointerLabelWidth / 2 - 10
2564
+ ) {
2565
+ left = 7;
2553
2566
  } else {
2554
2567
  if (
2555
2568
  !activatePointersOnLongPress &&
@@ -2561,7 +2574,10 @@ export const LineChart = (props: propTypes) => {
2561
2574
  left = -pointerLabelWidth - 4;
2562
2575
  } else if (
2563
2576
  activatePointersOnLongPress &&
2564
- pointerX > totalWidth - yAxisLabelWidth - pointerLabelWidth / 2
2577
+ pointerX - scrollX >
2578
+ (props.width + 10 ||
2579
+ Dimensions.get('window').width - yAxisLabelWidth - 15) -
2580
+ pointerLabelWidth / 2
2565
2581
  ) {
2566
2582
  left = -pointerLabelWidth - 4;
2567
2583
  } else {
@@ -3286,7 +3302,17 @@ export const LineChart = (props: propTypes) => {
3286
3302
  scrollRef.current.scrollToEnd({animated: scrollAnimation});
3287
3303
  }
3288
3304
  }}
3305
+ onScroll={ev => {
3306
+ if (
3307
+ pointerConfig &&
3308
+ pointerConfig.activatePointersOnLongPress &&
3309
+ pointerConfig.autoAdjustPointerLabelPosition
3310
+ ) {
3311
+ setScrollX(ev.nativeEvent.contentOffset.x);
3312
+ }
3313
+ }}
3289
3314
  showsHorizontalScrollIndicator={showScrollIndicator}
3315
+ indicatorStyle={props.indicatorColor}
3290
3316
  style={[
3291
3317
  {
3292
3318
  marginLeft:
@@ -76,32 +76,29 @@ export const PieChart = (props: propTypes) => {
76
76
  const extraRadiusForFocused = props.extraRadiusForFocused || radius / 10;
77
77
  const pi = props.semiCircle ? Math.PI / 2 : Math.PI;
78
78
  const [selectedIndex, setSelectedIndex] = useState(-1);
79
-
80
- if (props.data.length <= 1 || !props.focusOnPress || selectedIndex === -1) {
81
- return (
82
- <PieChartMain
83
- {...props}
84
- key="pie"
85
- setSelectedIndex={setSelectedIndex}
86
- selectedIndex={selectedIndex}
87
- />
88
- );
89
- } else {
90
- let startAngle = props.initialAngle || (props.semiCircle ? -pi : 0);
91
- // let startColor;
92
- let total = 0;
93
- props.data.forEach(item => {
94
- total += item.value;
95
- });
96
- if (selectedIndex !== 0) {
97
- let start = 0;
98
- for (let i = 0; i < selectedIndex; i++) {
99
- start += props.data[i].value;
100
- }
101
- startAngle += (2 * pi * start) / total;
79
+ let startAngle = props.initialAngle || (props.semiCircle ? -pi : 0);
80
+ let total = 0;
81
+ props.data.forEach(item => {
82
+ total += item.value;
83
+ });
84
+ if (selectedIndex !== 0) {
85
+ let start = 0;
86
+ for (let i = 0; i < selectedIndex; i++) {
87
+ start += props.data[i].value;
102
88
  }
103
- return (
104
- <View>
89
+ startAngle += (2 * pi * start) / total;
90
+ }
91
+ return (
92
+ <View
93
+ style={{
94
+ height: (radius + extraRadiusForFocused) * 2,
95
+ width: (radius + extraRadiusForFocused) * 2,
96
+ }}>
97
+ {!(
98
+ props.data.length <= 1 ||
99
+ !props.focusOnPress ||
100
+ selectedIndex === -1
101
+ ) && (
105
102
  <View
106
103
  style={{
107
104
  position: 'absolute',
@@ -126,22 +123,20 @@ export const PieChart = (props: propTypes) => {
126
123
  strokeWidth: 0,
127
124
  },
128
125
  ]}
129
- key="pie"
130
126
  radius={radius + extraRadiusForFocused}
131
127
  initialAngle={startAngle}
132
128
  showText={false}
133
129
  innerRadius={props.innerRadius || radius / 2.5}
134
130
  />
135
131
  </View>
136
- <View style={{position: 'absolute'}}>
137
- <PieChartMain
138
- {...props}
139
- key="pie"
140
- selectedIndex={selectedIndex}
141
- setSelectedIndex={setSelectedIndex}
142
- />
143
- </View>
132
+ )}
133
+ <View style={{position: 'absolute'}}>
134
+ <PieChartMain
135
+ {...props}
136
+ selectedIndex={selectedIndex}
137
+ setSelectedIndex={setSelectedIndex}
138
+ />
144
139
  </View>
145
- );
146
- }
140
+ </View>
141
+ );
147
142
  };
@@ -270,80 +270,47 @@ export const PieChartMain = (props: propTypes) => {
270
270
  (item.shiftY || 0);
271
271
 
272
272
  return (
273
- <>
274
- {/********************* Pie sections background with colors excluding the borders *********/}
275
- <Path
276
- key={index + 'a'}
277
- d={`M ${cx + (item.shiftX || 0)} ${
278
- cy + (item.shiftY || 0)
279
- } L ${sx} ${sy} A ${radius} ${radius} 0 ${
280
- semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
281
- } 1 ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
282
- cy + (item.shiftY || 0)
283
- }`}
284
- stroke={'transparent'}
285
- strokeWidth={0}
286
- fill={
287
- props.selectedIndex === index || item.peripheral
288
- ? 'transparent'
289
- : showGradient
290
- ? `url(#grad${index})`
291
- : item.color || colors[index % 9]
273
+ <Path
274
+ key={index + 'a'}
275
+ d={`M ${cx + (item.shiftX || 0)} ${
276
+ cy + (item.shiftY || 0)
277
+ } L ${sx} ${sy} A ${radius} ${radius} 0 ${
278
+ semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
279
+ } 1 ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
280
+ cy + (item.shiftY || 0)
281
+ }`}
282
+ stroke={item.strokeColor || strokeColor}
283
+ strokeWidth={
284
+ props.focusOnPress && props.selectedIndex === index
285
+ ? 0
286
+ : item.strokeWidth === 0
287
+ ? 0
288
+ : item.strokeWidth || strokeWidth
289
+ }
290
+ fill={
291
+ props.selectedIndex === index || item.peripheral
292
+ ? 'transparent'
293
+ : showGradient
294
+ ? `url(#grad${index})`
295
+ : item.color || colors[index % 9]
296
+ }
297
+ onPress={() => {
298
+ if (item.onPress) {
299
+ item.onPress();
300
+ } else if (props.onPress) {
301
+ props.onPress(item, index);
292
302
  }
293
- onPress={() => {
294
- if (item.onPress) {
295
- item.onPress();
296
- } else if (props.onPress) {
297
- props.onPress(item, index);
298
- }
299
- if (props.focusOnPress) {
300
- if (props.selectedIndex === index) {
301
- if (toggleFocusOnPress) {
302
- props.setSelectedIndex(-1);
303
- }
304
- } else {
305
- props.setSelectedIndex(index);
303
+ if (props.focusOnPress) {
304
+ if (props.selectedIndex === index) {
305
+ if (toggleFocusOnPress) {
306
+ props.setSelectedIndex(-1);
306
307
  }
308
+ } else {
309
+ props.setSelectedIndex(index);
307
310
  }
308
- }}
309
- />
310
-
311
- {/********************* Pie sections borders (made separately as they can have separate strokeWidths) *********/}
312
- <Path
313
- key={index + 'line1'}
314
- d={`M ${cx + (item.shiftX || 0)} ${
315
- cy + (item.shiftY || 0)
316
- } L ${sx} ${sy}`}
317
- stroke={item.strokeColor || strokeColor}
318
- strokeWidth={
319
- item.strokeWidth === 0 ? 0 : item.strokeWidth || strokeWidth
320
- }
321
- />
322
- <Path
323
- key={index + 'arc'}
324
- d={`M ${sx} ${sy} A ${radius} ${radius} 0 ${
325
- semiCircle ? 0 : data[index].value > total / 2 ? 1 : 0
326
- } 1 ${ax} ${ay}`}
327
- stroke={item.strokeColor || strokeColor}
328
- strokeWidth={
329
- props.focusOnPress && props.selectedIndex === index
330
- ? 0
331
- : item.strokeWidth === 0
332
- ? 0
333
- : item.strokeWidth || strokeWidth
334
311
  }
335
- />
336
- <Path
337
- key={index + 'line2'}
338
- d={`M ${ax} ${ay} L ${cx + (item.shiftX || 0)} ${
339
- cy + (item.shiftY || 0)
340
- }`}
341
- stroke={item.strokeColor || strokeColor}
342
- strokeWidth={
343
- item.strokeWidth === 0 ? 0 : item.strokeWidth || strokeWidth
344
- }
345
- />
346
- </>
312
+ }}
313
+ />
347
314
  );
348
315
  })
349
316
  )}
package/src/todos.md CHANGED
@@ -4,19 +4,15 @@
4
4
 
5
5
  ## To-dos in documentation-
6
6
 
7
- 1. Prepare a doc for Bar chart with negative values
8
- 2. Prepare a doc for Line chart with negative values
9
- 3. Prepare a doc for Bar chart with y axis on right side
10
- 4. Prepare a doc for Line chart with y axis on right side
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 Bar chart with barMarginBottom
14
- 8. Prepare a doc for reference lines
15
- 9. Prepare a doc for labelsPosition in Pie and Donut charts
16
- 8. Prepare a doc for adjustToWidth in Line and Area charts
17
- 9. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
18
- 10. Prepare a doc for vertical lines to explain noOfVerticalLines and verticalLinesSpacing props. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/205
19
- 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
7
+ 1. Prepare a doc for Line chart with negative values
8
+ 2. Prepare a doc for Line chart with y axis on right side
9
+ 3. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
10
+ 4. Prepare a doc for Line chart with smoothly scrolling data pointer and strip (along with pointerShiftX)
11
+ 5. Prepare a doc for labelsPosition in Pie and Donut charts
12
+ 6. Prepare a doc for adjustToWidth in Line and Area charts
13
+ 7. Prepare a doc for xAxisLabelTexts and xAxisLabelTextStyle in Bar, Line And Area Charts
14
+ 8. Prepare a doc for vertical lines to explain noOfVerticalLines and verticalLinesSpacing props. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/205
15
+ 9. Prepare a doc for negative marginBottom instead of marginTop for x axis labels. https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/190
20
16
 
21
17
 
22
18
  ## Architecture Enhancement