gifted-charts-core 0.1.43 → 0.1.44

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.
@@ -46,11 +46,33 @@ export var useBarChart = function (props) {
46
46
  if (yAxisOffset) {
47
47
  return props.data.map(function (item) {
48
48
  var _a;
49
- return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - (yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0) }));
49
+ return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - yAxisOffset }));
50
50
  });
51
51
  }
52
52
  return props.data;
53
53
  }, [yAxisOffset, props.data]);
54
+ var stackData = useMemo(function () {
55
+ if (!props.stackData) {
56
+ return undefined;
57
+ }
58
+ if (yAxisOffset) {
59
+ return props.stackData.map(function (item) {
60
+ var cumulativeSum = 0;
61
+ return __assign(__assign({}, item), { stacks: item.stacks.map(function (stackItem) {
62
+ var _a;
63
+ var stack = __assign(__assign({}, stackItem), { value: Math.max(
64
+ // yAxisOffset is reduced from stackItems as long as their cumulative sum is less than yAxisOffset
65
+ ((_a = stackItem.value) !== null && _a !== void 0 ? _a : 0) -
66
+ (cumulativeSum < yAxisOffset
67
+ ? yAxisOffset - cumulativeSum
68
+ : 0), 0) });
69
+ cumulativeSum += stackItem.value;
70
+ return stack;
71
+ }) });
72
+ });
73
+ }
74
+ return props.stackData;
75
+ }, [yAxisOffset, props.stackData]);
54
76
  var yAxisLabelWidth = (_b = props.yAxisLabelWidth) !== null && _b !== void 0 ? _b : (props.hideYAxisText
55
77
  ? AxesAndRulesDefaults.yAxisEmptyLabelWidth
56
78
  : AxesAndRulesDefaults.yAxisLabelWidth);
@@ -79,9 +101,8 @@ export var useBarChart = function (props) {
79
101
  // props.secondaryYAxis
80
102
  // )
81
103
  var lineData = useMemo(function () {
82
- var _a;
83
104
  if (!props.lineData) {
84
- return (_a = props.stackData) !== null && _a !== void 0 ? _a : data;
105
+ return stackData !== null && stackData !== void 0 ? stackData : data;
85
106
  }
86
107
  if (yAxisOffset) {
87
108
  return props.lineData.map(function (item) {
@@ -90,7 +111,7 @@ export var useBarChart = function (props) {
90
111
  });
91
112
  }
92
113
  return props.lineData;
93
- }, [yAxisOffset, props.lineData, data, props.stackData]);
114
+ }, [yAxisOffset, props.lineData, data, stackData]);
94
115
  var lineData2 = props.lineData2;
95
116
  var lineBehindBars = (_o = props.lineBehindBars) !== null && _o !== void 0 ? _o : BarDefaults.lineBehindBars;
96
117
  defaultLineConfig.initialSpacing = initialSpacing;
@@ -131,8 +152,8 @@ export var useBarChart = function (props) {
131
152
  var minItem = 0;
132
153
  var minPositiveItem = 0;
133
154
  var secondaryMinPositiveItem = 0;
134
- if (props.stackData) {
135
- props.stackData.forEach(function (stackItem, index) {
155
+ if (stackData) {
156
+ stackData.forEach(function (stackItem, index) {
136
157
  var _a, _b, _c;
137
158
  var stackSumMax = stackItem.stacks.reduce(function (acc, stack) { return acc + (stack.value >= 0 ? stack.value : 0); }, 0);
138
159
  var stackSumMin = stackItem.stacks.reduce(function (acc, stack) { return acc + (stack.value < 0 ? stack.value : 0); }, 0);
@@ -287,22 +308,22 @@ export var useBarChart = function (props) {
287
308
  ? (_50 = (_49 = props.secondaryYAxis) === null || _49 === void 0 ? void 0 : _49.yAxisOffset) !== null && _50 !== void 0 ? _50 : 0
288
309
  : yAxisOffset !== null && yAxisOffset !== void 0 ? yAxisOffset : 0;
289
310
  useEffect(function () {
290
- 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;
311
+ 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;
291
312
  if (showLine) {
292
313
  var pp = '';
293
314
  var pp2 = '';
294
- var firstBarWidth = (_d = (_c = (_b = ((_a = props.stackData) !== null && _a !== void 0 ? _a : data)) === null || _b === void 0 ? void 0 : _b[0].barWidth) !== null && _c !== void 0 ? _c : props.barWidth) !== null && _d !== void 0 ? _d : 30;
315
+ var firstBarWidth = (_c = (_b = (_a = (stackData !== null && stackData !== void 0 ? stackData : data)) === null || _a === void 0 ? void 0 : _a[0].barWidth) !== null && _b !== void 0 ? _b : props.barWidth) !== null && _c !== void 0 ? _c : 30;
295
316
  if (!lineConfig.curved) {
296
317
  for (var i = 0; i < lineData.length; i++) {
297
- if (i < ((_e = lineConfig.startIndex) !== null && _e !== void 0 ? _e : 0) ||
298
- i > ((_f = lineConfig.endIndex) !== null && _f !== void 0 ? _f : 0)) {
318
+ if (i < ((_d = lineConfig.startIndex) !== null && _d !== void 0 ? _d : 0) ||
319
+ i > ((_e = lineConfig.endIndex) !== null && _e !== void 0 ? _e : 0)) {
299
320
  continue;
300
321
  }
301
- 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;
322
+ var currentBarWidth = (_h = (_g = (_f = data === null || data === void 0 ? void 0 : data[i]) === null || _f === void 0 ? void 0 : _f.barWidth) !== null && _g !== void 0 ? _g : props.barWidth) !== null && _h !== void 0 ? _h : defaultBarWidth;
302
323
  var currentValue = props.lineData
303
324
  ? props.lineData[i].value
304
- : props.stackData
305
- ? props.stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
325
+ : stackData
326
+ ? stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
306
327
  : data[i].value;
307
328
  pp +=
308
329
  'L' +
@@ -318,22 +339,22 @@ export var useBarChart = function (props) {
318
339
  var arrowTipX = parseInt(ppArray[ppArray.length - 2].replace('L', ''));
319
340
  var y1 = parseInt(ppArray[ppArray.length - 3]);
320
341
  var x1 = parseInt(ppArray[ppArray.length - 4].replace('L', ''));
321
- var arrowPoints_1 = getArrowPoints(arrowTipX, arrowTipY, x1, y1, (_k = lineConfig.arrowConfig) === null || _k === void 0 ? void 0 : _k.length, (_l = lineConfig.arrowConfig) === null || _l === void 0 ? void 0 : _l.width, (_m = lineConfig.arrowConfig) === null || _m === void 0 ? void 0 : _m.showArrowBase);
342
+ var arrowPoints_1 = getArrowPoints(arrowTipX, arrowTipY, x1, y1, (_j = lineConfig.arrowConfig) === null || _j === void 0 ? void 0 : _j.length, (_k = lineConfig.arrowConfig) === null || _k === void 0 ? void 0 : _k.width, (_l = lineConfig.arrowConfig) === null || _l === void 0 ? void 0 : _l.showArrowBase);
322
343
  setArrowPoints(arrowPoints_1);
323
344
  }
324
345
  }
325
346
  else {
326
347
  var p1Array = [];
327
348
  for (var i = 0; i < lineData.length; i++) {
328
- if (i < ((_o = lineConfig.startIndex) !== null && _o !== void 0 ? _o : 0) ||
329
- i > ((_p = lineConfig.endIndex) !== null && _p !== void 0 ? _p : 0)) {
349
+ if (i < ((_m = lineConfig.startIndex) !== null && _m !== void 0 ? _m : 0) ||
350
+ i > ((_o = lineConfig.endIndex) !== null && _o !== void 0 ? _o : 0)) {
330
351
  continue;
331
352
  }
332
- 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;
353
+ var currentBarWidth = (_r = (_q = (_p = data === null || data === void 0 ? void 0 : data[i]) === null || _p === void 0 ? void 0 : _p.barWidth) !== null && _q !== void 0 ? _q : props.barWidth) !== null && _r !== void 0 ? _r : defaultBarWidth;
333
354
  var currentValue = props.lineData
334
355
  ? props.lineData[i].value
335
- : props.stackData
336
- ? props.stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
356
+ : stackData
357
+ ? stackData[i].stacks.reduce(function (total, item) { return total + item.value; }, 0)
337
358
  : data[i].value;
338
359
  p1Array.push([
339
360
  getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig, spacing),
@@ -346,11 +367,11 @@ export var useBarChart = function (props) {
346
367
  if (lineData2 === null || lineData2 === void 0 ? void 0 : lineData2.length) {
347
368
  if (!(lineConfig2 === null || lineConfig2 === void 0 ? void 0 : lineConfig2.curved)) {
348
369
  for (var i = 0; i < lineData2.length; i++) {
349
- if (i < ((_t = lineConfig2.startIndex) !== null && _t !== void 0 ? _t : 0) ||
350
- i > ((_u = lineConfig2.endIndex) !== null && _u !== void 0 ? _u : 0)) {
370
+ if (i < ((_s = lineConfig2.startIndex) !== null && _s !== void 0 ? _s : 0) ||
371
+ i > ((_t = lineConfig2.endIndex) !== null && _t !== void 0 ? _t : 0)) {
351
372
  continue;
352
373
  }
353
- 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;
374
+ var currentBarWidth = (_w = (_v = (_u = data === null || data === void 0 ? void 0 : data[i]) === null || _u === void 0 ? void 0 : _u.barWidth) !== null && _v !== void 0 ? _v : props.barWidth) !== null && _w !== void 0 ? _w : defaultBarWidth;
354
375
  var currentValue = lineData2[i].value;
355
376
  pp2 +=
356
377
  'L' +
@@ -364,11 +385,11 @@ export var useBarChart = function (props) {
364
385
  else {
365
386
  var p2Array = [];
366
387
  for (var i = 0; i < lineData2.length; i++) {
367
- if (i < ((_y = lineConfig2.startIndex) !== null && _y !== void 0 ? _y : 0) ||
368
- i > ((_z = lineConfig2.endIndex) !== null && _z !== void 0 ? _z : 0)) {
388
+ if (i < ((_x = lineConfig2.startIndex) !== null && _x !== void 0 ? _x : 0) ||
389
+ i > ((_y = lineConfig2.endIndex) !== null && _y !== void 0 ? _y : 0)) {
369
390
  continue;
370
391
  }
371
- 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;
392
+ var currentBarWidth = (_1 = (_0 = (_z = data === null || data === void 0 ? void 0 : data[i]) === null || _z === void 0 ? void 0 : _z.barWidth) !== null && _0 !== void 0 ? _0 : props.barWidth) !== null && _1 !== void 0 ? _1 : defaultBarWidth;
372
393
  var currentValue = lineData2[i].value;
373
394
  p2Array.push([
374
395
  getXForLineInBar(i, firstBarWidth, currentBarWidth, yAxisLabelWidth, lineConfig2, spacing),
@@ -405,11 +426,11 @@ export var useBarChart = function (props) {
405
426
  (_53 = lineConfig.arrowConfig) === null || _53 === void 0 ? void 0 : _53.showArrowBase
406
427
  ]);
407
428
  useEffect(function () {
408
- var _a, _b, _c, _d;
429
+ var _a, _b;
409
430
  if (initialPointerIndex !== -1) {
410
- var item_1 = (_b = ((_a = props.stackData) !== null && _a !== void 0 ? _a : data)) === null || _b === void 0 ? void 0 : _b[initialPointerIndex];
411
- var stackItem = (_c = props.stackData) === null || _c === void 0 ? void 0 : _c[initialPointerIndex];
412
- var stackSum = (_d = stackItem === null || stackItem === void 0 ? void 0 : stackItem.stacks) === null || _d === void 0 ? void 0 : _d.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
431
+ var item_1 = (_a = (stackData !== null && stackData !== void 0 ? stackData : data)) === null || _a === void 0 ? void 0 : _a[initialPointerIndex];
432
+ var stackItem = stackData === null || stackData === void 0 ? void 0 : stackData[initialPointerIndex];
433
+ var stackSum = (_b = stackItem === null || stackItem === void 0 ? void 0 : stackItem.stacks) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, stack) { var _a; return acc + ((_a = stack.value) !== null && _a !== void 0 ? _a : 0); }, 0);
413
434
  var x_1 = initialSpacing +
414
435
  (spacing + barWidth) * initialPointerIndex -
415
436
  (pointerRadius !== null && pointerRadius !== void 0 ? pointerRadius : pointerWidth / 2) +
@@ -541,7 +562,7 @@ export var useBarChart = function (props) {
541
562
  yAxisAtTop: yAxisAtTop,
542
563
  initialSpacing: initialSpacing,
543
564
  data: data,
544
- stackData: props.stackData,
565
+ stackData: stackData,
545
566
  // secondaryData,
546
567
  barWidth: (_57 = props.barWidth) !== null && _57 !== void 0 ? _57 : defaultBarWidth,
547
568
  xAxisThickness: xAxisThickness,
@@ -186,7 +186,7 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
186
186
  mostNegativeValue: number;
187
187
  overflowTop: number;
188
188
  extendedContainerHeight: number;
189
- getX: (index: number) => number;
189
+ getX: (spacingArray: number[], index: number) => number;
190
190
  getY: (value: number) => number;
191
191
  secondaryMaxValue: number;
192
192
  getSecondaryY: (value: number) => number;
@@ -307,9 +307,9 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
307
307
  arrowConfig: import("../utils/types").arrowConfigType | undefined;
308
308
  };
309
309
  addLeadingAndTrailingPathForAreaFill: (initialPath: string, value: number, dataLength: number) => string;
310
- getNextPoint: (data: lineDataItem[], index: number, around: boolean, before: boolean) => string;
311
- getStepPath: (data: lineDataItem[], i: number) => string;
312
- getSegmentPath: (data: lineDataItem[], i: number, lineSegment: LineSegment[] | undefined, startIndex: number, endIndex: number, isSecondary?: boolean) => string;
310
+ getNextPoint: (data: lineDataItem[], index: number, around: boolean, before: boolean, spacingArray: number[]) => string;
311
+ getStepPath: (data: lineDataItem[], i: number, spacingArray: number[]) => string;
312
+ getSegmentPath: (data: lineDataItem[], i: number, lineSegment: LineSegment[] | undefined, startIndex: number, endIndex: number, spacingArray: number[], isSecondary?: boolean) => string;
313
313
  gradientDirection: string;
314
314
  horizSections: {
315
315
  value: string;
@@ -384,4 +384,11 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
384
384
  initialisePointers: () => void;
385
385
  barAndLineChartsWrapperProps: BarAndLineChartsWrapperTypes;
386
386
  yAxisExtraHeightAtTop: number;
387
+ cumulativeSpacing1: number[];
388
+ cumulativeSpacing2: number[];
389
+ cumulativeSpacing3: number[];
390
+ cumulativeSpacing4: number[];
391
+ cumulativeSpacing5: number[];
392
+ cumulativeSpacingSecondary: number[];
393
+ cumulativeSpacingForSet: any[];
387
394
  };