react-native-gifted-charts 0.2.5 → 0.2.9

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": "0.2.5",
3
+ "version": "0.2.9",
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": [
@@ -1,7 +1,18 @@
1
1
  import React, {useEffect, useState} from 'react';
2
- import {View, ColorValue, LayoutAnimation, Platform} from 'react-native';
2
+ import {
3
+ View,
4
+ ColorValue,
5
+ LayoutAnimation,
6
+ Platform,
7
+ UIManager,
8
+ } from 'react-native';
3
9
  import LinearGradient from 'react-native-linear-gradient';
4
10
 
11
+ if (Platform.OS === 'android') {
12
+ UIManager.setLayoutAnimationEnabledExperimental &&
13
+ UIManager.setLayoutAnimationEnabledExperimental(true);
14
+ }
15
+
5
16
  type propTypes = {
6
17
  item: itemType;
7
18
  height: number;
@@ -44,7 +55,7 @@ type itemType = {
44
55
 
45
56
  const Animated2DWithGradient = (props: propTypes) => {
46
57
  const {item, opacity, animationDuration, noGradient, noAnimation} = props;
47
- const [height, setHeight] = useState(noAnimation ? props.height : 0);
58
+ const [height, setHeight] = useState(noAnimation ? props.height : 2);
48
59
  const [initialRender, setInitialRender] = useState(
49
60
  noAnimation ? false : true,
50
61
  );
@@ -112,6 +112,8 @@ type PropTypes = {
112
112
  hideOrigin?: Boolean;
113
113
  labelWidth?: number;
114
114
  yAxisLabelTexts?: Array<string>;
115
+ yAxisLabelPrefix?: String;
116
+ yAxisLabelSuffix?: String;
115
117
  };
116
118
  type lineConfigType = {
117
119
  curved?: Boolean;
@@ -290,6 +292,9 @@ export const BarChart = (props: PropTypes) => {
290
292
  const xAxisIndicesColor = props.xAxisIndicesColor || 'black';
291
293
  const yAxisIndicesColor = props.yAxisIndicesColor || 'black';
292
294
 
295
+ const yAxisLabelPrefix = props.yAxisLabelPrefix || '';
296
+ const yAxisLabelSuffix = props.yAxisLabelSuffix || '';
297
+
293
298
  const xAxisThickness =
294
299
  props.xAxisThickness === 0
295
300
  ? props.xAxisThickness
@@ -515,10 +520,33 @@ export const BarChart = (props: PropTypes) => {
515
520
  outputRange: [0, totalWidth],
516
521
  });
517
522
 
523
+ const getLabel = val => {
524
+ let label = '';
525
+ if (showFractionalValues) {
526
+ if (val) {
527
+ label = val;
528
+ } else {
529
+ label = '0';
530
+ }
531
+ } else {
532
+ if (val) {
533
+ label = val.toString().split('.')[0];
534
+ } else {
535
+ label = '0';
536
+ }
537
+ }
538
+
539
+ return yAxisLabelPrefix + label + yAxisLabelSuffix;
540
+ };
541
+
518
542
  const renderHorizSections = () => {
519
543
  return (
520
544
  <>
521
545
  {horizSections.map((sectionItems, index) => {
546
+ let label = getLabel(sectionItems.value);
547
+ if (hideOrigin && index === horizSections.length - 1) {
548
+ label = '';
549
+ }
522
550
  return (
523
551
  <View
524
552
  key={index}
@@ -561,17 +589,7 @@ export const BarChart = (props: PropTypes) => {
561
589
  ],
562
590
  },
563
591
  ]}>
564
- {showFractionalValues
565
- ? sectionItems.value
566
- ? sectionItems.value
567
- : hideOrigin
568
- ? ''
569
- : '0'
570
- : sectionItems.value
571
- ? sectionItems.value.toString().split('.')[0]
572
- : hideOrigin
573
- ? ''
574
- : '0'}
592
+ {label}
575
593
  </Text>
576
594
  ) : null}
577
595
  </View>
@@ -5,10 +5,16 @@ import {
5
5
  ColorValue,
6
6
  LayoutAnimation,
7
7
  Platform,
8
+ UIManager,
8
9
  } from 'react-native';
9
10
  import LinearGradient from 'react-native-linear-gradient';
10
11
  import {styles} from './styles';
11
12
 
13
+ if (Platform.OS === 'android') {
14
+ UIManager.setLayoutAnimationEnabledExperimental &&
15
+ UIManager.setLayoutAnimationEnabledExperimental(true);
16
+ }
17
+
12
18
  type trianglePropTypes = {
13
19
  style: any;
14
20
  width: number;
@@ -89,7 +95,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
89
95
  const layoutAppear = () => {
90
96
  LayoutAnimation.configureNext({
91
97
  duration: Platform.OS == 'ios' ? animationDuration : 20,
92
- create: {type: 'linear', property: 'opacity'},
98
+ create: {type: 'linear', property: 'scaleXY'},
93
99
  // update: { type: 'linear' }
94
100
  });
95
101
  setInitialRender(false);
@@ -186,6 +186,8 @@ type propTypes = {
186
186
  textShiftY?: number;
187
187
  yAxisLabelTexts?: Array<string>;
188
188
  width?: number;
189
+ yAxisLabelPrefix?: String;
190
+ yAxisLabelSuffix?: String;
189
191
  };
190
192
  type referenceConfigType = {
191
193
  thickness: number;
@@ -267,6 +269,9 @@ export const LineChart = (props: propTypes) => {
267
269
  const animateTogether = props.animateTogether || false;
268
270
  const animateOnDataChange = props.animateOnDataChange || false;
269
271
 
272
+ const yAxisLabelPrefix = props.yAxisLabelPrefix || '';
273
+ const yAxisLabelSuffix = props.yAxisLabelSuffix || '';
274
+
270
275
  if (!initialData) {
271
276
  initialData = [...data];
272
277
  animations = initialData.map(item => new Animated.Value(item.value));
@@ -1028,11 +1033,34 @@ export const LineChart = (props: propTypes) => {
1028
1033
  // )
1029
1034
  // }
1030
1035
 
1036
+ const getLabel = val => {
1037
+ let label = '';
1038
+ if (showFractionalValues) {
1039
+ if (val) {
1040
+ label = val;
1041
+ } else {
1042
+ label = '0';
1043
+ }
1044
+ } else {
1045
+ if (val) {
1046
+ label = val.toString().split('.')[0];
1047
+ } else {
1048
+ label = '0';
1049
+ }
1050
+ }
1051
+
1052
+ return yAxisLabelPrefix + label + yAxisLabelSuffix;
1053
+ };
1054
+
1031
1055
  const renderHorizSections = () => {
1032
1056
  return (
1033
1057
  <>
1034
1058
  {props.hideAxesAndRules !== true &&
1035
1059
  horizSections.map((sectionItems, index) => {
1060
+ let label = getLabel(sectionItems.value);
1061
+ if (hideOrigin && index === horizSections.length - 1) {
1062
+ label = '';
1063
+ }
1036
1064
  return (
1037
1065
  <View
1038
1066
  key={index}
@@ -1061,17 +1089,7 @@ export const LineChart = (props: propTypes) => {
1061
1089
  marginBottom: stepHeight / -2,
1062
1090
  },
1063
1091
  ]}>
1064
- {showFractionalValues
1065
- ? sectionItems.value
1066
- ? sectionItems.value
1067
- : hideOrigin
1068
- ? ''
1069
- : '0'
1070
- : sectionItems.value
1071
- ? sectionItems.value.toString().split('.')[0]
1072
- : hideOrigin
1073
- ? ''
1074
- : '0'}
1092
+ {label}
1075
1093
  </Text>
1076
1094
  ) : null}
1077
1095
  </View>