forked from maxGraph/maxGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMerge.stories.js
148 lines (126 loc) · 4.87 KB
/
Merge.stories.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
Copyright 2021-present The maxGraph project Contributors
Copyright (c) 2006-2020, JGraph Ltd
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
import { Graph, Perimeter, constants, RubberBandHandler } from '@maxgraph/core';
import { globalTypes } from '../.storybook/preview';
export default {
title: 'Misc/Merge',
argTypes: {
...globalTypes,
rubberBand: {
type: 'boolean',
defaultValue: true,
},
},
};
const Template = ({ label, ...args }) => {
const container = document.createElement('div');
container.style.position = 'relative';
container.style.overflow = 'hidden';
container.style.width = `${args.width}px`;
container.style.height = `${args.height}px`;
container.style.background = 'url(/images/grid.gif)';
container.style.cursor = 'default';
// Should we allow overriding constants?
// constants.SHADOWCOLOR = '#c0c0c0';
// Creates the graph inside the given container
const graph = new Graph(container);
// No size handles, please...
graph.setCellsResizable(false);
// Makes all cells round with a white, bold label
let style = graph.stylesheet.getDefaultVertexStyle();
style.shape = constants.SHAPE.ELLIPSE;
style.perimiter = Perimeter.EllipsePerimeter;
style.fontColor = 'white';
style.gradientColor = 'white';
style.fontStyle = constants.FONT.BOLD;
style.fontSize = 14;
style.shadow = true;
// Makes all edge labels gray with a white background
style = graph.stylesheet.getDefaultEdgeStyle();
style.fontColor = 'gray';
style.fontStyle = constants.FONT.BOLD;
style.fontColor = 'black';
style.strokeWidth = 2;
// Enables rubberband selection
if (args.rubberBand) new RubberBandHandler(graph);
// Gets the default parent for inserting new cells. This
// is normally the first child of the root (ie. layer 0).
const parent = graph.getDefaultParent();
// Adds cells to the target model in a single step
// using custom ids for the vertices and edges
const w = 40;
const h = 40;
graph.batchUpdate(() => {
const a = graph.insertVertex(parent, 'a', 'A', 20, 20, w, h, { fillColor: 'blue' });
const b = graph.insertVertex(parent, 'b', 'B', 20, 200, w, h, { fillColor: 'blue' });
const c = graph.insertVertex(parent, 'c', 'C', 200, 20, w, h, { fillColor: 'red' });
const d = graph.insertVertex(parent, 'd', 'D', 200, 200, w, h, { fillColor: 'red' });
const ac = graph.insertEdge(parent, 'ac', 'ac', a, c, {
strokeColor: 'blue',
verticalAlign: 'bottom',
});
const ad = graph.insertEdge(parent, 'ad', 'ad', a, d, {
strokeColor: 'blue',
align: 'left',
verticalAlign: 'bottom',
});
const bd = graph.insertEdge(parent, 'bd', 'bd', b, d, {
strokeColor: 'blue',
verticalAlign: 'bottom',
});
});
// Creates the second graph model (without a container)
const graph2 = new Graph();
// Gets the default parent for inserting new cells. This
// is normally the first child of the root (ie. layer 0).
const parent2 = graph2.getDefaultParent();
// Adds cells to the target model in a single step
// using custom ids for the vertices
graph2.batchUpdate(() => {
const c = graph2.insertVertex(parent2, 'c', 'C', 200, 20, w, h, {
fillColor: 'green',
});
const d = graph2.insertVertex(parent2, 'd', 'D', 200, 200, w, h, {
fillColor: 'green',
});
const e = graph2.insertVertex(parent2, 'e', 'E', 400, 20, w, h, {
fillColor: 'green',
});
const f = graph2.insertVertex(parent2, 'f', 'F', 400, 200, w, h, {
fillColor: 'green',
});
const ce = graph2.insertEdge(parent2, 'ce', 'ce', c, e, {
strokeColor: 'green',
verticalAlign: 'bottom',
});
const ed = graph2.insertEdge(parent2, 'ed', 'ed', e, d, {
strokeColor: 'green',
align: 'right',
verticalAlign: 'bottom',
});
const fd = graph2.insertEdge(parent2, 'bd', 'fd', f, d, {
strokeColor: 'green',
verticalAlign: 'bottom',
});
});
// Merges the model from the second graph into the model of
// the first graph. Note: If you add a false to the parameter
// list then _not_ all edges will be cloned, that is, the
// edges are assumed to have an identity, and hence the edge
// "bd" will be changed to point from f to d, as specified in
// the edge for the same id in the second graph.
graph.getDataModel().mergeChildren(parent2, parent /* , false */);
return container;
};
export const Default = Template.bind({});