@@ -2,14 +2,21 @@ import createEngine, {
2
2
DiagramModel ,
3
3
DefaultNodeModel ,
4
4
DefaultPortModel ,
5
- RightAngleLinkFactory ,
5
+ RightAngleLinkFactory , LinkModel , RightAngleLinkModel ,
6
6
} from '@projectstorm/react-diagrams' ;
7
7
import * as React from 'react' ;
8
8
import { DemoButton , DemoWorkspaceWidget } from '../helpers/DemoWorkspaceWidget' ;
9
9
import { action } from '@storybook/addon-actions' ;
10
- import { CanvasWidget } from '@projectstorm/react-canvas-core' ;
10
+ import { AbstractModelFactory , CanvasWidget } from '@projectstorm/react-canvas-core' ;
11
11
import { DemoCanvasWidget } from '../helpers/DemoCanvasWidget' ;
12
12
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
+
13
20
export default ( ) => {
14
21
// setup the diagram engine
15
22
const engine = createEngine ( ) ;
@@ -20,24 +27,22 @@ export default () => {
20
27
21
28
// create four nodes in a way that straight links wouldn't work
22
29
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" ) ) ;
24
31
node1 . setPosition ( 340 , 350 ) ;
25
32
26
33
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" ) ) ;
28
35
node2 . setPosition ( 240 , 80 ) ;
29
36
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" ) ) ;
31
38
node3 . setPosition ( 540 , 180 ) ;
32
39
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" ) ) ;
34
41
node4 . setPosition ( 95 , 185 ) ;
35
42
36
- const rightAngleLink = engine . getLinkFactories ( ) . getFactory < RightAngleLinkFactory > ( RightAngleLinkFactory . NAME ) ;
37
-
38
43
// 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 ) ;
41
46
42
47
// add all to the main model
43
48
model . addAll ( node1 , node2 , node3 , node4 , link1 , link2 ) ;
0 commit comments