gridviz 2.0.36 → 2.0.38

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": "gridviz",
3
- "version": "2.0.36",
3
+ "version": "2.0.38",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
package/src/Tooltip.js CHANGED
@@ -99,11 +99,13 @@ export class Tooltip {
99
99
  * @param {MouseEvent} event
100
100
  */
101
101
  setPosition(event) {
102
+ let parentRect = this.parentElement.getBoundingClientRect()
103
+
102
104
  this.tooltip
103
- .style('left', event.pageX + this.xOffset + 'px')
104
- .style('top', event.pageY - this.yOffset + 'px')
105
+ .style('left', event.pageX - parentRect.left + this.xOffset + 'px')
106
+ .style('top', event.pageY - parentRect.top - this.yOffset + 'px')
105
107
 
106
- this.ensureTooltipInsideContainer(event)
108
+ this.ensureTooltipInsideContainer(event, parentRect)
107
109
  }
108
110
 
109
111
  /*
@@ -139,26 +141,28 @@ export class Tooltip {
139
141
  * @function ensureTooltipInsideContainer
140
142
  * @description Prevents the tooltip from overflowing out of the App container (ensures that the tooltip is inside the gridviz container)
141
143
  * @param {MouseEvent} event
144
+ * @param {DOMRect} parentRect
142
145
  */
143
- ensureTooltipInsideContainer = function (event) {
146
+ ensureTooltipInsideContainer = function (event, parentRect) {
144
147
  let ttNode = this.tooltip.node()
145
- let parentRect = this.parentElement.getBoundingClientRect()
146
148
 
147
149
  //too far right
148
- if (ttNode.offsetLeft > parentRect.left + parentRect.width - ttNode.clientWidth) {
149
- let left = event.pageX - ttNode.clientWidth - this.xOffset
150
+ let maxRight = parentRect.width
151
+ let ttRight = ttNode.offsetLeft + ttNode.clientWidth
152
+ if (ttRight > maxRight) {
153
+ let left = event.pageX - parentRect.left - ttNode.clientWidth - this.xOffset
150
154
  ttNode.style.left = left + 'px'
151
155
  // check if mouse covers tooltip
152
- if (ttNode.offsetLeft + ttNode.clientWidth > event.pageX) {
156
+ if (ttNode.offsetLeft + ttNode.clientWidth + parentRect.left > event.pageX) {
153
157
  //move tooltip left so it doesnt cover mouse
154
- let left2 = event.pageX - (ttNode.clientWidth + this.xOffset)
158
+ let left2 = event.pageX - (ttNode.clientWidth + this.xOffset + parentRect.left)
155
159
  ttNode.style.left = left2 + 'px'
156
160
  }
157
161
  }
158
162
 
159
163
  //too far down
160
- if (event.pageY + ttNode.clientHeight > parentRect.top + parentRect.height) {
161
- ttNode.style.top = event.pageY - ttNode.clientHeight + 'px'
164
+ if (ttNode.offsetTop + ttNode.clientHeight > parentRect.height) {
165
+ ttNode.style.top = ttNode.offsetTop - ttNode.clientHeight + 'px'
162
166
  }
163
167
  }
164
168
  }