-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathdiagram-navigate.html
72 lines (62 loc) · 2.89 KB
/
diagram-navigate.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="../src/js/jquery-3.6.3.min.js"></script>
<script src="../src/js/lodash-4.17.21.js"></script>
<script src="../src/js/backbone-1.4.1.js"></script>
<script type="text/javascript" src="../src/js/joint-3.6.5.js"></script>
<script type="text/javascript" src="../src/js/structurizr.js"></script>
<script type="text/javascript" src="../src/js/structurizr-util.js"></script>
<script type="text/javascript" src="../src/js/structurizr-ui.js"></script>
<script type="text/javascript" src="../src/js/structurizr-workspace.js"></script>
<script type="text/javascript" src="../src/js/structurizr-diagram.js"></script>
<link href="../src/css/joint-3.6.5.css" rel="stylesheet" media="screen" />
<link href="../src/css/structurizr-diagram.css" rel="stylesheet" media="screen" />
<style>
body {
font-family: Arial;
}
</style>
</head>
<body>
<div id="diagram" style="width: 1000px; height: 600px;"></div>
</body>
</html>
<script>
var diagram;
$.ajax({url: 'https://raw.githubusercontent.com/structurizr/ui/main/examples/big-bank-plc.json',
success: function(data){
structurizr.workspace = new structurizr.Workspace(JSON.parse(data));
diagram = new structurizr.ui.Diagram('diagram', false, function() {
diagram.changeView('SystemContext');
});
diagram.setNavigationEnabled(true);
diagram.onElementDoubleClicked(elementDoubleClicked);
diagram.onRelationshipDoubleClicked(elementDoubleClicked);
}});
function elementDoubleClicked(event, elementId) {
const element = structurizr.workspace.findElementById(elementId);
var views = [];
if (element.type === structurizr.constants.SOFTWARE_SYSTEM_ELEMENT_TYPE) {
if (diagram.getCurrentView().type === structurizr.constants.SYSTEM_LANDSCAPE_VIEW_TYPE || diagram.getCurrentView().softwareSystemId !== element.id) {
views = structurizr.workspace.findSystemContextViewsForSoftwareSystem(element.id);
if (views.length === 0) {
views = structurizr.workspace.findContainerViewsForSoftwareSystem(element.id);
}
} else if (diagram.getCurrentView().type === structurizr.constants.SYSTEM_CONTEXT_VIEW_TYPE) {
views = structurizr.workspace.findContainerViewsForSoftwareSystem(element.id);
}
} else if (element.type === "Container") {
views = structurizr.workspace.findComponentViewsForContainer(element.id);
}
if (views.length > 0) {
diagram.changeView(views[0].key);
}
}
function onRelationshipDoubleClicked(event, relationshipId) {
const relationship = structurizr.workspace.findRelationshipById(relationshipId);
if (relationship.url) {
window.open(relationship.url);
}
}
</script>