gifted-charts-core 0.0.37 → 0.0.38

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": "gifted-charts-core",
3
- "version": "0.0.37",
3
+ "version": "0.0.38",
4
4
  "description": "Mathematical and logical utilities used by react-gifted-charts and react-native-gifted-charts",
5
5
  "main": "./src/index.js",
6
6
  "files": [
@@ -26,7 +26,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
26
  import { getBarFrontColor, getBarWidth } from '../utils';
27
27
  export var getPropsForAnimated2DWithGradient = function (props) {
28
28
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
29
- var barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, barBorderRadius = props.barBorderRadius, item = props.item, barBorderTopLeftRadius = props.barBorderTopLeftRadius, barBorderTopRightRadius = props.barBorderTopRightRadius, barBorderBottomLeftRadius = props.barBorderBottomLeftRadius, barBorderBottomRightRadius = props.barBorderBottomRightRadius, barWidth = props.barWidth, barInnerComponent = props.barInnerComponent, barStyle = props.barStyle, index = props.index, opacity = props.opacity, barHeight = props.barHeight, intactTopLabel = props.intactTopLabel, showValuesAsTopLabel = props.showValuesAsTopLabel, topLabelContainerStyle = props.topLabelContainerStyle, topLabelTextStyle = props.topLabelTextStyle, roundedBottom = props.roundedBottom, cappedBars = props.cappedBars, capRadius = props.capRadius, roundedTop = props.roundedTop, barBackgroundPattern = props.barBackgroundPattern, patternId = props.patternId, frontColor = props.frontColor, showGradient = props.showGradient, gradientColor = props.gradientColor, selectedIndex = props.selectedIndex, focusBarOnPress = props.focusBarOnPress, focusedBarConfig = props.focusedBarConfig, isThreeD = props.isThreeD;
29
+ var barBorderWidth = props.barBorderWidth, barBorderColor = props.barBorderColor, barBorderRadius = props.barBorderRadius, item = props.item, barBorderTopLeftRadius = props.barBorderTopLeftRadius, barBorderTopRightRadius = props.barBorderTopRightRadius, barBorderBottomLeftRadius = props.barBorderBottomLeftRadius, barBorderBottomRightRadius = props.barBorderBottomRightRadius, barWidth = props.barWidth, barInnerComponent = props.barInnerComponent, barStyle = props.barStyle, index = props.index, opacity = props.opacity, barHeight = props.barHeight, intactTopLabel = props.intactTopLabel, showValuesAsTopLabel = props.showValuesAsTopLabel, topLabelContainerStyle = props.topLabelContainerStyle, topLabelTextStyle = props.topLabelTextStyle, roundedBottom = props.roundedBottom, cappedBars = props.cappedBars, capRadius = props.capRadius, roundedTop = props.roundedTop, barBackgroundPattern = props.barBackgroundPattern, patternId = props.patternId, frontColor = props.frontColor, showGradient = props.showGradient, gradientColor = props.gradientColor, selectedIndex = props.selectedIndex, focusBarOnPress = props.focusBarOnPress, focusedBarConfig = props.focusedBarConfig, isThreeD = props.isThreeD, yAxisOffset = props.yAxisOffset;
30
30
  var isFocused = (focusBarOnPress !== null && focusBarOnPress !== void 0 ? focusBarOnPress : false) && selectedIndex === index;
31
31
  var itemOrPropsBarBorderRadius = (_b = (_a = item.barBorderRadius) !== null && _a !== void 0 ? _a : barBorderRadius) !== null && _b !== void 0 ? _b : 0;
32
32
  var localBarBorderRadius = (isFocused !== null && isFocused !== void 0 ? isFocused : false)
@@ -93,9 +93,10 @@ export var getPropsForAnimated2DWithGradient = function (props) {
93
93
  : localOpacity,
94
94
  height: barHeight,
95
95
  intactTopLabel: intactTopLabel,
96
- showValuesAsTopLabel: (showValuesAsTopLabel !== null && showValuesAsTopLabel !== void 0 ? showValuesAsTopLabel : false),
96
+ showValuesAsTopLabel: showValuesAsTopLabel !== null && showValuesAsTopLabel !== void 0 ? showValuesAsTopLabel : false,
97
97
  topLabelContainerStyle: topLabelContainerStyle,
98
- topLabelTextStyle: topLabelTextStyle
98
+ topLabelTextStyle: topLabelTextStyle,
99
+ yAxisOffset: yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0
99
100
  };
100
101
  return {
101
102
  commonStyleForBar: commonStyleForBar,
@@ -67,7 +67,8 @@ export const getPropsForAnimated2DWithGradient = (
67
67
  selectedIndex,
68
68
  focusBarOnPress,
69
69
  focusedBarConfig,
70
- isThreeD
70
+ isThreeD,
71
+ yAxisOffset
71
72
  } = props
72
73
 
73
74
  const isFocused = (focusBarOnPress ?? false) && selectedIndex === index
@@ -120,7 +121,11 @@ export const getPropsForAnimated2DWithGradient = (
120
121
  }
121
122
  ]
122
123
 
123
- if (roundedBottom ?? (isFocused && focusedBarConfig?.roundedBottom) ?? false) {
124
+ if (
125
+ roundedBottom ??
126
+ (isFocused && focusedBarConfig?.roundedBottom) ??
127
+ false
128
+ ) {
124
129
  commonStyleForBar.push({
125
130
  borderBottomLeftRadius: localBarWidth / 2,
126
131
  borderBottomRightRadius: localBarWidth / 2
@@ -170,9 +175,10 @@ export const getPropsForAnimated2DWithGradient = (
170
175
  : localOpacity,
171
176
  height: barHeight,
172
177
  intactTopLabel,
173
- showValuesAsTopLabel: (showValuesAsTopLabel ?? false),
178
+ showValuesAsTopLabel: showValuesAsTopLabel ?? false,
174
179
  topLabelContainerStyle,
175
- topLabelTextStyle
180
+ topLabelTextStyle,
181
+ yAxisOffset: yAxisOffset ?? 0
176
182
  }
177
183
 
178
184
  return {
@@ -172,6 +172,7 @@ export declare const useBarChart: (props: extendedBarChartPropsType) => {
172
172
  labelTextStyle: any;
173
173
  pointerConfig: import("../utils/types").Pointer | undefined;
174
174
  yAxisExtraHeightAtTop: number;
175
+ yAxisOffset: number;
175
176
  };
176
177
  barAndLineChartsWrapperProps: BarAndLineChartsWrapperTypes;
177
178
  yAxisExtraHeightAtTop: number;
@@ -30,7 +30,7 @@ import { getArrowPoints, getAxesAndRulesProps, getExtendedContainerHeightWithPad
30
30
  import { AxesAndRulesDefaults, BarDefaults, chartTypes, defaultLineConfig, defaultPointerConfig } from '../utils/constants';
31
31
  export var useBarChart = function (props) {
32
32
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46;
33
- var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue;
33
+ var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset;
34
34
  var _47 = __read(useState(''), 2), points = _47[0], setPoints = _47[1];
35
35
  var _48 = __read(useState(''), 2), points2 = _48[0], setPoints2 = _48[1];
36
36
  var _49 = __read(useState(''), 2), arrowPoints = _49[0], setArrowPoints = _49[1];
@@ -52,29 +52,29 @@ export var useBarChart = function (props) {
52
52
  if (!props.data) {
53
53
  return [];
54
54
  }
55
- if (props.yAxisOffset) {
55
+ if (yAxisOffset) {
56
56
  return props.data.map(function (item) {
57
- var _a, _b;
58
- item.value = ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - ((_b = props.yAxisOffset) !== null && _b !== void 0 ? _b : 0);
57
+ var _a;
58
+ item.value = ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - (yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0);
59
59
  return item;
60
60
  });
61
61
  }
62
62
  return props.data;
63
- }, [props.yAxisOffset, props.data]);
63
+ }, [yAxisOffset, props.data]);
64
64
  var secondaryData = getSecondaryDataWithOffsetIncluded(props.secondaryData, props.secondaryYAxis);
65
65
  var lineData = useMemo(function () {
66
66
  var _a;
67
67
  if (!props.lineData) {
68
68
  return (_a = props.stackData) !== null && _a !== void 0 ? _a : data;
69
69
  }
70
- if (props.yAxisOffset) {
70
+ if (yAxisOffset) {
71
71
  return props.lineData.map(function (item) {
72
- var _a, _b;
73
- return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - ((_b = props.yAxisOffset) !== null && _b !== void 0 ? _b : 0) }));
72
+ var _a;
73
+ return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - (yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0) }));
74
74
  });
75
75
  }
76
76
  return props.lineData;
77
- }, [props.yAxisOffset, props.lineData, data, props.stackData]);
77
+ }, [yAxisOffset, props.lineData, data, props.stackData]);
78
78
  var lineData2 = props.lineData2;
79
79
  var lineBehindBars = (_m = props.lineBehindBars) !== null && _m !== void 0 ? _m : BarDefaults.lineBehindBars;
80
80
  defaultLineConfig.initialSpacing = initialSpacing;
@@ -437,7 +437,8 @@ export var useBarChart = function (props) {
437
437
  label: (_f = item.label) !== null && _f !== void 0 ? _f : (((_g = props.xAxisLabelTexts) === null || _g === void 0 ? void 0 : _g[index]) ? props.xAxisLabelTexts[index] : ''),
438
438
  labelTextStyle: (_h = item.labelTextStyle) !== null && _h !== void 0 ? _h : props.xAxisLabelTextStyle,
439
439
  pointerConfig: pointerConfig,
440
- yAxisExtraHeightAtTop: yAxisExtraHeightAtTop
440
+ yAxisExtraHeightAtTop: yAxisExtraHeightAtTop,
441
+ yAxisOffset: yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0
441
442
  };
442
443
  };
443
444
  var barAndLineChartsWrapperProps = {
@@ -488,7 +489,7 @@ export var useBarChart = function (props) {
488
489
  showFractionalValues: showFractionalValues,
489
490
  axesAndRulesProps: getAxesAndRulesProps(props, stepValue, secondaryMaxValue),
490
491
  yAxisLabelTexts: props.yAxisLabelTexts,
491
- yAxisOffset: props.yAxisOffset,
492
+ yAxisOffset: yAxisOffset,
492
493
  rotateYAxisTexts: props.rotateYAxisTexts,
493
494
  hideAxesAndRules: props.hideAxesAndRules,
494
495
  showXAxisIndices: showXAxisIndices,
@@ -40,7 +40,7 @@ export interface extendedBarChartPropsType extends BarChartPropsType {
40
40
  }
41
41
 
42
42
  export const useBarChart = (props: extendedBarChartPropsType) => {
43
- const { heightValue, widthValue, opacValue } = props
43
+ const { heightValue, widthValue, opacValue, yAxisOffset } = props
44
44
  const [points, setPoints] = useState('')
45
45
  const [points2, setPoints2] = useState('')
46
46
  const [arrowPoints, setArrowPoints] = useState('')
@@ -68,14 +68,14 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
68
68
  if (!props.data) {
69
69
  return []
70
70
  }
71
- if (props.yAxisOffset) {
71
+ if (yAxisOffset) {
72
72
  return props.data.map((item) => {
73
- item.value = (item.value ?? 0) - (props.yAxisOffset ?? 0)
73
+ item.value = (item.value ?? 0) - (yAxisOffset ?? 0)
74
74
  return item
75
75
  })
76
76
  }
77
77
  return props.data
78
- }, [props.yAxisOffset, props.data])
78
+ }, [yAxisOffset, props.data])
79
79
 
80
80
  const secondaryData = getSecondaryDataWithOffsetIncluded(
81
81
  props.secondaryData,
@@ -86,14 +86,14 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
86
86
  if (!props.lineData) {
87
87
  return props.stackData ?? data
88
88
  }
89
- if (props.yAxisOffset) {
89
+ if (yAxisOffset) {
90
90
  return props.lineData.map((item) => ({
91
91
  ...item,
92
- value: (item.value ?? 0) - (props.yAxisOffset ?? 0)
92
+ value: (item.value ?? 0) - (yAxisOffset ?? 0)
93
93
  }))
94
94
  }
95
95
  return props.lineData
96
- }, [props.yAxisOffset, props.lineData, data, props.stackData])
96
+ }, [yAxisOffset, props.lineData, data, props.stackData])
97
97
 
98
98
  const lineData2 = props.lineData2
99
99
 
@@ -655,7 +655,8 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
655
655
  (props.xAxisLabelTexts?.[index] ? props.xAxisLabelTexts[index] : ''),
656
656
  labelTextStyle: item.labelTextStyle ?? props.xAxisLabelTextStyle,
657
657
  pointerConfig,
658
- yAxisExtraHeightAtTop
658
+ yAxisExtraHeightAtTop,
659
+ yAxisOffset: yAxisOffset ?? 0
659
660
  }
660
661
  }
661
662
 
@@ -714,7 +715,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
714
715
  ),
715
716
 
716
717
  yAxisLabelTexts: props.yAxisLabelTexts,
717
- yAxisOffset: props.yAxisOffset,
718
+ yAxisOffset: yAxisOffset,
718
719
  rotateYAxisTexts: props.rotateYAxisTexts,
719
720
  hideAxesAndRules: props.hideAxesAndRules,
720
721
 
@@ -111,6 +111,7 @@ export interface StackedBarChartPropsType {
111
111
  animationDuration?: number;
112
112
  pointerConfig?: Pointer;
113
113
  showValuesAsTopLabel?: boolean;
114
+ yAxisOffset: number;
114
115
  }
115
116
  export interface BarChartPropsType {
116
117
  width?: number;
@@ -435,6 +436,7 @@ export interface Animated2DWithGradientPropsType {
435
436
  barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode;
436
437
  commonStyleForBar?: ViewStyle[];
437
438
  barStyleWithBackground?: ViewStyle[];
439
+ yAxisOffset: number;
438
440
  }
439
441
  export interface RenderBarsPropsType {
440
442
  style?: any;
@@ -515,6 +517,7 @@ export interface RenderBarsPropsType {
515
517
  pointerConfig?: Pointer;
516
518
  focusBarOnPress?: boolean;
517
519
  noOfSectionsBelowXAxis?: number;
520
+ yAxisOffset: number;
518
521
  }
519
522
  export interface trianglePropTypes {
520
523
  style: any;
@@ -566,5 +569,6 @@ export interface CommonPropsFor2Dand3DbarsType {
566
569
  showValuesAsTopLabel: boolean;
567
570
  topLabelContainerStyle: any;
568
571
  topLabelTextStyle: any;
572
+ yAxisOffset: number;
569
573
  }
570
574
  export {};
@@ -1,4 +1,8 @@
1
- import { type ColorValue, type GestureResponderEvent, type ViewStyle } from 'react-native'
1
+ import {
2
+ type ColorValue,
3
+ type GestureResponderEvent,
4
+ type ViewStyle
5
+ } from 'react-native'
2
6
  import { type yAxisSides } from '../utils/constants'
3
7
  import {
4
8
  type CurveType,
@@ -125,6 +129,7 @@ export interface StackedBarChartPropsType {
125
129
  animationDuration?: number
126
130
  pointerConfig?: Pointer
127
131
  showValuesAsTopLabel?: boolean
132
+ yAxisOffset: number
128
133
  }
129
134
 
130
135
  export interface BarChartPropsType {
@@ -471,6 +476,7 @@ export interface Animated2DWithGradientPropsType {
471
476
  barInnerComponent?: (item?: barDataItem, index?: number) => ReactNode
472
477
  commonStyleForBar?: ViewStyle[]
473
478
  barStyleWithBackground?: ViewStyle[]
479
+ yAxisOffset: number
474
480
  }
475
481
 
476
482
  export interface RenderBarsPropsType {
@@ -532,7 +538,10 @@ export interface RenderBarsPropsType {
532
538
  barBorderTopRightRadius?: number
533
539
  barBorderBottomLeftRadius?: number
534
540
  barBorderBottomRightRadius?: number
535
- barInnerComponent?: (item?: barDataItem | stackDataItem, index?: number) => ReactNode
541
+ barInnerComponent?: (
542
+ item?: barDataItem | stackDataItem,
543
+ index?: number
544
+ ) => ReactNode
536
545
  autoShiftLabels?: boolean
537
546
  barBackgroundPattern?: () => ReactNode
538
547
  patternId?: string
@@ -554,6 +563,7 @@ export interface RenderBarsPropsType {
554
563
  pointerConfig?: Pointer
555
564
  focusBarOnPress?: boolean
556
565
  noOfSectionsBelowXAxis?: number
566
+ yAxisOffset: number
557
567
  }
558
568
 
559
569
  export interface trianglePropTypes {
@@ -609,4 +619,5 @@ export interface CommonPropsFor2Dand3DbarsType {
609
619
  showValuesAsTopLabel: boolean
610
620
  topLabelContainerStyle: any
611
621
  topLabelTextStyle: any
622
+ yAxisOffset: number
612
623
  }