-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
188 lines (181 loc) · 8.32 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>jdistpatcher-viewers</title>
<script type="text/javascript" src="dist/jd_viewers_0.0.12.bundle.min.js" defer></script>
<link rel="stylesheet" href="static/style.css" type="text/css" media="all" />
</head>
<body>
<div id="jd-viewers-app">
<form id="jd-viewers-form">
<label for="jobid">JobId:</label>
<input type="text" size="60" id="jobid" required="true"
value="mock_jobid-I20200317-103136-0485-5599422-np2" />
</br>
<button type="submit" name="visual-output">Generate Visual Output</button>
<button type="submit" name="functional-predictions">Generate Functional Predictions</button>
</form>
<input type='button' id='btn-png' value='Display as PNG' />
<input type='button' id='btn-png-download' value='Save as PNG' />
<input type='button' id='btn-svg' value='Display as SVG' />
<input type='button' id='btn-svg-download' value='Save as SVG' />
<p>
<div id="canvas-wrapper">
<canvas id="canvas" />
</div>
<img id="svg"></img>
<img id="png"></img>
</p>
</div>
</body>
<script>
async function eventHandler(event){
event.preventDefault();
// remove canvas-wrapper (if some available)
const el = document.getElementById("canvas-wrapper");
if (el !== null) el.parentNode.removeChild(el);
// create new canvas-wrapper
const canvasElement = document.getElementById("canvas");
if (canvasElement === null) {
const newDiv = document.createElement("div");
newDiv.id = "canvas-wrapper";
const newCanvas = document.createElement("canvas");
newCanvas.id = "canvas";
newDiv.appendChild(newCanvas);
document.body.appendChild(newDiv);
}
// reset images if not empty
const png = document.getElementById("png");
png.src = ""
const svg = document.getElementById("svg");
svg.src = ""
const submitter = event.submitter.name.trim();
const jobId = event.target.querySelector("#jobid").value.trim();
const jobIdObj = {
value: jobId,
required: true,
minLength: 35,
maxLength: 60,
pattern: /([a-z_])*-([A-Z0-9])*-\d*-\d*-\d*-(np2|p1m|p2m)$/,
}
if (validateJobId(jobIdObj)) {
let sssJsonData;
if (jobId === "mock_jobid-I20200317-103136-0485-5599422-np2") {
sssJsonData = "./src/testdata/ncbiblast.json";
} else {
sssJsonData = validateSubmittedJobIdInput(jobId);
}
const sssJsonResponse = await fetchData(sssJsonData);
const sssDataObj = dataAsType(sssJsonResponse, "SSSResultModel");
let iprmcXmlData;
if (jobId === "mock_jobid-I20200317-103136-0485-5599422-np2") {
iprmcXmlData = "./src/testdata/iprmc.xml";
} else {
iprmcXmlData = validateSubmittedDbfetchInput(sssDataObj)
}
const iprmcXmlResponse = await fetchData(iprmcXmlData, "xml");
// convert XML into Flattened JSON
const iprmcJSONResponse = getIPRMCDataModelFlatFromXML(iprmcXmlResponse);
const iprmcDataObj = dataAsType(iprmcJSONResponse, "IPRMCResultModelFlat");
// viz app
let fabricjs;
let submitterShort = ";"
if (submitter == "visual-output") {
submitterShort = "vo";
// Render Options
const options = {
colorScheme: "dynamic",
numberHits: 100,
numberHsps: 10,
logSkippedHsps: true,
canvasWrapperStroke: true,
staticCanvas: false
};
// Call render method to display the viz
fabricjs = new VisualOutput("canvas", sssDataObj, options);
fabricjs.render();
} else if (submitter == "functional-predictions"){
submitterShort = "fp";
// Render Options
const options = {
colorScheme: "dynamic",
numberHits: 30,
canvasWrapperStroke: true,
staticCanvas: false
};
// Call render method to display the viz
fabricjs = new FunctionalPredictions("canvas", sssDataObj, iprmcDataObj, options);
fabricjs.render();
}
// export as SVG and PNG
document.getElementById("btn-svg").onclick = function () {
const img = document.getElementById(
"svg"
);
img.src = svgToMiniDataURI(fabricjs.canvas.toSVG().toString());
// remove canvas-wrapper
const el = document.getElementById("canvas-wrapper");
el.parentNode?.removeChild(el);
};
document.getElementById("btn-png").onclick = function () {
const img = document.getElementById(
"png"
);
img.src = fabricjs.canvas
.toDataURL({
format: "png",
enableRetinaScaling: true,
withoutTransform: true,
})
.toString();
img.width = fabricjs.canvas.getWidth();
// remove canvas-wrapper
const el = document.getElementById("canvas-wrapper");
el.parentNode?.removeChild(el);
};
// download as SVG and PNG
document.getElementById("btn-svg-download").onclick = function () {
const img = document.getElementById(
"svg"
);
img.src = svgToMiniDataURI(fabricjs.canvas.toSVG().toString());
const a = document.createElement('a');
a.href = img.src;
a.download = `${jobId}-${submitterShort}.svg`;
a.target = '_blank';
document.body.appendChild(a); a.click(); document.body.removeChild(a);
};
document.getElementById("btn-png-download").onclick = function () {
const img = document.getElementById(
"png"
);
img.src = fabricjs.canvas
.toDataURL({
format: "png",
enableRetinaScaling: true,
withoutTransform: true,
})
.toString();
img.width = fabricjs.canvas.getWidth();
const a = document.createElement('a');
a.href = img.src;
a.download = `${jobId}-${submitterShort}.png`;
a.target = '_blank';
document.body.appendChild(a); a.click(); document.body.removeChild(a);
};
} else {
alert("The jobId provided is not valid!");
return;
}
}
document.addEventListener("DOMContentLoaded", () => {
// Form submit handler
const element = document.getElementById("jd-viewers-form");
const jobIdElement = element.querySelector("#jobid");
element.addEventListener("submit", eventHandler);
});
</script>
</html>