1 import {Workflow} from "../..";
2 import {PluginBase} from "../plugin-base";
4 export class ZoomPlugin extends PluginBase {
5 private svg: SVGSVGElement;
6 private dispose: Function | undefined;
8 registerWorkflow(workflow: Workflow): void {
9 super.registerWorkflow(workflow);
10 this.svg = workflow.svgRoot;
12 this.dispose = this.attachWheelListener();
15 attachWheelListener(): () => void {
16 const handler = this.onMouseWheel.bind(this);
17 this.svg.addEventListener("mousewheel", handler, true);
18 return () => this.svg.removeEventListener("mousewheel", handler, true);
21 onMouseWheel(event: MouseWheelEvent) {
23 const scale = this.workflow.scale;
24 const scaleUpdate = scale - event.deltaY / 500;
26 const zoominOut = scaleUpdate < scale;
27 const zoomingIn = scaleUpdate > scale;
29 if (zoomingIn && this.workflow.maxScale < scaleUpdate) {
33 if (zoominOut && this.workflow.minScale > scaleUpdate) {
37 this.workflow.scaleAtPoint(scaleUpdate, event.clientX, event.clientY);
38 event.stopPropagation();
42 if (typeof this.dispose === "function") {
46 this.dispose = undefined;