squarified 0.6.1 → 0.6.2

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.
@@ -1095,8 +1095,8 @@ function squarify(data, rect, config, scale = 1) {
1095
1095
  const totalArea = rect.w * rect.h;
1096
1096
  const containerSize = Math.min(rect.w, rect.h);
1097
1097
  const scaleFactor = Math.max(0.5, Math.min(1, containerSize / 800));
1098
- // evaluate minimum renderable size
1099
- const minRenderableSize = Math.max(20, containerSize * 0.05) / scale;
1098
+ const baseMinSize = 20;
1099
+ const minRenderableSize = Math.max(8, baseMinSize / Math.sqrt(scale));
1100
1100
  const minRenderableArea = minRenderableSize * minRenderableSize;
1101
1101
  const scaledGap = config.rectGap * scaleFactor;
1102
1102
  const scaledRadius = config.rectRadius * scaleFactor;
@@ -1364,17 +1364,17 @@ class Component extends Schedule {
1364
1364
  }
1365
1365
  return result;
1366
1366
  }
1367
- getViewportAABB(matrixE, matrixF, scale) {
1367
+ getViewportAABB(matrixE, matrixF) {
1368
1368
  const { width, height } = this.render.options;
1369
- const worldX = -matrixE / scale;
1370
- const worldY = -matrixF / scale;
1371
- const worldWidth = width / scale;
1372
- const worldHeight = height / scale;
1369
+ const viewportX = -matrixE;
1370
+ const viewportY = -matrixF;
1371
+ const viewportWidth = width;
1372
+ const viewportHeight = height;
1373
1373
  return {
1374
- x: worldX,
1375
- y: worldY,
1376
- width: worldWidth,
1377
- height: worldHeight
1374
+ x: viewportX,
1375
+ y: viewportY,
1376
+ width: viewportWidth,
1377
+ height: viewportHeight
1378
1378
  };
1379
1379
  }
1380
1380
  getAABBUnion(a, b) {
@@ -1390,8 +1390,8 @@ class Component extends Schedule {
1390
1390
  };
1391
1391
  }
1392
1392
  handleTransformCacheInvalidation(oldMatrix, newMatrix) {
1393
- const oldViewportAABB = this.getViewportAABB(oldMatrix.e, oldMatrix.f, oldMatrix.a);
1394
- const newViewportAABB = this.getViewportAABB(newMatrix.e, newMatrix.f, newMatrix.a);
1393
+ const oldViewportAABB = this.getViewportAABB(oldMatrix.e, oldMatrix.f);
1394
+ const newViewportAABB = this.getViewportAABB(newMatrix.e, newMatrix.f);
1395
1395
  const affectedAABB = this.getAABBUnion(oldViewportAABB, newViewportAABB);
1396
1396
  this.clearFontCacheInAABB(affectedAABB);
1397
1397
  }
@@ -1699,10 +1699,9 @@ class DOMEvent extends Event {
1699
1699
  native: e.native,
1700
1700
  module: node
1701
1701
  });
1702
- // For MacOS
1703
1702
  }
1704
1703
  findRelativeNode(e) {
1705
- return findRelativeNode(captureBoxXY(this.el, e.native, this.matrix.a, this.matrix.d, this.matrix.e, this.matrix.f), this.component.layoutNodes);
1704
+ return findRelativeNode(captureBoxXY(this.el, e.native, 1, 1, this.matrix.e, this.matrix.f), this.component.layoutNodes);
1706
1705
  }
1707
1706
  }
1708
1707
 
@@ -1093,8 +1093,8 @@ function squarify(data, rect, config, scale = 1) {
1093
1093
  const totalArea = rect.w * rect.h;
1094
1094
  const containerSize = Math.min(rect.w, rect.h);
1095
1095
  const scaleFactor = Math.max(0.5, Math.min(1, containerSize / 800));
1096
- // evaluate minimum renderable size
1097
- const minRenderableSize = Math.max(20, containerSize * 0.05) / scale;
1096
+ const baseMinSize = 20;
1097
+ const minRenderableSize = Math.max(8, baseMinSize / Math.sqrt(scale));
1098
1098
  const minRenderableArea = minRenderableSize * minRenderableSize;
1099
1099
  const scaledGap = config.rectGap * scaleFactor;
1100
1100
  const scaledRadius = config.rectRadius * scaleFactor;
@@ -1362,17 +1362,17 @@ class Component extends Schedule {
1362
1362
  }
1363
1363
  return result;
1364
1364
  }
1365
- getViewportAABB(matrixE, matrixF, scale) {
1365
+ getViewportAABB(matrixE, matrixF) {
1366
1366
  const { width, height } = this.render.options;
1367
- const worldX = -matrixE / scale;
1368
- const worldY = -matrixF / scale;
1369
- const worldWidth = width / scale;
1370
- const worldHeight = height / scale;
1367
+ const viewportX = -matrixE;
1368
+ const viewportY = -matrixF;
1369
+ const viewportWidth = width;
1370
+ const viewportHeight = height;
1371
1371
  return {
1372
- x: worldX,
1373
- y: worldY,
1374
- width: worldWidth,
1375
- height: worldHeight
1372
+ x: viewportX,
1373
+ y: viewportY,
1374
+ width: viewportWidth,
1375
+ height: viewportHeight
1376
1376
  };
1377
1377
  }
1378
1378
  getAABBUnion(a, b) {
@@ -1388,8 +1388,8 @@ class Component extends Schedule {
1388
1388
  };
1389
1389
  }
1390
1390
  handleTransformCacheInvalidation(oldMatrix, newMatrix) {
1391
- const oldViewportAABB = this.getViewportAABB(oldMatrix.e, oldMatrix.f, oldMatrix.a);
1392
- const newViewportAABB = this.getViewportAABB(newMatrix.e, newMatrix.f, newMatrix.a);
1391
+ const oldViewportAABB = this.getViewportAABB(oldMatrix.e, oldMatrix.f);
1392
+ const newViewportAABB = this.getViewportAABB(newMatrix.e, newMatrix.f);
1393
1393
  const affectedAABB = this.getAABBUnion(oldViewportAABB, newViewportAABB);
1394
1394
  this.clearFontCacheInAABB(affectedAABB);
1395
1395
  }
@@ -1697,10 +1697,9 @@ class DOMEvent extends Event {
1697
1697
  native: e.native,
1698
1698
  module: node
1699
1699
  });
1700
- // For MacOS
1701
1700
  }
1702
1701
  findRelativeNode(e) {
1703
- return findRelativeNode(captureBoxXY(this.el, e.native, this.matrix.a, this.matrix.d, this.matrix.e, this.matrix.f), this.component.layoutNodes);
1702
+ return findRelativeNode(captureBoxXY(this.el, e.native, 1, 1, this.matrix.e, this.matrix.f), this.component.layoutNodes);
1704
1703
  }
1705
1704
  }
1706
1705
 
@@ -403,16 +403,14 @@ declare class Component extends Schedule {
403
403
  constructor(config: GraphicConfig, ...args: ConstructorParameters<typeof Schedule>);
404
404
  clearFontCacheInAABB(aabb: AABB): void;
405
405
  private getModulesInAABB;
406
- getViewportAABB(matrixE: number, matrixF: number, scale: number): AABB;
406
+ getViewportAABB(matrixE: number, matrixF: number): AABB;
407
407
  private getAABBUnion;
408
408
  handleTransformCacheInvalidation(oldMatrix: {
409
409
  e: number;
410
410
  f: number;
411
- a: number;
412
411
  }, newMatrix: {
413
412
  e: number;
414
413
  f: number;
415
- a: number;
416
414
  }): void;
417
415
  private isAABBIntersecting;
418
416
  private drawBroundRect;
package/dist/index.d.mts CHANGED
@@ -1 +1 @@
1
- export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bb8ZzMCD.js';
1
+ export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bks7tGiV.js';
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bb8ZzMCD.js';
1
+ export { B as BasicTreemapInstance, c as CreateTreemapOptions, D as DOMEventType, Y as DefaultMap, E as ExposedEventCallback, n as ExposedEventDefinition, o as ExposedEventMethods, x as GraphicConfig, w as GraphicFont, G as GraphicLayout, O as InheritedCollectionsWithParamter, L as LayoutModule, M as Module, N as NativeModule, k as Plugin, P as PluginContext, l as PluginHooks, p as PrimitiveEventMetadata, S as Series, e as TreemapInstance, T as TreemapOptions, K as applyCanvasTransform, f as c2m, J as createCanvasElement, F as createRoundBlock, H as createTitleText, d as createTreemap, m as definePlugin, g as findRelativeNode, h as findRelativeNodeById, i as flattenModule, j as getNodeDepth, y as hashCode, q as isClickEvent, r as isContextMenuEvent, t as isMouseEvent, X as isScrollWheelOrRightButtonOnMouseupAndDown, u as isWheelEvent, Q as mixin, A as noop, z as perferNumeric, I as raf, W as smoothFrame, s as sortChildrenByKey, U as stackMatrixTransform, V as stackMatrixTransformWithGraphAndLayer, R as typedForIn, v as visit } from './index-Bks7tGiV.js';
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var domEvent = require('./dom-event-CxIxc4YC.js');
3
+ var domEvent = require('./dom-event-ClwTQnot.js');
4
4
 
5
5
  function createTreemap(// @ts-expect-error todo fix
6
6
  options) {
package/dist/index.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { l as logger, m as mixin, E as Event, a as assertExists, b as bindParentForModule, C as Component, D as DOMEvent } from './dom-event-CKb3Ko4-.mjs';
2
- export { G as DefaultMap, x as applyCanvasTransform, c as c2m, w as createCanvasElement, r as createRoundBlock, t as createTitleText, h as definePlugin, f as findRelativeNode, d as findRelativeNodeById, e as flattenModule, g as getNodeDepth, o as hashCode, i as isClickEvent, j as isContextMenuEvent, k as isMouseEvent, F as isScrollWheelOrRightButtonOnMouseupAndDown, n as isWheelEvent, q as noop, p as perferNumeric, u as raf, B as smoothFrame, s as sortChildrenByKey, z as stackMatrixTransform, A as stackMatrixTransformWithGraphAndLayer, y as typedForIn, v as visit } from './dom-event-CKb3Ko4-.mjs';
1
+ import { l as logger, m as mixin, E as Event, a as assertExists, b as bindParentForModule, C as Component, D as DOMEvent } from './dom-event-DrYYfglv.mjs';
2
+ export { G as DefaultMap, x as applyCanvasTransform, c as c2m, w as createCanvasElement, r as createRoundBlock, t as createTitleText, h as definePlugin, f as findRelativeNode, d as findRelativeNodeById, e as flattenModule, g as getNodeDepth, o as hashCode, i as isClickEvent, j as isContextMenuEvent, k as isMouseEvent, F as isScrollWheelOrRightButtonOnMouseupAndDown, n as isWheelEvent, q as noop, p as perferNumeric, u as raf, B as smoothFrame, s as sortChildrenByKey, z as stackMatrixTransform, A as stackMatrixTransformWithGraphAndLayer, y as typedForIn, v as visit } from './dom-event-DrYYfglv.mjs';
3
3
 
4
4
  function createTreemap(// @ts-expect-error todo fix
5
5
  options) {
package/dist/plugin.d.mts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-Bb8ZzMCD.js';
1
+ import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-Bks7tGiV.js';
2
2
 
3
3
  declare const presetHighlightPlugin: {
4
4
  name: "treemap:preset-highlight";
package/dist/plugin.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-Bb8ZzMCD.js';
1
+ import { P as PluginContext, D as DOMEventType, a as DOMEventMetadata, L as LayoutModule, b as DOMEvent, C as ColorMappings, B as BasicTreemapInstance } from './index-Bks7tGiV.js';
2
2
 
3
3
  declare const presetHighlightPlugin: {
4
4
  name: "treemap:preset-highlight";
package/dist/plugin.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var domEvent = require('./dom-event-CxIxc4YC.js');
3
+ var domEvent = require('./dom-event-ClwTQnot.js');
4
4
 
5
5
  // Currently, etoile is an internal module, so we won't need too much easing functions.
6
6
  // And the animation logic is implemented by user code.
@@ -90,7 +90,7 @@ const presetHighlightPlugin = domEvent.definePlugin({
90
90
  });
91
91
  meta.highlight?.add(mask);
92
92
  meta.highlight?.setZIndexForHighlight('1');
93
- domEvent.stackMatrixTransform(mask, matrix.e, matrix.f, matrix.a);
93
+ domEvent.stackMatrixTransform(mask, matrix.e, matrix.f, 1);
94
94
  meta.highlight?.update();
95
95
  }, {
96
96
  duration: ANIMATION_DURATION
@@ -162,7 +162,7 @@ const presetDragElementPlugin = domEvent.definePlugin({
162
162
  meta.dragOptions.lastY = lastY;
163
163
  component.cleanup();
164
164
  component.draw(false, false);
165
- domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
165
+ domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
166
166
  component.update();
167
167
  return true;
168
168
  }, {
@@ -480,13 +480,13 @@ function updateViewport(pluginContext, { stateManager: state, component, matrix
480
480
  component.cleanup();
481
481
  const { width, height } = component.render.options;
482
482
  component.layoutNodes = component.calculateLayoutNodes(component.data, {
483
- w: width,
484
- h: height,
483
+ w: width * matrix.a,
484
+ h: height * matrix.d,
485
485
  x: 0,
486
486
  y: 0
487
- }, matrix.a);
487
+ }, 1);
488
488
  component.draw(true, false);
489
- domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
489
+ domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
490
490
  component.update();
491
491
  if (state.canTransition('IDLE')) {
492
492
  state.transition('IDLE');
@@ -513,8 +513,7 @@ function handleZoom(pluginContext, event, domEvent) {
513
513
  const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
514
514
  const oldMatrix = {
515
515
  e: matrix.e,
516
- f: matrix.f,
517
- a: matrix.a
516
+ f: matrix.f
518
517
  };
519
518
  const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
520
519
  const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
@@ -532,8 +531,7 @@ function handleZoom(pluginContext, event, domEvent) {
532
531
  matrix.f = mouseY - (mouseY - matrix.f) * scaleDiff;
533
532
  const newMatrix = {
534
533
  e: matrix.e,
535
- f: matrix.f,
536
- a: matrix.a
534
+ f: matrix.f
537
535
  };
538
536
  component.handleTransformCacheInvalidation(oldMatrix, newMatrix);
539
537
  updateViewport(pluginContext, domEvent, false);
@@ -582,17 +580,19 @@ const presetZoomablePlugin = domEvent.definePlugin({
582
580
  const [nodeX, nodeY, nodeW, nodeH] = targetModule.layout;
583
581
  const { width, height } = component.render.options;
584
582
  const currentScale = matrix.a;
583
+ // To prevent unlimited scale factor growth.
585
584
  const scaleX = width * ZOOM_PADDING_RATIO / nodeW;
586
585
  const scaleY = height * ZOOM_PADDING_RATIO / nodeH;
587
- const idealScale = Math.min(scaleX, scaleY);
586
+ const idleScale = Math.min(scaleX, scaleY);
588
587
  const maxAllowedScale = currentScale * MAX_SCALE_MULTIPLIER;
589
- const targetScale = Math.max(currentScale, Math.min(idealScale, maxAllowedScale));
590
- const nodeWorldCenterX = nodeX + nodeW / 2;
591
- const nodeWorldCenterY = nodeY + nodeH / 2;
592
- const viewCenterX = width / 2;
593
- const viewCenterY = height / 2;
594
- const targetE = viewCenterX - nodeWorldCenterX * targetScale;
595
- const targetF = viewCenterY - nodeWorldCenterY * targetScale;
588
+ const targetScale = Math.max(currentScale, Math.min(idleScale, maxAllowedScale));
589
+ // Real world args
590
+ const viewportCenterX = width / 2;
591
+ const viewportCenterY = height / 2;
592
+ const originalNodeCenterX = (nodeX + nodeW / 2) / currentScale;
593
+ const originalNodeCenterY = (nodeY + nodeH / 2) / currentScale;
594
+ const targetE = viewportCenterX - originalNodeCenterX * targetScale;
595
+ const targetF = viewportCenterY - originalNodeCenterY * targetScale;
596
596
  const scaleMeta = getScaleOptions.call(this);
597
597
  if (scaleMeta) {
598
598
  scaleMeta.scaleOptions.scale = targetScale;
@@ -615,8 +615,7 @@ const presetZoomablePlugin = domEvent.definePlugin({
615
615
  };
616
616
  const finalMatrix = {
617
617
  e: targetE,
618
- f: targetF,
619
- a: targetScale
618
+ f: targetF
620
619
  };
621
620
  component.handleTransformCacheInvalidation(oldMatrix, finalMatrix);
622
621
  domEvent.smoothFrame((progress)=>{
@@ -632,13 +631,13 @@ const presetZoomablePlugin = domEvent.definePlugin({
632
631
  }
633
632
  component.cleanup();
634
633
  component.layoutNodes = component.calculateLayoutNodes(component.data, {
635
- w: width,
636
- h: height,
634
+ w: width * matrix.a,
635
+ h: height * matrix.d,
637
636
  x: 0,
638
637
  y: 0
639
- }, matrix.a);
638
+ }, 1);
640
639
  component.draw(true, false);
641
- domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
640
+ domEvent.stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
642
641
  component.update();
643
642
  }, {
644
643
  duration: ANIMATION_DURATION,
package/dist/plugin.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { h as definePlugin, B as smoothFrame, r as createRoundBlock, z as stackMatrixTransform, S as Schedule, H as DEFAULT_MATRIX_LOC, F as isScrollWheelOrRightButtonOnMouseupAndDown, A as stackMatrixTransformWithGraphAndLayer, j as isContextMenuEvent, o as hashCode, P as PI_2, n as isWheelEvent, m as mixin } from './dom-event-CKb3Ko4-.mjs';
1
+ import { h as definePlugin, B as smoothFrame, r as createRoundBlock, z as stackMatrixTransform, S as Schedule, H as DEFAULT_MATRIX_LOC, F as isScrollWheelOrRightButtonOnMouseupAndDown, A as stackMatrixTransformWithGraphAndLayer, j as isContextMenuEvent, o as hashCode, P as PI_2, n as isWheelEvent, m as mixin } from './dom-event-DrYYfglv.mjs';
2
2
 
3
3
  // Currently, etoile is an internal module, so we won't need too much easing functions.
4
4
  // And the animation logic is implemented by user code.
@@ -88,7 +88,7 @@ const presetHighlightPlugin = definePlugin({
88
88
  });
89
89
  meta.highlight?.add(mask);
90
90
  meta.highlight?.setZIndexForHighlight('1');
91
- stackMatrixTransform(mask, matrix.e, matrix.f, matrix.a);
91
+ stackMatrixTransform(mask, matrix.e, matrix.f, 1);
92
92
  meta.highlight?.update();
93
93
  }, {
94
94
  duration: ANIMATION_DURATION
@@ -160,7 +160,7 @@ const presetDragElementPlugin = definePlugin({
160
160
  meta.dragOptions.lastY = lastY;
161
161
  component.cleanup();
162
162
  component.draw(false, false);
163
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
163
+ stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
164
164
  component.update();
165
165
  return true;
166
166
  }, {
@@ -478,13 +478,13 @@ function updateViewport(pluginContext, { stateManager: state, component, matrix
478
478
  component.cleanup();
479
479
  const { width, height } = component.render.options;
480
480
  component.layoutNodes = component.calculateLayoutNodes(component.data, {
481
- w: width,
482
- h: height,
481
+ w: width * matrix.a,
482
+ h: height * matrix.d,
483
483
  x: 0,
484
484
  y: 0
485
- }, matrix.a);
485
+ }, 1);
486
486
  component.draw(true, false);
487
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
487
+ stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
488
488
  component.update();
489
489
  if (state.canTransition('IDLE')) {
490
490
  state.transition('IDLE');
@@ -511,8 +511,7 @@ function handleZoom(pluginContext, event, domEvent) {
511
511
  const { scale, minScale, maxScale, scaleFactor } = meta.scaleOptions;
512
512
  const oldMatrix = {
513
513
  e: matrix.e,
514
- f: matrix.f,
515
- a: matrix.a
514
+ f: matrix.f
516
515
  };
517
516
  const dynamicScaleFactor = Math.max(scaleFactor, scale * 0.1);
518
517
  const delta = event.native.deltaY < 0 ? dynamicScaleFactor : -dynamicScaleFactor;
@@ -530,8 +529,7 @@ function handleZoom(pluginContext, event, domEvent) {
530
529
  matrix.f = mouseY - (mouseY - matrix.f) * scaleDiff;
531
530
  const newMatrix = {
532
531
  e: matrix.e,
533
- f: matrix.f,
534
- a: matrix.a
532
+ f: matrix.f
535
533
  };
536
534
  component.handleTransformCacheInvalidation(oldMatrix, newMatrix);
537
535
  updateViewport(pluginContext, domEvent, false);
@@ -580,17 +578,19 @@ const presetZoomablePlugin = definePlugin({
580
578
  const [nodeX, nodeY, nodeW, nodeH] = targetModule.layout;
581
579
  const { width, height } = component.render.options;
582
580
  const currentScale = matrix.a;
581
+ // To prevent unlimited scale factor growth.
583
582
  const scaleX = width * ZOOM_PADDING_RATIO / nodeW;
584
583
  const scaleY = height * ZOOM_PADDING_RATIO / nodeH;
585
- const idealScale = Math.min(scaleX, scaleY);
584
+ const idleScale = Math.min(scaleX, scaleY);
586
585
  const maxAllowedScale = currentScale * MAX_SCALE_MULTIPLIER;
587
- const targetScale = Math.max(currentScale, Math.min(idealScale, maxAllowedScale));
588
- const nodeWorldCenterX = nodeX + nodeW / 2;
589
- const nodeWorldCenterY = nodeY + nodeH / 2;
590
- const viewCenterX = width / 2;
591
- const viewCenterY = height / 2;
592
- const targetE = viewCenterX - nodeWorldCenterX * targetScale;
593
- const targetF = viewCenterY - nodeWorldCenterY * targetScale;
586
+ const targetScale = Math.max(currentScale, Math.min(idleScale, maxAllowedScale));
587
+ // Real world args
588
+ const viewportCenterX = width / 2;
589
+ const viewportCenterY = height / 2;
590
+ const originalNodeCenterX = (nodeX + nodeW / 2) / currentScale;
591
+ const originalNodeCenterY = (nodeY + nodeH / 2) / currentScale;
592
+ const targetE = viewportCenterX - originalNodeCenterX * targetScale;
593
+ const targetF = viewportCenterY - originalNodeCenterY * targetScale;
594
594
  const scaleMeta = getScaleOptions.call(this);
595
595
  if (scaleMeta) {
596
596
  scaleMeta.scaleOptions.scale = targetScale;
@@ -613,8 +613,7 @@ const presetZoomablePlugin = definePlugin({
613
613
  };
614
614
  const finalMatrix = {
615
615
  e: targetE,
616
- f: targetF,
617
- a: targetScale
616
+ f: targetF
618
617
  };
619
618
  component.handleTransformCacheInvalidation(oldMatrix, finalMatrix);
620
619
  smoothFrame((progress)=>{
@@ -630,13 +629,13 @@ const presetZoomablePlugin = definePlugin({
630
629
  }
631
630
  component.cleanup();
632
631
  component.layoutNodes = component.calculateLayoutNodes(component.data, {
633
- w: width,
634
- h: height,
632
+ w: width * matrix.a,
633
+ h: height * matrix.d,
635
634
  x: 0,
636
635
  y: 0
637
- }, matrix.a);
636
+ }, 1);
638
637
  component.draw(true, false);
639
- stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, matrix.a);
638
+ stackMatrixTransformWithGraphAndLayer(component.elements, matrix.e, matrix.f, 1);
640
639
  component.update();
641
640
  }, {
642
641
  duration: ANIMATION_DURATION,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "squarified",
3
- "version": "0.6.1",
3
+ "version": "0.6.2",
4
4
  "description": "squarified tree map",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",