-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathindex.html
455 lines (432 loc) · 13.6 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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
<!DOCTYPE html>
<html lang="en">
<head>
<title>Patient Viz</title>
<meta charset="utf-8">
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" type="text/css" href="lib/jk-js/lib/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="style.css">
<script src="lib/jk-js/lib/d3/d3.min.js" charset="utf-8"></script>
<script src="lib/colorbrewer/colorbrewer.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/busy.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/zui.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/time.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/text.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/path.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/stat.js" charset="utf-8"></script>
<script src="lib/jk-js/jkjs/util.js" charset="utf-8"></script>
<script src="js/typepool.js" charset="utf-8"></script>
<script src="js/type.js" charset="utf-8"></script>
<script src="js/event.js" charset="utf-8"></script>
<script src="js/overview.js" charset="utf-8"></script>
<script src="js/eventview.js" charset="utf-8"></script>
<script src="js/typeview.js" charset="utf-8"></script>
<script src="js/linechart.js" charset="utf-8"></script>
<script src="js/histogram.js" charset="utf-8"></script>
<script src="js/labels.js" charset="utf-8"></script>
<script src="js/cluster.js" charset="utf-8"></script>
<script src="js/shared.js" charset="utf-8"></script>
</head>
<body onload="start()">
<header id="pHead" class="navbar navbar-default navbar-static-top">
<div class="container">
<ul class="list-inline" id="pHeadList">
<li><div>
<strong>Time:</strong>
<span id="pStart"></span> - <span id="pEnd"></span>
</div></li><li><div class="checkbox">
<label>
<input id="pShowSpans" type="checkbox" checked="checked"> Show Spans
</label>
<label id="pShowLabel">
<input id="pShow" type="checkbox"> Show All Events
</label>
<label>
<input id="pVSel" type="checkbox"> Vertical Sel.
</label>
<label>
<input id="pUseLens" type="checkbox"> Use Lens
</label>
<label>
Y-Aggr: <select id="pYCluster"></select>
</label>
<label>
Connect: <input id="pConnectRange" type="range" value="0" min="0" max="50"> <span id="pConnectRangeDisplay">0</span>
</label>
</div></li>
<li><div id="hCon"><strong>Sort types: </strong></div></li>
<li><div id="xMode"><strong>X: </strong></div></li>
<li><div id="yMode"><strong>Y: </strong></div></li>
</ul>
</div>
</header>
<div id="pTypesLeft"></div>
<div id="pContent">
<div id="pSVG"></div>
</div>
<div id="pTypesRight"></div>
<script>
var SLOW_MODE = false;
var DEBUG_V_SEGMENTS = false;
var SHOW_EVENT_GROUPS = false;
function start() {
jkjs.busy.imgBusy = "lib/jk-js/jkjs/img/busy.gif";
jkjs.busy.imgWarn = "lib/jk-js/jkjs/img/warning.png";
jkjs.text.exact(!SLOW_MODE);
function setPidSel(ps) {
var curId;
if(ps) {
ps.on("change", function() {
var pn = ps.node();
var op = d3.select(pn.options[pn.selectedIndex]).datum();
loadFile(op, lastDictionaryFile, true);
});
var dd = ps.node();
curId = d3.select(dd.options[dd.selectedIndex]).text();
} else {
curId = 0;
}
d3.text("patients.txt", "text/plain", function(error, data) {
if(error) {
busy.setState(jkjs.busy.state.warn, "Error loading file list.");
console.warn(error);
return;
}
var pids = data.split("\n").map(function(pid) {
return (""+pid).trim();
}).filter(function(pid) {
return pid != "";
});
if(ps) {
var pidOpts = ps.selectAll("option").data(pids);
pidOpts.exit().remove();
pidOpts.enter().append("option");
pidOpts.text(function(pid) {
return pid;
});
pidOpts.sort();
ps.selectAll("option").each(function(p, i) {
if(p !== curId) {
return;
}
var tmpChg = ps.on("change");
ps.on("change", null);
ps.node().selectedIndex = i;
ps.on("change", tmpChg);
});
} else {
if(pids.length > 2 && pids[2] === "json/998093F33FE2D940.json") {
curId = 2;
}
if(curId < pids.length) {
loadFile(pids[curId], lastDictionaryFile || dictionaryDefault, true);
} else {
console.warn("no patients found!");
busy.setState(jkjs.busy.state.warn, "No file list found.");
}
}
});
}
var showLabelsOnDrag = !SLOW_MODE;
var topPad = 71; // bootstraps navbar
var divContent = d3.select("#pContent").style({
"display": "inline-block",
"margin": "0 5px",
"padding": 0,
"box-sizing": "border-box",
"font-size": "10px",
"font-family": "monospace"
});
var divSVG = d3.select("#pSVG");
var width = 800;
var height = 600;
var ovWidth = 256;
var ovHeight = Math.floor(256 / width * height);
var handler = {
getSize: function() {
return {
width: ovWidth,
height: ovHeight
};
},
getBox: function() {
return box;
},
getZUI: function() {
return zui;
}
};
var inTransition = 0;
var zui = jkjs.zui.create(divSVG, {
width: width + "px",
height: height + "px"
}, {
width: width,
height: height
}, function() {
return box;
}, function(target, translate, scale, w, h, canvasRect, isSmooth) {
if(isSmooth) {
labels && labels.setShowLabels(false);
pool.inTransition(true);
inTransition += 1;
setTimeout(function() {
inTransition -= 1;
if(inTransition == 0) {
labels && labels.setShowLabels(true);
pool.inTransition(false);
updateViewport();
}
}, jkjs.zui.animationDuration);
}
jkjs.zui.applyCanvasZoom(target, translate, scale, w, h, canvasRect, isSmooth);
var visRect = jkjs.zui.computeVisibleRect(translate, scale, w, h);
overview.updateCameraRect(canvasRect, visRect, isSmooth);
pool.onViewportChange(box, visRect, scale, isSmooth);
}, [ 1e-6, 12 ]); // be generous with zooming! FIXME: adapt zoom extent depending on minTimeDiff #34
function updateViewport() {
zui.move(0, 0, false);
}
zui.svg.style({
"cursor": "crosshair"
});
if(!showLabelsOnDrag) {
zui.svg.on("mousedown.labels", function() {
labels && labels.setShowLabels(false);
}).on("mouseup.labels", function() {
labels && labels.setShowLabels(true);
updateViewport();
}).on("mousewheel.labels", function() {
labels && labels.setShowLabels(true);
updateViewport();
});
}
var suppl = divSVG.append("svg");
var overview = new Overview(d3.select("#pTypesRight"), handler);
overview.getSVG().on("mousedown.labels", function() {
labels && labels.setShowLabels(false);
}).on("mouseup.labels", function() {
labels && labels.setShowLabels(true);
updateViewport();
});
var pool = null;
var eventList = null;
var typeList = null;
var linechart = null;
var histogram = null;
var box = null;
var labels = null;
function setBox(w, h) {
box = {
x: 0,
y: 0,
width: w,
height: h
};
overview.onBoxUpdate();
};
var mainG = zui.inner.append("g").attr({
"id": "mainG"
});
var secG = zui.svg.append("g");
var busy = new jkjs.busy.layer(zui.svg, {
x: 0,
y: 0,
width: width,
height: height
});
var fullRect = zui.svg.append("rect").attr({
"x": 0,
"y": 0,
"width": width,
"height": height,
"stroke": "black",
"stroke-width": 1,
"fill": "none"
});
var blank = zui.svg.append("rect").attr({
"x": 0,
"y": 0,
"width": width,
"height": height,
"fill": "white",
"opacity": 0
});
function setSize(w, h) {
width = w;
height = h;
if(box) {
setBox(box.width, box.height);
}
overview.onSizeUpdate();
fullRect.attr({
"width": width,
"height": height
});
blank.attr({
"width": width,
"height": height
});
busy.setRect({
x: 0,
y: 0,
width: width,
height: height
});
zui.setSize({
width: width + "px",
height: height + "px"
}, {
width: width,
height: height
});
if(pool) {
pool.onSizeUpdate(width, height);
}
}
var views = initViews(mainG, secG, suppl, blank, d3.select("#pTypesRight"), d3.select("#pTypesLeft"), overview, setBox, onVC, busy, updateViewport);
pool = views[0];
eventList = views[1];
typeList = views[2];
linechart = views[3];
histogram = views[4];
labels = views[5];
d3.select("#pVSel").on("change", function() {
pool.verticalSelection(d3.select("#pVSel").node().checked);
});
d3.select("#pShow").on("change", function() {
pool.showOnlyWeightedEvents(!d3.select("#pShow").node().checked);
});
d3.select("#pShowSpans").on("change", function() {
pool.showSpans(d3.select("#pShowSpans").node().checked);
overview.clearShadow();
pool.updateLook();
});
function updateRange() {
var value = d3.select("#pConnectRange").node().value;
d3.select("#pConnectRangeDisplay").text(value);
pool.maxConnectSlot(value);
}
d3.select("#pConnectRange").style({
"width": "50px",
"display": "inline-block"
}).on("change", updateRange);
if(!SLOW_MODE) {
d3.select("#pConnectRange").on("input", updateRange);
}
var args = jkjs.util.getQueryStrings();
var dictionaryDefault = 'json/dictionary.json';
var dictionary = null;
var lastDictionaryFile = null;
if(args["p"]) {
// we need to remove '/' from the end of arguments because chrome likes
// to add those if the page was not called via 'index.html'
loadFile(args["p"].replace(/\/+$/,''), args["d"] ? args["d"].replace(/\/+$/,'') : dictionaryDefault, false);
} else {
setPidSel(null);
}
function loadFile(pid, dictionaryFile, createState) {
if(createState) {
var url = jkjs.util.getOwnURL() + "?p=" + pid + "&d=" + dictionaryFile;
window.history.pushState({
pid: pid,
dictionary: dictionaryFile
},"", url);
}
var inputFile = pid;
busy.setState(jkjs.busy.state.busy);
overview.clearShadow(); // having a use element would slow down DOM manipulations by at least 20s
typeList.clearLists();
eventList.setEvents([], false, false);
d3.json(inputFile, function(err, json_patient) {
if(err) {
console.warn("Failed loading patient: '"+inputFile+"' Note: Give the patient file as argument 'p'");
busy.setState(jkjs.busy.state.warn, "Failed loading file: '"+inputFile+"' Note: Put the file as argument 'p'.");
return console.warn(err);
}
d3.json(dictionaryFile, function(err_dict, json_dictionary) {
if(err_dict) {
console.warn("Failed loading dictionary: '"+dictionaryFile+"'");
busy.setState(jkjs.busy.state.warn, "Invalid dictionary file.");
return console.warn(err_dict);
}
dictionary = json_dictionary;
lastDictionaryFile = dictionaryFile;
var error = true;
try {
setPidSel(loadPerson(pid, json_patient, pool, eventList, typeList, linechart, histogram, dictionary, suppl));
busy.setState(jkjs.busy.state.norm);
relayout();
zui.showAll(false);
error = false;
} finally {
if(error) {
busy.setState(jkjs.busy.state.warn, "Error while loading file.");
}
}
});
});
}
window.onpopstate = function(e) {
if(e.state) {
loadFile(e.state.pid, e.state.dictionary, false);
}
};
function onVC() {
relayout();
zui.showAll(false);
}
function relayout() {
topPad = d3.select("#pHead").node().offsetHeight + 10; // comfort space
var bodyHeight = window.innerHeight;
var body = d3.select("body").style({
"width": "100%",
"height": bodyHeight + "px"
});
var bodyPadding = topPad;
var bodyWidth = body.node().offsetWidth;
var listWidthLeft = d3.select("#pTypesLeft").node().offsetWidth;
var listWidthRight = d3.select("#pTypesRight").node().offsetWidth;
var correctWidth = bodyWidth - listWidthLeft - listWidthRight - 36; // 2 * 5px margin on both sides + 16px buffer
var allowedHeight = bodyHeight - bodyPadding - 16; // 10px bottom margin + 6px buffer
var bodyHPad = 18;
divContent.style({
"left": (listWidthLeft + bodyHPad) + "px",
"height": allowedHeight + "px",
"width": correctWidth + "px"
});
divSVG.style({
"left": (listWidthLeft + bodyHPad) + "px",
"height": allowedHeight + "px",
"width": correctWidth + "px",
"position": "absolute",
"top": bodyPadding + "px"
});
if(ovWidth !== listWidthRight) {
var ovw = listWidthRight;
ovHeight = overview.getHeightForWidth(ovw);
ovWidth = ovw;
overview.onSizeUpdate();
}
var shadowHeight = overview.getHeightForWidth(listWidthRight);
var listHeightLeft = allowedHeight;
var listHeightRight = allowedHeight - shadowHeight;
eventList && eventList.resize(listHeightRight, bodyPadding);
typeList && typeList.resize(listHeightLeft, bodyPadding);
if(box) {
var supplHeight = suppl.node().offsetHeight;
// firefox might not have values for that
if(!supplHeight) {
supplHeight = 108;
}
setSize(correctWidth, allowedHeight - supplHeight);
}
labels && labels.isInit(false);
}
window.onresize = function() {
relayout();
};
}
</script>
</body>
</html>