Created
April 14, 2020 12:35
-
-
Save hckhanh/cc8cc69fa0125b88e3f8fa1bf055b093 to your computer and use it in GitHub Desktop.
DagredWidget (class component) for react-diagrams
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DagreWidget extends React.Component<DagreWidgetProps, any> { | |
engine: DagreEngine; | |
constructor(props: any) { | |
super(props); | |
this.engine = new DagreEngine({ | |
graph: { | |
rankdir: "RL", | |
ranker: "longest-path", | |
marginx: 25, | |
marginy: 25 | |
}, | |
includeLinks: true | |
}); | |
} | |
autoDistribute = () => { | |
this.engine.redistribute(this.props.model); | |
// only happens if pathfing is enabled (check line 25) | |
this.reroute(); | |
this.props.engine.repaintCanvas(); | |
}; | |
componentDidMount(): void { | |
setTimeout(() => { | |
this.autoDistribute(); | |
}, 500); | |
} | |
reroute() { | |
this.props.engine | |
.getLinkFactories() | |
.getFactory<PathFindingLinkFactory>(PathFindingLinkFactory.NAME) | |
.calculateRoutingMatrix(); | |
} | |
render() { | |
return ( | |
<CanvasWidget | |
className={this.props.className} | |
engine={this.props.engine} | |
/> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment