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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gridviz",
3
- "version": "2.0.31",
3
+ "version": "2.0.33",
4
4
  "description": "Visualization tool for gridded statistics",
5
5
  "keywords": [
6
6
  "statistics",
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
  }