Skip to content

Commit c5f6624

Browse files
authored
pcui-graph version 1.0 (#5)
* update pcui-graph to version 1.0
1 parent 3477903 commit c5f6624

40 files changed

+11798
-18019
lines changed
Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,15 @@
11
import React from 'react';
2-
import Graph from './index.js';
2+
import { Graph } from '../src/index.js';
33

44
class BaseComponent extends React.Component {
55
constructor(props) {
66
super(props);
7-
if (props.onClick) {
8-
this.onClick = props.onClick;
9-
}
10-
if (props.onChange) {
11-
this.onChange = props.onChange;
12-
}
13-
if (props.link) {
14-
this.link = props.link;
15-
}
167
}
178
attachElement = (nodeElement, containerElement) => {
189
if (!nodeElement) return;
19-
this.element = new Graph({
20-
...this.props,
10+
this.element = new Graph(this.props.schema, {
11+
...this.props.options,
2112
dom: nodeElement,
22-
container: containerElement,
23-
parent: undefined
2413
});
2514
if (this.onClick) {
2615
this.element.on('click', this.onClick);

.storybook/main.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const path = require('path');
22
module.exports = {
3-
stories: ['../src/components/Graph/index.stories.jsx'],
3+
stories: ['./stories/**'],
44
addons: [
55
'@storybook/addon-actions/register',
66
'@storybook/addon-links',
@@ -24,6 +24,14 @@ module.exports = {
2424
}],
2525
}
2626
);
27+
28+
config.module.rules.unshift(
29+
{
30+
test: /\.mjs$/,
31+
include: /node_modules/,
32+
type: "javascript/auto",
33+
}
34+
);
2735
// Return the altered config
2836
return config;
2937
},
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
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

Comments
 (0)