react-native-gifted-charts 1.0.16 → 1.0.17

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.0.16",
3
+ "version": "1.0.17",
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": [
@@ -37,6 +37,7 @@ type propTypes = {
37
37
  maxValue?: number;
38
38
  barBackgroundPattern?: Function;
39
39
  patternId?: String;
40
+ barMarginBottom?: number;
40
41
  };
41
42
  type itemType = {
42
43
  value?: number;
@@ -58,6 +59,7 @@ type itemType = {
58
59
  barBorderRadius?: number;
59
60
  barBackgroundPattern?: Function;
60
61
  patternId?: String;
62
+ barMarginBottom?: number;
61
63
  };
62
64
 
63
65
  const Animated2DWithGradient = (props: propTypes) => {
@@ -72,6 +74,7 @@ const Animated2DWithGradient = (props: propTypes) => {
72
74
  noAnimation,
73
75
  containerHeight,
74
76
  maxValue,
77
+ barMarginBottom,
75
78
  } = props;
76
79
  const [height, setHeight] = useState(noAnimation ? props.height : 2);
77
80
  const [initialRender, setInitialRender] = useState(
@@ -114,18 +117,20 @@ const Animated2DWithGradient = (props: propTypes) => {
114
117
  position: 'absolute',
115
118
  bottom: 0,
116
119
  width: '100%',
117
- height: noAnimation
118
- ? (Math.abs(item.value) * (containerHeight || 200)) /
119
- (maxValue || 200)
120
- : height,
120
+ height:
121
+ (noAnimation
122
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
123
+ (maxValue || 200)
124
+ : height) - (barMarginBottom || 0),
121
125
  }}>
122
126
  <View
123
127
  style={{
124
128
  width: '100%',
125
- height: noAnimation
126
- ? (Math.abs(item.value) * (containerHeight || 200)) /
127
- (maxValue || 200)
128
- : height,
129
+ height:
130
+ (noAnimation
131
+ ? (Math.abs(item.value) * (containerHeight || 200)) /
132
+ (maxValue || 200)
133
+ : height) - (barMarginBottom || 0),
129
134
  }}>
130
135
  {noGradient ? (
131
136
  <View
@@ -168,7 +173,7 @@ const Animated2DWithGradient = (props: propTypes) => {
168
173
  height:
169
174
  item.capThickness === 0
170
175
  ? 0
171
- : item.capThickness || props.capThickness || 0,
176
+ : item.capThickness || props.capThickness || 6,
172
177
  backgroundColor:
173
178
  item.capColor || props.capColor || 'black',
174
179
  borderTopLeftRadius:
@@ -223,12 +228,12 @@ const Animated2DWithGradient = (props: propTypes) => {
223
228
  {props.cappedBars && (
224
229
  <View
225
230
  style={{
226
- // position: 'absolute',
227
- // width: '100%',
231
+ position: 'absolute',
232
+ width: '100%',
228
233
  height:
229
234
  item.capThickness === 0
230
235
  ? 0
231
- : item.capThickness || props.capThickness || 0,
236
+ : item.capThickness || props.capThickness || 6,
232
237
  backgroundColor:
233
238
  item.capColor || props.capColor || 'black',
234
239
  borderTopLeftRadius:
@@ -61,6 +61,7 @@ type Props = {
61
61
  autoShiftLabels?: Boolean;
62
62
  barBackgroundPattern?: Function;
63
63
  patternId?: String;
64
+ barMarginBottom?: number;
64
65
  };
65
66
  type itemType = {
66
67
  value?: number;
@@ -87,6 +88,7 @@ type itemType = {
87
88
  labelWidth?: number;
88
89
  barBackgroundPattern?: Function;
89
90
  patternId?: String;
91
+ barMarginBottom?: number;
90
92
  };
91
93
  const RenderBars = (props: Props) => {
92
94
  const {
@@ -108,6 +110,9 @@ const RenderBars = (props: Props) => {
108
110
  autoShiftLabels,
109
111
  } = props;
110
112
 
113
+ const barMarginBottom =
114
+ item.barMarginBottom === 0 ? 0 : props.barMarginBottom || 0;
115
+
111
116
  const renderLabel = (label: String, labelTextStyle: any, value: number) => {
112
117
  return (
113
118
  <View
@@ -313,17 +318,17 @@ const RenderBars = (props: Props) => {
313
318
  style={[
314
319
  {
315
320
  // overflow: 'visible',
316
- marginBottom: 60,
321
+ marginBottom: 60 + barMarginBottom,
317
322
  width: item.barWidth || props.barWidth || 30,
318
323
  height:
319
- item.value >= 0 &&
324
+ (item.value >= 0 &&
320
325
  (!isThreeD || isAnimated) &&
321
326
  item.topLabelComponent
322
327
  ? (item.topLabelComponentHeight || 30) +
323
328
  (Math.abs(item.value) * (containerHeight || 200)) /
324
329
  (maxValue || 200)
325
330
  : (Math.abs(item.value) * (containerHeight || 200)) /
326
- (maxValue || 200),
331
+ (maxValue || 200)) - barMarginBottom,
327
332
  marginRight: spacing,
328
333
  },
329
334
  item.value < 0 && {
@@ -391,7 +396,8 @@ const RenderBars = (props: Props) => {
391
396
  animationDuration={animationDuration || 800}
392
397
  height={
393
398
  (Math.abs(item.value) * (containerHeight || 200)) /
394
- (maxValue || 200)
399
+ (maxValue || 200) -
400
+ barMarginBottom
395
401
  }
396
402
  intactTopLabel={props.intactTopLabel}
397
403
  horizontal={props.horizontal}
@@ -423,7 +429,8 @@ const RenderBars = (props: Props) => {
423
429
  intactTopLabel={props.intactTopLabel}
424
430
  height={
425
431
  (Math.abs(item.value) * (containerHeight || 200)) /
426
- (maxValue || 200)
432
+ (maxValue || 200) -
433
+ barMarginBottom
427
434
  }
428
435
  value={item.value}
429
436
  />
@@ -447,6 +454,7 @@ const RenderBars = (props: Props) => {
447
454
  (Math.abs(item.value) * (containerHeight || 200)) /
448
455
  (maxValue || 200)
449
456
  }
457
+ barMarginBottom={barMarginBottom}
450
458
  cappedBars={props.cappedBars}
451
459
  capThickness={props.capThickness}
452
460
  capColor={props.capColor}
@@ -477,6 +485,7 @@ const RenderBars = (props: Props) => {
477
485
  (Math.abs(item.value) * (containerHeight || 200)) /
478
486
  (maxValue || 200)
479
487
  }
488
+ barMarginBottom={barMarginBottom}
480
489
  cappedBars={props.cappedBars}
481
490
  capThickness={props.capThickness}
482
491
  capColor={props.capColor}
@@ -505,6 +514,7 @@ const RenderBars = (props: Props) => {
505
514
  (Math.abs(item.value) * (containerHeight || 200)) /
506
515
  (maxValue || 200)
507
516
  }
517
+ barMarginBottom={barMarginBottom}
508
518
  cappedBars={props.cappedBars}
509
519
  capThickness={props.capThickness}
510
520
  capColor={props.capColor}
@@ -127,6 +127,7 @@ type PropTypes = {
127
127
  labelsExtraHeight?: number;
128
128
  barBackgroundPattern?: Function;
129
129
  patternId?: String;
130
+ barMarginBottom?: number;
130
131
  };
131
132
  type lineConfigType = {
132
133
  initialSpacing?: number;
@@ -1269,6 +1270,7 @@ export const BarChart = (props: PropTypes) => {
1269
1270
  autoShiftLabels={autoShiftLabels}
1270
1271
  barBackgroundPattern={props.barBackgroundPattern}
1271
1272
  patternId={props.patternId}
1273
+ barMarginBottom={props.barMarginBottom}
1272
1274
  />
1273
1275
  ))}
1274
1276
  </Fragment>
@@ -304,6 +304,9 @@ type itemType = {
304
304
  verticalLineUptoDataPoint?: Boolean;
305
305
  verticalLineColor?: string;
306
306
  verticalLineThickness?: number;
307
+ pointerShiftX?: number;
308
+ pointerShiftY?: number;
309
+ onPress?: Function;
307
310
  };
308
311
 
309
312
  type sectionType = {
@@ -332,7 +335,10 @@ export const LineChart = (props: propTypes) => {
332
335
  const scrollRef = useRef();
333
336
  const [pointerX, setPointerX] = useState(0);
334
337
  const [pointerY, setPointerY] = useState(0);
335
- const [pointerItem, setPointerItem] = useState({});
338
+ const [pointerItem, setPointerItem] = useState({
339
+ pointerShiftX: 0,
340
+ pointerShiftY: 0,
341
+ });
336
342
  const [points, setPoints] = useState('');
337
343
  const [points2, setPoints2] = useState('');
338
344
  const [points3, setPoints3] = useState('');
@@ -408,6 +414,63 @@ export const LineChart = (props: propTypes) => {
408
414
  newFillPoints = '';
409
415
  let counter = 0;
410
416
 
417
+ const initialSpacing =
418
+ props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
419
+ const thickness = props.thickness || 2;
420
+
421
+ const spacing = props.spacing === 0 ? 0 : props.spacing || 60;
422
+
423
+ const xAxisThickness = props.xAxisThickness || 1;
424
+ const dataPointsHeight1 =
425
+ props.dataPointsHeight1 || props.dataPointsHeight || 2;
426
+ const dataPointsWidth1 = props.dataPointsWidth1 || props.dataPointsWidth || 2;
427
+ const dataPointsRadius1 =
428
+ props.dataPointsRadius1 || props.dataPointsRadius || 3;
429
+ const dataPointsColor1 =
430
+ props.dataPointsColor1 || props.dataPointsColor || 'black';
431
+ const dataPointsShape1 =
432
+ props.dataPointsShape1 || props.dataPointsShape || 'circular';
433
+
434
+ const dataPointsHeight2 =
435
+ props.dataPointsHeight2 || props.dataPointsHeight || 2;
436
+ const dataPointsWidth2 = props.dataPointsWidth2 || props.dataPointsWidth || 2;
437
+ const dataPointsRadius2 =
438
+ props.dataPointsRadius2 || props.dataPointsRadius || 3;
439
+ const dataPointsColor2 =
440
+ props.dataPointsColor2 || props.dataPointsColor || 'blue';
441
+ const dataPointsShape2 =
442
+ props.dataPointsShape2 || props.dataPointsShape || 'circular';
443
+
444
+ const dataPointsHeight3 =
445
+ props.dataPointsHeight3 || props.dataPointsHeight || 2;
446
+ const dataPointsWidth3 = props.dataPointsWidth3 || props.dataPointsWidth || 2;
447
+ const dataPointsRadius3 =
448
+ props.dataPointsRadius3 || props.dataPointsRadius || 3;
449
+ const dataPointsColor3 =
450
+ props.dataPointsColor3 || props.dataPointsColor || 'red';
451
+ const dataPointsShape3 =
452
+ props.dataPointsShape3 || props.dataPointsShape || 'circular';
453
+
454
+ const dataPointsHeight4 =
455
+ props.dataPointsHeight4 || props.dataPointsHeight || 2;
456
+ const dataPointsWidth4 = props.dataPointsWidth4 || props.dataPointsWidth || 2;
457
+ const dataPointsRadius4 =
458
+ props.dataPointsRadius4 || props.dataPointsRadius || 3;
459
+ const dataPointsColor4 =
460
+ props.dataPointsColor4 || props.dataPointsColor || 'red';
461
+ const dataPointsShape4 =
462
+ props.dataPointsShape4 || props.dataPointsShape || 'circular';
463
+
464
+ const dataPointsHeight5 =
465
+ props.dataPointsHeight5 || props.dataPointsHeight || 2;
466
+ const dataPointsWidth5 = props.dataPointsWidth5 || props.dataPointsWidth || 2;
467
+ const dataPointsRadius5 =
468
+ props.dataPointsRadius5 || props.dataPointsRadius || 3;
469
+ const dataPointsColor5 =
470
+ props.dataPointsColor5 || props.dataPointsColor || 'red';
471
+ const dataPointsShape5 =
472
+ props.dataPointsShape5 || props.dataPointsShape || 'circular';
473
+
411
474
  if (animateOnDataChange) {
412
475
  animations.forEach((item, index) => {
413
476
  item.addListener(val => {
@@ -548,56 +611,6 @@ export const LineChart = (props: propTypes) => {
548
611
  }, [animationDuration, widthValue5]);
549
612
 
550
613
  const areaChart = props.areaChart || false;
551
- const dataPointsHeight1 =
552
- props.dataPointsHeight1 || props.dataPointsHeight || 2;
553
- const dataPointsWidth1 = props.dataPointsWidth1 || props.dataPointsWidth || 2;
554
- const dataPointsRadius1 =
555
- props.dataPointsRadius1 || props.dataPointsRadius || 3;
556
- const dataPointsColor1 =
557
- props.dataPointsColor1 || props.dataPointsColor || 'black';
558
- const dataPointsShape1 =
559
- props.dataPointsShape1 || props.dataPointsShape || 'circular';
560
-
561
- const dataPointsHeight2 =
562
- props.dataPointsHeight2 || props.dataPointsHeight || 2;
563
- const dataPointsWidth2 = props.dataPointsWidth2 || props.dataPointsWidth || 2;
564
- const dataPointsRadius2 =
565
- props.dataPointsRadius2 || props.dataPointsRadius || 3;
566
- const dataPointsColor2 =
567
- props.dataPointsColor2 || props.dataPointsColor || 'blue';
568
- const dataPointsShape2 =
569
- props.dataPointsShape2 || props.dataPointsShape || 'circular';
570
-
571
- const dataPointsHeight3 =
572
- props.dataPointsHeight3 || props.dataPointsHeight || 2;
573
- const dataPointsWidth3 = props.dataPointsWidth3 || props.dataPointsWidth || 2;
574
- const dataPointsRadius3 =
575
- props.dataPointsRadius3 || props.dataPointsRadius || 3;
576
- const dataPointsColor3 =
577
- props.dataPointsColor3 || props.dataPointsColor || 'red';
578
- const dataPointsShape3 =
579
- props.dataPointsShape3 || props.dataPointsShape || 'circular';
580
-
581
- const dataPointsHeight4 =
582
- props.dataPointsHeight4 || props.dataPointsHeight || 2;
583
- const dataPointsWidth4 = props.dataPointsWidth4 || props.dataPointsWidth || 2;
584
- const dataPointsRadius4 =
585
- props.dataPointsRadius4 || props.dataPointsRadius || 3;
586
- const dataPointsColor4 =
587
- props.dataPointsColor4 || props.dataPointsColor || 'red';
588
- const dataPointsShape4 =
589
- props.dataPointsShape4 || props.dataPointsShape || 'circular';
590
-
591
- const dataPointsHeight5 =
592
- props.dataPointsHeight5 || props.dataPointsHeight || 2;
593
- const dataPointsWidth5 = props.dataPointsWidth5 || props.dataPointsWidth || 2;
594
- const dataPointsRadius5 =
595
- props.dataPointsRadius5 || props.dataPointsRadius || 3;
596
- const dataPointsColor5 =
597
- props.dataPointsColor5 || props.dataPointsColor || 'red';
598
- const dataPointsShape5 =
599
- props.dataPointsShape5 || props.dataPointsShape || 'circular';
600
-
601
614
  const textFontSize1 = props.textFontSize1 || props.textFontSize || 10;
602
615
  const textFontSize2 = props.textFontSize2 || props.textFontSize || 10;
603
616
  const textFontSize3 = props.textFontSize3 || props.textFontSize || 10;
@@ -608,13 +621,6 @@ export const LineChart = (props: propTypes) => {
608
621
  const textColor3 = props.textColor3 || props.textColor || 'gray';
609
622
  const textColor4 = props.textColor4 || props.textColor || 'gray';
610
623
  const textColor5 = props.textColor5 || props.textColor || 'gray';
611
- const initialSpacing =
612
- props.initialSpacing === 0 ? 0 : props.initialSpacing || 40;
613
- const thickness = props.thickness || 2;
614
-
615
- const spacing = props.spacing === 0 ? 0 : props.spacing || 60;
616
-
617
- const xAxisThickness = props.xAxisThickness || 1;
618
624
  const xAxisColor = props.xAxisColor || 'black';
619
625
 
620
626
  let totalWidth = initialSpacing;
@@ -1936,6 +1942,9 @@ export const LineChart = (props: propTypes) => {
1936
1942
  : 'none'
1937
1943
  : dataPointsColor
1938
1944
  }
1945
+ onPress={() => {
1946
+ item.onPress ? item.onPress(item, index) : null;
1947
+ }}
1939
1948
  />
1940
1949
  )}
1941
1950
  </Fragment>
@@ -1957,6 +1966,9 @@ export const LineChart = (props: propTypes) => {
1957
1966
  : 'none'
1958
1967
  : dataPointsColor
1959
1968
  }
1969
+ onPress={() => {
1970
+ item.onPress ? item.onPress(item, index) : null;
1971
+ }}
1960
1972
  />
1961
1973
  )}
1962
1974
  </Fragment>
@@ -2054,14 +2066,22 @@ export const LineChart = (props: propTypes) => {
2054
2066
  <View
2055
2067
  style={{
2056
2068
  position: 'absolute',
2057
- height: pointerHeight || pointerRadius * 2,
2058
- width: pointerWidth || pointerRadius * 2,
2059
- backgroundColor: pointerColor,
2060
- borderRadius: pointerRadius || 0,
2061
- left: pointerX,
2069
+ left: pointerX + (pointerItem.pointerShiftX || 0),
2062
2070
  top: pointerY,
2063
2071
  }}>
2064
- {pointerComponent ? pointerComponent() : null}
2072
+ {pointerComponent ? (
2073
+ pointerComponent()
2074
+ ) : (
2075
+ <View
2076
+ style={{
2077
+ height: pointerHeight || pointerRadius * 2,
2078
+ width: pointerWidth || pointerRadius * 2,
2079
+ marginTop: pointerItem.pointerShiftY || 0,
2080
+ backgroundColor: pointerColor,
2081
+ borderRadius: pointerRadius || 0,
2082
+ }}
2083
+ />
2084
+ )}
2065
2085
  {showPointerStrip && (
2066
2086
  <View
2067
2087
  style={{
@@ -2124,7 +2144,7 @@ export const LineChart = (props: propTypes) => {
2124
2144
  onResponderGrant={evt => {
2125
2145
  if (!pointerConfig) return;
2126
2146
  let x = evt.nativeEvent.locationX;
2127
- let factor = x / (initialSpacing + spacing);
2147
+ let factor = (x - initialSpacing) / spacing;
2128
2148
  factor = Math.round(factor);
2129
2149
  factor = Math.min(factor, data.length - 1);
2130
2150
  factor = Math.max(factor, 0);
@@ -2146,7 +2166,7 @@ export const LineChart = (props: propTypes) => {
2146
2166
  onResponderMove={evt => {
2147
2167
  if (!pointerConfig) return;
2148
2168
  let x = evt.nativeEvent.locationX;
2149
- let factor = x / (initialSpacing + spacing);
2169
+ let factor = (x - initialSpacing) / spacing;
2150
2170
  factor = Math.round(factor);
2151
2171
  factor = Math.min(factor, data.length - 1);
2152
2172
  factor = Math.max(factor, 0);
@@ -2331,7 +2351,7 @@ export const LineChart = (props: propTypes) => {
2331
2351
  onResponderGrant={evt => {
2332
2352
  if (!pointerConfig) return;
2333
2353
  let x = evt.nativeEvent.locationX;
2334
- let factor = x / (initialSpacing + spacing);
2354
+ let factor = (x - initialSpacing) / spacing;
2335
2355
  factor = Math.round(factor);
2336
2356
  factor = Math.min(factor, data.length - 1);
2337
2357
  factor = Math.max(factor, 0);
@@ -2353,7 +2373,7 @@ export const LineChart = (props: propTypes) => {
2353
2373
  onResponderMove={evt => {
2354
2374
  if (!pointerConfig) return;
2355
2375
  let x = evt.nativeEvent.locationX;
2356
- let factor = x / (initialSpacing + spacing);
2376
+ let factor = (x - initialSpacing) / spacing;
2357
2377
  factor = Math.round(factor);
2358
2378
  factor = Math.min(factor, data.length - 1);
2359
2379
  factor = Math.max(factor, 0);
package/src/todos.md CHANGED
@@ -1,8 +1,7 @@
1
1
  ## Feature requests
2
2
 
3
3
  1. OnPress function on Pie Chart https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/111
4
- 2. Scroll through data points instead of justing clicking on them https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/116
5
- 3. Bottom margin between bar and x axis https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/126
4
+ 2. Bottom margin between bar and x axis https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/126
6
5
 
7
6
  ## To-dos in documentation-
8
7
 
@@ -11,3 +10,4 @@
11
10
  3. Prepare a doc for Bar chart with y axis on right side
12
11
  4. Prepare a doc for Line chart with y axis on right side
13
12
  5. Prepare a doc for Bar chart combined with Line chart having a separate data for the Line chart
13
+ 6. Prepare a doc for Line chart with smoothly scrolling data pointer and strip