Skip to content

Commit

Permalink
Refactor canvas dims functions
Browse files Browse the repository at this point in the history
Signed-off-by: CTomlyn <[email protected]>
  • Loading branch information
tomlyn committed Nov 6, 2023
1 parent dd76dd1 commit b5fe9ca
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,8 @@ export default class SVGCanvasRenderer {
}
const svgRect = this.zoomUtils.getViewportDimensions();
const transformedSVGRect = this.zoomUtils.getTransformedRect(svgRect, 1);
const canv = this.zoomUtils.getCanvasDimensionsAdjustedForScale(1);
const canvWithPadding = this.zoomUtils.getCanvasDimensionsAdjustedForScale(1, this.zoomUtils.getZoomToFitPadding());
const canv = this.zoomUtils.getCanvasDimensions();
const canvWithPadding = this.zoomUtils.getCanvasDimensionsWithPadding();

this.boundingRectsGrp.selectChildren(".d3-bounding").remove();

Expand Down Expand Up @@ -1366,7 +1366,7 @@ export default class SVGCanvasRenderer {
}

setCanvasUnderlaySize(x = 0, y = 0) {
const canv = this.zoomUtils.getCanvasDimensionsAdjustedForScale(1, this.zoomUtils.getZoomToFitPadding());
const canv = this.zoomUtils.getCanvasDimensionsWithPadding();
if (canv) {
this.canvasUnderlay
.attr("x", canv.left - 50)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ export default class SVGCanvasUtilsZoom {
// If there's no saved zoom, and enablePanIntoViewOnOpen is set, pan so
// the canvas area (containing nodes and comments) is visible in the viewport.
if (!newZoom && this.ren.config.enablePanIntoViewOnOpen) {
const canvWithPadding = this.getCanvasDimensionsAdjustedForScale(1, this.getZoomToFitPadding());
const canvWithPadding = this.getCanvasDimensionsWithPadding();
if (canvWithPadding) {
newZoom = { x: -canvWithPadding.left, y: -canvWithPadding.top, k: 1 };
}
Expand Down Expand Up @@ -599,8 +599,7 @@ export default class SVGCanvasUtilsZoom {

// Zooms the canvas to fit in the current viewport.
zoomToFit() {
const padding = this.getZoomToFitPadding();
const canvasDimensions = this.getCanvasDimensionsAdjustedForScale(1, padding);
const canvasDimensions = this.getCanvasDimensionsWithPadding();
const viewPortDimensions = this.getViewportDimensions();

if (canvasDimensions) {
Expand Down Expand Up @@ -667,20 +666,6 @@ export default class SVGCanvasUtilsZoom {
return null;
}

// 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.
getZoomToFitPadding() {
let padding = this.ren.canvasLayout.zoomToFitPadding;

if (this.ren.dispUtils.isDisplayingSubFlow()) {
// Allocate some space for connecting lines and the binding node ports
const newPadding = this.getMaxZoomToFitPaddingForConnections() + (2 * this.ren.canvasLayout.supernodeBindingPortRadius);
padding = Math.max(padding, newPadding);
}
return padding;
}

// Returns the maximum amount for padding, when zooming to fit the canvas
// objects within a subflow, to allow the connection lines to be displayed
// without them doubling back on themselves.
Expand Down Expand Up @@ -758,11 +743,19 @@ export default class SVGCanvasUtilsZoom {
// based on the position and width and height of the nodes and comments. It
// does not include the 'super binding nodes' which are the binding nodes in
// a sub-flow that map to a port in the containing supernode. The dimensions
// are scaled by k and padded by pad (if provided).
getCanvasDimensionsAdjustedForScale(k, pad) {
// include an appropriate padding amount.
getCanvasDimensionsWithPadding() {
return this.getCanvasDimensions();
}

// Returns the dimensions in SVG coordinates of the canvas area. This is
// based on the position and width and height of the nodes and comments. It
// does not include the 'super binding nodes' which are the binding nodes in
// a sub-flow that map to a port in the containing supernode.
getCanvasDimensions() {
const gap = this.ren.canvasLayout.commentHighlightGap;
const canvasDimensions = this.ren.activePipeline.getCanvasDimensions(gap);
return this.convertRectAdjustedForScaleWithPadding(canvasDimensions, k, pad);
return this.convertRectAdjustedForScaleWithPadding(canvasDimensions, 1, this.getZoomToFitPadding());
}

// Returns a rect object describing the rect passed in but
Expand All @@ -781,4 +774,18 @@ export default class SVGCanvasUtilsZoom {
}
return null;
}

// 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.
getZoomToFitPadding() {
let padding = this.ren.canvasLayout.zoomToFitPadding;

if (this.ren.dispUtils.isDisplayingSubFlow()) {
// Allocate some space for connecting lines and the binding node ports
const newPadding = this.getMaxZoomToFitPaddingForConnections() + (2 * this.ren.canvasLayout.supernodeBindingPortRadius);
padding = Math.max(padding, newPadding);
}
return padding;
}
}

0 comments on commit b5fe9ca

Please sign in to comment.