1+ import React from 'react' ;
2+ import { GRAPH_ACTIONS } from '../../../src/constants' ;
3+ import Component from '../../base-component' ;
4+
5+ var name = 'Directed Graph' ;
6+ var config = {
7+ title : `Advanced/${ name } `
8+ } ;
9+
10+ export default {
11+ title : config . title ,
12+ component : Component ,
13+ parameters : {
14+ docs : { }
15+ }
16+ } ;
17+
18+ const GRAPH_ENUM = {
19+ NODE : {
20+ STATE : 0 ,
21+ } ,
22+ EDGE : {
23+ EDGE : 0 ,
24+ }
25+ } ;
26+
27+ const GRAPH_SCHEMA = {
28+ nodes : {
29+ [ GRAPH_ENUM . NODE . STATE ] : {
30+ name : 'state' ,
31+ fill : 'rgb(54, 67, 70, 0.8)' ,
32+ stroke : '#20292b' ,
33+ icon : '' ,
34+ iconColor : '#FFFFFF' ,
35+ contextMenuItems : [
36+ {
37+ text : 'Add transition' ,
38+ action : GRAPH_ACTIONS . ADD_EDGE ,
39+ edgeType : GRAPH_ENUM . EDGE . EDGE
40+ } ,
41+ {
42+ text : 'Delete state' ,
43+ action : GRAPH_ACTIONS . DELETE_NODE
44+ }
45+ ]
46+ }
47+ } ,
48+ edges : {
49+ [ GRAPH_ENUM . EDGE . EDGE ] : {
50+ stroke : '#0379EE' ,
51+ strokeWidth : 2 ,
52+ targetMarkerStroke : '#0379EE' ,
53+ targetMarker : true ,
54+ from : [
55+ GRAPH_ENUM . NODE . STATE ,
56+ GRAPH_ENUM . NODE . START_STATE ,
57+ GRAPH_ENUM . NODE . DEFAULT_STATE
58+ ] ,
59+ to : [
60+ GRAPH_ENUM . NODE . STATE ,
61+ GRAPH_ENUM . NODE . DEFAULT_STATE ,
62+ GRAPH_ENUM . NODE . END_STATE
63+ ] ,
64+ contextMenuItems : [
65+ {
66+ text : 'Delete edge' ,
67+ action : GRAPH_ACTIONS . DELETE_EDGE
68+ }
69+ ]
70+ }
71+ }
72+ } ;
73+
74+ var GRAPH_DATA = {
75+ nodes : {
76+ 1234 : {
77+ id : 1234 ,
78+ nodeType : GRAPH_ENUM . NODE . STATE ,
79+ name : 'NODE A' ,
80+ posX : 100 ,
81+ posY : 100
82+ } ,
83+ 1235 : {
84+ id : 1235 ,
85+ nodeType : GRAPH_ENUM . NODE . STATE ,
86+ name : 'NODE B' ,
87+ posX : 100 ,
88+ posY : 300
89+ } ,
90+ 1236 : {
91+ id : 1236 ,
92+ nodeType : GRAPH_ENUM . NODE . STATE ,
93+ name : 'NODE C' ,
94+ posX : 300 ,
95+ posY : 200
96+ }
97+ } ,
98+ edges : {
99+ '1234-1235' : {
100+ edgeType : GRAPH_ENUM . EDGE . EDGE ,
101+ from : 1234 ,
102+ to : 1235
103+ } ,
104+ '1235-1236' : {
105+ edgeType : GRAPH_ENUM . EDGE . EDGE ,
106+ from : 1235 ,
107+ to : 1236
108+ } ,
109+ }
110+ } ;
111+
112+ const GRAPH_CONTEXT_MENU_ITEMS_ITEMS = [
113+ {
114+ text : 'Add new state' ,
115+ action : GRAPH_ACTIONS . ADD_NODE ,
116+ nodeType : GRAPH_ENUM . NODE . STATE ,
117+ attributes : {
118+ name : 'New state' ,
119+ speed : 1.0 ,
120+ loop : false
121+ }
122+ }
123+ ] ;
124+
125+ export const DirectedGraphExample = ( args ) => {
126+ return < Component schema = { GRAPH_SCHEMA } options = { {
127+ initialData : GRAPH_DATA ,
128+ contextMenuItems : GRAPH_CONTEXT_MENU_ITEMS_ITEMS ,
129+ passiveUIEvents : false ,
130+ includeFonts : true ,
131+ incrementNodeNames : true ,
132+ defaultStyles : {
133+ background : {
134+ color : '#20292B' ,
135+ gridSize : 10
136+ } ,
137+ edge : {
138+ connectionStyle : 'default'
139+ }
140+ }
141+ } } /> ;
142+ } ;
143+
144+ document . querySelector ( '#root' ) . setAttribute ( 'style' , 'position: fixed; width: 100%; height: 100%' ) ;
145+ document . body . setAttribute ( 'style' , 'margin: 0px; padding: 0px;' ) ;
146+
147+ setTimeout ( ( ) => {
148+ Object . keys ( GRAPH_ACTIONS ) . forEach ( ( key ) => {
149+ const graphAction = GRAPH_ACTIONS [ key ] ;
150+ document . querySelector ( '.pcui-graph' ) . ui . on ( graphAction , ( data ) => {
151+ console . log ( graphAction , data ) ;
152+ } ) ;
153+ } ) ;
154+ } , 500 ) ;
0 commit comments