Skip to content

Commit cff5442

Browse files
update for new links ... port model needs RightAngleLinkModel
1 parent 3dd329b commit cff5442

File tree

1 file changed

+15
-10
lines changed
  • packages/diagrams-demo-gallery/demos/demo-right-angles-routing

1 file changed

+15
-10
lines changed

packages/diagrams-demo-gallery/demos/demo-right-angles-routing/index.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,21 @@ import createEngine, {
22
DiagramModel,
33
DefaultNodeModel,
44
DefaultPortModel,
5-
RightAngleLinkFactory,
5+
RightAngleLinkFactory, LinkModel, RightAngleLinkModel,
66
} from '@projectstorm/react-diagrams';
77
import * as React from 'react';
88
import { DemoButton, DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget';
99
import { action } from '@storybook/addon-actions';
10-
import { CanvasWidget } from '@projectstorm/react-canvas-core';
10+
import {AbstractModelFactory, CanvasWidget} from '@projectstorm/react-canvas-core';
1111
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget';
1212

13+
// When new link is created by clicking on port the RightAngleLinkModel needs to be returned.
14+
export class RightAnglePortModel extends DefaultPortModel {
15+
createLinkModel(factory?: AbstractModelFactory<LinkModel>) {
16+
return new RightAngleLinkModel();
17+
}
18+
}
19+
1320
export default () => {
1421
// setup the diagram engine
1522
const engine = createEngine();
@@ -20,24 +27,22 @@ export default () => {
2027

2128
// create four nodes in a way that straight links wouldn't work
2229
const node1 = new DefaultNodeModel("Node A", "rgb(0,192,255)");
23-
const port1 = node1.addPort(new DefaultPortModel(false, "out-1", "Out"));
30+
const port1 = node1.addPort(new RightAnglePortModel(false, "out-1", "Out"));
2431
node1.setPosition(340, 350);
2532

2633
const node2 = new DefaultNodeModel("Node B", "rgb(255,255,0)");
27-
const port2 = node2.addPort(new DefaultPortModel(false, "out-1", "Out"));
34+
const port2 = node2.addPort(new RightAnglePortModel(false, "out-1", "Out"));
2835
node2.setPosition(240, 80);
2936
const node3 = new DefaultNodeModel("Node C", "rgb(192,255,255)");
30-
const port3 = node3.addPort(new DefaultPortModel(true, "in-1", "In"));
37+
const port3 = node3.addPort(new RightAnglePortModel(true, "in-1", "In"));
3138
node3.setPosition(540, 180);
3239
const node4 = new DefaultNodeModel("Node D", "rgb(192,0,255)");
33-
const port4 = node4.addPort(new DefaultPortModel(true, "in-1", "In"));
40+
const port4 = node4.addPort(new RightAnglePortModel(true, "in-1", "In"));
3441
node4.setPosition(95, 185);
3542

36-
const rightAngleLink = engine.getLinkFactories().getFactory<RightAngleLinkFactory>(RightAngleLinkFactory.NAME);
37-
3843
// linking things together
39-
const link1 = port1.link(port4, rightAngleLink);
40-
const link2 = port2.link(port3, rightAngleLink);
44+
const link1 = port1.link(port4);
45+
const link2 = port2.link(port3);
4146

4247
// add all to the main model
4348
model.addAll(node1, node2, node3, node4, link1, link2);

0 commit comments

Comments
 (0)