sag_components 1.0.1069 → 1.0.1071

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.
@@ -93,24 +93,27 @@ const Heatmap = props => {
93
93
  duration: 0.4
94
94
  },
95
95
  onMouseEnter: e => {
96
- var _barRefs$current$inde;
96
+ var _barRefs$current$inde, _barsContainerRef$cur;
97
97
  const barRect = (_barRefs$current$inde = barRefs.current[index]) === null || _barRefs$current$inde === void 0 ? void 0 : _barRefs$current$inde.getBoundingClientRect();
98
+ const parentRect = (_barsContainerRef$cur = barsContainerRef.current) === null || _barsContainerRef$cur === void 0 ? void 0 : _barsContainerRef$cur.getBoundingClientRect();
98
99
  if (barRect && e.clientX > barRect.x && e.clientX < barRect.x + barRect.width && e.clientY > barRect.y && e.clientY < barRect.y + barRect.height) {
99
- var _e$nativeEvent, _e$nativeEvent2;
100
100
  setTooltip({
101
101
  label: `${item.label} - ${Math.round(item.value / totalValue * 100)}%`
102
102
  });
103
- // Prevent setting tooltip position if mouse is over the tooltip element
104
103
  if (e.target.classList.contains('TooltipContainer')) {
105
104
  return; // Exit early if mouse is over the tooltip
106
105
  }
107
- if ((_e$nativeEvent = e.nativeEvent) !== null && _e$nativeEvent !== void 0 && _e$nativeEvent.layerX && (_e$nativeEvent2 = e.nativeEvent) !== null && _e$nativeEvent2 !== void 0 && _e$nativeEvent2.layerY) {
108
- var _e$nativeEvent3, _e$nativeEvent4;
106
+ if (parentRect) {
107
+ let tooltipX = e.clientX; // Default: Position to the right of the cursor
108
+ const tooltipWidth = 200; // Estimate tooltip width (adjust as needed)
109
+
110
+ // If tooltip would overflow, move it to the left of the cursor
111
+ if (tooltipX + tooltipWidth > parentRect.right) {
112
+ tooltipX = e.clientX - tooltipWidth - 10;
113
+ }
109
114
  setTooltipPosition({
110
- // eslint-disable-next-line no-unsafe-optional-chaining
111
- x: ((_e$nativeEvent3 = e.nativeEvent) === null || _e$nativeEvent3 === void 0 ? void 0 : _e$nativeEvent3.layerX) + 10,
112
- // eslint-disable-next-line no-unsafe-optional-chaining
113
- y: ((_e$nativeEvent4 = e.nativeEvent) === null || _e$nativeEvent4 === void 0 ? void 0 : _e$nativeEvent4.layerY) + 20
115
+ x: tooltipX,
116
+ y: +30
114
117
  });
115
118
  }
116
119
  }
@@ -123,21 +126,22 @@ const Heatmap = props => {
123
126
  }
124
127
  },
125
128
  onMouseMove: e => {
126
- var _barRefs$current$inde3;
129
+ var _barRefs$current$inde3, _barsContainerRef$cur2;
127
130
  const barRect = (_barRefs$current$inde3 = barRefs.current[index]) === null || _barRefs$current$inde3 === void 0 ? void 0 : _barRefs$current$inde3.getBoundingClientRect();
131
+ const parentRect = (_barsContainerRef$cur2 = barsContainerRef.current) === null || _barsContainerRef$cur2 === void 0 ? void 0 : _barsContainerRef$cur2.getBoundingClientRect();
128
132
  if (barRect && e.clientX > barRect.x && e.clientX < barRect.x + barRect.width && e.clientY > barRect.y && e.clientY < barRect.y + barRect.height) {
129
- var _e$nativeEvent5, _e$nativeEvent6;
130
- // Prevent setting tooltip position if mouse is over the tooltip element
131
133
  if (e.target.classList.contains('TooltipContainer')) {
132
134
  return; // Exit early if mouse is over the tooltip
133
135
  }
134
- if ((_e$nativeEvent5 = e.nativeEvent) !== null && _e$nativeEvent5 !== void 0 && _e$nativeEvent5.layerX && (_e$nativeEvent6 = e.nativeEvent) !== null && _e$nativeEvent6 !== void 0 && _e$nativeEvent6.layerY) {
135
- var _e$nativeEvent7, _e$nativeEvent8;
136
+ if (parentRect) {
137
+ let tooltipX = e.clientX;
138
+ const tooltipWidth = 200;
139
+ if (tooltipX + tooltipWidth > parentRect.right) {
140
+ tooltipX = e.clientX - tooltipWidth - 10;
141
+ }
136
142
  setTooltipPosition({
137
- // eslint-disable-next-line no-unsafe-optional-chaining
138
- x: ((_e$nativeEvent7 = e.nativeEvent) === null || _e$nativeEvent7 === void 0 ? void 0 : _e$nativeEvent7.layerX) + 10,
139
- // eslint-disable-next-line no-unsafe-optional-chaining
140
- y: ((_e$nativeEvent8 = e.nativeEvent) === null || _e$nativeEvent8 === void 0 ? void 0 : _e$nativeEvent8.layerY) + 20
143
+ x: tooltipX,
144
+ y: +30
141
145
  });
142
146
  }
143
147
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sag_components",
3
- "version": "1.0.1069",
3
+ "version": "1.0.1071",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {