2021-09-07 09:07:27 +00:00
|
|
|
import { Graph, InternalEvent, RubberBand } from '@maxgraph/core';
|
2021-04-21 04:54:09 +00:00
|
|
|
import { globalTypes } from '../.storybook/preview';
|
2021-04-20 12:22:55 +00:00
|
|
|
|
2021-04-15 04:09:10 +00:00
|
|
|
export default {
|
2021-04-19 12:56:58 +00:00
|
|
|
title: 'Basic/HelloWorld',
|
|
|
|
argTypes: {
|
2021-04-21 04:54:09 +00:00
|
|
|
...globalTypes,
|
2021-04-19 12:56:58 +00:00
|
|
|
contextMenu: {
|
|
|
|
type: 'boolean',
|
2021-04-30 11:05:49 +00:00
|
|
|
defaultValue: false,
|
2021-04-19 12:56:58 +00:00
|
|
|
},
|
|
|
|
rubberBand: {
|
|
|
|
type: 'boolean',
|
2021-04-30 11:05:49 +00:00
|
|
|
defaultValue: true,
|
|
|
|
},
|
|
|
|
},
|
2021-04-15 04:09:10 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const Template = ({ label, ...args }) => {
|
|
|
|
const container = document.createElement('div');
|
|
|
|
container.style.position = 'relative';
|
|
|
|
container.style.overflow = 'hidden';
|
2021-04-19 12:56:58 +00:00
|
|
|
container.style.width = `${args.width}px`;
|
|
|
|
container.style.height = `${args.height}px`;
|
2021-04-20 12:22:55 +00:00
|
|
|
container.style.background = 'url(/images/grid.gif)';
|
2021-04-15 04:09:10 +00:00
|
|
|
container.style.cursor = 'default';
|
|
|
|
|
2021-09-08 01:05:28 +00:00
|
|
|
if (!args.contextMenu) InternalEvent.disableContextMenu(container);
|
2021-09-07 09:07:27 +00:00
|
|
|
|
2021-08-30 14:20:26 +00:00
|
|
|
const graph = new Graph(container);
|
2021-04-15 04:09:10 +00:00
|
|
|
|
2021-09-08 01:05:28 +00:00
|
|
|
if (args.rubberBand) new RubberBand(graph);
|
2021-04-15 04:09:10 +00:00
|
|
|
|
|
|
|
const parent = graph.getDefaultParent();
|
|
|
|
|
|
|
|
graph.batchUpdate(() => {
|
|
|
|
// Add cells to the model in a single step
|
|
|
|
const vertex1 = graph.insertVertex({
|
|
|
|
parent,
|
|
|
|
value: 'Hello',
|
|
|
|
position: [20, 20],
|
|
|
|
size: [80, 30],
|
|
|
|
relative: false,
|
|
|
|
});
|
2021-04-19 12:56:58 +00:00
|
|
|
|
2021-04-15 04:09:10 +00:00
|
|
|
const vertex2 = graph.insertVertex({
|
|
|
|
parent,
|
|
|
|
value: 'World!',
|
|
|
|
position: [200, 150],
|
|
|
|
size: [80, 30],
|
|
|
|
relative: false,
|
|
|
|
});
|
2021-04-19 12:56:58 +00:00
|
|
|
|
2021-04-15 04:09:10 +00:00
|
|
|
const edge = graph.insertEdge({
|
|
|
|
parent,
|
|
|
|
source: vertex1,
|
|
|
|
target: vertex2,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
return container;
|
2021-04-30 11:05:49 +00:00
|
|
|
};
|
2021-04-15 04:09:10 +00:00
|
|
|
|
2021-04-30 11:05:49 +00:00
|
|
|
export const Default = Template.bind({});
|