From 4c4f47ab98fc09ca399e032b29e220caaced6027 Mon Sep 17 00:00:00 2001 From: CTomlyn Date: Fri, 3 Nov 2023 21:18:00 -0700 Subject: [PATCH] Move methods Signed-off-by: CTomlyn --- .../src/common-canvas/svg-canvas-renderer.js | 6 +- .../common-canvas/svg-canvas-utils-zoom.js | 103 +++++++++--------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-renderer.js b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-renderer.js index 4db83e3ca0..406d34408b 100644 --- a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-renderer.js +++ b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-renderer.js @@ -159,7 +159,7 @@ export default class SVGCanvasRenderer { // Show the 'Back to Parent' control, if we are showing a sub-flow // in full screen mode or, the alwaysDisplayBackToParentFlow option is // switched on to always display it (used by apps that manage their own - // supernodes/sub-flows. + // supernodes/sub-flows). if (this.dispUtils.isDisplayingSubFlowFullPage() || this.canvasLayout.alwaysDisplayBackToParentFlow) { this.addBackToParentFlowArrow(this.canvasSVG); @@ -191,7 +191,7 @@ export default class SVGCanvasRenderer { } // Returns true if the space bar is pressed and held down. This is called - // from outside canvas via svg-canvas-d3 as well as internally. + // from outside canvas via svg-canvas-d3. isSpaceKeyPressed() { return this.zoomUtils.isSpaceKeyPressed(); } @@ -201,7 +201,7 @@ export default class SVGCanvasRenderer { } translateBy(x, y, animateTime) { - this.zoomUtils.refreshOnSizeChange.translateBy(x, y, animateTime); + this.zoomUtils.translateBy(x, y, animateTime); } zoomIn() { diff --git a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-zoom.js b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-zoom.js index 474467724b..5e26de0f1c 100644 --- a/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-zoom.js +++ b/canvas_modules/common-canvas/src/common-canvas/svg-canvas-utils-zoom.js @@ -26,8 +26,8 @@ import { INTERACTION_CARBON, INTERACTION_MOUSE, INTERACTION_TRACKPAD, LINK_SELECTION_NONE } from "./constants/canvas-constants.js"; -// This utility files provides a drag handler which manages drag operations to move -// and resize nodes and comments. +// This utility file provides a d3-zoom handler which manages zoom operations +// on the canvas as well as various utility functions to handle zoom behavior. export default class SVGCanvasUtilsZoom { @@ -98,26 +98,71 @@ export default class SVGCanvasUtilsZoom { } + setSpaceKeyPressed(state) { + this.spaceKeyPressed = state; + } + + // Returns true if the space bar is pressed and held down. + isSpaceKeyPressed() { + return this.spaceKeyPressed; + } + // Returns the dragObjectsHandler getZoomHandler() { return this.zoomHandler; } + // Returns the zoom transform object. getZoomTransform() { return this.zoomTransform; } + // Returns a copy of the zoom transform object. + getZoom() { + return { ...this.zoomTransform }; + } + getZoomScale() { return this.zoomTransform.k; } - setSpaceKeyPressed(state) { - this.spaceKeyPressed = state; + // Zooms the canvas to the extent specified in the zoom object. + zoomTo(zoomObject) { + const animateTime = 500; + this.zoomCanvasInvokeZoomBehavior(zoomObject, animateTime); } - // Returns true if the space bar is pressed and held down. - isSpaceKeyPressed() { - return this.spaceKeyPressed; + // Pans the canvas by the x and y amount specified in the time specified. + translateBy(x, y, animateTime) { + const z = this.getZoomTransform(); + const zoomObject = d3.zoomIdentity.translate(z.x + x, z.y + y).scale(z.k); + this.zoomCanvasInvokeZoomBehavior(zoomObject, animateTime); + } + + // Zooms in the canvas by an increment amount. + zoomIn() { + if (this.zoomTransform.k < this.maxScaleExtent) { + const newScale = Math.min(this.zoomTransform.k * 1.1, this.maxScaleExtent); + this.ren.canvasSVG.call(this.zoomHandler.scaleTo, newScale); + } + } + + // Zooms out the canvas by an increment amount. + zoomOut() { + if (this.zoomTransform.k > this.minScaleExtent) { + const newScale = Math.max(this.zoomTransform.k / 1.1, this.minScaleExtent); + this.ren.canvasSVG.call(this.zoomHandler.scaleTo, newScale); + } + } + + // Returns true if the canvas is currently zoomed to the maximum amount. + isZoomedToMax() { + return this.zoomTransform ? this.zoomTransform.k === this.maxScaleExtent : false; + } + + // Returns true if the canvas is currently zoomed to the minimum amount. + isZoomedToMin() { + return this.zoomTransform ? this.zoomTransform.k === this.minScaleExtent : false; } // Sets the maximum zoom extent by multiplying the current extent by @@ -620,50 +665,6 @@ export default class SVGCanvasUtilsZoom { return null; } - // Zooms the canvas to the extent specified in the zoom object. - zoomTo(zoomObject) { - const animateTime = 500; - this.zoomCanvasInvokeZoomBehavior(zoomObject, animateTime); - } - - // Returns a copy of the zoom transform object. - getZoom() { - return { x: this.zoomTransform.x, y: this.zoomTransform.y, k: this.zoomTransform.k }; - } - - // Pans the canvas by the x and y amount specified in the time specified. - translateBy(x, y, animateTime) { - const z = this.getZoomTransform(); - const zoomObject = d3.zoomIdentity.translate(z.x + x, z.y + y).scale(z.k); - this.zoomCanvasInvokeZoomBehavior(zoomObject, animateTime); - } - - // Zooms in the canvas by an increment amount. - zoomIn() { - if (this.zoomTransform.k < this.maxScaleExtent) { - const newScale = Math.min(this.zoomTransform.k * 1.1, this.maxScaleExtent); - this.ren.canvasSVG.call(this.zoomHandler.scaleTo, newScale); - } - } - - // Zooms out the canvas by an increment amount. - zoomOut() { - if (this.zoomTransform.k > this.minScaleExtent) { - const newScale = Math.max(this.zoomTransform.k / 1.1, this.minScaleExtent); - this.ren.canvasSVG.call(this.zoomHandler.scaleTo, newScale); - } - } - - // Returns true if the canvas is currently zoomed to the maximum amount. - isZoomedToMax() { - return this.zoomTransform ? this.zoomTransform.k === this.maxScaleExtent : false; - } - - // Returns true if the canvas is currently zoomed to the minimum amount. - isZoomedToMin() { - return this.zoomTransform ? this.zoomTransform.k === this.minScaleExtent : false; - } - // Returns the padding space for the canvas objects to be zoomed which takes // into account any connections that need to be made to/from any sub-flow // binding nodes plus any space needed for the binding nodes ports.