Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {
PipelineDagreLayout,
PipelineNodeModel,
getSpacerNodes,
getEdgesFromNodes
getEdgesFromNodes,
useVisualizationController
} from '@patternfly/react-topology';
import '@patternfly/react-styles/css/components/Topology/topology-components.css';
import withTopologySetup from './utils/withTopologySetup';
Expand Down Expand Up @@ -77,6 +78,9 @@ const getModel = (layout: string): Model => {
export const PipelineLayout = withTopologySetup(() => {
useLayoutFactory((type: string, graph: Graph): Layout | undefined => new PipelineDagreLayout(graph, { nodesep: 95 }));
useComponentFactory(pipelineComponentFactory);
const controller = useVisualizationController();
controller.setFitToScreenOnLayout(true);

// support pan zoom and drag
useComponentFactory(
React.useCallback<ComponentFactory>(kind => {
Expand Down
20 changes: 19 additions & 1 deletion packages/react-topology/src/Visualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ import {
ModelKind,
LayoutFactory,
Layout,
ViewPaddingSettings
ViewPaddingSettings,
GRAPH_LAYOUT_END_EVENT,
GraphLayoutEndEventListener
} from './types';
import defaultElementFactory from './elements/defaultElementFactory';
import Stateful from './utils/Stateful';
Expand Down Expand Up @@ -59,6 +61,8 @@ export class Visualization extends Stateful implements Controller {

private eventListeners: { [type: string]: EventListener[] } = {};

private fitToScreenListener: GraphLayoutEndEventListener;

@observable.shallow
private readonly store = {};

Expand Down Expand Up @@ -254,6 +258,20 @@ export class Visualization extends Stateful implements Controller {
}
}

setFitToScreenOnLayout(fitToScreen: boolean, padding: number = 80): void {
if (this.fitToScreenListener) {
this.removeEventListener(GRAPH_LAYOUT_END_EVENT, this.fitToScreenListener);
}

if (fitToScreen) {
this.fitToScreenListener = ({ graph }): void => {
graph.fit(padding);
};
this.addEventListener(GRAPH_LAYOUT_END_EVENT, this.fitToScreenListener);
return;
}
}

shouldRenderNode(node: Node): boolean {
if (!this.viewConstraintsEnabled) {
return true;
Expand Down
1 change: 1 addition & 0 deletions packages/react-topology/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ export interface Controller extends WithState {
getGraph(): Graph;
setGraph(graph: Graph): void;
getLayout(type: string | undefined): Layout | undefined;
setFitToScreenOnLayout(fitToScreen: boolean, padding?: number): void;
getElementById(id: string): GraphElement | undefined;
getNodeById(id: string): Node | undefined;
getEdgeById(id: string): Edge | undefined;
Expand Down