This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
forked from maxGraph/maxGraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLabelPosition.stories.js
62 lines (53 loc) · 1.88 KB
/
LabelPosition.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
import { Graph } from '@maxgraph/core';
import { globalTypes } from '../.storybook/preview';
export default {
title: 'Labels/LabelPosition',
argTypes: {
...globalTypes,
},
};
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';
// Creates the graph inside the given container
const graph = new Graph(container);
// Gets the default parent for inserting new cells. This
// is normally the first child of the root (ie. layer 0).
const parent = graph.getDefaultParent();
// Defines the common part of all cell styles as a string-prefix
const prefix = { shape: 'image', image: 'images/icons48/keys.png' };
// Adds cells to the model in a single step and set the vertex
// label positions using the label position styles. Vertical
// and horizontal label position styles can be combined.
// Note: Alternatively, vertex labels can be set be overriding
// CellRenderer.getLabelBounds.
graph.batchUpdate(() => {
graph.insertVertex(parent, null, 'Bottom', 60, 60, 60, 60, {
...prefix,
verticalLabelPosition: 'bottom',
verticalAlign: 'top',
});
graph.insertVertex(parent, null, 'Top', 140, 60, 60, 60, {
...prefix,
verticalLabelPosition: 'top',
verticalAlign: 'bottom',
});
graph.insertVertex(parent, null, 'Left', 60, 160, 60, 60, {
...prefix,
labelPosition: 'left',
align: 'right',
});
graph.insertVertex(parent, null, 'Right', 140, 160, 60, 60, {
...prefix,
labelPosition: 'right',
align: 'left',
});
});
return container;
};
export const Default = Template.bind({});