gifted-charts-core 0.1.49 → 0.1.51

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/README.md CHANGED
@@ -1 +1,4 @@
1
- This library contains the common code used by [react-native-gifted-charts](https://www.npmjs.com/package/react-native-gifted-charts) and [react-gifted-charts](https://www.npmjs.com/package/react-gifted-charts).
1
+ This library contains the common code used by [react-native-gifted-charts](https://www.npmjs.com/package/react-native-gifted-charts) and [react-gifted-charts](https://www.npmjs.com/package/react-gifted-charts). <br/><br />
2
+
3
+
4
+ ![Gifted charts](https://raw.githubusercontent.com/Abhinandan-Kushwaha/react-native-gifted-charts/14f8fa316ed9b2d6bd188ad73484c82fca857fe0/docs/dev/gifted-charts-architecture.drawio.svg)
@@ -1,8 +1,8 @@
1
1
  import { type ColorValue, type ViewStyle } from 'react-native';
2
- import { type FocusedBarConfig, type BarChartPropsType, type CommonPropsFor2dand3dBarsType, type barDataItem, type stackDataItem } from './types';
2
+ import { type FocusedBarConfig, type BarChartPropsType, type CommonPropsFor2dand3dBarsType, type barDataItem, type stackDataItem, barDataItemNullSafe } from './types';
3
3
  import { type ReactNode } from 'react';
4
4
  interface Animated2dWithGradientPropsType extends BarChartPropsType {
5
- item: barDataItem;
5
+ item: barDataItemNullSafe;
6
6
  index: number;
7
7
  barHeight: number;
8
8
  selectedIndex: number;
@@ -0,0 +1,8 @@
1
+ import { TooltipProps } from '../utils/types';
2
+ import { RenderBarsPropsType } from './types';
3
+ export declare const useRenderBars: (props: RenderBarsPropsType) => {
4
+ heightFactor: number;
5
+ barHeight: number;
6
+ leftSpacing: number;
7
+ tooltipProps: TooltipProps;
8
+ };
@@ -0,0 +1,51 @@
1
+ import { AxesAndRulesDefaults } from '../utils/constants';
2
+ export var useRenderBars = function (props) {
3
+ var _a, _b, _c;
4
+ var data = props.data, item = props.item, index = props.index, barWidth = props.barWidth, initialSpacing = props.initialSpacing, propSpacing = props.propSpacing, secondaryNegativeStepHeight = props.secondaryNegativeStepHeight, secondaryStepHeight = props.secondaryStepHeight, secondaryNegativeStepValue = props.secondaryNegativeStepValue, secondaryStepValue = props.secondaryStepValue, negativeStepHeight = props.negativeStepHeight, negativeStepValue = props.negativeStepValue, stepHeight = props.stepHeight, stepValue = props.stepValue, minHeight = props.minHeight, _d = props.xAxisThickness, xAxisThickness = _d === void 0 ? AxesAndRulesDefaults.xAxisThickness : _d, leftShiftForLastIndexTooltip = props.leftShiftForLastIndexTooltip, leftShiftForTooltip = props.leftShiftForTooltip, renderTooltip = props.renderTooltip, autoCenterTooltip = props.autoCenterTooltip, horizontal = props.horizontal, containerHeight = props.containerHeight, containerHeightIncludingBelowXAxis = props.containerHeightIncludingBelowXAxis;
5
+ var heightFactor = item.isSecondary
6
+ ? item.value < 0
7
+ ? (secondaryNegativeStepHeight !== null && secondaryNegativeStepHeight !== void 0 ? secondaryNegativeStepHeight : secondaryStepHeight) /
8
+ (secondaryNegativeStepValue !== null && secondaryNegativeStepValue !== void 0 ? secondaryNegativeStepValue : secondaryStepValue)
9
+ : secondaryStepHeight / secondaryStepValue
10
+ : item.value < 0
11
+ ? negativeStepHeight / negativeStepValue
12
+ : stepHeight / stepValue;
13
+ var barHeight = Math.max(minHeight, Math.abs(item.value) * heightFactor - xAxisThickness);
14
+ var leftSpacing = initialSpacing;
15
+ for (var i = 0; i < index; i++) {
16
+ leftSpacing +=
17
+ ((_a = data[i].spacing) !== null && _a !== void 0 ? _a : propSpacing) + (data[i].barWidth || barWidth);
18
+ }
19
+ var containsNegativeValue = data.some(function (item) { return item.value < 0; });
20
+ var chartHeightBelowXAxis = containerHeightIncludingBelowXAxis - containerHeight;
21
+ var getBotomForTooltip = function () {
22
+ if (item.value < 0) {
23
+ return chartHeightBelowXAxis - barHeight - 34;
24
+ }
25
+ else {
26
+ return ((containsNegativeValue
27
+ ? barHeight + chartHeightBelowXAxis - 8
28
+ : barHeight) + 2);
29
+ }
30
+ };
31
+ var tooltipProps = {
32
+ barHeight: barHeight,
33
+ barWidth: item.barWidth || barWidth,
34
+ item: item,
35
+ index: index,
36
+ isLast: index === data.length - 1,
37
+ leftSpacing: leftSpacing,
38
+ leftShiftForLastIndexTooltip: leftShiftForLastIndexTooltip,
39
+ leftShiftForTooltip: (_c = (_b = item.leftShiftForTooltip) !== null && _b !== void 0 ? _b : leftShiftForTooltip) !== null && _c !== void 0 ? _c : 0,
40
+ renderTooltip: renderTooltip,
41
+ autoCenterTooltip: autoCenterTooltip,
42
+ horizontal: horizontal,
43
+ bottom: getBotomForTooltip()
44
+ };
45
+ return {
46
+ heightFactor: heightFactor,
47
+ barHeight: barHeight,
48
+ leftSpacing: leftSpacing,
49
+ tooltipProps: tooltipProps
50
+ };
51
+ };
@@ -1,4 +1,5 @@
1
1
  import { type StackedBarChartPropsType, type stackDataItem } from './types';
2
+ import { TooltipProps } from '../utils/types';
2
3
  export declare const useRenderStackBars: (props: StackedBarChartPropsType) => {
3
4
  containsNegativeValue: boolean;
4
5
  noAnimation: boolean;
@@ -23,17 +24,5 @@ export declare const useRenderStackBars: (props: StackedBarChartPropsType) => {
23
24
  borderBottomLeftRadius: number;
24
25
  borderBottomRightRadius: number;
25
26
  };
26
- tooltipProps: {
27
- barHeight: number;
28
- barWidth: number;
29
- item: stackDataItem;
30
- index: number;
31
- isLast: boolean;
32
- leftSpacing: number;
33
- leftShiftForLastIndexTooltip: number;
34
- leftShiftForTooltip: number;
35
- renderTooltip: Function | undefined;
36
- autoCenterTooltip: boolean | undefined;
37
- horizontal: boolean;
38
- };
27
+ tooltipProps: TooltipProps;
39
28
  };
@@ -17,8 +17,11 @@ var __read = (this && this.__read) || function (o, n) {
17
17
  import { useState } from 'react';
18
18
  export var useRenderStackBars = function (props) {
19
19
  var _a, _b, _c, _d, _e, _f, _g, _h;
20
- var item = props.item, index = props.index, containerHeight = props.containerHeight, maxValue = props.maxValue, propSpacing = props.propSpacing, initialSpacing = props.initialSpacing, stackData = props.stackData, isAnimated = props.isAnimated, xAxisThickness = props.xAxisThickness, renderTooltip = props.renderTooltip, leftShiftForTooltip = props.leftShiftForTooltip, leftShiftForLastIndexTooltip = props.leftShiftForLastIndexTooltip, autoCenterTooltip = props.autoCenterTooltip, horizontal = props.horizontal, stepHeight = props.stepHeight, stepValue = props.stepValue, negativeStepHeight = props.negativeStepHeight, negativeStepValue = props.negativeStepValue, secondaryStepHeight = props.secondaryStepHeight, secondaryStepValue = props.secondaryStepValue, secondaryNegativeStepHeight = props.secondaryNegativeStepHeight, secondaryNegativeStepValue = props.secondaryNegativeStepValue;
20
+ var item = props.item, index = props.index, _j = props.containerHeight, containerHeight = _j === void 0 ? 200 : _j, containerHeightIncludingBelowXAxis = props.containerHeightIncludingBelowXAxis, maxValue = props.maxValue, propSpacing = props.propSpacing, initialSpacing = props.initialSpacing, stackData = props.stackData, isAnimated = props.isAnimated, xAxisThickness = props.xAxisThickness, renderTooltip = props.renderTooltip, leftShiftForTooltip = props.leftShiftForTooltip, leftShiftForLastIndexTooltip = props.leftShiftForLastIndexTooltip, autoCenterTooltip = props.autoCenterTooltip, horizontal = props.horizontal, stepHeight = props.stepHeight, stepValue = props.stepValue, negativeStepHeight = props.negativeStepHeight, negativeStepValue = props.negativeStepValue, secondaryStepHeight = props.secondaryStepHeight, secondaryStepValue = props.secondaryStepValue, secondaryNegativeStepHeight = props.secondaryNegativeStepHeight, secondaryNegativeStepValue = props.secondaryNegativeStepValue;
21
21
  var containsNegativeValue = item.stacks.some(function (item) { return item.value < 0; });
22
+ var anyStackContainsNegativeValue = stackData.some(function (item) {
23
+ return item.stacks.some(function (stack) { return stack.value < 0; });
24
+ });
22
25
  var noAnimation = containsNegativeValue || !isAnimated;
23
26
  var localBarInnerComponent = (_a = item.barInnerComponent) !== null && _a !== void 0 ? _a : props.barInnerComponent;
24
27
  var borderRadius = item.borderRadius, borderTopLeftRadius = item.borderTopLeftRadius, borderTopRightRadius = item.borderTopRightRadius, borderBottomLeftRadius = item.borderBottomLeftRadius, borderBottomRightRadius = item.borderBottomRightRadius;
@@ -40,7 +43,7 @@ export var useRenderStackBars = function (props) {
40
43
  Math.abs(stack.value) *
41
44
  (stack.value < 0 ? negativeHeightFactor : heightFactor);
42
45
  }, 0);
43
- var _j = __read(useState(noAnimation ? totalHeight : 1), 2), height = _j[0], setHeight = _j[1];
46
+ var _k = __read(useState(noAnimation ? totalHeight : 1), 2), height = _k[0], setHeight = _k[1];
44
47
  var getBarHeight = function (value, marginBottom) {
45
48
  return (Math.abs(value) * (value < 0 ? negativeHeightFactor : heightFactor) -
46
49
  (marginBottom !== null && marginBottom !== void 0 ? marginBottom : 0));
@@ -48,10 +51,6 @@ export var useRenderStackBars = function (props) {
48
51
  var getPosition = function (index, height) {
49
52
  /* Returns bottom position for stack item
50
53
  negative values are below origin (-> negative position) */
51
- // const height = getBarHeight(
52
- // item.stacks[index].value,
53
- // item.stacks[index].marginBottom
54
- // )
55
54
  var itemValue = item.stacks[index].value;
56
55
  var isNegative = itemValue <= 0;
57
56
  var position = isNegative ? -(height || 0) - xAxisThickness : 0;
@@ -72,10 +71,19 @@ export var useRenderStackBars = function (props) {
72
71
  var _a;
73
72
  return (((_a = item.stacks
74
73
  .map(function (_, index) {
75
- return getPosition(index, getBarHeight(index, _.marginBottom));
74
+ return getPosition(index, getBarHeight(_.value, _.marginBottom));
76
75
  })
77
76
  .sort(function (a, b) { return a - b; })) === null || _a === void 0 ? void 0 : _a[0]) || 0);
78
77
  };
78
+ var getPositiveBoxesHeightSum = function () {
79
+ var sum = 0;
80
+ item.stacks.forEach(function (_, ind) {
81
+ var value = _.value;
82
+ sum += value > 0 ? getBarHeight(value, _.marginBottom) : 0;
83
+ console.log(ind, sum);
84
+ });
85
+ return sum;
86
+ };
79
87
  var lowestBarPosition = getLowestPosition();
80
88
  var getStackBorderRadii = function (item, index) {
81
89
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
@@ -88,8 +96,25 @@ export var useRenderStackBars = function (props) {
88
96
  };
89
97
  return borderRadii;
90
98
  };
99
+ var chartHeightBelowXAxis = containerHeightIncludingBelowXAxis - containerHeight;
100
+ var barHeight = totalHeight;
101
+ var getBotomForTooltip = function () {
102
+ var _a;
103
+ if (anyStackContainsNegativeValue) {
104
+ // If any of the stacks has a negative value
105
+ if (item.stacks.some(function (stack) { return stack.value > 0; })) {
106
+ // if a box in the current stack has a +ve value
107
+ return chartHeightBelowXAxis + ((_a = getPositiveBoxesHeightSum()) !== null && _a !== void 0 ? _a : 0) - 8;
108
+ }
109
+ else
110
+ return chartHeightBelowXAxis - barHeight - 34;
111
+ }
112
+ else {
113
+ return barHeight + 2;
114
+ }
115
+ };
91
116
  var tooltipProps = {
92
- barHeight: totalHeight,
117
+ barHeight: barHeight,
93
118
  barWidth: item.barWidth || props.barWidth || 30,
94
119
  item: item,
95
120
  index: index,
@@ -99,7 +124,8 @@ export var useRenderStackBars = function (props) {
99
124
  leftShiftForTooltip: (_h = (_g = item.leftShiftForTooltip) !== null && _g !== void 0 ? _g : leftShiftForTooltip) !== null && _h !== void 0 ? _h : 0,
100
125
  renderTooltip: renderTooltip,
101
126
  autoCenterTooltip: autoCenterTooltip,
102
- horizontal: horizontal
127
+ horizontal: horizontal,
128
+ bottom: getBotomForTooltip()
103
129
  };
104
130
  return {
105
131
  containsNegativeValue: containsNegativeValue,
@@ -1,4 +1,4 @@
1
- import { type lineConfigType, type barDataItem, type stackDataItem, BarChartPropsTypeForWeb } from './types';
1
+ import { type lineConfigType, type barDataItem, type stackDataItem, BarChartPropsTypeForWeb, barDataItemNullSafe } from './types';
2
2
  import { type BarAndLineChartsWrapperTypes, type secondaryYAxisType } from '../utils/types';
3
3
  import { type Animated } from 'react-native';
4
4
  export interface extendedBarChartPropsType extends BarChartPropsTypeForWeb {
@@ -41,7 +41,7 @@ export declare const useBarChart: (props: extendedBarChartPropsType) => {
41
41
  setPointerItem: import("react").Dispatch<import("react").SetStateAction<barDataItem | stackDataItem | undefined>>;
42
42
  initialSpacing: number;
43
43
  spacing: number;
44
- data: barDataItem[];
44
+ data: barDataItemNullSafe[];
45
45
  barWidth: number;
46
46
  setPointerX: import("react").Dispatch<import("react").SetStateAction<number>>;
47
47
  setPointerIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
@@ -120,6 +120,7 @@ export declare const useBarChart: (props: extendedBarChartPropsType) => {
120
120
  item: any;
121
121
  index: number;
122
122
  containerHeight: number;
123
+ containerHeightIncludingBelowXAxis: number;
123
124
  maxValue: number;
124
125
  spacing: any;
125
126
  propSpacing: number;
@@ -49,7 +49,10 @@ export var useBarChart = function (props) {
49
49
  return (__assign(__assign({}, item), { value: ((_a = item.value) !== null && _a !== void 0 ? _a : 0) - yAxisOffset }));
50
50
  });
51
51
  }
52
- return props.data;
52
+ return props.data.map(function (item) {
53
+ var _a;
54
+ return (__assign(__assign({}, item), { value: (_a = item.value) !== null && _a !== void 0 ? _a : 0 }));
55
+ });
53
56
  }, [yAxisOffset, props.data]);
54
57
  var stackData = useMemo(function () {
55
58
  if (!props.stackData) {
@@ -474,6 +477,7 @@ export var useBarChart = function (props) {
474
477
  item: item,
475
478
  index: index,
476
479
  containerHeight: containerHeight,
480
+ containerHeightIncludingBelowXAxis: containerHeightIncludingBelowXAxis,
477
481
  maxValue: maxValue,
478
482
  spacing: (_a = item.spacing) !== null && _a !== void 0 ? _a : spacing,
479
483
  propSpacing: spacing,
@@ -74,7 +74,7 @@ export interface StackedBarChartPropsType {
74
74
  disablePress?: boolean;
75
75
  item: stackDataItem;
76
76
  index: number;
77
- containerHeight?: number;
77
+ containerHeight: number;
78
78
  maxValue: number;
79
79
  spacing: number;
80
80
  propSpacing?: number;
@@ -136,7 +136,7 @@ export interface StackedBarChartPropsType {
136
136
  secondaryNegativeStepHeight: number;
137
137
  secondaryNegativeStepValue: number;
138
138
  secondaryNoOfSectionsBelowXAxis: number;
139
- containerHeightIncludingBelowXAxis?: number;
139
+ containerHeightIncludingBelowXAxis: number;
140
140
  }
141
141
  export interface BarChartPropsType {
142
142
  width?: number;
@@ -407,7 +407,7 @@ interface sectionType {
407
407
  value: string;
408
408
  }
409
409
  export interface barDataItem {
410
- value: number;
410
+ value?: number;
411
411
  onPress?: any;
412
412
  onLongPress?: any;
413
413
  onPressOut?: any;
@@ -454,8 +454,11 @@ export interface barDataItem {
454
454
  onMouseEnter?: Function;
455
455
  onMouseLeave?: Function;
456
456
  }
457
+ export interface barDataItemNullSafe extends barDataItem {
458
+ value: number;
459
+ }
457
460
  export interface Animated2DWithGradientPropsType {
458
- item: barDataItem;
461
+ item: barDataItemNullSafe;
459
462
  index: number;
460
463
  height: number;
461
464
  minHeight: number;
@@ -513,11 +516,12 @@ export interface RenderBarsPropsType {
513
516
  side?: string;
514
517
  labelTextStyle?: any;
515
518
  secondaryLabelTextStyle?: any;
516
- item: barDataItem;
519
+ item: barDataItemNullSafe;
517
520
  index: number;
518
521
  label: string;
519
522
  secondaryLabel: string;
520
- containerHeight?: number;
523
+ containerHeight: number;
524
+ containerHeightIncludingBelowXAxis: number;
521
525
  maxValue: number;
522
526
  spacing: number;
523
527
  propSpacing?: number;
@@ -633,7 +637,7 @@ export interface CommonPropsFor2dand3dBarsType {
633
637
  patternId?: string;
634
638
  barWidth: number;
635
639
  barStyle?: object;
636
- item: barDataItem;
640
+ item: barDataItemNullSafe;
637
641
  index: number;
638
642
  frontColor: ColorValue;
639
643
  showGradient: boolean;
@@ -1,5 +1,5 @@
1
- import { type LineChartPropsType, type lineDataItem } from './types';
2
- import { type BarAndLineChartsWrapperTypes, EdgePosition, type LineSegment } from '../utils/types';
1
+ import { lineDataItemNullSafe, type LineChartPropsType, type lineDataItem } from './types';
2
+ import { type BarAndLineChartsWrapperTypes, EdgePosition, type LineSegment, DataSetNullSafe } from '../utils/types';
3
3
  export interface extendedLineChartPropsType extends LineChartPropsType {
4
4
  parentWidth: number;
5
5
  }
@@ -92,14 +92,14 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
92
92
  setSelectedIndex: import("react").Dispatch<import("react").SetStateAction<number>>;
93
93
  noOfSections: number;
94
94
  containerHeight: number;
95
- data: lineDataItem[];
96
- data2: lineDataItem[];
97
- data3: lineDataItem[];
98
- data4: lineDataItem[];
99
- data5: lineDataItem[];
100
- secondaryData: lineDataItem[] | import("..").barDataItem[];
101
- dataSet: import("../utils/types").DataSet[] | undefined;
102
- data0: lineDataItem[] | undefined;
95
+ data: lineDataItemNullSafe[];
96
+ data2: lineDataItemNullSafe[];
97
+ data3: lineDataItemNullSafe[];
98
+ data4: lineDataItemNullSafe[];
99
+ data5: lineDataItemNullSafe[];
100
+ secondaryData: lineDataItemNullSafe[] | import("..").barDataItemNullSafe[];
101
+ dataSet: DataSetNullSafe[] | undefined;
102
+ data0: lineDataItemNullSafe[] | undefined;
103
103
  scrollToEnd: boolean;
104
104
  scrollAnimation: boolean;
105
105
  scrollEventThrottle: number;
@@ -107,6 +107,7 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
107
107
  animationDuration: number;
108
108
  onDataChangeAnimationDuration: number;
109
109
  animateTogether: boolean;
110
+ renderDataPointsAfterAnimationEnds: boolean;
110
111
  animateOnDataChange: boolean;
111
112
  startIndex1: number;
112
113
  startIndex2: number;
@@ -307,9 +308,9 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
307
308
  arrowConfig: import("../utils/types").arrowConfigType | undefined;
308
309
  };
309
310
  addLeadingAndTrailingPathForAreaFill: (initialPath: string, value: number, dataLength: number) => 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;
311
+ getNextPoint: (data: lineDataItemNullSafe[], index: number, around: boolean, before: boolean, spacingArray: number[]) => string;
312
+ getStepPath: (data: lineDataItemNullSafe[], i: number, spacingArray: number[]) => string;
313
+ getSegmentPath: (data: lineDataItemNullSafe[], i: number, lineSegment: LineSegment[] | undefined, startIndex: number, endIndex: number, spacingArray: number[], isSecondary?: boolean) => string;
313
314
  gradientDirection: string;
314
315
  horizSections: {
315
316
  value: string;
@@ -396,7 +397,11 @@ export declare const useLineChart: (props: extendedLineChartPropsType) => {
396
397
  cumulativeSpacingForSet: any[];
397
398
  stripOverDataPoints: boolean | undefined;
398
399
  strips: any;
400
+ selectedLineNumber: number;
401
+ setSelectedLineNumber: import("react").Dispatch<import("react").SetStateAction<number>>;
399
402
  lastLineNumber: number;
400
403
  focusTogether: boolean;
401
404
  focusProximity: number;
405
+ handleFocus: (index: number, item: lineDataItemNullSafe, locationY: number, onStripPress: Function) => void;
406
+ handleUnFocus: () => void;
402
407
  };