react-native-gifted-charts 1.3.19 → 1.3.20

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.19",
3
+ "version": "1.3.20",
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": [
@@ -5,6 +5,7 @@ import {
5
5
  LayoutAnimation,
6
6
  Platform,
7
7
  UIManager,
8
+ Text,
8
9
  } from 'react-native';
9
10
  import LinearGradient from 'react-native-linear-gradient';
10
11
  import Svg, {Defs, Rect} from 'react-native-svg';
@@ -35,6 +36,9 @@ type propTypes = {
35
36
  capRadius?: number;
36
37
  horizontal: boolean;
37
38
  intactTopLabel: boolean;
39
+ showValuesAsTopLabel: boolean;
40
+ topLabelContainerStyle?: any;
41
+ topLabelTextStyle?: any;
38
42
  barBorderRadius?: number;
39
43
  barBorderTopLeftRadius?: number;
40
44
  barBorderTopRightRadius?: number;
@@ -67,6 +71,10 @@ const Animated2DWithGradient = (props: propTypes) => {
67
71
  barBorderTopRightRadius,
68
72
  barBorderBottomLeftRadius,
69
73
  barBorderBottomRightRadius,
74
+ intactTopLabel,
75
+ showValuesAsTopLabel,
76
+ topLabelContainerStyle,
77
+ topLabelTextStyle,
70
78
  } = props;
71
79
  const [height, setHeight] = useState(noAnimation ? props.height : 0.2);
72
80
  const [initialRender, setInitialRender] = useState(
@@ -299,7 +307,7 @@ const Animated2DWithGradient = (props: propTypes) => {
299
307
  </Svg>
300
308
  )}
301
309
  </View>
302
- {item.topLabelComponent && (
310
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
303
311
  <View
304
312
  style={[
305
313
  {
@@ -308,8 +316,7 @@ const Animated2DWithGradient = (props: propTypes) => {
308
316
  height: item.barWidth || barWidth || 30,
309
317
  width: item.barWidth || barWidth || 30,
310
318
  justifyContent:
311
- (props.horizontal && !props.intactTopLabel) ||
312
- item.value < 0
319
+ (props.horizontal && !intactTopLabel) || item.value < 0
313
320
  ? 'center'
314
321
  : 'flex-end',
315
322
  alignItems: 'center',
@@ -317,10 +324,14 @@ const Animated2DWithGradient = (props: propTypes) => {
317
324
  },
318
325
  item.value < 0 && {transform: [{rotate: '180deg'}]},
319
326
  props.horizontal &&
320
- !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
321
- item.topLabelContainerStyle,
327
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
328
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
322
329
  ]}>
323
- {item.topLabelComponent()}
330
+ {showValuesAsTopLabel ? (
331
+ <Text style={topLabelTextStyle}>{item.value}</Text>
332
+ ) : (
333
+ item.topLabelComponent?.()
334
+ )}
324
335
  </View>
325
336
  )}
326
337
  </View>
@@ -22,6 +22,7 @@ type Props = {
22
22
  topColor?: ColorValue;
23
23
  topLabelComponent?: Component;
24
24
  topLabelContainerStyle?: any;
25
+ topLabelTextStyle?: any;
25
26
  opacity?: number;
26
27
  side?: String;
27
28
  labelTextStyle?: any;
@@ -59,6 +60,7 @@ type Props = {
59
60
  horizontal: boolean;
60
61
  rtl: boolean;
61
62
  intactTopLabel: boolean;
63
+ showValuesAsTopLabel?: boolean;
62
64
  barBorderRadius?: number;
63
65
  barBorderTopLeftRadius?: number;
64
66
  barBorderTopRightRadius?: number;
@@ -121,6 +123,10 @@ const RenderBars = (props: Props) => {
121
123
  xAxisThickness,
122
124
  horizontal,
123
125
  rtl,
126
+ intactTopLabel,
127
+ showValuesAsTopLabel,
128
+ topLabelContainerStyle,
129
+ topLabelTextStyle,
124
130
  pointerConfig,
125
131
  } = props;
126
132
 
@@ -315,7 +321,7 @@ const RenderBars = (props: Props) => {
315
321
  patternIdFromProps={props.patternId}
316
322
  />
317
323
  )}
318
- {item.topLabelComponent && (
324
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
319
325
  <View
320
326
  style={[
321
327
  {
@@ -324,17 +330,21 @@ const RenderBars = (props: Props) => {
324
330
  height: item.barWidth || props.barWidth || 30,
325
331
  width: item.barWidth || props.barWidth || 30,
326
332
  justifyContent:
327
- (horizontal && !props.intactTopLabel) || item.value < 0
333
+ (horizontal && !intactTopLabel) || item.value < 0
328
334
  ? 'center'
329
335
  : 'flex-end',
330
336
  alignItems: 'center',
331
337
  },
332
338
  item.value < 0 && {transform: [{rotate: '180deg'}]},
333
339
  horizontal &&
334
- !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
335
- item.topLabelContainerStyle,
340
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
341
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
336
342
  ]}>
337
- {item.topLabelComponent()}
343
+ {showValuesAsTopLabel ? (
344
+ <Text style={topLabelTextStyle}>{item.value}</Text>
345
+ ) : (
346
+ item.topLabelComponent?.()
347
+ )}
338
348
  </View>
339
349
  )}
340
350
  </>
@@ -395,6 +405,41 @@ const RenderBars = (props: Props) => {
395
405
  (pointerConfig && pointerConfig.barTouchable !== true);
396
406
 
397
407
  const barContent = () => {
408
+ const animated2DWithGradient = noGradient => (
409
+ <Animated2DWithGradient
410
+ barBackgroundPattern={props.barBackgroundPattern}
411
+ patternId={props.patternId}
412
+ barWidth={props.barWidth || 30}
413
+ barStyle={barStyle}
414
+ item={item}
415
+ opacity={opacity}
416
+ animationDuration={animationDuration || 800}
417
+ roundedBottom={props.roundedBottom || false}
418
+ roundedTop={props.roundedTop || false}
419
+ noGradient={noGradient}
420
+ gradientColor={noGradient ? undefined : props.gradientColor}
421
+ frontColor={props.frontColor || 'black'}
422
+ containerHeight={containerHeight}
423
+ maxValue={maxValue}
424
+ height={barHeight}
425
+ minHeight={minHeight ?? 0}
426
+ barMarginBottom={barMarginBottom}
427
+ cappedBars={props.cappedBars}
428
+ capThickness={props.capThickness}
429
+ capColor={props.capColor}
430
+ capRadius={props.capRadius}
431
+ horizontal={horizontal}
432
+ intactTopLabel={intactTopLabel}
433
+ showValuesAsTopLabel={!!showValuesAsTopLabel}
434
+ topLabelContainerStyle={topLabelContainerStyle}
435
+ topLabelTextStyle={topLabelTextStyle}
436
+ barBorderRadius={props.barBorderRadius || 0}
437
+ barBorderTopLeftRadius={barBorderTopLeftRadius}
438
+ barBorderTopRightRadius={barBorderTopRightRadius}
439
+ barBorderBottomLeftRadius={barBorderBottomLeftRadius}
440
+ barBorderBottomRightRadius={barBorderBottomRightRadius}
441
+ />
442
+ );
398
443
  return (
399
444
  <>
400
445
  {(props.showXAxisIndices || item.showXAxisIndex) && (
@@ -420,7 +465,6 @@ const RenderBars = (props: Props) => {
420
465
  item.barBackgroundPattern || props.barBackgroundPattern
421
466
  }
422
467
  patternId={item.patternId || props.patternId}
423
- topLabelContainerStyle={item.topLabelContainerStyle}
424
468
  width={item.barWidth || props.barWidth || 30}
425
469
  barStyle={barStyle}
426
470
  item={item}
@@ -435,11 +479,13 @@ const RenderBars = (props: Props) => {
435
479
  topColor={item.topColor || props.topColor || ''}
436
480
  showGradient={item.showGradient || props.showGradient || false}
437
481
  gradientColor={item.gradientColor || props.gradientColor}
438
- topLabelComponent={item.topLabelComponent}
439
482
  opacity={opacity || 1}
440
483
  animationDuration={animationDuration || 800}
441
484
  height={barHeight}
442
- intactTopLabel={props.intactTopLabel}
485
+ intactTopLabel={intactTopLabel}
486
+ showValuesAsTopLabel={!!showValuesAsTopLabel}
487
+ topLabelContainerStyle={topLabelContainerStyle}
488
+ topLabelTextStyle={topLabelTextStyle}
443
489
  horizontal={horizontal}
444
490
  />
445
491
  ) : (
@@ -450,7 +496,6 @@ const RenderBars = (props: Props) => {
450
496
  patternId={item.patternId || props.patternId}
451
497
  style={{}}
452
498
  color={''}
453
- topLabelContainerStyle={item.topLabelContainerStyle}
454
499
  width={item.barWidth || props.barWidth || 30}
455
500
  sideWidth={
456
501
  item.sideWidth ||
@@ -465,111 +510,26 @@ const RenderBars = (props: Props) => {
465
510
  topColor={item.topColor || props.topColor || ''}
466
511
  showGradient={item.showGradient || props.showGradient || false}
467
512
  gradientColor={item.gradientColor || props.gradientColor}
468
- topLabelComponent={item.topLabelComponent || null}
469
513
  opacity={opacity || 1}
470
514
  horizontal={horizontal}
471
- intactTopLabel={props.intactTopLabel}
515
+ intactTopLabel={intactTopLabel}
516
+ showValuesAsTopLabel={!!showValuesAsTopLabel}
517
+ topLabelContainerStyle={topLabelContainerStyle}
518
+ topLabelTextStyle={topLabelTextStyle}
472
519
  height={barHeight}
473
520
  value={item.value}
474
521
  />
475
522
  )
476
523
  ) : item.showGradient || props.showGradient ? (
477
524
  isAnimated ? (
478
- <Animated2DWithGradient
479
- barBackgroundPattern={props.barBackgroundPattern}
480
- patternId={props.patternId}
481
- barWidth={props.barWidth || 30}
482
- barStyle={barStyle}
483
- item={item}
484
- opacity={opacity}
485
- animationDuration={animationDuration || 800}
486
- roundedBottom={props.roundedBottom || false}
487
- roundedTop={props.roundedTop || false}
488
- gradientColor={props.gradientColor}
489
- frontColor={props.frontColor || 'black'}
490
- containerHeight={containerHeight}
491
- maxValue={maxValue}
492
- height={barHeight}
493
- minHeight={minHeight ?? 0}
494
- barMarginBottom={barMarginBottom}
495
- cappedBars={props.cappedBars}
496
- capThickness={props.capThickness}
497
- capColor={props.capColor}
498
- capRadius={props.capRadius}
499
- horizontal={horizontal}
500
- intactTopLabel={props.intactTopLabel}
501
- barBorderRadius={props.barBorderRadius || 0}
502
- barBorderTopLeftRadius={barBorderTopLeftRadius}
503
- barBorderTopRightRadius={barBorderTopRightRadius}
504
- barBorderBottomLeftRadius={barBorderBottomLeftRadius}
505
- barBorderBottomRightRadius={barBorderBottomRightRadius}
506
- />
525
+ animated2DWithGradient(false)
507
526
  ) : (
508
527
  static2DWithGradient(item)
509
528
  )
510
529
  ) : isAnimated ? (
511
- <Animated2DWithGradient
512
- barBackgroundPattern={props.barBackgroundPattern}
513
- patternId={props.patternId}
514
- barWidth={props.barWidth || 30}
515
- barStyle={barStyle}
516
- item={item}
517
- opacity={opacity}
518
- animationDuration={animationDuration || 800}
519
- roundedBottom={props.roundedBottom || false}
520
- roundedTop={props.roundedTop || false}
521
- gradientColor={props.gradientColor}
522
- noGradient
523
- frontColor={props.frontColor || 'black'}
524
- containerHeight={containerHeight}
525
- maxValue={maxValue}
526
- height={barHeight}
527
- minHeight={minHeight || 0}
528
- barMarginBottom={barMarginBottom}
529
- cappedBars={props.cappedBars}
530
- capThickness={props.capThickness}
531
- capColor={props.capColor}
532
- capRadius={props.capRadius}
533
- horizontal={horizontal}
534
- intactTopLabel={props.intactTopLabel}
535
- barBorderRadius={props.barBorderRadius || 0}
536
- barBorderTopLeftRadius={barBorderTopLeftRadius}
537
- barBorderTopRightRadius={barBorderTopRightRadius}
538
- barBorderBottomLeftRadius={barBorderBottomLeftRadius}
539
- barBorderBottomRightRadius={barBorderBottomRightRadius}
540
- />
530
+ animated2DWithGradient(true)
541
531
  ) : (
542
- <Animated2DWithGradient
543
- barBackgroundPattern={props.barBackgroundPattern}
544
- patternId={props.patternId}
545
- barWidth={props.barWidth || 30}
546
- barStyle={barStyle}
547
- item={item}
548
- opacity={opacity}
549
- animationDuration={animationDuration || 800}
550
- roundedBottom={props.roundedBottom || false}
551
- roundedTop={props.roundedTop || false}
552
- gradientColor={props.gradientColor}
553
- noGradient
554
- noAnimation
555
- frontColor={props.frontColor || 'black'}
556
- containerHeight={containerHeight}
557
- maxValue={maxValue}
558
- height={barHeight}
559
- minHeight={minHeight || 0}
560
- barMarginBottom={barMarginBottom}
561
- cappedBars={props.cappedBars}
562
- capThickness={props.capThickness}
563
- capColor={props.capColor}
564
- capRadius={props.capRadius}
565
- horizontal={horizontal}
566
- intactTopLabel={props.intactTopLabel}
567
- barBorderRadius={props.barBorderRadius || 0}
568
- barBorderTopLeftRadius={barBorderTopLeftRadius}
569
- barBorderTopRightRadius={barBorderTopRightRadius}
570
- barBorderBottomLeftRadius={barBorderBottomLeftRadius}
571
- barBorderBottomRightRadius={barBorderBottomRightRadius}
572
- />
532
+ animated2DWithGradient(true)
573
533
  )}
574
534
  {isAnimated
575
535
  ? renderAnimatedLabel(label, labelTextStyle, item.value)
@@ -303,6 +303,7 @@ export const BarChart = (props: BarChartPropsType) => {
303
303
  pointerConfig?.persistPointer ?? defaultPointerConfig.persistPointer;
304
304
  const hidePointer1 =
305
305
  pointerConfig?.hidePointer1 ?? defaultPointerConfig.hidePointer1;
306
+ const pointerEvents = pointerConfig?.pointerEvents;
306
307
 
307
308
  const disableScroll =
308
309
  props.disableScroll ||
@@ -612,6 +613,7 @@ export const BarChart = (props: BarChartPropsType) => {
612
613
  pointerConfig,
613
614
  pointerLabelComponent,
614
615
  scrollX: 0,
616
+ pointerEvents,
615
617
  });
616
618
  };
617
619
 
@@ -712,7 +714,7 @@ export const BarChart = (props: BarChartPropsType) => {
712
714
  {renderChart()}
713
715
  {pointerX > 0 ? (
714
716
  <View
715
- pointerEvents="none"
717
+ pointerEvents={pointerEvents ?? 'none'}
716
718
  style={{
717
719
  position: 'absolute',
718
720
  height:
@@ -755,6 +757,9 @@ export const BarChart = (props: BarChartPropsType) => {
755
757
  horizontal: horizontal,
756
758
  rtl: rtl,
757
759
  intactTopLabel: intactTopLabel,
760
+ showValuesAsTopLabel: props.showValuesAsTopLabel,
761
+ topLabelContainerStyle: props.topLabelContainerStyle,
762
+ topLabelTextStyle: props.topLabelTextStyle,
758
763
  barBorderRadius: props.barBorderRadius,
759
764
  barBorderTopLeftRadius: props.barBorderTopLeftRadius,
760
765
  barBorderTopRightRadius: props.barBorderTopRightRadius,
@@ -126,6 +126,9 @@ export type BarChartPropsType = {
126
126
  yAxisAtTop?: boolean;
127
127
 
128
128
  intactTopLabel?: boolean;
129
+ showValuesAsTopLabel?: boolean;
130
+ topLabelContainerStyle?: any;
131
+ topLabelTextStyle?: any;
129
132
 
130
133
  horizSections?: Array<sectionType>;
131
134
  barBorderRadius?: number;
@@ -6,6 +6,7 @@ import {
6
6
  LayoutAnimation,
7
7
  Platform,
8
8
  UIManager,
9
+ Text,
9
10
  } from 'react-native';
10
11
  import LinearGradient from 'react-native-linear-gradient';
11
12
  import Svg, {Defs, Rect} from 'react-native-svg';
@@ -32,12 +33,13 @@ type animatedBarPropTypes = {
32
33
  frontColor: ColorValue;
33
34
  sideColor: ColorValue;
34
35
  topColor: ColorValue;
35
- topLabelComponent: any;
36
- topLabelContainerStyle: any;
37
36
  opacity: number;
38
37
  side: String;
39
38
  horizontal: boolean;
40
39
  intactTopLabel: boolean;
40
+ showValuesAsTopLabel: boolean;
41
+ topLabelContainerStyle?: any;
42
+ topLabelTextStyle?: any;
41
43
  barBackgroundPattern?: Function;
42
44
  patternId?: String;
43
45
  barStyle?: object;
@@ -107,9 +109,18 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
107
109
  setTimeout(() => elevate(), Platform.OS == 'ios' ? 10 : 100);
108
110
  };
109
111
 
110
- const {item, width, sideWidth, barStyle} = props;
111
-
112
- const {barBackgroundPattern, patternId} = props;
112
+ const {
113
+ item,
114
+ width,
115
+ sideWidth,
116
+ barStyle,
117
+ barBackgroundPattern,
118
+ patternId,
119
+ intactTopLabel,
120
+ showValuesAsTopLabel,
121
+ topLabelContainerStyle,
122
+ topLabelTextStyle,
123
+ } = props;
113
124
 
114
125
  const showGradient = props.showGradient || false;
115
126
  const gradientColor = props.gradientColor || 'white';
@@ -118,9 +129,6 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
118
129
  const sideColor = props.sideColor || '#cc2233';
119
130
  const topColor = props.topColor || '#ff4433';
120
131
 
121
- const topLabelComponent = props.topLabelComponent || null;
122
- const topLabelContainerStyle = props.topLabelContainerStyle || {};
123
-
124
132
  const opacity = props.opacity || 1;
125
133
 
126
134
  return (
@@ -194,16 +202,17 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
194
202
  ) : null}
195
203
 
196
204
  <View
197
- style={[{
198
- width: width,
199
- height: height, //animatedHeight
200
- backgroundColor: frontColor,
201
- borderLeftWidth: StyleSheet.hairlineWidth,
202
- borderTopWidth: StyleSheet.hairlineWidth,
203
- borderColor: 'white',
204
- opacity: opacity,
205
- },
206
- item.barStyle || barStyle
205
+ style={[
206
+ {
207
+ width: width,
208
+ height: height, //animatedHeight
209
+ backgroundColor: frontColor,
210
+ borderLeftWidth: StyleSheet.hairlineWidth,
211
+ borderTopWidth: StyleSheet.hairlineWidth,
212
+ borderColor: 'white',
213
+ opacity: opacity,
214
+ },
215
+ item.barStyle || barStyle,
207
216
  ]}>
208
217
  {showGradient && (
209
218
  <LinearGradient
@@ -230,7 +239,7 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
230
239
 
231
240
  {/******************* Top Label *****************/}
232
241
 
233
- {topLabelComponent && (
242
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
234
243
  <View
235
244
  style={[
236
245
  {
@@ -243,11 +252,15 @@ const AnimatedBar = (props: animatedBarPropTypes) => {
243
252
  opacity: opacity,
244
253
  },
245
254
  props.horizontal &&
246
- !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
255
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
247
256
  props.side === 'right' && {transform: [{rotateY: '180deg'}]},
248
- topLabelContainerStyle,
257
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
249
258
  ]}>
250
- {topLabelComponent()}
259
+ {showValuesAsTopLabel ? (
260
+ <Text style={topLabelTextStyle}>{item.value}</Text>
261
+ ) : (
262
+ item.topLabelComponent?.()
263
+ )}
251
264
  </View>
252
265
  )}
253
266
 
@@ -103,6 +103,9 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
103
103
  const xAxisLabelsVerticalShift =
104
104
  axesAndRulesProps.xAxisLabelsVerticalShift ??
105
105
  AxesAndRulesDefaults.xAxisLabelsVerticalShift;
106
+ const xAxisLabelsHeight =
107
+ axesAndRulesProps.xAxisLabelsHeight;
108
+ const xAxisTextNumberOfLines = axesAndRulesProps.xAxisTextNumberOfLines;
106
109
  const dashWidth =
107
110
  axesAndRulesProps.dashWidth ?? AxesAndRulesDefaults.dashWidth;
108
111
  const dashGap = axesAndRulesProps.dashGap ?? AxesAndRulesDefaults.dashGap;
@@ -334,7 +337,7 @@ const BarAndLineChartsWrapper = (props: BarAndLineChartsWrapperTypes) => {
334
337
  stepHeight / 2 +
335
338
  xAxisLabelsVerticalShift +
336
339
  50,
337
- marginBottom: 15, //This is to not let the Things that should be rendered below the chart overlap with it
340
+ marginBottom: (xAxisLabelsHeight ?? xAxisTextNumberOfLines*18) - 50, //This is to not let the Things that should be rendered below the chart overlap with it
338
341
  };
339
342
 
340
343
  return (
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import {View, StyleSheet, ColorValue} from 'react-native';
2
+ import {View, StyleSheet, ColorValue, Text} from 'react-native';
3
3
  import LinearGradient from 'react-native-linear-gradient';
4
4
  import Svg, {Defs, Rect} from 'react-native-svg';
5
5
  import {styles} from './styles';
@@ -15,12 +15,13 @@ type PropTypes = {
15
15
  frontColor: ColorValue;
16
16
  sideColor: ColorValue;
17
17
  topColor: ColorValue;
18
- topLabelComponent: any;
19
- topLabelContainerStyle: any;
20
18
  opacity: number;
21
19
  side: String;
22
20
  horizontal: boolean;
23
21
  intactTopLabel: boolean;
22
+ showValuesAsTopLabel: boolean;
23
+ topLabelContainerStyle?: any;
24
+ topLabelTextStyle?: any;
24
25
  value: number;
25
26
  barBackgroundPattern?: Function;
26
27
  patternId?: String;
@@ -80,8 +81,12 @@ const ThreeDBar = (props: PropTypes) => {
80
81
  const sideColor = props.sideColor || '#cc2233';
81
82
  const topColor = props.topColor || '#ff4433';
82
83
 
83
- const topLabelComponent = props.topLabelComponent || null;
84
- const topLabelContainerStyle = props.topLabelContainerStyle || {};
84
+ const {
85
+ intactTopLabel,
86
+ showValuesAsTopLabel,
87
+ topLabelContainerStyle,
88
+ topLabelTextStyle,
89
+ } = props;
85
90
 
86
91
  const opacity = props.opacity || 1;
87
92
  return (
@@ -184,7 +189,7 @@ const ThreeDBar = (props: PropTypes) => {
184
189
 
185
190
  {/******************* Top Label *****************/}
186
191
 
187
- {topLabelComponent && (
192
+ {(item.topLabelComponent || showValuesAsTopLabel) && (
188
193
  <View
189
194
  style={[
190
195
  {
@@ -197,13 +202,17 @@ const ThreeDBar = (props: PropTypes) => {
197
202
  },
198
203
  value < 0 && {transform: [{rotate: '180deg'}]},
199
204
  props.horizontal &&
200
- !props.intactTopLabel && {transform: [{rotate: '270deg'}]},
205
+ !intactTopLabel && {transform: [{rotate: '270deg'}]},
201
206
  props.side === 'right'
202
207
  ? {right: (-1 * width) / 4}
203
208
  : {left: (-1 * width) / 4},
204
- topLabelContainerStyle,
209
+ topLabelContainerStyle ?? item.topLabelContainerStyle,
205
210
  ]}>
206
- {topLabelComponent()}
211
+ {showValuesAsTopLabel ? (
212
+ <Text style={topLabelTextStyle}>{item.value}</Text>
213
+ ) : (
214
+ item.topLabelComponent?.()
215
+ )}
207
216
  </View>
208
217
  )}
209
218
 
@@ -27,6 +27,7 @@ export const StripAndLabel = props => {
27
27
  pointerLabelComponent,
28
28
  secondaryPointerItem,
29
29
  scrollX,
30
+ pointerEvents,
30
31
  } = props;
31
32
  let left = 0,
32
33
  top = 0;
@@ -125,7 +126,7 @@ export const StripAndLabel = props => {
125
126
 
126
127
  {pointerLabelComponent && (
127
128
  <View
128
- pointerEvents="none"
129
+ pointerEvents={pointerEvents ?? 'none'}
129
130
  style={[
130
131
  {
131
132
  position: 'absolute',
@@ -45,6 +45,7 @@ import {
45
45
  chartTypes,
46
46
  defaultArrowConfig,
47
47
  defaultPointerConfig,
48
+ loc,
48
49
  screenWidth,
49
50
  } from '../utils/constants';
50
51
  import BarAndLineChartsWrapper from '../Components/BarAndLineChartsWrapper';
@@ -258,17 +259,14 @@ export const LineChart = (props: LineChartPropsType) => {
258
259
  const startIndex5 = props.startIndex5 || 0;
259
260
  const endIndex5 = props.endIndex5 ?? data5.length - 1;
260
261
 
261
- const startIndicesFromSet = dataSet?.map(set => set.startIndex ?? 0);
262
- const endIndicesFromSet = dataSet?.map(
263
- set => set.endIndex ?? set.data.length - 1,
264
- );
265
-
266
262
  const lineSegments = props.lineSegments;
267
263
  const lineSegments2 = props.lineSegments2;
268
264
  const lineSegments3 = props.lineSegments3;
269
265
  const lineSegments4 = props.lineSegments4;
270
266
  const lineSegments5 = props.lineSegments5;
271
267
 
268
+ const highlightedRange = props.highlightedRange;
269
+
272
270
  if (!initialData) {
273
271
  initialData = data0 ?? [...data];
274
272
  animations = initialData.map(item => new Animated.Value(item.value));
@@ -885,13 +883,57 @@ export const LineChart = (props: LineChartPropsType) => {
885
883
  getNextPoint(data, i, around)
886
884
  );
887
885
  };
888
- const getSegmentPath = (data, i, lineSegment) =>
889
- 'L' +
890
- getX(i) +
891
- ' ' +
892
- getY(data[i].value) +
893
- ' ' +
894
- getSegmentString(lineSegment, i);
886
+
887
+ const getRegionPrefix = (currentPointRegion, nextPointRegion) =>
888
+ currentPointRegion === loc.OUT && nextPointRegion === loc.IN
889
+ ? 'RangeEnter' + JSON.stringify(highlightedRange)
890
+ : 'RangeExit';
891
+
892
+ const getSegmentPath = (data, i, lineSegment, startIndex, endIndex) => {
893
+ let path =
894
+ 'L' +
895
+ getX(i) +
896
+ ' ' +
897
+ getY(data[i].value) +
898
+ ' ' +
899
+ getSegmentString(lineSegment, i);
900
+
901
+ if (highlightedRange && i !== endIndex) {
902
+ const {from, to} = highlightedRange;
903
+ console.log('from..',from);
904
+ console.log('to..',to);
905
+ const currentPointRegion =
906
+ data[i].value >= from && data[i].value <= to ? loc.IN : loc.OUT;
907
+ const nextPointRegion =
908
+ data[i + 1].value >= from && data[i + 1].value <= to ? loc.IN : loc.OUT;
909
+ console.log('currentPointRegion..',currentPointRegion);
910
+ console.log('nextPointRegion..',nextPointRegion);
911
+ if (currentPointRegion !== nextPointRegion) {
912
+ const x1 = getX(i),
913
+ y1 = getY(data[i].value),
914
+ x2 = getX(i + 1),
915
+ y2 = getY(data[i + 1].value);
916
+
917
+ if (x2 - x1 === 0) {
918
+ } else {
919
+ const y = data[i + 1].value > data[i].value ? getY(from) : getY(to);
920
+ const m = (y2 - y1) / (x2 - x1);
921
+ const x = (y - y1) / m + x1;
922
+
923
+ path +=
924
+ getRegionPrefix(currentPointRegion, nextPointRegion) +
925
+ 'L' +
926
+ x +
927
+ ' ' +
928
+ y +
929
+ ' ';
930
+ }
931
+ } else {
932
+ }
933
+ }
934
+ console.log('path..',path);
935
+ return path;
936
+ };
895
937
 
896
938
  useEffect(() => {
897
939
  if (dataSet) {
@@ -907,8 +949,8 @@ export const LineChart = (props: LineChartPropsType) => {
907
949
  const pArray: Array<Array<number>> = [];
908
950
  for (let i = 0; i < setData.length; i++) {
909
951
  if (
910
- i >= (startIndicesFromSet?.[index] ?? 0) &&
911
- i <= (endIndicesFromSet?.[index] ?? -1)
952
+ i >= (set.startIndex ?? 0) &&
953
+ i <= (set.endIndex ?? set.data.length - 1)
912
954
  ) {
913
955
  pArray.push([getX(i), getY(setData[i].value)]);
914
956
  }
@@ -953,13 +995,19 @@ export const LineChart = (props: LineChartPropsType) => {
953
995
  let pp = '';
954
996
  for (let i = 0; i < setData.length; i++) {
955
997
  if (
956
- i >= (startIndicesFromSet?.[index] ?? 0) &&
957
- i <= (endIndicesFromSet?.[index] ?? -1)
998
+ i >= (set.startIndex ?? 0) &&
999
+ i <= (set.endIndex ?? set.data.length - 1)
958
1000
  ) {
959
1001
  if (set.stepChart || stepChart) {
960
1002
  pp += getStepPath(setData, i);
961
1003
  } else {
962
- pp += getSegmentPath(setData, i, set.lineSegments);
1004
+ pp += getSegmentPath(
1005
+ setData,
1006
+ i,
1007
+ set.lineSegments,
1008
+ set.startIndex ?? 0,
1009
+ set.endIndex ?? set.data.length - 1,
1010
+ );
963
1011
  }
964
1012
  }
965
1013
  }
@@ -1018,7 +1066,13 @@ export const LineChart = (props: LineChartPropsType) => {
1018
1066
  if (stepChart || stepChart1) {
1019
1067
  pp += getStepPath(data, i);
1020
1068
  } else {
1021
- pp += getSegmentPath(data, i, lineSegments);
1069
+ pp += getSegmentPath(
1070
+ data,
1071
+ i,
1072
+ lineSegments,
1073
+ startIndex1,
1074
+ endIndex1,
1075
+ );
1022
1076
  }
1023
1077
  }
1024
1078
  if (data2.length && i >= startIndex2 && i <= endIndex2) {
@@ -1026,28 +1080,52 @@ export const LineChart = (props: LineChartPropsType) => {
1026
1080
  pp2 += getStepPath(data2, i);
1027
1081
  (' ');
1028
1082
  } else {
1029
- pp2 += getSegmentPath(data2, i, lineSegments2);
1083
+ pp2 += getSegmentPath(
1084
+ data2,
1085
+ i,
1086
+ lineSegments2,
1087
+ startIndex2,
1088
+ endIndex2,
1089
+ );
1030
1090
  }
1031
1091
  }
1032
1092
  if (data3.length && i >= startIndex3 && i <= endIndex3) {
1033
1093
  if (stepChart || stepChart3) {
1034
1094
  pp3 += getStepPath(data3, i);
1035
1095
  } else {
1036
- pp3 += getSegmentPath(data2, i, lineSegments2);
1096
+ pp3 += getSegmentPath(
1097
+ data2,
1098
+ i,
1099
+ lineSegments2,
1100
+ startIndex3,
1101
+ endIndex3,
1102
+ );
1037
1103
  }
1038
1104
  }
1039
1105
  if (data4.length && i >= startIndex4 && i <= endIndex4) {
1040
1106
  if (stepChart || stepChart4) {
1041
1107
  pp4 += getStepPath(data4, i);
1042
1108
  } else {
1043
- pp4 += getSegmentPath(data4, i, lineSegments4);
1109
+ pp4 += getSegmentPath(
1110
+ data4,
1111
+ i,
1112
+ lineSegments4,
1113
+ startIndex4,
1114
+ endIndex4,
1115
+ );
1044
1116
  }
1045
1117
  }
1046
1118
  if (data5.length && i >= startIndex5 && i <= endIndex5) {
1047
1119
  if (stepChart || stepChart5) {
1048
1120
  pp5 += getStepPath(data5, i);
1049
1121
  } else {
1050
- pp5 += getSegmentPath(data5, i, lineSegments5);
1122
+ pp5 += getSegmentPath(
1123
+ data5,
1124
+ i,
1125
+ lineSegments5,
1126
+ startIndex5,
1127
+ endIndex4,
1128
+ );
1051
1129
  }
1052
1130
  }
1053
1131
  }
@@ -1691,6 +1769,7 @@ export const LineChart = (props: LineChartPropsType) => {
1691
1769
  const hideSecondaryPointer =
1692
1770
  pointerConfig?.hideSecondaryPointer ??
1693
1771
  defaultPointerConfig.hideSecondaryPointer;
1772
+ const pointerEvents = pointerConfig?.pointerEvents;
1694
1773
  const disableScroll =
1695
1774
  props.disableScroll ||
1696
1775
  (pointerConfig
@@ -2263,6 +2342,7 @@ export const LineChart = (props: LineChartPropsType) => {
2263
2342
  pointerLabelComponent,
2264
2343
  secondaryPointerItem,
2265
2344
  scrollX,
2345
+ pointerEvents,
2266
2346
  });
2267
2347
  };
2268
2348
 
@@ -2330,7 +2410,7 @@ export const LineChart = (props: LineChartPropsType) => {
2330
2410
  if (!points) return null;
2331
2411
  const isCurved = points.includes('C');
2332
2412
  let ar: [any] = [{}];
2333
- if (points.includes('segmentStart')) {
2413
+ if (points.includes('RangeStart')) {
2334
2414
  ar = getSegmentedPathObjects(
2335
2415
  points,
2336
2416
  color,
@@ -2338,6 +2418,19 @@ export const LineChart = (props: LineChartPropsType) => {
2338
2418
  thickness,
2339
2419
  strokeDashArray,
2340
2420
  isCurved,
2421
+ 'RangeEnter',
2422
+ 'RangeExit',
2423
+ );
2424
+ } else if (points.includes('segmentStart')) {
2425
+ ar = getSegmentedPathObjects(
2426
+ points,
2427
+ color,
2428
+ currentLineThickness,
2429
+ thickness,
2430
+ strokeDashArray,
2431
+ isCurved,
2432
+ 'segmentStart',
2433
+ 'segmentEnd',
2341
2434
  );
2342
2435
  }
2343
2436
  const lineSvgPropsOuter: LineSvgProps = {
@@ -2358,10 +2451,12 @@ export const LineChart = (props: LineChartPropsType) => {
2358
2451
  ) {
2359
2452
  lineSvgPropsOuter.strokeDasharray = strokeDashArray;
2360
2453
  }
2454
+
2455
+ return null;
2361
2456
  return (
2362
2457
  <Svg>
2363
2458
  {lineGradient && getLineGradientComponent()}
2364
- {points.includes('segmentStart') ? (
2459
+ {points.includes('segmentStart') || points.includes('RangeStart') ? (
2365
2460
  ar.map((item, index) => {
2366
2461
  const lineSvgProps: LineSvgProps = {
2367
2462
  d: item.d,
@@ -3387,14 +3482,15 @@ export const LineChart = (props: LineChartPropsType) => {
3387
3482
  : null}
3388
3483
  {pointerX > 0 ? (
3389
3484
  <View
3390
- pointerEvents="none"
3485
+ pointerEvents={pointerEvents ?? 'none'}
3391
3486
  style={{
3392
3487
  position: 'absolute',
3393
3488
  height:
3394
3489
  extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight,
3395
3490
  bottom: 58 + labelsExtraHeight + xAxisLabelsVerticalShift,
3396
- width: totalWidth,
3491
+ // width: totalWidth,
3397
3492
  zIndex: 20,
3493
+ backgroundColor: 'orange',
3398
3494
  }}>
3399
3495
  {!stripOverPointer && renderStripAndLabel()}
3400
3496
  {dataSet ? (
@@ -4,6 +4,7 @@ import {
4
4
  CurveType,
5
5
  DataSet,
6
6
  EdgePosition,
7
+ HighlightedRange,
7
8
  LineSegment,
8
9
  Pointer,
9
10
  RuleType,
@@ -310,6 +311,7 @@ export type LineChartPropsType = {
310
311
  lineSegments3?: Array<LineSegment>;
311
312
  lineSegments4?: Array<LineSegment>;
312
313
  lineSegments5?: Array<LineSegment>;
314
+ highlightedRange?: HighlightedRange;
313
315
  };
314
316
 
315
317
  type referenceConfigType = {
@@ -24,12 +24,18 @@ export enum yAxisSides {
24
24
  RIGHT,
25
25
  }
26
26
 
27
+ export enum loc {
28
+ IN,
29
+ OUT
30
+ }
31
+
27
32
  export const ruleTypes: RuleTypes = {
28
33
  SOLID: 'solid',
29
34
  DASHED: 'dashed',
30
35
  DOTTED: 'dotted',
31
36
  };
32
37
 
38
+
33
39
  export const AxesAndRulesDefaults = {
34
40
  yAxisSide: yAxisSides.LEFT,
35
41
  yAxisColor: 'black',
@@ -239,6 +245,7 @@ export const defaultPointerConfig = {
239
245
  hidePointer5: false,
240
246
  hideSecondaryPointer: false,
241
247
  barTouchable: false,
248
+ // pointerEvents: PointerEvent
242
249
  };
243
250
 
244
251
  // Pie chart specific
@@ -168,7 +168,7 @@ export const bezierCommand = (
168
168
 
169
169
  export const getSegmentString = (lineSegment, index) => {
170
170
  const segment = lineSegment?.find(segment => segment.startIndex === index);
171
- return segment ? 'segmentStart' + JSON.stringify(segment) + 'segmentEnd' : '';
171
+ return segment ? startDelimeter + JSON.stringify(segment) + endDelimeter : '';
172
172
  };
173
173
 
174
174
  export const getCurvePathWithSegments = (
@@ -183,7 +183,7 @@ export const getCurvePathWithSegments = (
183
183
  newPath +=
184
184
  (pathArray[i].startsWith('M') ? '' : 'C') +
185
185
  pathArray[i] +
186
- (segment ? 'segmentStart' + JSON.stringify(segment) + 'segmentEnd' : '');
186
+ (segment ? startDelimeter + JSON.stringify(segment) + endDelimeter : '');
187
187
  }
188
188
  return newPath;
189
189
  };
@@ -200,6 +200,17 @@ export const getPreviousSegmentsLastPoint = (isCurved, previousSegment) => {
200
200
  );
201
201
  };
202
202
 
203
+ // export const getRegionPathObjects = (
204
+ // points,
205
+ // color,
206
+ // currentLineThickness,
207
+ // thickness,
208
+ // strokeDashArray,
209
+ // isCurved,
210
+ // ) => {
211
+
212
+ // }
213
+
203
214
  export const getSegmentedPathObjects = (
204
215
  points,
205
216
  color,
@@ -207,15 +218,17 @@ export const getSegmentedPathObjects = (
207
218
  thickness,
208
219
  strokeDashArray,
209
220
  isCurved,
221
+ startDelimeter,
222
+ endDelimeter,
210
223
  ) => {
211
224
  const ar: [any] = [{}];
212
225
  let tempStr = points;
213
226
 
214
- if (!points.startsWith('segmentStart')) {
227
+ if (!points.startsWith(startDelimeter)) {
215
228
  /********************** line upto first segment *****************/
216
229
 
217
230
  const lineSvgProps: LineProperties = {
218
- d: points.substring(0, points.indexOf('segmentStart')),
231
+ d: points.substring(0, points.indexOf(startDelimeter)),
219
232
  color,
220
233
  strokeWidth: currentLineThickness || thickness,
221
234
  };
@@ -225,20 +238,20 @@ export const getSegmentedPathObjects = (
225
238
  ar.push(lineSvgProps);
226
239
  }
227
240
 
228
- while (tempStr.includes('segmentStart')) {
229
- const startDelimeterIndex = tempStr.indexOf('segmentStart');
230
- const endDelimeterIndex = tempStr.indexOf('segmentEnd');
241
+ while (tempStr.includes(startDelimeter)) {
242
+ const startDelimeterIndex = tempStr.indexOf(startDelimeter);
243
+ const endDelimeterIndex = tempStr.indexOf(endDelimeter);
231
244
 
232
245
  const segmentConfig = JSON.parse(
233
246
  tempStr.substring(
234
- startDelimeterIndex + 'segmentStart'.length,
247
+ startDelimeterIndex + startDelimeter.length,
235
248
  endDelimeterIndex,
236
249
  ),
237
250
  );
238
251
 
239
252
  const {startIndex, endIndex} = segmentConfig;
240
253
  const segmentLength = endIndex - startIndex;
241
- let segment = tempStr.substring(endDelimeterIndex + 'segmentEnd'.length);
254
+ let segment = tempStr.substring(endDelimeterIndex + endDelimeter.length);
242
255
  let c = 0,
243
256
  s = 0,
244
257
  i;
@@ -270,9 +283,9 @@ export const getSegmentedPathObjects = (
270
283
  }
271
284
  ar.push(lineSvgProps);
272
285
 
273
- tempStr = tempStr.substring(endDelimeterIndex + 'segmentEnd'.length + i);
286
+ tempStr = tempStr.substring(endDelimeterIndex + endDelimeter.length + i);
274
287
 
275
- const nextDelimiterIndex = tempStr.indexOf('segmentStart');
288
+ const nextDelimiterIndex = tempStr.indexOf(startDelimeter);
276
289
  const stringUptoNextSegment = tempStr.substring(0, nextDelimiterIndex);
277
290
 
278
291
  /********************** line upto the next segment *****************/
@@ -318,6 +331,7 @@ export const getSegmentedPathObjects = (
318
331
  }
319
332
 
320
333
  ar.shift();
334
+ console.log('ar...',ar)
321
335
  return ar;
322
336
  };
323
337
 
@@ -380,6 +394,7 @@ export const getAxesAndRulesProps = (
380
394
  xAxisColor: props.xAxisColor,
381
395
  xAxisLength: props.xAxisLength,
382
396
  xAxisType: props.xAxisType,
397
+ xAxisTextNumberOfLines: props.xAxisTextNumberOfLines ?? 1,
383
398
  xAxisLabelsHeight: props.xAxisLabelsHeight,
384
399
  xAxisLabelsVerticalShift: props.xAxisLabelsVerticalShift,
385
400
  dashWidth: props.dashWidth,
@@ -29,6 +29,8 @@ export type RulesConfig = {
29
29
  dashGap?: number;
30
30
  };
31
31
 
32
+ export type PointerEvents = "box-none" | "none" | "box-only" | "auto";
33
+
32
34
  export type secondaryYAxisType = {
33
35
  noOfSections?: number;
34
36
  maxValue?: number;
@@ -274,8 +276,17 @@ export type Pointer = {
274
276
  hideSecondaryPointer?: boolean;
275
277
  strokeDashArray?: Array<number>;
276
278
  barTouchable?: boolean;
279
+ pointerEvents?: PointerEvents;
277
280
  };
278
281
 
282
+ export type HighlightedRange = {
283
+ from: number;
284
+ to: number;
285
+ color?: string | ColorValue;
286
+ thickness?: number;
287
+ strokeDashArray?: Array<number>;
288
+ }
289
+
279
290
  export type LineSegment = {
280
291
  startIndex: number;
281
292
  endIndex: number;