gifted-charts-core 0.1.14 → 0.1.15

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.14",
3
+ "version": "0.1.15",
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": [
@@ -24,4 +24,17 @@ export declare const useRenderStackBars: (props: StackedBarChartPropsType) => {
24
24
  borderBottomLeftRadius: number;
25
25
  borderBottomRightRadius: number;
26
26
  };
27
+ tooltipProps: {
28
+ barHeight: number;
29
+ barWidth: number;
30
+ item: stackDataItem;
31
+ index: number;
32
+ isLast: boolean;
33
+ leftSpacing: number;
34
+ leftShiftForLastIndexTooltip: number;
35
+ leftShiftForTooltip: number;
36
+ renderTooltip: Function | undefined;
37
+ autoCenterTooltip: boolean | undefined;
38
+ horizontal: boolean;
39
+ };
27
40
  };
@@ -16,8 +16,8 @@ var __read = (this && this.__read) || function (o, n) {
16
16
  };
17
17
  import { useState } from 'react';
18
18
  export var useRenderStackBars = function (props) {
19
- var _a, _b, _c, _d, _e, _f;
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;
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;
21
21
  var cotainsNegative = item.stacks.some(function (item) { return item.value < 0; });
22
22
  var noAnimation = cotainsNegative || !isAnimated;
23
23
  var localBarInnerComponent = (_a = item.barInnerComponent) !== null && _a !== void 0 ? _a : props.barInnerComponent;
@@ -33,7 +33,7 @@ export var useRenderStackBars = function (props) {
33
33
  return acc +
34
34
  (Math.abs(stack.value) * (containerHeight !== null && containerHeight !== void 0 ? containerHeight : 200)) / (maxValue || 200);
35
35
  }, 0);
36
- var _g = __read(useState(noAnimation ? totalHeight : 1), 2), height = _g[0], setHeight = _g[1];
36
+ var _j = __read(useState(noAnimation ? totalHeight : 1), 2), height = _j[0], setHeight = _j[1];
37
37
  var getBarHeight = function (value, marginBottom) {
38
38
  return ((Math.abs(value) * (containerHeight !== null && containerHeight !== void 0 ? containerHeight : 200)) / (maxValue || 200) -
39
39
  (marginBottom !== null && marginBottom !== void 0 ? marginBottom : 0));
@@ -76,6 +76,19 @@ export var useRenderStackBars = function (props) {
76
76
  };
77
77
  return borderRadii;
78
78
  };
79
+ var tooltipProps = {
80
+ barHeight: totalHeight,
81
+ barWidth: item.barWidth || props.barWidth || 30,
82
+ item: item,
83
+ index: index,
84
+ isLast: index === stackData.length - 1,
85
+ leftSpacing: leftSpacing,
86
+ leftShiftForLastIndexTooltip: leftShiftForLastIndexTooltip,
87
+ leftShiftForTooltip: (_h = (_g = item.leftShiftForTooltip) !== null && _g !== void 0 ? _g : leftShiftForTooltip) !== null && _h !== void 0 ? _h : 0,
88
+ renderTooltip: renderTooltip,
89
+ autoCenterTooltip: autoCenterTooltip,
90
+ horizontal: horizontal
91
+ };
79
92
  return {
80
93
  cotainsNegative: cotainsNegative,
81
94
  noAnimation: noAnimation,
@@ -94,6 +107,7 @@ export var useRenderStackBars = function (props) {
94
107
  getPosition: getPosition,
95
108
  getLowestPosition: getLowestPosition,
96
109
  lowestBarPosition: lowestBarPosition,
97
- getStackBorderRadii: getStackBorderRadii
110
+ getStackBorderRadii: getStackBorderRadii,
111
+ tooltipProps: tooltipProps
98
112
  };
99
113
  };
@@ -11,7 +11,12 @@ export const useRenderStackBars = (props: StackedBarChartPropsType) => {
11
11
  initialSpacing,
12
12
  stackData,
13
13
  isAnimated,
14
- xAxisThickness
14
+ xAxisThickness,
15
+ renderTooltip,
16
+ leftShiftForTooltip,
17
+ leftShiftForLastIndexTooltip,
18
+ autoCenterTooltip,
19
+ horizontal
15
20
  } = props
16
21
  const cotainsNegative = item.stacks.some((item) => item.value < 0)
17
22
  const noAnimation = cotainsNegative || !isAnimated
@@ -117,6 +122,20 @@ export const useRenderStackBars = (props: StackedBarChartPropsType) => {
117
122
  return borderRadii
118
123
  }
119
124
 
125
+ const tooltipProps = {
126
+ barHeight: totalHeight,
127
+ barWidth: item.barWidth || props.barWidth || 30,
128
+ item,
129
+ index,
130
+ isLast: index === stackData.length - 1,
131
+ leftSpacing,
132
+ leftShiftForLastIndexTooltip,
133
+ leftShiftForTooltip: item.leftShiftForTooltip ?? leftShiftForTooltip ?? 0,
134
+ renderTooltip,
135
+ autoCenterTooltip,
136
+ horizontal
137
+ }
138
+
120
139
  return {
121
140
  cotainsNegative,
122
141
  noAnimation,
@@ -135,6 +154,7 @@ export const useRenderStackBars = (props: StackedBarChartPropsType) => {
135
154
  getPosition,
136
155
  getLowestPosition,
137
156
  lowestBarPosition,
138
- getStackBorderRadii
157
+ getStackBorderRadii,
158
+ tooltipProps
139
159
  }
140
160
  }
@@ -103,6 +103,7 @@ export interface StackedBarChartPropsType {
103
103
  renderTooltip: Function | undefined;
104
104
  leftShiftForTooltip?: number;
105
105
  leftShiftForLastIndexTooltip: number;
106
+ autoCenterTooltip?: boolean;
106
107
  initialSpacing: number;
107
108
  selectedIndex: number;
108
109
  setSelectedIndex: Function;
@@ -121,6 +121,7 @@ export interface StackedBarChartPropsType {
121
121
  renderTooltip: Function | undefined
122
122
  leftShiftForTooltip?: number
123
123
  leftShiftForLastIndexTooltip: number
124
+ autoCenterTooltip?: boolean
124
125
  initialSpacing: number
125
126
  selectedIndex: number
126
127
  setSelectedIndex: Function