maxGraph/packages/html/stories/HelloWorld.stories.js

65 lines
1.5 KiB
JavaScript
Raw Normal View History

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';
export default {
title: 'Basic/HelloWorld',
argTypes: {
2021-04-21 04:54:09 +00:00
...globalTypes,
contextMenu: {
type: 'boolean',
defaultValue: false,
},
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';
2021-09-08 01:05:28 +00:00
if (!args.contextMenu) InternalEvent.disableContextMenu(container);
2021-09-07 09:07:27 +00:00
const graph = new Graph(container);
2021-09-08 01:05:28 +00:00
if (args.rubberBand) new RubberBand(graph);
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,
});
const vertex2 = graph.insertVertex({
parent,
value: 'World!',
position: [200, 150],
size: [80, 30],
relative: false,
});
const edge = graph.insertEdge({
parent,
source: vertex1,
target: vertex2,
});
});
return container;
};
export const Default = Template.bind({});