react-native-gifted-charts 1.2.5 → 1.2.8

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.5",
3
+ "version": "1.2.8",
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": [
@@ -63,6 +63,7 @@ type Props = {
63
63
  barBackgroundPattern?: Function;
64
64
  patternId?: String;
65
65
  barMarginBottom?: number;
66
+ onPress?: Function;
66
67
  };
67
68
  type itemType = {
68
69
  value?: number;
@@ -319,7 +320,13 @@ const RenderBars = (props: Props) => {
319
320
  <TouchableOpacity
320
321
  disabled={item.disablePress || props.disablePress}
321
322
  activeOpacity={props.activeOpacity || 0.2}
322
- onPress={item.onPress}
323
+ onPress={() => {
324
+ item.onPress
325
+ ? item.onPress()
326
+ : props.onPress
327
+ ? props.onPress(item, index)
328
+ : null;
329
+ }}
323
330
  style={[
324
331
  {
325
332
  // overflow: 'visible',
@@ -130,6 +130,7 @@ type PropTypes = {
130
130
  barBackgroundPattern?: Function;
131
131
  patternId?: String;
132
132
  barMarginBottom?: number;
133
+ onPress?: Function;
133
134
  };
134
135
  type lineConfigType = {
135
136
  initialSpacing?: number;
@@ -845,7 +846,9 @@ export const BarChart = (props: PropTypes) => {
845
846
  props.hideAxesAndRules !== true &&
846
847
  !hideYAxisText &&
847
848
  horizSectionsBelow.map((sectionItems, index) => {
848
- let label = getLabel(sectionItems.value);
849
+ let label = getLabel(
850
+ horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
851
+ );
849
852
  return (
850
853
  <View
851
854
  key={index}
@@ -1456,6 +1459,7 @@ export const BarChart = (props: PropTypes) => {
1456
1459
  labelTextStyle={
1457
1460
  item.labelTextStyle || props.xAxisLabelTextStyle
1458
1461
  }
1462
+ onPress={props.onPress}
1459
1463
  />
1460
1464
  ))}
1461
1465
  </Fragment>
@@ -819,7 +819,7 @@ export const LineChart = (props: propTypes) => {
819
819
  ppp4 = '',
820
820
  ppp5 = '';
821
821
 
822
- if (!animateOnDataChange) {
822
+ if (data.length && !animateOnDataChange) {
823
823
  ppp =
824
824
  'L' +
825
825
  (initialSpacing - dataPointsWidth1 / 2) +
@@ -1007,35 +1007,37 @@ export const LineChart = (props: propTypes) => {
1007
1007
 
1008
1008
  // console.log('xx---->>>', xx)
1009
1009
  if (areaChart) {
1010
- xx =
1011
- 'M ' +
1012
- (initialSpacing - dataPointsWidth1 / 2) +
1013
- ',' +
1014
- (containerHeight + 10 - xAxisThickness) +
1015
- ' ' +
1016
- 'L ' +
1017
- (initialSpacing - dataPointsWidth1 / 2) +
1018
- ',' +
1019
- (containerHeight +
1020
- 10 -
1021
- (data[0].value * containerHeight) / maxValue) +
1022
- ' ' +
1023
- xx +
1024
- ' ' +
1025
- 'L ' +
1026
- (initialSpacing -
1027
- dataPointsWidth1 / 2 +
1028
- spacing * (data.length - 1)) +
1029
- ',' +
1030
- (containerHeight + 10 - xAxisThickness) +
1031
- ' ' +
1032
- 'L ' +
1033
- (initialSpacing - dataPointsWidth1 / 2) +
1034
- ',' +
1035
- (containerHeight + 10 - xAxisThickness) +
1036
- ' ';
1037
- setFillPoints(xx);
1038
- // console.log('xx later ---->>>', xx)
1010
+ if (data.length) {
1011
+ xx =
1012
+ 'M ' +
1013
+ (initialSpacing - dataPointsWidth1 / 2) +
1014
+ ',' +
1015
+ (containerHeight + 10 - xAxisThickness) +
1016
+ ' ' +
1017
+ 'L ' +
1018
+ (initialSpacing - dataPointsWidth1 / 2) +
1019
+ ',' +
1020
+ (containerHeight +
1021
+ 10 -
1022
+ (data[0].value * containerHeight) / maxValue) +
1023
+ ' ' +
1024
+ xx +
1025
+ ' ' +
1026
+ 'L ' +
1027
+ (initialSpacing -
1028
+ dataPointsWidth1 / 2 +
1029
+ spacing * (data.length - 1)) +
1030
+ ',' +
1031
+ (containerHeight + 10 - xAxisThickness) +
1032
+ ' ' +
1033
+ 'L ' +
1034
+ (initialSpacing - dataPointsWidth1 / 2) +
1035
+ ',' +
1036
+ (containerHeight + 10 - xAxisThickness) +
1037
+ ' ';
1038
+ setFillPoints(xx);
1039
+ // console.log('xx later ---->>>', xx)
1040
+ }
1039
1041
 
1040
1042
  if (data2.length) {
1041
1043
  xx2 =
@@ -1240,32 +1242,44 @@ export const LineChart = (props: propTypes) => {
1240
1242
  const startFillColor1 =
1241
1243
  props.startFillColor1 || props.startFillColor || 'gray';
1242
1244
  const endFillColor1 = props.endFillColor1 || props.endFillColor || 'white';
1243
- const startOpacity1 = props.startOpacity1 || props.startOpacity || 1;
1244
- const endOpacity1 = props.endOpacity1 || props.endOpacity || 1;
1245
+ const startOpacity = props.startOpacity === 0 ? 0 : props.startOpacity || 1;
1246
+ const endOpacity = props.endOpacity === 0 ? 0 : props.endOpacity || 1;
1247
+ const startOpacity1 =
1248
+ props.startOpacity1 === 0 ? 0 : props.startOpacity1 || startOpacity;
1249
+ const endOpacity1 =
1250
+ props.endOpacity1 === 0 ? 0 : props.endOpacity1 || endOpacity;
1245
1251
 
1246
1252
  const startFillColor2 =
1247
1253
  props.startFillColor2 || props.startFillColor || 'gray';
1248
1254
  const endFillColor2 = props.endFillColor2 || props.endFillColor || 'white';
1249
- const startOpacity2 = props.startOpacity2 || props.startOpacity || 1;
1250
- const endOpacity2 = props.endOpacity2 || props.endOpacity || 1;
1255
+ const startOpacity2 =
1256
+ props.startOpacity2 === 0 ? 0 : props.startOpacity2 || startOpacity;
1257
+ const endOpacity2 =
1258
+ props.endOpacity2 === 0 ? 0 : props.endOpacity2 || endOpacity;
1251
1259
 
1252
1260
  const startFillColor3 =
1253
1261
  props.startFillColor3 || props.startFillColor || 'gray';
1254
1262
  const endFillColor3 = props.endFillColor3 || props.endFillColor || 'white';
1255
- const startOpacity3 = props.startOpacity3 || props.startOpacity || 1;
1256
- const endOpacity3 = props.endOpacity3 || props.endOpacity || 1;
1263
+ const startOpacity3 =
1264
+ props.startOpacity3 === 0 ? 0 : props.startOpacity3 || startOpacity;
1265
+ const endOpacity3 =
1266
+ props.endOpacity3 === 0 ? 0 : props.endOpacity3 || endOpacity;
1257
1267
 
1258
1268
  const startFillColor4 =
1259
1269
  props.startFillColor4 || props.startFillColor || 'gray';
1260
1270
  const endFillColor4 = props.endFillColor4 || props.endFillColor || 'white';
1261
- const startOpacity4 = props.startOpacity4 || props.startOpacity || 1;
1262
- const endOpacity4 = props.endOpacity4 || props.endOpacity || 1;
1271
+ const startOpacity4 =
1272
+ props.startOpacity4 === 0 ? 0 : props.startOpacity4 || startOpacity;
1273
+ const endOpacity4 =
1274
+ props.endOpacity4 === 0 ? 0 : props.endOpacity4 || endOpacity;
1263
1275
 
1264
1276
  const startFillColor5 =
1265
1277
  props.startFillColor5 || props.startFillColor || 'gray';
1266
1278
  const endFillColor5 = props.endFillColor5 || props.endFillColor || 'white';
1267
- const startOpacity5 = props.startOpacity5 || props.startOpacity || 1;
1268
- const endOpacity5 = props.endOpacity5 || props.endOpacity || 1;
1279
+ const startOpacity5 =
1280
+ props.startOpacity5 === 0 ? 0 : props.startOpacity5 || startOpacity;
1281
+ const endOpacity5 =
1282
+ props.endOpacity5 === 0 ? 0 : props.endOpacity5 || endOpacity;
1269
1283
 
1270
1284
  const rulesThickness =
1271
1285
  props.rulesThickness === 0 ? 0 : props.rulesThickness || 1;
@@ -1866,7 +1880,9 @@ export const LineChart = (props: propTypes) => {
1866
1880
  props.hideAxesAndRules !== true &&
1867
1881
  !hideYAxisText &&
1868
1882
  horizSectionsBelow.map((sectionItems, index) => {
1869
- let label = getLabel(sectionItems.value);
1883
+ let label = getLabel(
1884
+ horizSectionsBelow[horizSectionsBelow.length - 1 - index].value,
1885
+ );
1870
1886
  return (
1871
1887
  <View
1872
1888
  key={index}
@@ -1,6 +1,14 @@
1
1
  import React from 'react';
2
2
  import {ColorValue, View} from 'react-native';
3
- import Svg, {Path, Circle, Text as SvgText, FontStyle} from 'react-native-svg';
3
+ import Svg, {
4
+ Path,
5
+ Circle,
6
+ Text as SvgText,
7
+ FontStyle,
8
+ Defs,
9
+ RadialGradient,
10
+ Stop,
11
+ } from 'react-native-svg';
4
12
 
5
13
  type propTypes = {
6
14
  radius?: number;
@@ -36,12 +44,17 @@ type propTypes = {
36
44
  tiltAngle?: string;
37
45
  initialAngle?: number;
38
46
  labelsPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
47
+ showGradient?: boolean;
48
+ gradientCenterColor?: string;
49
+ onPress?: Function;
50
+ onLabelPress?: Function;
39
51
  };
40
52
  type itemType = {
41
53
  value: number;
42
54
  shiftX?: number;
43
55
  shiftY?: number;
44
56
  color?: string;
57
+ gradientCenterColor?: string;
45
58
  text?: string;
46
59
  textColor?: string;
47
60
  textSize?: number;
@@ -53,6 +66,8 @@ type itemType = {
53
66
  shiftTextX?: number;
54
67
  shiftTextY?: number;
55
68
  labelPosition?: 'onBorder' | 'outward' | 'inward' | 'mid';
69
+ onPress?: Function;
70
+ onLabelPress?: Function;
56
71
  };
57
72
 
58
73
  export const PieChart = (props: propTypes) => {
@@ -102,6 +117,8 @@ export const PieChart = (props: propTypes) => {
102
117
  const showTextBackground = props.showTextBackground || false;
103
118
  const textBackgroundColor = props.textBackgroundColor || 'white';
104
119
  const showValuesAsLabels = props.showValuesAsLabels || false;
120
+ const showGradient = props.showGradient || false;
121
+ const gradientCenterColor = props.gradientCenterColor || 'white';
105
122
 
106
123
  const colors = [
107
124
  'cyan',
@@ -186,8 +203,34 @@ export const PieChart = (props: propTypes) => {
186
203
  }`}
187
204
  height={radius * 2 + strokeWidth}
188
205
  width={radius * 2 + strokeWidth}>
206
+ <Defs>
207
+ {data.map((item, index) => {
208
+ return (
209
+ <RadialGradient
210
+ id={'grad' + index}
211
+ cx="50%"
212
+ cy="50%"
213
+ rx="50%"
214
+ ry="50%"
215
+ fx="50%"
216
+ fy="50%"
217
+ gradientUnits="userSpaceOnUse">
218
+ <Stop
219
+ offset="0%"
220
+ stopColor={item.gradientCenterColor || gradientCenterColor}
221
+ stopOpacity="1"
222
+ />
223
+ <Stop
224
+ offset="100%"
225
+ stopColor={item.color || colors[index % 9]}
226
+ stopOpacity="1"
227
+ />
228
+ </RadialGradient>
229
+ );
230
+ })}
231
+ </Defs>
189
232
  {data.map((item, index) => {
190
- console.log('index', index);
233
+ // console.log('index', index);
191
234
  let nextItem;
192
235
  if (index === pData.length - 1) nextItem = pData[0];
193
236
  else nextItem = pData[index + 1];
@@ -219,14 +262,24 @@ export const PieChart = (props: propTypes) => {
219
262
  }`}
220
263
  stroke={strokeColor}
221
264
  strokeWidth={strokeWidth}
222
- fill={item.color || colors[index % 9]}
265
+ fill={
266
+ showGradient
267
+ ? `url(#grad${index})`
268
+ : item.color || colors[index % 9]
269
+ }
270
+ onPress={() => {
271
+ item.onPress
272
+ ? item.onPress
273
+ : props.onPress
274
+ ? props.onPress(item, index)
275
+ : null;
276
+ }}
223
277
  />
224
278
  );
225
279
  })}
226
280
 
227
281
  {showText &&
228
282
  data.map((item, index) => {
229
-
230
283
  let mx = cx * (1 + Math.sin(2 * pi * mData[index] + initialAngle));
231
284
  let my = cy * (1 - Math.cos(2 * pi * mData[index] + initialAngle));
232
285
 
@@ -270,6 +323,17 @@ export const PieChart = (props: propTypes) => {
270
323
  textSize
271
324
  }
272
325
  fill={item.textBackgroundColor || textBackgroundColor}
326
+ onPress={() => {
327
+ item.onLabelPress
328
+ ? item.onLabelPress()
329
+ : props.onLabelPress
330
+ ? props.onLabelPress(item, index)
331
+ : item.onPress
332
+ ? item.onPress()
333
+ : props.onPress
334
+ ? props.onPress(item, index)
335
+ : null;
336
+ }}
273
337
  />
274
338
  )}
275
339
  <SvgText
@@ -283,7 +347,18 @@ export const PieChart = (props: propTypes) => {
283
347
  (item.shiftTextX || 0) -
284
348
  (item.textSize || textSize) / 1.8
285
349
  }
286
- y={y + (item.shiftTextY || 0)}>
350
+ y={y + (item.shiftTextY || 0)}
351
+ onPress={() => {
352
+ item.onLabelPress
353
+ ? item.onLabelPress()
354
+ : props.onLabelPress
355
+ ? props.onLabelPress(item, index)
356
+ : item.onPress
357
+ ? item.onPress()
358
+ : props.onPress
359
+ ? props.onPress(item, index)
360
+ : null;
361
+ }}>
287
362
  {item.text || (showValuesAsLabels ? item.value + '' : '')}
288
363
  </SvgText>
289
364
  </>
package/src/todos.md CHANGED
@@ -1,6 +1,6 @@
1
1
  ## Feature requests
2
2
 
3
- 1. OnPress function on Pie Chart https://github.com/Abhinandan-Kushwaha/react-native-gifted-charts/issues/111
3
+ None at the moment!
4
4
 
5
5
  ## To-dos in documentation-
6
6