2022-01-08 01:49:35 +00:00
|
|
|
import { Graph, Perimeter, constants, RubberBandHandler } from '@maxgraph/core';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
import { globalTypes } from '../.storybook/preview';
|
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'Misc/Merge',
|
|
|
|
argTypes: {
|
|
|
|
...globalTypes,
|
|
|
|
rubberBand: {
|
|
|
|
type: 'boolean',
|
2021-08-30 14:20:26 +00:00
|
|
|
defaultValue: true,
|
|
|
|
},
|
|
|
|
},
|
2021-04-25 03:39:40 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
2021-09-10 05:17:59 +00:00
|
|
|
// Should we allow overriding constants?
|
2022-01-08 01:49:35 +00:00
|
|
|
// constants.SHADOWCOLOR = '#c0c0c0';
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Creates the graph inside the given container
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// No size handles, please...
|
|
|
|
graph.setCellsResizable(false);
|
|
|
|
|
|
|
|
// Makes all cells round with a white, bold label
|
|
|
|
let style = graph.stylesheet.getDefaultVertexStyle();
|
2022-01-08 01:49:35 +00:00
|
|
|
style.shape = constants.SHAPE.ELLIPSE;
|
2021-08-30 14:20:26 +00:00
|
|
|
style.perimiter = Perimeter.EllipsePerimeter;
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'white';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.gradientColor = 'white';
|
2022-01-08 01:49:35 +00:00
|
|
|
style.fontStyle = constants.FONT.BOLD;
|
2021-05-02 06:04:34 +00:00
|
|
|
style.fontSize = 14;
|
|
|
|
style.shadow = true;
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Makes all edge labels gray with a white background
|
|
|
|
style = graph.stylesheet.getDefaultEdgeStyle();
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'gray';
|
2022-01-08 01:49:35 +00:00
|
|
|
style.fontStyle = constants.FONT.BOLD;
|
2021-05-02 13:56:17 +00:00
|
|
|
style.fontColor = 'black';
|
2021-05-02 06:04:34 +00:00
|
|
|
style.strokeWidth = 2;
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Enables rubberband selection
|
2022-01-08 01:49:35 +00:00
|
|
|
if (args.rubberBand) new RubberBandHandler(graph);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
2022-01-08 01:49:35 +00:00
|
|
|
graph.batchUpdate(() => {
|
2021-08-30 14:20:26 +00:00
|
|
|
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');
|
2021-04-25 03:39:40 +00:00
|
|
|
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'
|
|
|
|
);
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// Creates the second graph model (without a container)
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph2 = new Graph();
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// 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
|
2022-01-08 01:49:35 +00:00
|
|
|
graph2.batchUpdate(() => {
|
2021-08-30 14:20:26 +00:00
|
|
|
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');
|
2021-04-25 03:39:40 +00:00
|
|
|
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'
|
|
|
|
);
|
2022-01-08 01:49:35 +00:00
|
|
|
});
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
// 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.
|
2022-01-08 01:49:35 +00:00
|
|
|
graph.getDataModel().mergeChildren(parent2, parent /* , false */);
|
2021-04-25 03:39:40 +00:00
|
|
|
|
|
|
|
return container;
|
2021-08-30 14:20:26 +00:00
|
|
|
};
|
2021-04-25 03:39:40 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
export const Default = Template.bind({});
|