gifted-charts-core 0.1.4 → 0.1.6

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.1.4",
3
+ "version": "0.1.6",
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": [
@@ -3,6 +3,7 @@ import { type lineConfigType, type BarChartPropsType, type barDataItem, type sta
3
3
  import { type BarAndLineChartsWrapperTypes, type secondaryYAxisType } from '../utils/types';
4
4
  import { type Animated } from 'react-native';
5
5
  export interface extendedBarChartPropsType extends BarChartPropsType {
6
+ parentWidth: number;
6
7
  heightValue?: Animated.Value;
7
8
  widthValue?: Animated.Value;
8
9
  opacValue?: Animated.Value;
@@ -125,7 +126,7 @@ export declare const useBarChart: (props: extendedBarChartPropsType) => {
125
126
  spacing: any;
126
127
  propSpacing: number;
127
128
  xAxisThickness: number;
128
- barWidth: number | undefined;
129
+ barWidth: number;
129
130
  opacity: number;
130
131
  disablePress: any;
131
132
  rotateLabel: boolean;
@@ -30,24 +30,12 @@ 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, _47;
33
- var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset;
33
+ var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset, adjustToWidth = props.adjustToWidth, parentWidth = props.parentWidth;
34
34
  var _48 = __read(useState(''), 2), points = _48[0], setPoints = _48[1];
35
35
  var _49 = __read(useState(''), 2), points2 = _49[0], setPoints2 = _49[1];
36
36
  var _50 = __read(useState(''), 2), arrowPoints = _50[0], setArrowPoints = _50[1];
37
37
  var _51 = __read(useState(-1), 2), selectedIndex = _51[0], setSelectedIndex = _51[1];
38
38
  var showLine = (_a = props.showLine) !== null && _a !== void 0 ? _a : BarDefaults.showLine;
39
- var spacing = (_b = props.spacing) !== null && _b !== void 0 ? _b : BarDefaults.spacing;
40
- var initialSpacing = (_c = props.initialSpacing) !== null && _c !== void 0 ? _c : spacing;
41
- var endSpacing = (_d = props.endSpacing) !== null && _d !== void 0 ? _d : spacing;
42
- var showFractionalValues = (_e = props.showFractionalValues) !== null && _e !== void 0 ? _e : AxesAndRulesDefaults.showFractionalValues;
43
- var horizontal = (_f = props.horizontal) !== null && _f !== void 0 ? _f : BarDefaults.horizontal;
44
- var rtl = (_g = props.rtl) !== null && _g !== void 0 ? _g : BarDefaults.rtl;
45
- var yAxisAtTop = (_h = props.yAxisAtTop) !== null && _h !== void 0 ? _h : BarDefaults.yAxisAtTop;
46
- var intactTopLabel = (_j = props.intactTopLabel) !== null && _j !== void 0 ? _j : BarDefaults.intactTopLabel;
47
- var heightFromProps = horizontal ? props.width : props.height;
48
- var widthFromProps = horizontal ? props.height : props.width;
49
- var isAnimated = (_k = props.isAnimated) !== null && _k !== void 0 ? _k : BarDefaults.isAnimated;
50
- var animationDuration = (_l = props.animationDuration) !== null && _l !== void 0 ? _l : BarDefaults.animationDuration;
51
39
  var data = useMemo(function () {
52
40
  if (!props.data) {
53
41
  return [];
@@ -60,6 +48,30 @@ export var useBarChart = function (props) {
60
48
  }
61
49
  return props.data;
62
50
  }, [yAxisOffset, props.data]);
51
+ var yAxisLabelWidth = (_b = props.yAxisLabelWidth) !== null && _b !== void 0 ? _b : (props.hideYAxisText
52
+ ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
53
+ : AxesAndRulesDefaults.yAxisLabelWidth);
54
+ var autoComputedSectionWidth = props.initialSpacing !== undefined
55
+ ? (parentWidth - yAxisLabelWidth) / data.length - props.initialSpacing
56
+ : (parentWidth - yAxisLabelWidth) / (data.length + 0.5);
57
+ var autoComputedBarWidth = autoComputedSectionWidth * 0.6;
58
+ var defaultBarWidth = adjustToWidth
59
+ ? autoComputedBarWidth
60
+ : BarDefaults.barWidth;
61
+ var barWidth = (_c = props.barWidth) !== null && _c !== void 0 ? _c : defaultBarWidth;
62
+ var autoComputedSpacing = autoComputedSectionWidth * 0.4;
63
+ var spacing = (_d = props.spacing) !== null && _d !== void 0 ? _d : (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing);
64
+ var initialSpacing = (_e = props.initialSpacing) !== null && _e !== void 0 ? _e : spacing;
65
+ var endSpacing = (_f = props.endSpacing) !== null && _f !== void 0 ? _f : spacing;
66
+ var showFractionalValues = (_g = props.showFractionalValues) !== null && _g !== void 0 ? _g : AxesAndRulesDefaults.showFractionalValues;
67
+ var horizontal = (_h = props.horizontal) !== null && _h !== void 0 ? _h : BarDefaults.horizontal;
68
+ var rtl = (_j = props.rtl) !== null && _j !== void 0 ? _j : BarDefaults.rtl;
69
+ var yAxisAtTop = (_k = props.yAxisAtTop) !== null && _k !== void 0 ? _k : BarDefaults.yAxisAtTop;
70
+ var intactTopLabel = (_l = props.intactTopLabel) !== null && _l !== void 0 ? _l : BarDefaults.intactTopLabel;
71
+ var heightFromProps = horizontal ? props.width : props.height;
72
+ var widthFromProps = horizontal ? props.height : props.width;
73
+ var isAnimated = (_m = props.isAnimated) !== null && _m !== void 0 ? _m : BarDefaults.isAnimated;
74
+ var animationDuration = (_o = props.animationDuration) !== null && _o !== void 0 ? _o : BarDefaults.animationDuration;
63
75
  var secondaryData = getSecondaryDataWithOffsetIncluded(props.secondaryData, props.secondaryYAxis);
64
76
  var lineData = useMemo(function () {
65
77
  var _a;
@@ -75,7 +87,7 @@ export var useBarChart = function (props) {
75
87
  return props.lineData;
76
88
  }, [yAxisOffset, props.lineData, data, props.stackData]);
77
89
  var lineData2 = props.lineData2;
78
- var lineBehindBars = (_m = props.lineBehindBars) !== null && _m !== void 0 ? _m : BarDefaults.lineBehindBars;
90
+ var lineBehindBars = (_p = props.lineBehindBars) !== null && _p !== void 0 ? _p : BarDefaults.lineBehindBars;
79
91
  defaultLineConfig.initialSpacing = initialSpacing;
80
92
  defaultLineConfig.endIndex = lineData.length - 1;
81
93
  defaultLineConfig.animationDuration = animationDuration;
@@ -90,12 +102,12 @@ export var useBarChart = function (props) {
90
102
  ? props.stepHeight * noOfSections
91
103
  : AxesAndRulesDefaults.containerHeight);
92
104
  var horizSections = [{ value: '0' }];
93
- var stepHeight = (_o = props.stepHeight) !== null && _o !== void 0 ? _o : containerHeight / noOfSections;
94
- var labelWidth = (_p = props.labelWidth) !== null && _p !== void 0 ? _p : AxesAndRulesDefaults.labelWidth;
95
- var scrollToEnd = (_q = props.scrollToEnd) !== null && _q !== void 0 ? _q : BarDefaults.scrollToEnd;
96
- var scrollAnimation = (_r = props.scrollAnimation) !== null && _r !== void 0 ? _r : BarDefaults.scrollAnimation;
97
- var scrollEventThrottle = (_s = props.scrollEventThrottle) !== null && _s !== void 0 ? _s : BarDefaults.scrollEventThrottle;
98
- var labelsExtraHeight = (_t = props.labelsExtraHeight) !== null && _t !== void 0 ? _t : AxesAndRulesDefaults.labelsExtraHeight;
105
+ var stepHeight = (_q = props.stepHeight) !== null && _q !== void 0 ? _q : containerHeight / noOfSections;
106
+ var labelWidth = (_r = props.labelWidth) !== null && _r !== void 0 ? _r : AxesAndRulesDefaults.labelWidth;
107
+ var scrollToEnd = (_s = props.scrollToEnd) !== null && _s !== void 0 ? _s : BarDefaults.scrollToEnd;
108
+ var scrollAnimation = (_t = props.scrollAnimation) !== null && _t !== void 0 ? _t : BarDefaults.scrollAnimation;
109
+ var scrollEventThrottle = (_u = props.scrollEventThrottle) !== null && _u !== void 0 ? _u : BarDefaults.scrollEventThrottle;
110
+ var labelsExtraHeight = (_v = props.labelsExtraHeight) !== null && _v !== void 0 ? _v : AxesAndRulesDefaults.labelsExtraHeight;
99
111
  var totalWidth = initialSpacing;
100
112
  var maxItem = 0;
101
113
  var minItem = 0;
@@ -111,7 +123,8 @@ export var useBarChart = function (props) {
111
123
  minItem = stackSumMin;
112
124
  }
113
125
  totalWidth +=
114
- ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) + spacing;
126
+ ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) +
127
+ spacing;
115
128
  });
116
129
  }
117
130
  else {
@@ -124,7 +137,7 @@ export var useBarChart = function (props) {
124
137
  minItem = item.value;
125
138
  }
126
139
  totalWidth +=
127
- ((_b = (_a = item.barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) +
140
+ ((_b = (_a = item.barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) +
128
141
  ((_c = item.spacing) !== null && _c !== void 0 ? _c : spacing);
129
142
  });
130
143
  }
@@ -146,30 +159,26 @@ export var useBarChart = function (props) {
146
159
  var maxValue = getMaxValue(props.maxValue, props.stepValue, noOfSections, maxAndMin.maxItem);
147
160
  var secondaryMaxValue = lineConfig.isSecondary
148
161
  ? typeof props.secondaryYAxis !== 'boolean'
149
- ? (_u = props.secondaryYAxis.maxValue) !== null && _u !== void 0 ? _u : secondaryMaxAndMin.maxItem
162
+ ? (_w = props.secondaryYAxis.maxValue) !== null && _w !== void 0 ? _w : secondaryMaxAndMin.maxItem
150
163
  : secondaryMaxAndMin.maxItem
151
164
  : maxValue;
152
- var mostNegativeValue = (_v = props.mostNegativeValue) !== null && _v !== void 0 ? _v : maxAndMin.minItem;
153
- var stepValue = (_w = props.stepValue) !== null && _w !== void 0 ? _w : maxValue / noOfSections;
154
- var noOfSectionsBelowXAxis = (_x = props.noOfSectionsBelowXAxis) !== null && _x !== void 0 ? _x : -mostNegativeValue / stepValue;
155
- var showScrollIndicator = (_y = props.showScrollIndicator) !== null && _y !== void 0 ? _y : BarDefaults.showScrollIndicator;
156
- var side = (_z = props.side) !== null && _z !== void 0 ? _z : BarDefaults.side;
157
- var rotateLabel = (_0 = props.rotateLabel) !== null && _0 !== void 0 ? _0 : AxesAndRulesDefaults.rotateLabel;
158
- var opacity = (_1 = props.opacity) !== null && _1 !== void 0 ? _1 : BarDefaults.opacity;
159
- var isThreeD = (_2 = props.isThreeD) !== null && _2 !== void 0 ? _2 : BarDefaults.isThreeD;
160
- var showXAxisIndices = (_3 = props.showXAxisIndices) !== null && _3 !== void 0 ? _3 : AxesAndRulesDefaults.showXAxisIndices;
161
- var xAxisIndicesHeight = (_4 = props.xAxisIndicesHeight) !== null && _4 !== void 0 ? _4 : AxesAndRulesDefaults.xAxisIndicesHeight;
162
- var xAxisIndicesWidth = (_5 = props.xAxisIndicesWidth) !== null && _5 !== void 0 ? _5 : AxesAndRulesDefaults.xAxisIndicesWidth;
163
- var xAxisIndicesColor = (_6 = props.xAxisIndicesColor) !== null && _6 !== void 0 ? _6 : AxesAndRulesDefaults.xAxisIndicesColor;
164
- var xAxisThickness = (_7 = props.xAxisThickness) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisThickness;
165
- var xAxisTextNumberOfLines = (_8 = props.xAxisTextNumberOfLines) !== null && _8 !== void 0 ? _8 : AxesAndRulesDefaults.xAxisTextNumberOfLines;
166
- var xAxisLabelsVerticalShift = (_9 = props.xAxisLabelsVerticalShift) !== null && _9 !== void 0 ? _9 : AxesAndRulesDefaults.xAxisLabelsVerticalShift;
165
+ var mostNegativeValue = (_x = props.mostNegativeValue) !== null && _x !== void 0 ? _x : maxAndMin.minItem;
166
+ var stepValue = (_y = props.stepValue) !== null && _y !== void 0 ? _y : maxValue / noOfSections;
167
+ var noOfSectionsBelowXAxis = (_z = props.noOfSectionsBelowXAxis) !== null && _z !== void 0 ? _z : -mostNegativeValue / stepValue;
168
+ var showScrollIndicator = (_0 = props.showScrollIndicator) !== null && _0 !== void 0 ? _0 : BarDefaults.showScrollIndicator;
169
+ var side = (_1 = props.side) !== null && _1 !== void 0 ? _1 : BarDefaults.side;
170
+ var rotateLabel = (_2 = props.rotateLabel) !== null && _2 !== void 0 ? _2 : AxesAndRulesDefaults.rotateLabel;
171
+ var opacity = (_3 = props.opacity) !== null && _3 !== void 0 ? _3 : BarDefaults.opacity;
172
+ var isThreeD = (_4 = props.isThreeD) !== null && _4 !== void 0 ? _4 : BarDefaults.isThreeD;
173
+ var showXAxisIndices = (_5 = props.showXAxisIndices) !== null && _5 !== void 0 ? _5 : AxesAndRulesDefaults.showXAxisIndices;
174
+ var xAxisIndicesHeight = (_6 = props.xAxisIndicesHeight) !== null && _6 !== void 0 ? _6 : AxesAndRulesDefaults.xAxisIndicesHeight;
175
+ var xAxisIndicesWidth = (_7 = props.xAxisIndicesWidth) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisIndicesWidth;
176
+ var xAxisIndicesColor = (_8 = props.xAxisIndicesColor) !== null && _8 !== void 0 ? _8 : AxesAndRulesDefaults.xAxisIndicesColor;
177
+ var xAxisThickness = (_9 = props.xAxisThickness) !== null && _9 !== void 0 ? _9 : AxesAndRulesDefaults.xAxisThickness;
178
+ var xAxisTextNumberOfLines = (_10 = props.xAxisTextNumberOfLines) !== null && _10 !== void 0 ? _10 : AxesAndRulesDefaults.xAxisTextNumberOfLines;
179
+ var xAxisLabelsVerticalShift = (_11 = props.xAxisLabelsVerticalShift) !== null && _11 !== void 0 ? _11 : AxesAndRulesDefaults.xAxisLabelsVerticalShift;
167
180
  var horizontalRulesStyle = props.horizontalRulesStyle;
168
- var yAxisLabelWidth = (_10 = props.yAxisLabelWidth) !== null && _10 !== void 0 ? _10 : (props.hideYAxisText
169
- ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
170
- : AxesAndRulesDefaults.yAxisLabelWidth);
171
- var autoShiftLabels = (_11 = props.autoShiftLabels) !== null && _11 !== void 0 ? _11 : false;
172
- var barWidth = (_12 = props.barWidth) !== null && _12 !== void 0 ? _12 : BarDefaults.barWidth;
181
+ var autoShiftLabels = (_12 = props.autoShiftLabels) !== null && _12 !== void 0 ? _12 : false;
173
182
  var barBorderColor = (_13 = props.barBorderColor) !== null && _13 !== void 0 ? _13 : BarDefaults.barBorderColor;
174
183
  var extendedContainerHeight = getExtendedContainerHeightWithPadding(containerHeight, 0);
175
184
  var containerHeightIncludingBelowXAxis = extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
@@ -232,7 +241,7 @@ export var useBarChart = function (props) {
232
241
  i > ((_f = lineConfig.endIndex) !== null && _f !== void 0 ? _f : 0)) {
233
242
  continue;
234
243
  }
235
- var currentBarWidth = (_j = (_h = (_g = data === null || data === void 0 ? void 0 : data[i]) === null || _g === void 0 ? void 0 : _g.barWidth) !== null && _h !== void 0 ? _h : props.barWidth) !== null && _j !== void 0 ? _j : BarDefaults.barWidth;
244
+ var currentBarWidth = (_j = (_h = (_g = data === null || data === void 0 ? void 0 : data[i]) === null || _g === void 0 ? void 0 : _g.barWidth) !== null && _h !== void 0 ? _h : props.barWidth) !== null && _j !== void 0 ? _j : defaultBarWidth;
236
245
  var currentValue = props.lineData
237
246
  ? props.lineData[i].value
238
247
  : props.stackData
@@ -263,7 +272,7 @@ export var useBarChart = function (props) {
263
272
  i > ((_p = lineConfig.endIndex) !== null && _p !== void 0 ? _p : 0)) {
264
273
  continue;
265
274
  }
266
- var currentBarWidth = (_s = (_r = (_q = data === null || data === void 0 ? void 0 : data[i]) === null || _q === void 0 ? void 0 : _q.barWidth) !== null && _r !== void 0 ? _r : props.barWidth) !== null && _s !== void 0 ? _s : BarDefaults.barWidth;
275
+ var currentBarWidth = (_s = (_r = (_q = data === null || data === void 0 ? void 0 : data[i]) === null || _q === void 0 ? void 0 : _q.barWidth) !== null && _r !== void 0 ? _r : props.barWidth) !== null && _s !== void 0 ? _s : defaultBarWidth;
267
276
  var currentValue = props.lineData
268
277
  ? props.lineData[i].value
269
278
  : props.stackData
@@ -284,7 +293,7 @@ export var useBarChart = function (props) {
284
293
  i > ((_u = lineConfig2.endIndex) !== null && _u !== void 0 ? _u : 0)) {
285
294
  continue;
286
295
  }
287
- var currentBarWidth = (_x = (_w = (_v = data === null || data === void 0 ? void 0 : data[i]) === null || _v === void 0 ? void 0 : _v.barWidth) !== null && _w !== void 0 ? _w : props.barWidth) !== null && _x !== void 0 ? _x : BarDefaults.barWidth;
296
+ var currentBarWidth = (_x = (_w = (_v = data === null || data === void 0 ? void 0 : data[i]) === null || _v === void 0 ? void 0 : _v.barWidth) !== null && _w !== void 0 ? _w : props.barWidth) !== null && _x !== void 0 ? _x : defaultBarWidth;
288
297
  var currentValue = lineData2[i].value;
289
298
  pp2 +=
290
299
  'L' +
@@ -302,7 +311,7 @@ export var useBarChart = function (props) {
302
311
  i > ((_z = lineConfig2.endIndex) !== null && _z !== void 0 ? _z : 0)) {
303
312
  continue;
304
313
  }
305
- var currentBarWidth = (_2 = (_1 = (_0 = data === null || data === void 0 ? void 0 : data[i]) === null || _0 === void 0 ? void 0 : _0.barWidth) !== null && _1 !== void 0 ? _1 : props.barWidth) !== null && _2 !== void 0 ? _2 : BarDefaults.barWidth;
314
+ var currentBarWidth = (_2 = (_1 = (_0 = data === null || data === void 0 ? void 0 : data[i]) === null || _0 === void 0 ? void 0 : _0.barWidth) !== null && _1 !== void 0 ? _1 : props.barWidth) !== null && _2 !== void 0 ? _2 : defaultBarWidth;
306
315
  var currentValue = lineData2[i].value;
307
316
  p2Array.push([
308
317
  getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig2, spacing),
@@ -382,7 +391,7 @@ export var useBarChart = function (props) {
382
391
  outputRange: [0, initialSpacing + totalWidth + endSpacing]
383
392
  });
384
393
  var getPropsCommonForBarAndStack = function (item, index) {
385
- var _a, _b, _c, _d, _e, _f, _g, _h;
394
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
386
395
  return {
387
396
  key: index,
388
397
  item: item,
@@ -392,9 +401,9 @@ export var useBarChart = function (props) {
392
401
  spacing: (_a = item.spacing) !== null && _a !== void 0 ? _a : spacing,
393
402
  propSpacing: spacing,
394
403
  xAxisThickness: xAxisThickness,
395
- barWidth: props.barWidth,
404
+ barWidth: (_b = props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth,
396
405
  opacity: opacity,
397
- disablePress: (_b = item.disablePress) !== null && _b !== void 0 ? _b : props.disablePress,
406
+ disablePress: (_c = item.disablePress) !== null && _c !== void 0 ? _c : props.disablePress,
398
407
  rotateLabel: rotateLabel,
399
408
  showXAxisIndices: showXAxisIndices,
400
409
  xAxisIndicesHeight: xAxisIndicesHeight,
@@ -428,15 +437,15 @@ export var useBarChart = function (props) {
428
437
  xAxisLabelsHeight: props.xAxisLabelsHeight,
429
438
  xAxisLabelsVerticalShift: xAxisLabelsVerticalShift,
430
439
  renderTooltip: props.renderTooltip,
431
- leftShiftForTooltip: (_c = props.leftShiftForTooltip) !== null && _c !== void 0 ? _c : 0,
440
+ leftShiftForTooltip: (_d = props.leftShiftForTooltip) !== null && _d !== void 0 ? _d : 0,
432
441
  initialSpacing: initialSpacing,
433
442
  selectedIndex: selectedIndex,
434
443
  setSelectedIndex: setSelectedIndex,
435
- activeOpacity: (_d = props.activeOpacity) !== null && _d !== void 0 ? _d : 0.2,
444
+ activeOpacity: (_e = props.activeOpacity) !== null && _e !== void 0 ? _e : 0.2,
436
445
  noOfSectionsBelowXAxis: noOfSectionsBelowXAxis,
437
- leftShiftForLastIndexTooltip: (_e = props.leftShiftForLastIndexTooltip) !== null && _e !== void 0 ? _e : 0,
438
- label: (_f = item.label) !== null && _f !== void 0 ? _f : (((_g = props.xAxisLabelTexts) === null || _g === void 0 ? void 0 : _g[index]) ? props.xAxisLabelTexts[index] : ''),
439
- labelTextStyle: (_h = item.labelTextStyle) !== null && _h !== void 0 ? _h : props.xAxisLabelTextStyle,
446
+ leftShiftForLastIndexTooltip: (_f = props.leftShiftForLastIndexTooltip) !== null && _f !== void 0 ? _f : 0,
447
+ label: (_g = item.label) !== null && _g !== void 0 ? _g : (((_h = props.xAxisLabelTexts) === null || _h === void 0 ? void 0 : _h[index]) ? props.xAxisLabelTexts[index] : ''),
448
+ labelTextStyle: (_j = item.labelTextStyle) !== null && _j !== void 0 ? _j : props.xAxisLabelTextStyle,
440
449
  pointerConfig: pointerConfig,
441
450
  yAxisExtraHeightAtTop: yAxisExtraHeightAtTop,
442
451
  yAxisOffset: yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0
@@ -458,7 +467,7 @@ export var useBarChart = function (props) {
458
467
  data: data,
459
468
  stackData: props.stackData,
460
469
  secondaryData: secondaryData,
461
- barWidth: (_46 = props.barWidth) !== null && _46 !== void 0 ? _46 : BarDefaults.barWidth,
470
+ barWidth: (_46 = props.barWidth) !== null && _46 !== void 0 ? _46 : defaultBarWidth,
462
471
  xAxisThickness: xAxisThickness,
463
472
  totalWidth: totalWidth,
464
473
  disableScroll: disableScroll,
@@ -32,6 +32,7 @@ import {
32
32
  import { type Animated } from 'react-native'
33
33
 
34
34
  export interface extendedBarChartPropsType extends BarChartPropsType {
35
+ parentWidth: number,
35
36
  heightValue?: Animated.Value
36
37
  widthValue?: Animated.Value
37
38
  opacValue?: Animated.Value
@@ -40,13 +41,54 @@ export interface extendedBarChartPropsType extends BarChartPropsType {
40
41
  }
41
42
 
42
43
  export const useBarChart = (props: extendedBarChartPropsType) => {
43
- const { heightValue, widthValue, opacValue, yAxisOffset } = props
44
+ const {
45
+ heightValue,
46
+ widthValue,
47
+ opacValue,
48
+ yAxisOffset,
49
+ adjustToWidth,
50
+ parentWidth,
51
+ } = props
44
52
  const [points, setPoints] = useState('')
45
53
  const [points2, setPoints2] = useState('')
46
54
  const [arrowPoints, setArrowPoints] = useState('')
47
55
  const [selectedIndex, setSelectedIndex] = useState(-1)
48
56
  const showLine = props.showLine ?? BarDefaults.showLine
49
- const spacing = props.spacing ?? BarDefaults.spacing
57
+
58
+ const data = useMemo(() => {
59
+ if (!props.data) {
60
+ return []
61
+ }
62
+ if (yAxisOffset) {
63
+ return props.data.map((item) => ({
64
+ ...item,
65
+ value: (item.value ?? 0) - (yAxisOffset ?? 0)
66
+ }))
67
+ }
68
+ return props.data
69
+ }, [yAxisOffset, props.data])
70
+
71
+ const yAxisLabelWidth =
72
+ props.yAxisLabelWidth ??
73
+ (props.hideYAxisText
74
+ ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
75
+ : AxesAndRulesDefaults.yAxisLabelWidth)
76
+
77
+ const autoComputedSectionWidth =
78
+ props.initialSpacing !== undefined
79
+ ? (parentWidth - yAxisLabelWidth) / data.length - props.initialSpacing
80
+ : (parentWidth - yAxisLabelWidth) / (data.length + 0.5)
81
+
82
+ const autoComputedBarWidth = autoComputedSectionWidth * 0.6
83
+ const defaultBarWidth = adjustToWidth
84
+ ? autoComputedBarWidth
85
+ : BarDefaults.barWidth
86
+ const barWidth = props.barWidth ?? defaultBarWidth
87
+
88
+ const autoComputedSpacing = autoComputedSectionWidth * 0.4
89
+
90
+ const spacing =
91
+ props.spacing ?? (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing)
50
92
  const initialSpacing = props.initialSpacing ?? spacing
51
93
  const endSpacing = props.endSpacing ?? spacing
52
94
  const showFractionalValues =
@@ -64,19 +106,6 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
64
106
  const animationDuration =
65
107
  props.animationDuration ?? BarDefaults.animationDuration
66
108
 
67
- const data = useMemo(() => {
68
- if (!props.data) {
69
- return []
70
- }
71
- if (yAxisOffset) {
72
- return props.data.map((item) => ({
73
- ...item,
74
- value: (item.value ?? 0) - (yAxisOffset ?? 0)
75
- }))
76
- }
77
- return props.data
78
- }, [yAxisOffset, props.data])
79
-
80
109
  const secondaryData = getSecondaryDataWithOffsetIncluded(
81
110
  props.secondaryData,
82
111
  props.secondaryYAxis
@@ -151,9 +180,8 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
151
180
  minItem = stackSumMin
152
181
  }
153
182
  totalWidth +=
154
- (stackItem.stacks[0].barWidth ??
155
- props.barWidth ??
156
- BarDefaults.barWidth) + spacing
183
+ (stackItem.stacks[0].barWidth ?? props.barWidth ?? defaultBarWidth) +
184
+ spacing
157
185
  })
158
186
  } else {
159
187
  data.forEach((item: barDataItem) => {
@@ -164,7 +192,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
164
192
  minItem = item.value
165
193
  }
166
194
  totalWidth +=
167
- (item.barWidth ?? props.barWidth ?? BarDefaults.barWidth) +
195
+ (item.barWidth ?? props.barWidth ?? defaultBarWidth) +
168
196
  (item.spacing ?? spacing)
169
197
  })
170
198
  }
@@ -239,15 +267,8 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
239
267
  props.xAxisLabelsVerticalShift ??
240
268
  AxesAndRulesDefaults.xAxisLabelsVerticalShift
241
269
  const horizontalRulesStyle = props.horizontalRulesStyle
242
- const yAxisLabelWidth =
243
- props.yAxisLabelWidth ??
244
- (props.hideYAxisText
245
- ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
246
- : AxesAndRulesDefaults.yAxisLabelWidth)
247
270
 
248
271
  const autoShiftLabels = props.autoShiftLabels ?? false
249
-
250
- const barWidth = props.barWidth ?? BarDefaults.barWidth
251
272
  const barBorderColor = props.barBorderColor ?? BarDefaults.barBorderColor
252
273
 
253
274
  const extendedContainerHeight = getExtendedContainerHeightWithPadding(
@@ -357,7 +378,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
357
378
  continue
358
379
  }
359
380
  const currentBarWidth =
360
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
381
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
361
382
  const currentValue = props.lineData
362
383
  ? props.lineData[i].value
363
384
  : props.stackData
@@ -417,7 +438,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
417
438
  continue
418
439
  }
419
440
  const currentBarWidth =
420
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
441
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
421
442
  const currentValue = props.lineData
422
443
  ? props.lineData[i].value
423
444
  : props.stackData
@@ -460,7 +481,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
460
481
  continue
461
482
  }
462
483
  const currentBarWidth =
463
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
484
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
464
485
  const currentValue = lineData2[i].value
465
486
  pp2 +=
466
487
  'L' +
@@ -492,7 +513,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
492
513
  continue
493
514
  }
494
515
  const currentBarWidth =
495
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
516
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
496
517
  const currentValue = lineData2[i].value
497
518
  p2Array.push([
498
519
  getXForLineInBar(
@@ -609,7 +630,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
609
630
  spacing: item.spacing ?? spacing,
610
631
  propSpacing: spacing,
611
632
  xAxisThickness,
612
- barWidth: props.barWidth,
633
+ barWidth: props.barWidth ?? defaultBarWidth,
613
634
  opacity,
614
635
  disablePress: item.disablePress ?? props.disablePress,
615
636
  rotateLabel,
@@ -679,7 +700,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
679
700
  data,
680
701
  stackData: props.stackData,
681
702
  secondaryData,
682
- barWidth: props.barWidth ?? BarDefaults.barWidth,
703
+ barWidth: props.barWidth ?? defaultBarWidth,
683
704
  xAxisThickness,
684
705
  totalWidth,
685
706
  disableScroll,
@@ -278,6 +278,8 @@ export interface BarChartPropsType {
278
278
  onMomentumScrollEnd?: Function;
279
279
  focusBarOnPress?: boolean;
280
280
  focusedBarConfig?: FocusedBarConfig;
281
+ adjustToWidth?: boolean;
282
+ parentWidth?: number;
281
283
  }
282
284
  export interface FocusedBarConfig {
283
285
  color?: ColorValue;
@@ -464,7 +466,7 @@ export interface RenderBarsPropsType {
464
466
  spacing: number;
465
467
  propSpacing?: number;
466
468
  data?: any;
467
- barWidth?: number;
469
+ barWidth: number;
468
470
  sideWidth?: number;
469
471
  labelWidth?: number;
470
472
  isThreeD?: boolean;
@@ -313,6 +313,9 @@ export interface BarChartPropsType {
313
313
 
314
314
  focusBarOnPress?: boolean
315
315
  focusedBarConfig?: FocusedBarConfig
316
+
317
+ adjustToWidth?: boolean
318
+ parentWidth?: number
316
319
  }
317
320
 
318
321
  export interface FocusedBarConfig {
@@ -506,7 +509,7 @@ export interface RenderBarsPropsType {
506
509
  spacing: number
507
510
  propSpacing?: number
508
511
  data?: any
509
- barWidth?: number
512
+ barWidth: number
510
513
  sideWidth?: number
511
514
  labelWidth?: number
512
515
 
@@ -5,7 +5,10 @@ interface Points {
5
5
  points: string;
6
6
  color: string;
7
7
  }
8
- export declare const useLineChartBiColor: (props: LineChartBicolorPropsType) => {
8
+ interface extendedLineChartBicolorPropsType extends LineChartBicolorPropsType {
9
+ parentWidth: number;
10
+ }
11
+ export declare const useLineChartBiColor: (props: extendedLineChartBicolorPropsType) => {
9
12
  toggle: boolean;
10
13
  setToggle: import("react").Dispatch<import("react").SetStateAction<boolean>>;
11
14
  pointsArray: Points[];
@@ -19,7 +19,11 @@ interface Points {
19
19
  color: string
20
20
  }
21
21
 
22
- export const useLineChartBiColor = (props: LineChartBicolorPropsType) => {
22
+ interface extendedLineChartBicolorPropsType extends LineChartBicolorPropsType {
23
+ parentWidth: number
24
+ }
25
+
26
+ export const useLineChartBiColor = (props: extendedLineChartBicolorPropsType) => {
23
27
  const [toggle, setToggle] = useState(false)
24
28
  const [pointsArray, setPointsArray] = useState<Points[]>([])
25
29
  const [fillPointsArray, setFillPointsArray] = useState<Points[]>([])
@@ -4,7 +4,7 @@ import { type BarAndLineChartsWrapperTypes, EdgePosition, type LineSegment } fro
4
4
  import { type Animated } from 'react-native';
5
5
  export interface extendedLineChartPropsType extends LineChartPropsType {
6
6
  animations?: Animated.Value[];
7
- screenWidth: number;
7
+ parentWidth: number;
8
8
  }
9
9
  export declare const useLineChart: (props: extendedLineChartPropsType) => {
10
10
  curvature: number;
@@ -31,7 +31,7 @@ import { adjustToOffset, computeMaxAndMinItems, getAllArrowProperties, getArrowP
31
31
  import { EdgePosition } from '../utils/types';
32
32
  export var useLineChart = function (props) {
33
33
  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, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, _65, _66, _67, _68, _69, _70, _71, _72, _73, _74, _75, _76, _77, _78, _79, _80, _81, _82, _83, _84, _85, _86, _87, _88, _89, _90, _91, _92, _93, _94, _95, _96, _97, _98, _99, _100, _101, _102, _103, _104, _105, _106, _107, _108, _109, _110, _111, _112, _113, _114, _115, _116, _117, _118, _119, _120, _121, _122, _123, _124, _125, _126, _127, _128, _129, _130, _131, _132, _133, _134, _135, _136, _137, _138, _139, _140, _141, _142, _143, _144, _145, _146, _147, _148, _149, _150, _151, _152, _153, _154, _155, _156, _157, _158, _159, _160, _161, _162, _163, _164, _165, _166, _167, _168, _169, _170, _171, _172, _173, _174, _175, _176, _177, _178, _179, _180, _181, _182, _183, _184, _185, _186, _187, _188, _189, _190, _191, _192, _193, _194, _195, _196, _197, _198, _199, _200, _201, _202, _203, _204, _205, _206, _207, _208, _209, _210, _211, _212, _213, _214, _215, _216, _217, _218, _219, _220, _221, _222, _223, _224, _225, _226, _227, _228, _229, _230, _231, _232, _233, _234, _235, _236, _237, _238, _239, _240, _241, _242, _243, _244, _245, _246, _247, _248, _249, _250, _251, _252, _253, _254, _255, _256, _257, _258, _259, _260, _261, _262, _263, _264, _265, _266, _267, _268, _269, _270, _271, _272, _273, _274, _275, _276, _277, _278, _279, _280, _281, _282, _283, _284, _285, _286, _287, _288, _289, _290, _291;
34
- var animations = props.animations, showDataPointsForMissingValues = props.showDataPointsForMissingValues, _292 = props.interpolateMissingValues, interpolateMissingValues = _292 === void 0 ? true : _292, onlyPositive = props.onlyPositive, yAxisOffset = props.yAxisOffset, screenWidth = props.screenWidth;
34
+ var animations = props.animations, showDataPointsForMissingValues = props.showDataPointsForMissingValues, _292 = props.interpolateMissingValues, interpolateMissingValues = _292 === void 0 ? true : _292, onlyPositive = props.onlyPositive, yAxisOffset = props.yAxisOffset, parentWidth = props.parentWidth;
35
35
  var curvature = (_a = props.curvature) !== null && _a !== void 0 ? _a : LineDefaults.curvature;
36
36
  var curveType = (_b = props.curveType) !== null && _b !== void 0 ? _b : LineDefaults.curveType;
37
37
  var _293 = __read(useState(0), 2), scrollX = _293[0], setScrollX = _293[1];
@@ -156,7 +156,7 @@ export var useLineChart = function (props) {
156
156
  ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
157
157
  : AxesAndRulesDefaults.yAxisLabelWidth);
158
158
  var spacing = (_5 = props.spacing) !== null && _5 !== void 0 ? _5 : (adjustToWidth
159
- ? (((_6 = props.width) !== null && _6 !== void 0 ? _6 : screenWidth - yAxisLabelWidth) - initialSpacing) /
159
+ ? (((_6 = props.width) !== null && _6 !== void 0 ? _6 : parentWidth - yAxisLabelWidth) - initialSpacing) /
160
160
  Math.max((data0 !== null && data0 !== void 0 ? data0 : data).length - 1, 1)
161
161
  : LineDefaults.spacing);
162
162
  var xAxisThickness = (_7 = props.xAxisThickness) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisThickness;
@@ -43,7 +43,7 @@ export interface extendedLineChartPropsType extends LineChartPropsType {
43
43
  // heightValue: Animated.Value
44
44
  // widthValue: Animated.Value
45
45
  // opacValue: Animated.Value
46
- screenWidth: number
46
+ parentWidth: number
47
47
  }
48
48
 
49
49
  export const useLineChart = (props: extendedLineChartPropsType) => {
@@ -53,7 +53,7 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
53
53
  interpolateMissingValues = true,
54
54
  onlyPositive,
55
55
  yAxisOffset,
56
- screenWidth
56
+ parentWidth
57
57
  } = props
58
58
  const curvature = props.curvature ?? LineDefaults.curvature
59
59
  const curveType = props.curveType ?? LineDefaults.curveType
@@ -245,7 +245,7 @@ export const useLineChart = (props: extendedLineChartPropsType) => {
245
245
  const spacing =
246
246
  props.spacing ??
247
247
  (adjustToWidth
248
- ? ((props.width ?? screenWidth - yAxisLabelWidth) - initialSpacing) /
248
+ ? ((props.width ?? parentWidth - yAxisLabelWidth) - initialSpacing) /
249
249
  Math.max((data0 ?? data).length - 1, 1)
250
250
  : LineDefaults.spacing)
251
251
 
@@ -292,6 +292,7 @@ export interface LineChartPropsType {
292
292
  showDataPointsForMissingValues?: boolean;
293
293
  interpolateMissingValues?: boolean;
294
294
  onlyPositive?: boolean;
295
+ parentWidth?: number;
295
296
  }
296
297
  export interface lineDataItem {
297
298
  value: number;
@@ -522,6 +523,7 @@ export interface LineChartBicolorPropsType {
522
523
  formatYLabel?: (label: string) => string;
523
524
  onScroll?: Function;
524
525
  endReachedOffset?: number;
526
+ parentWidth?: number;
525
527
  }
526
528
  export interface IDataSanitisationProps {
527
529
  showDataPointsForMissingValues: boolean | undefined;
@@ -325,6 +325,7 @@ export interface LineChartPropsType {
325
325
  showDataPointsForMissingValues?: boolean
326
326
  interpolateMissingValues?: boolean
327
327
  onlyPositive?: boolean
328
+ parentWidth?: number
328
329
  }
329
330
 
330
331
  export interface lineDataItem {
@@ -584,6 +585,7 @@ export interface LineChartBicolorPropsType {
584
585
  formatYLabel?: (label: string) => string
585
586
  onScroll?: Function
586
587
  endReachedOffset?: number
588
+ parentWidth?: number
587
589
  }
588
590
 
589
591
  export interface IDataSanitisationProps {
@@ -26,7 +26,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
26
26
  import { defaultAnimationDuration } from '../utils/constants';
27
27
  export var usePiePro = function (props) {
28
28
  var _a, _b;
29
- var data = props.data, isAnimated = props.isAnimated, donut = props.donut, semiCircle = props.semiCircle, _c = props.radius, radius = _c === void 0 ? 120 : _c, _d = props.innerRadius, innerRadius = _d === void 0 ? donut ? radius / 2.5 : 0 : _d, _e = props.strokeWidth, strokeWidth = _e === void 0 ? 0 : _e, _f = props.edgesRadius, edgesRadius = _f === void 0 ? 0 : _f, _g = props.startAngle, startAngle = _g === void 0 ? 0 : _g, ring = props.ring;
29
+ var data = props.data, isAnimated = props.isAnimated, donut = props.donut, semiCircle = props.semiCircle, _c = props.radius, radius = _c === void 0 ? 120 : _c, _d = props.innerRadius, innerRadius = _d === void 0 ? donut ? radius / 2.5 : 0 : _d, _e = props.strokeWidth, strokeWidth = _e === void 0 ? props.ring ? 10 : 0 : _e, _f = props.edgesRadius, edgesRadius = _f === void 0 ? 0 : _f, _g = props.startAngle, startAngle = _g === void 0 ? 0 : _g, ring = props.ring;
30
30
  var endAngle = (_a = props.endAngle) !== null && _a !== void 0 ? _a : startAngle + Math.PI * (semiCircle ? 1 : 2);
31
31
  var total = data.reduce(function (acc, item) { return acc + (item === null || item === void 0 ? void 0 : item.value); }, 0);
32
32
  var animationDuration = (_b = props.animationDuration) !== null && _b !== void 0 ? _b : defaultAnimationDuration;
@@ -39,7 +39,7 @@ export const usePiePro = (props: PieChartPropsType): IusePiePro => {
39
39
  semiCircle,
40
40
  radius = 120,
41
41
  innerRadius = donut ? radius / 2.5 : 0,
42
- strokeWidth = 0,
42
+ strokeWidth = props.ring ? 10 : 0,
43
43
  edgesRadius = 0,
44
44
  startAngle = 0,
45
45
  ring
@@ -531,6 +531,7 @@ export var getAxesAndRulesProps = function (props, stepValue, maxValue) {
531
531
  verticalLinesHeight: props.verticalLinesHeight,
532
532
  verticalLinesColor: props.verticalLinesColor,
533
533
  verticalLinesShift: props.verticalLinesShift,
534
+ verticalLinesStrokeDashArray: props.verticalLinesStrokeDashArray,
534
535
  verticalLinesZIndex: props.verticalLinesZIndex,
535
536
  verticalLinesSpacing: props.verticalLinesSpacing,
536
537
  noOfVerticalLines: props.noOfVerticalLines,
@@ -711,6 +711,7 @@ export const getAxesAndRulesProps = (
711
711
  verticalLinesHeight: props.verticalLinesHeight,
712
712
  verticalLinesColor: props.verticalLinesColor,
713
713
  verticalLinesShift: props.verticalLinesShift,
714
+ verticalLinesStrokeDashArray: props.verticalLinesStrokeDashArray,
714
715
  verticalLinesZIndex: props.verticalLinesZIndex,
715
716
  verticalLinesSpacing: props.verticalLinesSpacing,
716
717
  noOfVerticalLines: props.noOfVerticalLines,