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 pathOverlays.stories.js
104 lines (87 loc) · 2.71 KB
/
Overlays.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
import {
Graph,
CellOverlay,
InternalEvent,
CellTracker,
utils,
ImageBox,
} from '@maxgraph/core';
import { globalTypes } from '../.storybook/preview';
export default {
title: 'Effects/Overlays',
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);
// Disables basic selection and cell handling
graph.setEnabled(false);
// Highlights the vertices when the mouse enters
const highlight = new CellTracker(graph, '#00FF00');
// Enables tooltips for the overlays
graph.setTooltips(true);
// Installs a handler for click events in the graph
// that toggles the overlay for the respective cell
graph.addListener(InternalEvent.CLICK, (sender, evt) => {
const cell = evt.getProperty('cell');
if (cell != null) {
const overlays = graph.getCellOverlays(cell);
if (overlays == null) {
// Creates a new overlay with an image and a tooltip
const overlay = new CellOverlay(
new ImageBox('/images/check.png', 16, 16),
'Overlay tooltip'
);
// Installs a handler for clicks on the overlay
overlay.addListener(InternalEvent.CLICK, (sender, evt2) => {
utils.alert('Overlay clicked');
});
// Sets the overlay for the cell in the graph
graph.addCellOverlay(cell, overlay);
} else {
graph.removeCellOverlays(cell);
}
}
});
// Installs a handler for double click events in the graph
// that shows an alert box
graph.addListener(InternalEvent.DOUBLE_CLICK, (sender, evt) => {
const cell = evt.getProperty('cell');
alert(`Doubleclick: ${cell != null ? 'Cell' : 'Graph'}`);
evt.consume();
});
// 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 model in a single step
graph.batchUpdate(() => {
const v1 = graph.insertVertex({
parent,
value: 'Click,',
position: [20, 20],
size: [60, 40],
});
const v2 = graph.insertVertex({
parent,
value: 'Doubleclick',
position: [200, 150],
size: [100, 40],
});
const e1 = graph.insertEdge({
parent,
source: v1,
target: v2,
});
});
return container;
};
export const Default = Template.bind({});