Skip to content

Commit

Permalink
Move methods
Browse files Browse the repository at this point in the history
Signed-off-by: CTomlyn <[email protected]>
  • Loading branch information
tomlyn committed Nov 4, 2023
1 parent 57ff52c commit 4c4f47a
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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();
}
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 4c4f47a

Please sign in to comment.