gridviz 2.0.35 → 2.0.37

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.35",
3
+ "version": "2.0.37",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
package/src/Tooltip.js CHANGED
@@ -100,8 +100,8 @@ export class Tooltip {
100
100
  */
101
101
  setPosition(event) {
102
102
  this.tooltip
103
- .style('left', event.pageX + this.xOffset + 'px')
104
- .style('top', event.pageY - this.yOffset + 'px')
103
+ .style('left', event.pageX - this.parentElement.offsetLeft + this.xOffset + 'px')
104
+ .style('top', event.pageY - this.parentElement.offsetTop - this.yOffset + 'px')
105
105
 
106
106
  this.ensureTooltipInsideContainer(event)
107
107
  }
@@ -141,26 +141,26 @@ export class Tooltip {
141
141
  * @param {MouseEvent} event
142
142
  */
143
143
  ensureTooltipInsideContainer = function (event) {
144
- let node = this.tooltip.node()
145
- let rect = this.parentElement.getBoundingClientRect()
146
- let parentWidth = rect.width
147
- let parentHeight = rect.height
144
+ let ttNode = this.tooltip.node()
145
+ let parentRect = this.parentElement.getBoundingClientRect()
148
146
 
149
147
  //too far right
150
- if (node.offsetLeft > rect.left + parentWidth - node.clientWidth) {
151
- let left = event.x - node.clientWidth - this.xOffset
152
- node.style.left = left + 'px'
148
+ let maxRight = parentRect.width
149
+ let ttRight = ttNode.offsetLeft + ttNode.clientWidth
150
+ if (ttRight > maxRight) {
151
+ let left = event.pageX - this.parentElement.offsetLeft - ttNode.clientWidth - this.xOffset
152
+ ttNode.style.left = left + 'px'
153
153
  // check if mouse covers tooltip
154
- if (node.offsetLeft + node.clientWidth > event.x) {
154
+ if (ttNode.offsetLeft + ttNode.clientWidth + this.parentElement.offsetLeft > event.pageX) {
155
155
  //move tooltip left so it doesnt cover mouse
156
- let left2 = event.x - (node.clientWidth + this.xOffset)
157
- node.style.left = left2 + 'px'
156
+ let left2 = event.pageX - (ttNode.clientWidth + this.xOffset + this.parentElement.offsetLeft)
157
+ ttNode.style.left = left2 + 'px'
158
158
  }
159
159
  }
160
160
 
161
161
  //too far down
162
- if (node.offsetTop + node.clientHeight > rect.top + parentHeight) {
163
- node.style.top = node.offsetTop - node.clientHeight + 'px'
162
+ if (ttNode.offsetTop + ttNode.clientHeight > parentRect.height) {
163
+ ttNode.style.top = ttNode.offsetTop - ttNode.clientHeight + 'px'
164
164
  }
165
165
  }
166
166
  }