gridviz 2.0.43 → 2.0.45
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/dist/gridviz.js +50 -20
- package/dist/gridviz.min.js +1 -1
- package/package.json +1 -1
- package/src/App.js +43 -17
- package/src/Tooltip.js +6 -2
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -37,17 +37,17 @@ export class App {
|
|
|
37
37
|
this.layers = []
|
|
38
38
|
|
|
39
39
|
//get container element
|
|
40
|
-
container = container || document.getElementById('gridviz')
|
|
41
|
-
if (!container) {
|
|
40
|
+
this.container = container || document.getElementById('gridviz')
|
|
41
|
+
if (!this.container) {
|
|
42
42
|
console.error('Cannot find gridviz container element.')
|
|
43
43
|
return
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
//set dimensions
|
|
47
47
|
/** @type {number} */
|
|
48
|
-
this.w = opts.w || container.offsetWidth
|
|
48
|
+
this.w = opts.w || this.container.offsetWidth
|
|
49
49
|
/** @type {number} */
|
|
50
|
-
this.h = opts.h || container.offsetHeight
|
|
50
|
+
this.h = opts.h || this.container.offsetHeight
|
|
51
51
|
|
|
52
52
|
//create canvas element if user doesnt specify one
|
|
53
53
|
/** @type {HTMLCanvasElement} */
|
|
@@ -56,7 +56,7 @@ export class App {
|
|
|
56
56
|
canvas = document.createElement('canvas')
|
|
57
57
|
canvas.setAttribute('width', '' + this.w)
|
|
58
58
|
canvas.setAttribute('height', '' + this.h)
|
|
59
|
-
container.appendChild(canvas)
|
|
59
|
+
this.container.appendChild(canvas)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
/** Make geo canvas
|
|
@@ -161,7 +161,7 @@ export class App {
|
|
|
161
161
|
if (monitor) monitorDuration('End redraw')
|
|
162
162
|
|
|
163
163
|
// listen for resize events on the App's container and handle them
|
|
164
|
-
this.defineResizeObserver(container, canvas)
|
|
164
|
+
this.defineResizeObserver(this.container, canvas)
|
|
165
165
|
|
|
166
166
|
return this
|
|
167
167
|
}
|
|
@@ -186,7 +186,9 @@ export class App {
|
|
|
186
186
|
this.legendDivId = opts.legendDivId || 'gvizLegend'
|
|
187
187
|
this.legend = select('#' + this.legendDivId)
|
|
188
188
|
if (this.legend.empty()) {
|
|
189
|
-
this.legend = select(
|
|
189
|
+
this.legend = select(
|
|
190
|
+
this.container.id && this.container.id != '' ? '#' + this.container.id : 'body'
|
|
191
|
+
)
|
|
190
192
|
.append('div')
|
|
191
193
|
.attr('id', this.legendDivId)
|
|
192
194
|
.style('position', 'absolute')
|
|
@@ -208,7 +210,7 @@ export class App {
|
|
|
208
210
|
|
|
209
211
|
// set App container as default parent element for tooltip
|
|
210
212
|
if (!opts.tooltip) opts.tooltip = {}
|
|
211
|
-
if (!opts.tooltip.parentElement) opts.tooltip.parentElement = container
|
|
213
|
+
if (!opts.tooltip.parentElement) opts.tooltip.parentElement = this.container
|
|
212
214
|
|
|
213
215
|
/**
|
|
214
216
|
* @private
|
|
@@ -278,15 +280,14 @@ export class App {
|
|
|
278
280
|
if (this.canvasSave) this.cg.ctx.drawImage(this.canvasSave, 0, 0)
|
|
279
281
|
}
|
|
280
282
|
}
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
container.addEventListener('
|
|
288
|
-
|
|
289
|
-
})
|
|
283
|
+
|
|
284
|
+
// add event listeners to container
|
|
285
|
+
this.mouseOverHandler = (e) => focusCell(e)
|
|
286
|
+
this.mouseMoveHandler = (e) => focusCell(e)
|
|
287
|
+
this.mouseOutHandler = (e) => this.tooltip.hide()
|
|
288
|
+
this.container.addEventListener('mouseover', this.mouseOverHandler)
|
|
289
|
+
this.container.addEventListener('mousemove', this.mouseMoveHandler)
|
|
290
|
+
this.container.addEventListener('mouseout', this.mouseOutHandler)
|
|
290
291
|
|
|
291
292
|
// add extra logic to onZoomStartFun
|
|
292
293
|
this.cg.onZoomStartFun = (e) => {
|
|
@@ -639,4 +640,29 @@ export class App {
|
|
|
639
640
|
|
|
640
641
|
resizeObserver.observe(container)
|
|
641
642
|
}
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* @description Destroy the app and it's event listeners
|
|
646
|
+
* This should significantly reduce the memory used when creating and destroying gridviz app instances (for example in leaflet-gridviz)
|
|
647
|
+
* @memberof App
|
|
648
|
+
*/
|
|
649
|
+
destroy() {
|
|
650
|
+
// clear layers
|
|
651
|
+
this.layers = []
|
|
652
|
+
this.bgLayers = []
|
|
653
|
+
|
|
654
|
+
// remove event listeners from container
|
|
655
|
+
this.container.removeEventListener('mouseover', this.mouseOverHandler)
|
|
656
|
+
this.container.removeEventListener('mousemove', this.mouseMoveHandler)
|
|
657
|
+
this.container.removeEventListener('mouseout', this.mouseOutHandler)
|
|
658
|
+
|
|
659
|
+
// remove canvas
|
|
660
|
+
this.cg.canvas.remove()
|
|
661
|
+
|
|
662
|
+
// remove legend
|
|
663
|
+
this.legend?.remove()
|
|
664
|
+
|
|
665
|
+
// remove tooltip
|
|
666
|
+
this.tooltip.tooltip?.remove()
|
|
667
|
+
}
|
|
642
668
|
}
|
package/src/Tooltip.js
CHANGED
|
@@ -48,11 +48,15 @@ export class Tooltip {
|
|
|
48
48
|
this.parentElement = opts.parentElement || document.body
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
|
-
* @
|
|
51
|
+
* @public
|
|
52
52
|
* @type {import("d3-selection").Selection} */
|
|
53
53
|
this.tooltip = select('#' + this.div)
|
|
54
54
|
if (this.tooltip.empty())
|
|
55
|
-
this.tooltip = select(
|
|
55
|
+
this.tooltip = select(
|
|
56
|
+
'#' + this.parentElement.id && this.parentElement.id != ''
|
|
57
|
+
? '#' + this.parentElement.id
|
|
58
|
+
: 'body'
|
|
59
|
+
)
|
|
56
60
|
.append('div')
|
|
57
61
|
.attr('id', this.div)
|
|
58
62
|
|