mirror of https://github.com/apache/nifi.git
NIFI-13285: If there is no transform to restore for the current viewport, executing a zoom fit (#8874)
* NIFI-13285: - If there is no transform to restore for the current viewport, executing a zoom fit. * NIFI-13285: - Adjusting the canvas position styles and zoom fit calculations. This closes #8874
This commit is contained in:
parent
f0e1cdcb22
commit
ffa5e8473d
|
@ -609,7 +609,7 @@ export class CanvasView {
|
||||||
/**
|
/**
|
||||||
* Zooms to fit the entire graph on the canvas.
|
* Zooms to fit the entire graph on the canvas.
|
||||||
*/
|
*/
|
||||||
public fit(): void {
|
public fit(allowTransition: boolean): void {
|
||||||
const translate = [this.x, this.y];
|
const translate = [this.x, this.y];
|
||||||
const scale: number = this.k;
|
const scale: number = this.k;
|
||||||
let newScale: number;
|
let newScale: number;
|
||||||
|
@ -617,8 +617,8 @@ export class CanvasView {
|
||||||
// get the canvas normalized width and height
|
// get the canvas normalized width and height
|
||||||
const canvasContainer: any = document.getElementById('canvas-container');
|
const canvasContainer: any = document.getElementById('canvas-container');
|
||||||
const canvasBoundingBox: any = canvasContainer.getBoundingClientRect();
|
const canvasBoundingBox: any = canvasContainer.getBoundingClientRect();
|
||||||
const canvasWidth = canvasBoundingBox.width;
|
const canvasWidth = canvasBoundingBox.width - 50;
|
||||||
const canvasHeight = canvasBoundingBox.height;
|
const canvasHeight = canvasBoundingBox.height - 50;
|
||||||
|
|
||||||
// get the bounding box for the graph
|
// get the bounding box for the graph
|
||||||
const graph: any = d3.select('#canvas');
|
const graph: any = d3.select('#canvas');
|
||||||
|
@ -627,6 +627,8 @@ export class CanvasView {
|
||||||
const graphHeight: number = graphBox.height / scale;
|
const graphHeight: number = graphBox.height / scale;
|
||||||
let graphLeft: number = graphBox.left / scale;
|
let graphLeft: number = graphBox.left / scale;
|
||||||
let graphTop: number = (graphBox.top - canvasBoundingBox.top) / scale;
|
let graphTop: number = (graphBox.top - canvasBoundingBox.top) / scale;
|
||||||
|
const x = translate[0] / scale;
|
||||||
|
const y = translate[1] / scale;
|
||||||
|
|
||||||
// adjust the scale to ensure the entire graph is visible
|
// adjust the scale to ensure the entire graph is visible
|
||||||
if (graphWidth > canvasWidth || graphHeight > canvasHeight) {
|
if (graphWidth > canvasWidth || graphHeight > canvasHeight) {
|
||||||
|
@ -637,15 +639,14 @@ export class CanvasView {
|
||||||
} else {
|
} else {
|
||||||
newScale = 1;
|
newScale = 1;
|
||||||
|
|
||||||
// since the entire graph will fit on the canvas, offset origin appropriately
|
graphLeft -= (canvasWidth - graphWidth) / 2;
|
||||||
graphLeft -= 100;
|
graphTop -= (canvasHeight - graphHeight) / 2;
|
||||||
graphTop -= 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.allowTransition = true;
|
this.allowTransition = allowTransition;
|
||||||
this.centerBoundingBox({
|
this.centerBoundingBox({
|
||||||
x: graphLeft - translate[0] / scale,
|
x: graphLeft - x,
|
||||||
y: graphTop - translate[1] / scale,
|
y: graphTop - y,
|
||||||
width: canvasWidth / newScale,
|
width: canvasWidth / newScale,
|
||||||
height: canvasHeight / newScale,
|
height: canvasHeight / newScale,
|
||||||
scale: newScale
|
scale: newScale
|
||||||
|
|
|
@ -33,6 +33,6 @@ export const zoomIn = createAction('[Transform] Zoom In');
|
||||||
|
|
||||||
export const zoomOut = createAction('[Transform] Zoom Out');
|
export const zoomOut = createAction('[Transform] Zoom Out');
|
||||||
|
|
||||||
export const zoomFit = createAction('[Transform] Zoom Fit');
|
export const zoomFit = createAction('[Transform] Zoom Fit', props<{ transition: boolean }>());
|
||||||
|
|
||||||
export const zoomActual = createAction('[Transform] Zoom Actual');
|
export const zoomActual = createAction('[Transform] Zoom Actual');
|
||||||
|
|
|
@ -84,7 +84,11 @@ export class TransformEffects {
|
||||||
if (isFinite(item.scale) && isFinite(item.translateX) && isFinite(item.translateY)) {
|
if (isFinite(item.scale) && isFinite(item.translateX) && isFinite(item.translateY)) {
|
||||||
// restore previous view
|
// restore previous view
|
||||||
this.canvasView.transform([item.translateX, item.translateY], item.scale);
|
this.canvasView.transform([item.translateX, item.translateY], item.scale);
|
||||||
|
} else {
|
||||||
|
this.store.dispatch(TransformActions.zoomFit({ transition: false }));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
this.store.dispatch(TransformActions.zoomFit({ transition: false }));
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// likely could not parse item... ignoring
|
// likely could not parse item... ignoring
|
||||||
|
@ -143,8 +147,9 @@ export class TransformEffects {
|
||||||
() =>
|
() =>
|
||||||
this.actions$.pipe(
|
this.actions$.pipe(
|
||||||
ofType(TransformActions.zoomFit),
|
ofType(TransformActions.zoomFit),
|
||||||
tap(() => {
|
map((action) => action.transition),
|
||||||
this.canvasView.fit();
|
tap((transition) => {
|
||||||
|
this.canvasView.fit(transition);
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
{ dispatch: false }
|
{ dispatch: false }
|
||||||
|
|
|
@ -17,9 +17,9 @@
|
||||||
|
|
||||||
.canvas-background {
|
.canvas-background {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: 98px;
|
top: 97px;
|
||||||
left: 0;
|
left: 0;
|
||||||
bottom: 0;
|
bottom: 33px;
|
||||||
right: 0;
|
right: 0;
|
||||||
background-size: 14px 14px;
|
background-size: 14px 14px;
|
||||||
z-index: 1;
|
z-index: 1;
|
||||||
|
@ -30,7 +30,7 @@
|
||||||
|
|
||||||
:host ::ng-deep svg.canvas-svg {
|
:host ::ng-deep svg.canvas-svg {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: calc(100% - 33px);
|
height: 100%;
|
||||||
|
|
||||||
-webkit-font-smoothing: antialiased;
|
-webkit-font-smoothing: antialiased;
|
||||||
-moz-osx-font-smoothing: grayscale;
|
-moz-osx-font-smoothing: grayscale;
|
||||||
|
|
|
@ -83,7 +83,7 @@ export class NavigationControl {
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomFit(): void {
|
zoomFit(): void {
|
||||||
this.store.dispatch(zoomFit());
|
this.store.dispatch(zoomFit({ transition: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
zoomActual(): void {
|
zoomActual(): void {
|
||||||
|
|
Loading…
Reference in New Issue