gifted-charts-core 0.1.4 → 0.1.5

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.5",
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": [
@@ -8,6 +8,7 @@ export interface extendedBarChartPropsType extends BarChartPropsType {
8
8
  opacValue?: Animated.Value;
9
9
  verticalLinesUptoDataPoint?: boolean;
10
10
  secondaryYAxis?: secondaryYAxisType | boolean;
11
+ screenWidth?: number;
11
12
  }
12
13
  export declare const useBarChart: (props: extendedBarChartPropsType) => {
13
14
  lineConfig: lineConfigType;
@@ -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;
34
- var _48 = __read(useState(''), 2), points = _48[0], setPoints = _48[1];
35
- var _49 = __read(useState(''), 2), points2 = _49[0], setPoints2 = _49[1];
36
- var _50 = __read(useState(''), 2), arrowPoints = _50[0], setArrowPoints = _50[1];
37
- var _51 = __read(useState(-1), 2), selectedIndex = _51[0], setSelectedIndex = _51[1];
33
+ var heightValue = props.heightValue, widthValue = props.widthValue, opacValue = props.opacValue, yAxisOffset = props.yAxisOffset, adjustToWidth = props.adjustToWidth, _48 = props.screenWidth, screenWidth = _48 === void 0 ? 300 : _48;
34
+ var _49 = __read(useState(''), 2), points = _49[0], setPoints = _49[1];
35
+ var _50 = __read(useState(''), 2), points2 = _50[0], setPoints2 = _50[1];
36
+ var _51 = __read(useState(''), 2), arrowPoints = _51[0], setArrowPoints = _51[1];
37
+ var _52 = __read(useState(-1), 2), selectedIndex = _52[0], setSelectedIndex = _52[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,26 @@ 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 = (screenWidth - yAxisLabelWidth) / (data.length + 1);
55
+ var autoComputedBarWidth = autoComputedSectionWidth * .6;
56
+ var defaultBarWidth = adjustToWidth ? autoComputedBarWidth : BarDefaults.barWidth;
57
+ var barWidth = (_c = props.barWidth) !== null && _c !== void 0 ? _c : defaultBarWidth;
58
+ var autoComputedSpacing = autoComputedSectionWidth * .4;
59
+ var spacing = (_d = props.spacing) !== null && _d !== void 0 ? _d : (adjustToWidth ? autoComputedSpacing : BarDefaults.spacing);
60
+ var initialSpacing = (_e = props.initialSpacing) !== null && _e !== void 0 ? _e : spacing;
61
+ var endSpacing = (_f = props.endSpacing) !== null && _f !== void 0 ? _f : spacing;
62
+ var showFractionalValues = (_g = props.showFractionalValues) !== null && _g !== void 0 ? _g : AxesAndRulesDefaults.showFractionalValues;
63
+ var horizontal = (_h = props.horizontal) !== null && _h !== void 0 ? _h : BarDefaults.horizontal;
64
+ var rtl = (_j = props.rtl) !== null && _j !== void 0 ? _j : BarDefaults.rtl;
65
+ var yAxisAtTop = (_k = props.yAxisAtTop) !== null && _k !== void 0 ? _k : BarDefaults.yAxisAtTop;
66
+ var intactTopLabel = (_l = props.intactTopLabel) !== null && _l !== void 0 ? _l : BarDefaults.intactTopLabel;
67
+ var heightFromProps = horizontal ? props.width : props.height;
68
+ var widthFromProps = horizontal ? props.height : props.width;
69
+ var isAnimated = (_m = props.isAnimated) !== null && _m !== void 0 ? _m : BarDefaults.isAnimated;
70
+ var animationDuration = (_o = props.animationDuration) !== null && _o !== void 0 ? _o : BarDefaults.animationDuration;
63
71
  var secondaryData = getSecondaryDataWithOffsetIncluded(props.secondaryData, props.secondaryYAxis);
64
72
  var lineData = useMemo(function () {
65
73
  var _a;
@@ -75,7 +83,7 @@ export var useBarChart = function (props) {
75
83
  return props.lineData;
76
84
  }, [yAxisOffset, props.lineData, data, props.stackData]);
77
85
  var lineData2 = props.lineData2;
78
- var lineBehindBars = (_m = props.lineBehindBars) !== null && _m !== void 0 ? _m : BarDefaults.lineBehindBars;
86
+ var lineBehindBars = (_p = props.lineBehindBars) !== null && _p !== void 0 ? _p : BarDefaults.lineBehindBars;
79
87
  defaultLineConfig.initialSpacing = initialSpacing;
80
88
  defaultLineConfig.endIndex = lineData.length - 1;
81
89
  defaultLineConfig.animationDuration = animationDuration;
@@ -90,12 +98,12 @@ export var useBarChart = function (props) {
90
98
  ? props.stepHeight * noOfSections
91
99
  : AxesAndRulesDefaults.containerHeight);
92
100
  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;
101
+ var stepHeight = (_q = props.stepHeight) !== null && _q !== void 0 ? _q : containerHeight / noOfSections;
102
+ var labelWidth = (_r = props.labelWidth) !== null && _r !== void 0 ? _r : AxesAndRulesDefaults.labelWidth;
103
+ var scrollToEnd = (_s = props.scrollToEnd) !== null && _s !== void 0 ? _s : BarDefaults.scrollToEnd;
104
+ var scrollAnimation = (_t = props.scrollAnimation) !== null && _t !== void 0 ? _t : BarDefaults.scrollAnimation;
105
+ var scrollEventThrottle = (_u = props.scrollEventThrottle) !== null && _u !== void 0 ? _u : BarDefaults.scrollEventThrottle;
106
+ var labelsExtraHeight = (_v = props.labelsExtraHeight) !== null && _v !== void 0 ? _v : AxesAndRulesDefaults.labelsExtraHeight;
99
107
  var totalWidth = initialSpacing;
100
108
  var maxItem = 0;
101
109
  var minItem = 0;
@@ -111,7 +119,7 @@ export var useBarChart = function (props) {
111
119
  minItem = stackSumMin;
112
120
  }
113
121
  totalWidth +=
114
- ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) + spacing;
122
+ ((_b = (_a = stackItem.stacks[0].barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) + spacing;
115
123
  });
116
124
  }
117
125
  else {
@@ -124,7 +132,7 @@ export var useBarChart = function (props) {
124
132
  minItem = item.value;
125
133
  }
126
134
  totalWidth +=
127
- ((_b = (_a = item.barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : BarDefaults.barWidth) +
135
+ ((_b = (_a = item.barWidth) !== null && _a !== void 0 ? _a : props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth) +
128
136
  ((_c = item.spacing) !== null && _c !== void 0 ? _c : spacing);
129
137
  });
130
138
  }
@@ -146,39 +154,35 @@ export var useBarChart = function (props) {
146
154
  var maxValue = getMaxValue(props.maxValue, props.stepValue, noOfSections, maxAndMin.maxItem);
147
155
  var secondaryMaxValue = lineConfig.isSecondary
148
156
  ? typeof props.secondaryYAxis !== 'boolean'
149
- ? (_u = props.secondaryYAxis.maxValue) !== null && _u !== void 0 ? _u : secondaryMaxAndMin.maxItem
157
+ ? (_w = props.secondaryYAxis.maxValue) !== null && _w !== void 0 ? _w : secondaryMaxAndMin.maxItem
150
158
  : secondaryMaxAndMin.maxItem
151
159
  : 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;
160
+ var mostNegativeValue = (_x = props.mostNegativeValue) !== null && _x !== void 0 ? _x : maxAndMin.minItem;
161
+ var stepValue = (_y = props.stepValue) !== null && _y !== void 0 ? _y : maxValue / noOfSections;
162
+ var noOfSectionsBelowXAxis = (_z = props.noOfSectionsBelowXAxis) !== null && _z !== void 0 ? _z : -mostNegativeValue / stepValue;
163
+ var showScrollIndicator = (_0 = props.showScrollIndicator) !== null && _0 !== void 0 ? _0 : BarDefaults.showScrollIndicator;
164
+ var side = (_1 = props.side) !== null && _1 !== void 0 ? _1 : BarDefaults.side;
165
+ var rotateLabel = (_2 = props.rotateLabel) !== null && _2 !== void 0 ? _2 : AxesAndRulesDefaults.rotateLabel;
166
+ var opacity = (_3 = props.opacity) !== null && _3 !== void 0 ? _3 : BarDefaults.opacity;
167
+ var isThreeD = (_4 = props.isThreeD) !== null && _4 !== void 0 ? _4 : BarDefaults.isThreeD;
168
+ var showXAxisIndices = (_5 = props.showXAxisIndices) !== null && _5 !== void 0 ? _5 : AxesAndRulesDefaults.showXAxisIndices;
169
+ var xAxisIndicesHeight = (_6 = props.xAxisIndicesHeight) !== null && _6 !== void 0 ? _6 : AxesAndRulesDefaults.xAxisIndicesHeight;
170
+ var xAxisIndicesWidth = (_7 = props.xAxisIndicesWidth) !== null && _7 !== void 0 ? _7 : AxesAndRulesDefaults.xAxisIndicesWidth;
171
+ var xAxisIndicesColor = (_8 = props.xAxisIndicesColor) !== null && _8 !== void 0 ? _8 : AxesAndRulesDefaults.xAxisIndicesColor;
172
+ var xAxisThickness = (_9 = props.xAxisThickness) !== null && _9 !== void 0 ? _9 : AxesAndRulesDefaults.xAxisThickness;
173
+ var xAxisTextNumberOfLines = (_10 = props.xAxisTextNumberOfLines) !== null && _10 !== void 0 ? _10 : AxesAndRulesDefaults.xAxisTextNumberOfLines;
174
+ var xAxisLabelsVerticalShift = (_11 = props.xAxisLabelsVerticalShift) !== null && _11 !== void 0 ? _11 : AxesAndRulesDefaults.xAxisLabelsVerticalShift;
167
175
  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;
176
+ var autoShiftLabels = (_12 = props.autoShiftLabels) !== null && _12 !== void 0 ? _12 : false;
173
177
  var barBorderColor = (_13 = props.barBorderColor) !== null && _13 !== void 0 ? _13 : BarDefaults.barBorderColor;
174
178
  var extendedContainerHeight = getExtendedContainerHeightWithPadding(containerHeight, 0);
175
179
  var containerHeightIncludingBelowXAxis = extendedContainerHeight + noOfSectionsBelowXAxis * stepHeight;
176
- var _52 = __read(useState(-1), 2), pointerIndex = _52[0], setPointerIndex = _52[1];
177
- var _53 = __read(useState(0), 2), pointerX = _53[0], setPointerX = _53[1];
178
- var _54 = __read(useState(0), 2), pointerY = _54[0], setPointerY = _54[1];
179
- var _55 = __read(useState(), 2), pointerItem = _55[0], setPointerItem = _55[1];
180
- var _56 = __read(useState(0), 2), responderStartTime = _56[0], setResponderStartTime = _56[1];
181
- var _57 = __read(useState(false), 2), responderActive = _57[0], setResponderActive = _57[1];
180
+ var _53 = __read(useState(-1), 2), pointerIndex = _53[0], setPointerIndex = _53[1];
181
+ var _54 = __read(useState(0), 2), pointerX = _54[0], setPointerX = _54[1];
182
+ var _55 = __read(useState(0), 2), pointerY = _55[0], setPointerY = _55[1];
183
+ var _56 = __read(useState(), 2), pointerItem = _56[0], setPointerItem = _56[1];
184
+ var _57 = __read(useState(0), 2), responderStartTime = _57[0], setResponderStartTime = _57[1];
185
+ var _58 = __read(useState(false), 2), responderActive = _58[0], setResponderActive = _58[1];
182
186
  var pointerConfig = props.pointerConfig;
183
187
  var getPointerProps = (_14 = props.getPointerProps) !== null && _14 !== void 0 ? _14 : null;
184
188
  var pointerHeight = (_15 = pointerConfig === null || pointerConfig === void 0 ? void 0 : pointerConfig.height) !== null && _15 !== void 0 ? _15 : defaultPointerConfig.height;
@@ -232,7 +236,7 @@ export var useBarChart = function (props) {
232
236
  i > ((_f = lineConfig.endIndex) !== null && _f !== void 0 ? _f : 0)) {
233
237
  continue;
234
238
  }
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;
239
+ 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
240
  var currentValue = props.lineData
237
241
  ? props.lineData[i].value
238
242
  : props.stackData
@@ -263,7 +267,7 @@ export var useBarChart = function (props) {
263
267
  i > ((_p = lineConfig.endIndex) !== null && _p !== void 0 ? _p : 0)) {
264
268
  continue;
265
269
  }
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;
270
+ 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
271
  var currentValue = props.lineData
268
272
  ? props.lineData[i].value
269
273
  : props.stackData
@@ -284,7 +288,7 @@ export var useBarChart = function (props) {
284
288
  i > ((_u = lineConfig2.endIndex) !== null && _u !== void 0 ? _u : 0)) {
285
289
  continue;
286
290
  }
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;
291
+ 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
292
  var currentValue = lineData2[i].value;
289
293
  pp2 +=
290
294
  'L' +
@@ -302,7 +306,7 @@ export var useBarChart = function (props) {
302
306
  i > ((_z = lineConfig2.endIndex) !== null && _z !== void 0 ? _z : 0)) {
303
307
  continue;
304
308
  }
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;
309
+ 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
310
  var currentValue = lineData2[i].value;
307
311
  p2Array.push([
308
312
  getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig2, spacing),
@@ -382,7 +386,7 @@ export var useBarChart = function (props) {
382
386
  outputRange: [0, initialSpacing + totalWidth + endSpacing]
383
387
  });
384
388
  var getPropsCommonForBarAndStack = function (item, index) {
385
- var _a, _b, _c, _d, _e, _f, _g, _h;
389
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
386
390
  return {
387
391
  key: index,
388
392
  item: item,
@@ -392,9 +396,9 @@ export var useBarChart = function (props) {
392
396
  spacing: (_a = item.spacing) !== null && _a !== void 0 ? _a : spacing,
393
397
  propSpacing: spacing,
394
398
  xAxisThickness: xAxisThickness,
395
- barWidth: props.barWidth,
399
+ barWidth: (_b = props.barWidth) !== null && _b !== void 0 ? _b : defaultBarWidth,
396
400
  opacity: opacity,
397
- disablePress: (_b = item.disablePress) !== null && _b !== void 0 ? _b : props.disablePress,
401
+ disablePress: (_c = item.disablePress) !== null && _c !== void 0 ? _c : props.disablePress,
398
402
  rotateLabel: rotateLabel,
399
403
  showXAxisIndices: showXAxisIndices,
400
404
  xAxisIndicesHeight: xAxisIndicesHeight,
@@ -428,15 +432,15 @@ export var useBarChart = function (props) {
428
432
  xAxisLabelsHeight: props.xAxisLabelsHeight,
429
433
  xAxisLabelsVerticalShift: xAxisLabelsVerticalShift,
430
434
  renderTooltip: props.renderTooltip,
431
- leftShiftForTooltip: (_c = props.leftShiftForTooltip) !== null && _c !== void 0 ? _c : 0,
435
+ leftShiftForTooltip: (_d = props.leftShiftForTooltip) !== null && _d !== void 0 ? _d : 0,
432
436
  initialSpacing: initialSpacing,
433
437
  selectedIndex: selectedIndex,
434
438
  setSelectedIndex: setSelectedIndex,
435
- activeOpacity: (_d = props.activeOpacity) !== null && _d !== void 0 ? _d : 0.2,
439
+ activeOpacity: (_e = props.activeOpacity) !== null && _e !== void 0 ? _e : 0.2,
436
440
  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,
441
+ leftShiftForLastIndexTooltip: (_f = props.leftShiftForLastIndexTooltip) !== null && _f !== void 0 ? _f : 0,
442
+ label: (_g = item.label) !== null && _g !== void 0 ? _g : (((_h = props.xAxisLabelTexts) === null || _h === void 0 ? void 0 : _h[index]) ? props.xAxisLabelTexts[index] : ''),
443
+ labelTextStyle: (_j = item.labelTextStyle) !== null && _j !== void 0 ? _j : props.xAxisLabelTextStyle,
440
444
  pointerConfig: pointerConfig,
441
445
  yAxisExtraHeightAtTop: yAxisExtraHeightAtTop,
442
446
  yAxisOffset: yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0
@@ -458,7 +462,7 @@ export var useBarChart = function (props) {
458
462
  data: data,
459
463
  stackData: props.stackData,
460
464
  secondaryData: secondaryData,
461
- barWidth: (_46 = props.barWidth) !== null && _46 !== void 0 ? _46 : BarDefaults.barWidth,
465
+ barWidth: (_46 = props.barWidth) !== null && _46 !== void 0 ? _46 : defaultBarWidth,
462
466
  xAxisThickness: xAxisThickness,
463
467
  totalWidth: totalWidth,
464
468
  disableScroll: disableScroll,
@@ -37,16 +37,45 @@ export interface extendedBarChartPropsType extends BarChartPropsType {
37
37
  opacValue?: Animated.Value
38
38
  verticalLinesUptoDataPoint?: boolean
39
39
  secondaryYAxis?: secondaryYAxisType | boolean
40
+ screenWidth?: number
40
41
  }
41
42
 
42
43
  export const useBarChart = (props: extendedBarChartPropsType) => {
43
- const { heightValue, widthValue, opacValue, yAxisOffset } = props
44
+ const { heightValue, widthValue, opacValue, yAxisOffset, adjustToWidth, screenWidth=300 } = props
44
45
  const [points, setPoints] = useState('')
45
46
  const [points2, setPoints2] = useState('')
46
47
  const [arrowPoints, setArrowPoints] = useState('')
47
48
  const [selectedIndex, setSelectedIndex] = useState(-1)
48
49
  const showLine = props.showLine ?? BarDefaults.showLine
49
- const spacing = props.spacing ?? BarDefaults.spacing
50
+
51
+ const data = useMemo(() => {
52
+ if (!props.data) {
53
+ return []
54
+ }
55
+ if (yAxisOffset) {
56
+ return props.data.map((item) => ({
57
+ ...item,
58
+ value: (item.value ?? 0) - (yAxisOffset ?? 0)
59
+ }))
60
+ }
61
+ return props.data
62
+ }, [yAxisOffset, props.data])
63
+
64
+ const yAxisLabelWidth =
65
+ props.yAxisLabelWidth ??
66
+ (props.hideYAxisText
67
+ ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
68
+ : AxesAndRulesDefaults.yAxisLabelWidth)
69
+
70
+ const autoComputedSectionWidth = (screenWidth - yAxisLabelWidth) / (data.length + 1)
71
+ const autoComputedBarWidth = autoComputedSectionWidth * .6
72
+
73
+ const defaultBarWidth = adjustToWidth ? autoComputedBarWidth : BarDefaults.barWidth
74
+ const barWidth = props.barWidth ?? defaultBarWidth
75
+
76
+ const autoComputedSpacing = autoComputedSectionWidth * .4
77
+
78
+ const spacing = props.spacing ?? ( adjustToWidth ? autoComputedSpacing : BarDefaults.spacing)
50
79
  const initialSpacing = props.initialSpacing ?? spacing
51
80
  const endSpacing = props.endSpacing ?? spacing
52
81
  const showFractionalValues =
@@ -64,18 +93,6 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
64
93
  const animationDuration =
65
94
  props.animationDuration ?? BarDefaults.animationDuration
66
95
 
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
96
 
80
97
  const secondaryData = getSecondaryDataWithOffsetIncluded(
81
98
  props.secondaryData,
@@ -153,7 +170,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
153
170
  totalWidth +=
154
171
  (stackItem.stacks[0].barWidth ??
155
172
  props.barWidth ??
156
- BarDefaults.barWidth) + spacing
173
+ defaultBarWidth) + spacing
157
174
  })
158
175
  } else {
159
176
  data.forEach((item: barDataItem) => {
@@ -164,7 +181,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
164
181
  minItem = item.value
165
182
  }
166
183
  totalWidth +=
167
- (item.barWidth ?? props.barWidth ?? BarDefaults.barWidth) +
184
+ (item.barWidth ?? props.barWidth ?? defaultBarWidth) +
168
185
  (item.spacing ?? spacing)
169
186
  })
170
187
  }
@@ -239,15 +256,8 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
239
256
  props.xAxisLabelsVerticalShift ??
240
257
  AxesAndRulesDefaults.xAxisLabelsVerticalShift
241
258
  const horizontalRulesStyle = props.horizontalRulesStyle
242
- const yAxisLabelWidth =
243
- props.yAxisLabelWidth ??
244
- (props.hideYAxisText
245
- ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
246
- : AxesAndRulesDefaults.yAxisLabelWidth)
247
259
 
248
260
  const autoShiftLabels = props.autoShiftLabels ?? false
249
-
250
- const barWidth = props.barWidth ?? BarDefaults.barWidth
251
261
  const barBorderColor = props.barBorderColor ?? BarDefaults.barBorderColor
252
262
 
253
263
  const extendedContainerHeight = getExtendedContainerHeightWithPadding(
@@ -357,7 +367,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
357
367
  continue
358
368
  }
359
369
  const currentBarWidth =
360
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
370
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
361
371
  const currentValue = props.lineData
362
372
  ? props.lineData[i].value
363
373
  : props.stackData
@@ -417,7 +427,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
417
427
  continue
418
428
  }
419
429
  const currentBarWidth =
420
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
430
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
421
431
  const currentValue = props.lineData
422
432
  ? props.lineData[i].value
423
433
  : props.stackData
@@ -460,7 +470,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
460
470
  continue
461
471
  }
462
472
  const currentBarWidth =
463
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
473
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
464
474
  const currentValue = lineData2[i].value
465
475
  pp2 +=
466
476
  'L' +
@@ -492,7 +502,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
492
502
  continue
493
503
  }
494
504
  const currentBarWidth =
495
- data?.[i]?.barWidth ?? props.barWidth ?? BarDefaults.barWidth
505
+ data?.[i]?.barWidth ?? props.barWidth ?? defaultBarWidth
496
506
  const currentValue = lineData2[i].value
497
507
  p2Array.push([
498
508
  getXForLineInBar(
@@ -609,7 +619,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
609
619
  spacing: item.spacing ?? spacing,
610
620
  propSpacing: spacing,
611
621
  xAxisThickness,
612
- barWidth: props.barWidth,
622
+ barWidth: props.barWidth ?? defaultBarWidth,
613
623
  opacity,
614
624
  disablePress: item.disablePress ?? props.disablePress,
615
625
  rotateLabel,
@@ -679,7 +689,7 @@ export const useBarChart = (props: extendedBarChartPropsType) => {
679
689
  data,
680
690
  stackData: props.stackData,
681
691
  secondaryData,
682
- barWidth: props.barWidth ?? BarDefaults.barWidth,
692
+ barWidth: props.barWidth ?? defaultBarWidth,
683
693
  xAxisThickness,
684
694
  totalWidth,
685
695
  disableScroll,
@@ -278,6 +278,7 @@ export interface BarChartPropsType {
278
278
  onMomentumScrollEnd?: Function;
279
279
  focusBarOnPress?: boolean;
280
280
  focusedBarConfig?: FocusedBarConfig;
281
+ adjustToWidth?: boolean;
281
282
  }
282
283
  export interface FocusedBarConfig {
283
284
  color?: ColorValue;
@@ -313,6 +313,8 @@ export interface BarChartPropsType {
313
313
 
314
314
  focusBarOnPress?: boolean
315
315
  focusedBarConfig?: FocusedBarConfig
316
+
317
+ adjustToWidth?: boolean
316
318
  }
317
319
 
318
320
  export interface FocusedBarConfig {
@@ -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