gridviz 2.1.8 → 2.1.10

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.1.8",
3
+ "version": "2.1.10",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
package/src/App.js CHANGED
@@ -248,9 +248,9 @@ export class App {
248
248
  // transparent background (e.g. leaflet) 'red painting' fix
249
249
  if (opts.transparentBackground) {
250
250
  if (focus) {
251
+ this.tooltip.html(focus.html)
251
252
  this.tooltip.setPosition(e)
252
253
  this.tooltip.show()
253
- this.tooltip.html(focus.html)
254
254
  } else {
255
255
  this.tooltip.hide()
256
256
  }
@@ -263,9 +263,9 @@ export class App {
263
263
  }
264
264
 
265
265
  if (focus) {
266
+ this.tooltip.html(focus.html)
266
267
  this.tooltip.setPosition(e)
267
268
  this.tooltip.show()
268
- this.tooltip.html(focus.html)
269
269
 
270
270
  //show cell position as a rectangle
271
271
  if (!this.canvasSave) {
@@ -72,19 +72,31 @@ export class DatasetComponent {
72
72
  getCellFromPosition(posGeo, cells) {
73
73
  //compute candidate cell position
74
74
  /** @type {number} */
75
- const r = this.getResolution()
75
+ //const r = this.getResolution()
76
76
  /** @type {number} */
77
- const cellX = r * Math.floor(posGeo.x / r)
77
+ //const cellX = r * Math.floor(posGeo.x / r)
78
78
  /** @type {number} */
79
- const cellY = r * Math.floor(posGeo.y / r)
79
+ //const cellY = r * Math.floor(posGeo.y / r)
80
80
 
81
- //get cell
81
+ /*/get cell
82
82
  for (const cell of cells) {
83
83
  if (cell.x != cellX) continue
84
84
  if (cell.y != cellY) continue
85
85
  return cell
86
86
  }
87
+ return undefined*/
88
+
89
+ /** @type {number} */
90
+ const r = this.getResolution()
91
+ for (const cell of cells) {
92
+ if (posGeo.x < cell.x) continue
93
+ else if (cell.x + r < posGeo.x) continue
94
+ else if (posGeo.y < cell.y) continue
95
+ else if (cell.y + r < posGeo.y) continue
96
+ else return cell
97
+ }
87
98
  return undefined
99
+
88
100
  }
89
101
 
90
102
  //getters and setters
package/src/Tooltip.js CHANGED
@@ -73,6 +73,7 @@ export class Tooltip {
73
73
  this.tooltip.style('position', 'absolute')
74
74
  this.tooltip.style('pointer-events', 'none')
75
75
  this.tooltip.style('opacity', '0')
76
+ this.tooltip.style('text-wrap', 'nowrap')
76
77
 
77
78
  // aria-labels (thanks to wahlatlas)
78
79
  this.tooltip.attr('role', 'tooltip').attr('aria-live', 'polite')
@@ -105,9 +106,10 @@ export class Tooltip {
105
106
  setPosition(event) {
106
107
  let parentRect = this.parentElement.getBoundingClientRect()
107
108
 
108
- this.tooltip
109
- .style('left', event.pageX - parentRect.left + this.xOffset + 'px')
110
- .style('top', event.pageY - parentRect.top - this.yOffset + 'px')
109
+ let x = event.pageX + this.xOffset
110
+ let y = event.pageY - this.yOffset
111
+
112
+ this.tooltip.style('left', x + 'px').style('top', y + 'px')
111
113
 
112
114
  this.ensureTooltipInsideContainer(event, parentRect)
113
115
  }
@@ -148,25 +150,31 @@ export class Tooltip {
148
150
  * @param {DOMRect} parentRect
149
151
  */
150
152
  ensureTooltipInsideContainer = function (event, parentRect) {
151
- let ttNode = this.tooltip.node()
153
+ let node = this.tooltip.node()
154
+ let parentWidth = parentRect.width
155
+ let parentHeight = parentRect.height
152
156
 
153
157
  //too far right
154
- let maxRight = parentRect.width
155
- let ttRight = ttNode.offsetLeft + ttNode.clientWidth
156
- if (ttRight > maxRight) {
157
- let left = event.pageX - parentRect.left - ttNode.clientWidth - this.xOffset
158
- ttNode.style.left = left + 'px'
158
+ if (node.offsetLeft > parentRect.left + parentWidth - node.clientWidth) {
159
+ let left = event.x - node.clientWidth - this.xOffset
160
+ node.style.left = left + 'px'
159
161
  // check if mouse covers tooltip
160
- if (ttNode.offsetLeft + ttNode.clientWidth + parentRect.left > event.pageX) {
162
+ if (node.offsetLeft + node.clientWidth > event.x) {
161
163
  //move tooltip left so it doesnt cover mouse
162
- let left2 = event.pageX - (ttNode.clientWidth + this.xOffset + parentRect.left)
163
- ttNode.style.left = left2 + 'px'
164
+ let left2 = event.x - node.clientWidth - this.xOffset
165
+ node.style.left = left2 + 'px'
164
166
  }
167
+ // node.style.top = node.offsetTop + config.yOffset + "px";
165
168
  }
166
169
 
167
170
  //too far down
168
- if (ttNode.offsetTop + ttNode.clientHeight > parentRect.height) {
169
- ttNode.style.top = ttNode.offsetTop - ttNode.clientHeight + 'px'
171
+ if (node.offsetTop + node.clientHeight > parentRect.top + parentHeight) {
172
+ node.style.top = node.offsetTop - node.clientHeight + 'px'
173
+ }
174
+
175
+ //too far up
176
+ if (node.offsetTop < parentRect.top) {
177
+ node.style.top = parentRect.top + this.yOffset + 'px'
170
178
  }
171
179
  }
172
180
  }