gridviz 2.0.31 → 2.0.33
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/README.md +36 -1
- package/dist/gridviz.js +38 -1
- package/dist/gridviz.min.js +1 -1
- package/package.json +1 -1
- package/src/App.js +37 -0
package/package.json
CHANGED
package/src/App.js
CHANGED
|
@@ -160,6 +160,9 @@ export class App {
|
|
|
160
160
|
|
|
161
161
|
if (monitor) monitorDuration('End redraw')
|
|
162
162
|
|
|
163
|
+
// listen for resize events on the App's container and handle them
|
|
164
|
+
this.defineResizeObserver(container, canvas)
|
|
165
|
+
|
|
163
166
|
return this
|
|
164
167
|
}
|
|
165
168
|
|
|
@@ -651,4 +654,38 @@ export class App {
|
|
|
651
654
|
this.cg.setViewFromURL()
|
|
652
655
|
return this
|
|
653
656
|
}
|
|
657
|
+
|
|
658
|
+
/**
|
|
659
|
+
* @description Add a resize event observer to the Apps container and update the canvas accordingly
|
|
660
|
+
* @param {HTMLDivElement} container The App's container element
|
|
661
|
+
* @param {HTMLCanvasElement} canvas The App canvas element
|
|
662
|
+
* @memberof App
|
|
663
|
+
*/
|
|
664
|
+
defineResizeObserver(container, canvas) {
|
|
665
|
+
// listen to resize events
|
|
666
|
+
const resizeObserver = new ResizeObserver((entries) => {
|
|
667
|
+
// make sure canvas has been built
|
|
668
|
+
if (container.clientWidth > 0 && container.clientHeight > 0) {
|
|
669
|
+
// make sure we dont exceed loop limit first
|
|
670
|
+
// see: https://stackoverflow.com/questions/49384120/resizeobserver-loop-limit-exceeded
|
|
671
|
+
window.requestAnimationFrame(() => {
|
|
672
|
+
if (!Array.isArray(entries) || !entries.length) {
|
|
673
|
+
return
|
|
674
|
+
}
|
|
675
|
+
// update the app and canvas size
|
|
676
|
+
if (this.h !== container.clientHeight || this.w !== container.clientWidth) {
|
|
677
|
+
this.h = container.clientHeight
|
|
678
|
+
this.w = container.clientWidth
|
|
679
|
+
this.cg.h = container.clientHeight
|
|
680
|
+
this.cg.w = container.clientWidth
|
|
681
|
+
canvas.setAttribute('width', '' + this.w)
|
|
682
|
+
canvas.setAttribute('height', '' + this.h)
|
|
683
|
+
this.redraw()
|
|
684
|
+
}
|
|
685
|
+
})
|
|
686
|
+
}
|
|
687
|
+
})
|
|
688
|
+
|
|
689
|
+
resizeObserver.observe(container)
|
|
690
|
+
}
|
|
654
691
|
}
|