-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
169 lines (151 loc) · 6.03 KB
/
index.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<!DOCTYPE html>
<head>
<title>NG Viewer</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jszip.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/svg-pan-zoom.min.js"></script>
<style>
body {
margin: 0;
}
.start-page {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
flex-direction: column;
background-color: #d9edc2;
}
.logo {
-webkit-text-stroke: 3px #3b6d36;
font-family: 'Roboto', sans-serif;
font-size: 50pt;
margin-bottom: 20px;
color: #d9edc2;
}
.open-file-dialog {
display: none;
}
.ng-button {
background-color: #d9edc2;
color: #3b6d36;
border: 2px solid #3b6d36;
border-radius: 0.5em;
text-align: center;
transition-duration: 0.4s;
cursor: pointer;
font-size: 12px;
height: 2.7em;
width: 10.5em;
}
.ng-button:hover {
background-color: #3b6d36;
color: #d9edc2;
}
/* ========== Node Styles ========== */
.node-border-active {
stroke-width: 2px;
stroke: red;
}
.node-border-hover {
stroke-width: 2px;
cursor: pointer;
}
</style>
</head>
<body>
<div id="start-page" class="start-page">
<h1 class="logo">NG Viewer</h1>
<button id="open-graph-button" class="ng-button">Open NG File</button>
<input type="file" id="open-file-dialog" class="open-file-dialog" multiple="false" accept=".ng">
</div>
<div id="svg-container"></div>
<script>
let graphAttrs = null;
let prevSelected = null;
function attachEventHandlersToNodes() {
const $graphNodes = $("g.node");
$graphNodes.hover(
function() {
$(this).find("path").addClass("node-border-hover")
},
function() {
$(this).find("path").removeClass("node-border-hover");
}
);
$graphNodes.on("click", function() {
// TODO: Use `nodeId` to get attributes
const nodeId = $(this).attr("id");
if (prevSelected !== null) {
prevSelected.removeClass("node-border-active");
}
prevSelected = $(this).find("path");
prevSelected.addClass("node-border-active");
if (graphAttrs !== null) {
const nodeAttrs = graphAttrs[nodeId];
// TODO: Render node attributes
console.log("========== Node Properties ==========")
console.log("Node Id: ", nodeId);
console.log("Node Attributes: ", nodeAttrs);
// TODO: Render node attributes
}
});
}
$("#open-graph-button").on("click", function (e) {
$("#open-file-dialog").click();
});
$("#open-file-dialog").on("change", function(e) {
function handleFile(f) {
console.log("Load NG file:", f.name);
JSZip.loadAsync(f).then(
function(zip) {
zip.forEach(function (relativePath, zipEntry) {
if (zipEntry.name === "graph.svg") {
console.log("Read ", zipEntry.name, " file...");
zipEntry.async("string").then(
function success(content) {
let $svgContainer = $("#svg-container");
$("#start-page").hide();
$svgContainer.html(content);
svgPanZoom($svgContainer.children().first().get(0), {
zoomEnabled: true,
controlIconsEnabled: true,
mouseWheelZoomEnabled: false
});
attachEventHandlersToNodes();
},
function error(e) {
console.log("Failed to load the ", zipEntry.name, " file from ", f.name);
}
);
} else if (zipEntry.name === "data.json") {
console.log("Read ", zipEntry.name, " file...");
zipEntry.async("string").then(
function success(content) {
graphAttrs = JSON.parse(content);
},
function error(e) {
console.log("Failed to load the ", zipEntry.name, " file from ", f.name);
}
);
} else {
alert("Unknown entry: " + zipEntry.name);
console.log("Unknown entry: ", zipEntry.name);
}
});
},
function (e) {
console.log("Error reading " + f.name + ": " + e.message);
}
);
}
var files = e.target.files;
for (var i = 0; i < files.length; i++) {
handleFile(files[i]);
}
});
</script>
</body>
</html>