react-native-gifted-charts 0.2.2 → 0.2.6

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
@@ -19,12 +19,13 @@ The most complete library for Bar, Line, Area, Pie, and Donut charts in React Na
19
19
 
20
20
  ![alt text](/demos/altBars.svg)
21
21
  ![alt text](/demos/barPairs.svg)
22
+ <img src='/demos/animatedDataLineChart.gif' alt='' width=300/>
23
+ <img src='/demos/pielabbelled.svg' alt='' height=280 width=270/>
22
24
  <img src='/demos/movingBars.gif' alt='' width=300/>
23
25
  <img src='/demos/lineLabelled.png' alt='' height=370 width=360/>
24
26
  ![alt text](/demos/lineArea.png)
25
27
  <img src='/demos/cappedCombined.png' alt='' height=280 width=280/>
26
- <img src='/demos/line.gif' alt='' height=280 width=270/>
27
- <img src='/demos/pielabbelled.svg' alt='' height=280 width=270/>
28
+ <img src='/demos/line.gif' alt='' height=300 width=290/>
28
29
 
29
30
  ---
30
31
 
@@ -98,6 +99,7 @@ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the
98
99
  | Issue | Solution |
99
100
  | ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
100
101
  | [BarChart - Value and section line don't match](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35) | [Comment by the owner](https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/35#issuecomment-972673281) |
102
+ | **Invariant Violation: requireNativeComponent: "RNCWebView" was not found in the UIManager.** | install `react-native-webview` |
101
103
 
102
104
  ## License
103
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-gifted-charts",
3
- "version": "0.2.2",
3
+ "version": "0.2.6",
4
4
  "description": "The most complete library for Bar, Line, Area, Pie and Donut charts in React Native. Allows 2D, 3D, gradient, animations and live data updates.",
5
5
  "main": "src/index.tsx",
6
6
  "files": [
@@ -19,7 +19,7 @@
19
19
  "bugs": {
20
20
  "url": "https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues"
21
21
  },
22
- "homepage": "https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts#readme",
22
+ "homepage": "https://gifted-charts.web.app/",
23
23
  "publishConfig": {
24
24
  "registry": "https://registry.npmjs.org/"
25
25
  },
@@ -561,16 +561,22 @@ export const BarChart = (props: PropTypes) => {
561
561
  ],
562
562
  },
563
563
  ]}>
564
- {showFractionalValues
564
+ {hideOrigin
565
+ ? index === horizSections.length - 1
566
+ ? ''
567
+ : showFractionalValues
568
+ ? sectionItems.value
569
+ ? sectionItems.value
570
+ : '0'
571
+ : sectionItems.value
572
+ ? sectionItems.value.toString().split('.')[0]
573
+ : '0'
574
+ : showFractionalValues
565
575
  ? sectionItems.value
566
576
  ? sectionItems.value
567
- : hideOrigin
568
- ? ''
569
577
  : '0'
570
578
  : sectionItems.value
571
579
  ? sectionItems.value.toString().split('.')[0]
572
- : hideOrigin
573
- ? ''
574
580
  : '0'}
575
581
  </Text>
576
582
  ) : null}
@@ -966,7 +972,7 @@ export const BarChart = (props: PropTypes) => {
966
972
  <ScrollView
967
973
  style={[
968
974
  {
969
- marginLeft: 36,
975
+ marginLeft: yAxisLabelWidth,
970
976
  position: 'absolute',
971
977
  bottom: stepHeight * -0.5 - 60 + xAxisThickness,
972
978
  },
@@ -25,6 +25,9 @@ import Svg, {
25
25
  import {svgPath, bezierCommand} from '../utils';
26
26
  import Rule from '../Components/lineSvg';
27
27
 
28
+ let initialData = null;
29
+ let animations = [];
30
+
28
31
  type propTypes = {
29
32
  height?: number;
30
33
  noOfSections?: number;
@@ -42,7 +45,9 @@ type propTypes = {
42
45
  thickness3?: number;
43
46
  rotateLabel?: Boolean;
44
47
  isAnimated?: Boolean;
48
+ animateOnDataChange?: Boolean;
45
49
  animationDuration?: number;
50
+ onDataChangeAnimationDuration?: number;
46
51
  animationEasing?: any;
47
52
  animateTogether?: boolean;
48
53
  xAxisThickness?: number;
@@ -247,7 +252,7 @@ export const LineChart = (props: propTypes) => {
247
252
  const [selectedIndex, setSelectedIndex] = useState(-1);
248
253
  const containerHeight = props.height || 200;
249
254
  const noOfSections = props.noOfSections || 10;
250
- const data = useMemo(() => props.data || [], [props.data]);
255
+ let data = useMemo(() => props.data || [], [props.data]);
251
256
  const data2 = useMemo(() => props.data2 || [], [props.data2]);
252
257
  const data3 = useMemo(() => props.data3 || [], [props.data3]);
253
258
 
@@ -257,7 +262,93 @@ export const LineChart = (props: propTypes) => {
257
262
  const widthValue3 = useMemo(() => new Animated.Value(0), []);
258
263
 
259
264
  const animationDuration = props.animationDuration || 800;
265
+ const onDataChangeAnimationDuration =
266
+ props.onDataChangeAnimationDuration || 400;
260
267
  const animateTogether = props.animateTogether || false;
268
+ const animateOnDataChange = props.animateOnDataChange || false;
269
+
270
+ if (!initialData) {
271
+ initialData = [...data];
272
+ animations = initialData.map(item => new Animated.Value(item.value));
273
+ }
274
+
275
+ let newPoints = '',
276
+ newFillPoints = '';
277
+ let counter = 0;
278
+
279
+ if (animateOnDataChange) {
280
+ animations.forEach((item, index) => {
281
+ item.addListener(val => {
282
+ data[index].value = val.value;
283
+ let pp = '',
284
+ ppp = '';
285
+ if (!props.curved) {
286
+ for (let i = 0; i < data.length; i++) {
287
+ pp +=
288
+ 'L' +
289
+ (initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
290
+ ' ' +
291
+ (containerHeight +
292
+ 10 -
293
+ (data[i].value * containerHeight) / maxValue) +
294
+ ' ';
295
+ }
296
+ if (areaChart) {
297
+ ppp =
298
+ 'L' +
299
+ (initialSpacing - dataPointsWidth1 / 2) +
300
+ ' ' +
301
+ (containerHeight + 10 - xAxisThickness) +
302
+ ' ';
303
+ ppp += pp;
304
+ ppp +=
305
+ 'L' +
306
+ (initialSpacing -
307
+ dataPointsWidth1 / 2 +
308
+ spacing * (data.length - 1)) +
309
+ ' ' +
310
+ (containerHeight + 10 - xAxisThickness);
311
+ ppp +=
312
+ 'L' +
313
+ (initialSpacing - dataPointsWidth1 / 2) +
314
+ ' ' +
315
+ (containerHeight + 10 - xAxisThickness) +
316
+ ' ';
317
+ }
318
+ newPoints = pp;
319
+ newFillPoints = ppp;
320
+ setPointsOnChange();
321
+ }
322
+ counter++;
323
+ });
324
+ });
325
+ }
326
+
327
+ const setPointsOnChange = () => {
328
+ if (counter === data.length) {
329
+ // console.log('here.......');
330
+ if (!props.curved) {
331
+ setPoints(newPoints.replace('L', 'M'));
332
+ if (areaChart) {
333
+ setFillPoints(newFillPoints.replace('L', 'M'));
334
+ }
335
+ }
336
+ }
337
+ };
338
+
339
+ useEffect(() => {
340
+ if (animateOnDataChange) {
341
+ Animated.parallel(
342
+ animations.map((anItem, index) =>
343
+ Animated.timing(anItem, {
344
+ toValue: data[index].value,
345
+ useNativeDriver: true,
346
+ duration: onDataChangeAnimationDuration,
347
+ }),
348
+ ),
349
+ ).start();
350
+ }
351
+ }, [animateOnDataChange, data, onDataChangeAnimationDuration]);
261
352
 
262
353
  const labelsAppear = useCallback(() => {
263
354
  opacValue.setValue(0);
@@ -359,7 +450,7 @@ export const LineChart = (props: propTypes) => {
359
450
  totalWidth += spacing;
360
451
  });
361
452
 
362
- const maxValue = props.maxValue || maxItem;
453
+ const maxValue = props.maxValue || maxItem || 10;
363
454
 
364
455
  useEffect(() => {
365
456
  // console.log('comes here............')
@@ -392,14 +483,17 @@ export const LineChart = (props: propTypes) => {
392
483
  pp3 = '';
393
484
  if (!props.curved) {
394
485
  for (let i = 0; i < data.length; i++) {
395
- pp +=
396
- 'L' +
397
- (initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
398
- ' ' +
399
- (containerHeight +
400
- 10 -
401
- (data[i].value * containerHeight) / maxValue) +
402
- ' ';
486
+ if (!animateOnDataChange) {
487
+ pp +=
488
+ 'L' +
489
+ (initialSpacing - dataPointsWidth1 / 2 + spacing * i) +
490
+ ' ' +
491
+ (containerHeight +
492
+ 10 -
493
+ (data[i].value * containerHeight) / maxValue) +
494
+ ' ';
495
+ setPoints(pp.replace('L', 'M'));
496
+ }
403
497
  if (data2.length) {
404
498
  pp2 +=
405
499
  'L' +
@@ -421,7 +515,6 @@ export const LineChart = (props: propTypes) => {
421
515
  ' ';
422
516
  }
423
517
  }
424
- setPoints(pp.replace('L', 'M'));
425
518
  setPoints2(pp2.replace('L', 'M'));
426
519
  setPoints3(pp3.replace('L', 'M'));
427
520
 
@@ -431,26 +524,29 @@ export const LineChart = (props: propTypes) => {
431
524
  ppp2 = '',
432
525
  ppp3 = '';
433
526
 
434
- ppp =
435
- 'L' +
436
- (initialSpacing - dataPointsWidth1 / 2) +
437
- ' ' +
438
- (containerHeight + 10 - xAxisThickness) +
439
- ' ';
440
- ppp += pp;
441
- ppp +=
442
- 'L' +
443
- (initialSpacing -
444
- dataPointsWidth1 / 2 +
445
- spacing * (data.length - 1)) +
446
- ' ' +
447
- (containerHeight + 10 - xAxisThickness);
448
- ppp +=
449
- 'L' +
450
- (initialSpacing - dataPointsWidth1 / 2) +
451
- ' ' +
452
- (containerHeight + 10 - xAxisThickness) +
453
- ' ';
527
+ if (!animateOnDataChange) {
528
+ ppp =
529
+ 'L' +
530
+ (initialSpacing - dataPointsWidth1 / 2) +
531
+ ' ' +
532
+ (containerHeight + 10 - xAxisThickness) +
533
+ ' ';
534
+ ppp += pp;
535
+ ppp +=
536
+ 'L' +
537
+ (initialSpacing -
538
+ dataPointsWidth1 / 2 +
539
+ spacing * (data.length - 1)) +
540
+ ' ' +
541
+ (containerHeight + 10 - xAxisThickness);
542
+ ppp +=
543
+ 'L' +
544
+ (initialSpacing - dataPointsWidth1 / 2) +
545
+ ' ' +
546
+ (containerHeight + 10 - xAxisThickness) +
547
+ ' ';
548
+ setFillPoints(ppp.replace('L', 'M'));
549
+ }
454
550
 
455
551
  if (data2.length) {
456
552
  ppp2 =
@@ -499,8 +595,6 @@ export const LineChart = (props: propTypes) => {
499
595
  ' ';
500
596
  setFillPoints3(ppp3.replace('L', 'M'));
501
597
  }
502
-
503
- setFillPoints(ppp.replace('L', 'M'));
504
598
  }
505
599
 
506
600
  // console.log('pp-------->', pp);
@@ -643,6 +737,7 @@ export const LineChart = (props: propTypes) => {
643
737
  /*************************************************************************************/
644
738
  }
645
739
  }, [
740
+ animateOnDataChange,
646
741
  areaChart,
647
742
  containerHeight,
648
743
  data,