react-native-gifted-charts 1.3.13 → 1.3.15

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.3.13",
3
+ "version": "1.3.15",
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": [
@@ -341,57 +341,47 @@ const RenderBars = (props: Props) => {
341
341
  (data[i].barWidth || props.barWidth || 30);
342
342
  }
343
343
 
344
- return (
345
- <>
346
- <TouchableOpacity
347
- disabled={
348
- item.disablePress ||
349
- props.disablePress ||
350
- (pointerConfig && pointerConfig.barTouchable !== false)
344
+ const barWrapperStyle = [
345
+ {
346
+ // overflow: 'visible',
347
+ marginBottom: 60 + barMarginBottom,
348
+ width: item.barWidth || props.barWidth || 30,
349
+ height: barHeight,
350
+ marginRight: spacing,
351
+ },
352
+ item.value < 0
353
+ ? {
354
+ transform: [
355
+ {
356
+ translateY:
357
+ (Math.abs(item.value) * (containerHeight || 200)) /
358
+ (maxValue || 200),
359
+ },
360
+ {rotateZ: '180deg'},
361
+ ],
351
362
  }
352
- activeOpacity={props.activeOpacity || 0.2}
353
- onPress={() => {
354
- if (renderTooltip) {
355
- setSelectedIndex(index);
356
- }
357
- item.onPress
358
- ? item.onPress()
359
- : props.onPress
360
- ? props.onPress(item, index)
361
- : null;
362
- }}
363
- style={[
364
- {
365
- // overflow: 'visible',
366
- marginBottom: 60 + barMarginBottom,
367
- width: item.barWidth || props.barWidth || 30,
368
- height: barHeight,
369
- marginRight: spacing,
370
- },
371
- item.value < 0
372
- ? {
373
- transform: [
374
- {
375
- translateY:
376
- (Math.abs(item.value) * (containerHeight || 200)) /
377
- (maxValue || 200),
378
- },
379
- {rotateZ: '180deg'},
380
- ],
381
- }
382
- : pointerConfig
383
- ? {
384
- transform: [
385
- {
386
- translateY: (containerHeight || 200) - (barHeight - 10),
387
- },
388
- ],
389
- }
390
- : null,
391
- // !isThreeD && !item.showGradient && !props.showGradient &&
392
- // { backgroundColor: item.frontColor || props.frontColor || 'black' },
393
- side !== 'right' && {zIndex: data.length - index},
394
- ]}>
363
+ : pointerConfig
364
+ ? {
365
+ transform: [
366
+ {
367
+ translateY: (containerHeight || 200) - (barHeight - 10),
368
+ },
369
+ ],
370
+ }
371
+ : null,
372
+ // !isThreeD && !item.showGradient && !props.showGradient &&
373
+ // { backgroundColor: item.frontColor || props.frontColor || 'black' },
374
+ side !== 'right' && {zIndex: data.length - index},
375
+ ];
376
+
377
+ const pressDisabled =
378
+ item.disablePress ||
379
+ props.disablePress ||
380
+ (pointerConfig && pointerConfig.barTouchable !== true);
381
+
382
+ const barContent = () => {
383
+ return (
384
+ <>
395
385
  {(props.showXAxisIndices || item.showXAxisIndex) && (
396
386
  <View
397
387
  style={{
@@ -569,7 +559,33 @@ const RenderBars = (props: Props) => {
569
559
  {isAnimated
570
560
  ? renderAnimatedLabel(label, labelTextStyle, item.value)
571
561
  : renderLabel(label, labelTextStyle, item.value)}
572
- </TouchableOpacity>
562
+ </>
563
+ );
564
+ };
565
+
566
+ return (
567
+ <>
568
+ {pressDisabled ? (
569
+ <View pointerEvents="none" style={barWrapperStyle}>
570
+ {barContent()}
571
+ </View>
572
+ ) : (
573
+ <TouchableOpacity
574
+ activeOpacity={props.activeOpacity || 0.2}
575
+ onPress={() => {
576
+ if (renderTooltip) {
577
+ setSelectedIndex(index);
578
+ }
579
+ item.onPress
580
+ ? item.onPress()
581
+ : props.onPress
582
+ ? props.onPress(item, index)
583
+ : null;
584
+ }}
585
+ style={barWrapperStyle}>
586
+ {barContent()}
587
+ </TouchableOpacity>
588
+ )}
573
589
  {renderTooltip && selectedIndex === index && (
574
590
  <View
575
591
  style={{
@@ -565,6 +565,7 @@ export const BarChart = (props: BarChartPropsType) => {
565
565
  pointerStripColor,
566
566
  pointerConfig,
567
567
  pointerLabelComponent,
568
+ scrollX: 0,
568
569
  });
569
570
  };
570
571
 
@@ -26,6 +26,7 @@ export const StripAndLabel = props => {
26
26
  pointerConfig,
27
27
  pointerLabelComponent,
28
28
  secondaryPointerItem,
29
+ scrollX,
29
30
  } = props;
30
31
  let left = 0,
31
32
  top = 0;
@@ -1450,6 +1450,13 @@ export const LineChart = (props: LineChartPropsType) => {
1450
1450
  const containerHeightIncludingBelowXAxis =
1451
1451
  extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
1452
1452
 
1453
+ const lineGradient = props.lineGradient ?? LineDefaults.lineGradient;
1454
+ const lineGradientDirection = props.lineGradientDirection ?? 'vertical';
1455
+ const lineGradientStartColor =
1456
+ props.lineGradientStartColor ?? LineDefaults.lineGradientStartColor;
1457
+ const lineGradientEndColor =
1458
+ props.lineGradientEndColor ?? LineDefaults.lineGradientEndColor;
1459
+
1453
1460
  const renderLabel = (
1454
1461
  index: number,
1455
1462
  label: String,
@@ -1637,7 +1644,7 @@ export const LineChart = (props: LineChartPropsType) => {
1637
1644
  const currentStripWidth = item.stripWidth ?? stripWidth;
1638
1645
  const currentStripOpacity = item.stripOpacity ?? stripOpacity;
1639
1646
  const currentStripColor = item.stripColor || stripColor;
1640
- const position= I18nManager.isRTL ? "right" :"left";
1647
+ const position = I18nManager.isRTL ? 'right' : 'left';
1641
1648
 
1642
1649
  return (
1643
1650
  <Fragment key={index}>
@@ -1698,8 +1705,9 @@ export const LineChart = (props: LineChartPropsType) => {
1698
1705
  height: dataPointsHeight,
1699
1706
  width: dataPointsWidth,
1700
1707
  top: getYOrSecondaryY(item.value),
1701
- [position]: initialSpacing - dataPointsWidth + spacing * index,
1702
- transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
1708
+ [position]:
1709
+ initialSpacing - dataPointsWidth + spacing * index,
1710
+ transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
1703
1711
  },
1704
1712
  ]}>
1705
1713
  {customDataPoint()}
@@ -1977,9 +1985,55 @@ export const LineChart = (props: LineChartPropsType) => {
1977
1985
  pointerConfig,
1978
1986
  pointerLabelComponent,
1979
1987
  secondaryPointerItem,
1988
+ scrollX,
1980
1989
  });
1981
1990
  };
1982
1991
 
1992
+ const getLineGradientComponent = () => {
1993
+ return props.lineGradientComponent ? (
1994
+ props.lineGradientComponent()
1995
+ ) : (
1996
+ <LinearGradient
1997
+ id="lineGradient"
1998
+ x1="0"
1999
+ y1="0"
2000
+ x2={lineGradientDirection === 'horizontal' ? '1' : '0'}
2001
+ y2={lineGradientDirection === 'vertical' ? '1' : '0'}>
2002
+ <Stop offset="0" stopColor={lineGradientStartColor} />
2003
+ <Stop offset="1" stopColor={lineGradientEndColor} />
2004
+ </LinearGradient>
2005
+ );
2006
+ };
2007
+
2008
+ const getAreaGradientComponent = (
2009
+ startFillColor: string,
2010
+ endFillColor: string,
2011
+ startOpacity: number,
2012
+ endOpacity: number,
2013
+ ) => {
2014
+ return props.areaGradientComponent ? (
2015
+ props.areaGradientComponent()
2016
+ ) : (
2017
+ <LinearGradient
2018
+ id="Gradient"
2019
+ x1="0"
2020
+ y1="0"
2021
+ x2={gradientDirection === 'horizontal' ? '1' : '0'}
2022
+ y2={gradientDirection === 'vertical' ? '1' : '0'}>
2023
+ <Stop
2024
+ offset="0"
2025
+ stopColor={startFillColor}
2026
+ stopOpacity={startOpacity.toString()}
2027
+ />
2028
+ <Stop
2029
+ offset="1"
2030
+ stopColor={endFillColor}
2031
+ stopOpacity={endOpacity.toString()}
2032
+ />
2033
+ </LinearGradient>
2034
+ );
2035
+ };
2036
+
1983
2037
  const lineSvgComponent = (
1984
2038
  points: any,
1985
2039
  currentLineThickness: number | undefined,
@@ -1998,6 +2052,7 @@ export const LineChart = (props: LineChartPropsType) => {
1998
2052
  ) => {
1999
2053
  return (
2000
2054
  <Svg>
2055
+ {lineGradient && getLineGradientComponent()}
2001
2056
  {strokeDashArray &&
2002
2057
  strokeDashArray.length === 2 &&
2003
2058
  typeof strokeDashArray[0] === 'number' &&
@@ -2005,7 +2060,13 @@ export const LineChart = (props: LineChartPropsType) => {
2005
2060
  <Path
2006
2061
  d={points}
2007
2062
  fill="none"
2008
- stroke={color}
2063
+ stroke={
2064
+ lineGradient
2065
+ ? props.lineGradientId
2066
+ ? `url(#${props.lineGradientId})`
2067
+ : `url(#lineGradient)`
2068
+ : color
2069
+ }
2009
2070
  strokeWidth={currentLineThickness || thickness}
2010
2071
  strokeDasharray={strokeDashArray}
2011
2072
  />
@@ -2013,36 +2074,34 @@ export const LineChart = (props: LineChartPropsType) => {
2013
2074
  <Path
2014
2075
  d={points}
2015
2076
  fill="none"
2016
- stroke={color}
2077
+ stroke={
2078
+ lineGradient
2079
+ ? props.lineGradientId
2080
+ ? `url(#${props.lineGradientId})`
2081
+ : `url(#lineGradient)`
2082
+ : color
2083
+ }
2017
2084
  strokeWidth={currentLineThickness || thickness}
2018
2085
  />
2019
2086
  )}
2020
2087
 
2021
2088
  {/*********************** For Area Chart ************/}
2022
2089
 
2023
- {atLeastOneAreaChart && (
2024
- <LinearGradient
2025
- id="Gradient"
2026
- x1="0"
2027
- y1="0"
2028
- x2={gradientDirection === 'horizontal' ? '1' : '0'}
2029
- y2={gradientDirection === 'vertical' ? '1' : '0'}>
2030
- <Stop
2031
- offset="0"
2032
- stopColor={startFillColor}
2033
- stopOpacity={startOpacity.toString()}
2034
- />
2035
- <Stop
2036
- offset="1"
2037
- stopColor={endFillColor}
2038
- stopOpacity={endOpacity.toString()}
2039
- />
2040
- </LinearGradient>
2041
- )}
2090
+ {atLeastOneAreaChart &&
2091
+ getAreaGradientComponent(
2092
+ startFillColor,
2093
+ endFillColor,
2094
+ startOpacity,
2095
+ endOpacity,
2096
+ )}
2042
2097
  {atLeastOneAreaChart && (
2043
2098
  <Path
2044
2099
  d={fillPoints}
2045
- fill="url(#Gradient)"
2100
+ fill={
2101
+ props.areaGradientId
2102
+ ? `url(#${props.areaGradientId})`
2103
+ : `url(#Gradient)`
2104
+ }
2046
2105
  stroke={'transparent'}
2047
2106
  strokeWidth={currentLineThickness || thickness}
2048
2107
  />
@@ -2408,7 +2467,7 @@ export const LineChart = (props: LineChartPropsType) => {
2408
2467
  (props.overflowBottom ?? dataPointsRadius1),
2409
2468
  width: totalWidth,
2410
2469
  zIndex: zIndex,
2411
- transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
2470
+ transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
2412
2471
  }}>
2413
2472
  {lineSvgComponent(
2414
2473
  points,
@@ -2673,7 +2732,7 @@ export const LineChart = (props: LineChartPropsType) => {
2673
2732
  (props.overflowBottom ?? dataPointsRadius1),
2674
2733
  width: animatedWidth,
2675
2734
  zIndex: zIndex,
2676
- transform: [{ scaleX: I18nManager.isRTL ? -1 : 1 }],
2735
+ transform: [{scaleX: I18nManager.isRTL ? -1 : 1}],
2677
2736
  // backgroundColor: 'wheat',
2678
2737
  }}>
2679
2738
  {lineSvgComponent(
@@ -234,6 +234,9 @@ export type LineChartPropsType = {
234
234
  endOpacity5?: number;
235
235
  gradientDirection?: string;
236
236
 
237
+ areaGradientComponent?: () => any;
238
+ areaGradientId?: string;
239
+
237
240
  textFontSize?: number;
238
241
  textColor?: string;
239
242
  textFontSize1?: number;
@@ -281,6 +284,12 @@ export type LineChartPropsType = {
281
284
  secondaryYAxis?: secondaryYAxisType;
282
285
  secondaryLineConfig?: secondaryLineConfigType;
283
286
  formatYLabel?: (label: string) => string;
287
+ lineGradient?: boolean;
288
+ lineGradientComponent?: () => any;
289
+ lineGradientId?: string;
290
+ lineGradientDirection?: string;
291
+ lineGradientStartColor?: string;
292
+ lineGradientEndColor?: string;
284
293
  };
285
294
 
286
295
  type referenceConfigType = {
@@ -190,6 +190,9 @@ export const LineDefaults = {
190
190
 
191
191
  startFillColor: 'gray',
192
192
  endFillColor: 'white',
193
+ lineGradient: false,
194
+ lineGradientStartColor: 'lightgreen',
195
+ lineGradientEndColor: 'orange',
193
196
  startOpacity: 1,
194
197
  endOpacity: 1,
195
198