-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
147 lines (130 loc) Β· 5.35 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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + TS</title>
<style>
html, body {
margin: 0;
height: 100%;
}
#app {
height: 100%;
background-color: #fdf2f8;
}
#test-box {
position: absolute;
display: block;
width: 400px;
height: 300px;
background-color: red;
z-index: -1;
}
</style>
</head>
<body>
<button id="screenshot" type="button">Save...</button>
<span>Warning: this is the default vite index.html file, not the chromospace app.</span>
<div id="test-box"></div>
<div id="app">
</div>
<script type="module">
import { parseTsv, parse3dg, addChunkToScene, addModelToScene, initScene, display, get } from './src/main.ts';
console.log("hello!");
const fetchTsv = async (url) => {
const response = await fetch(url);
if (!response.ok) throw new Error(`fetch failed: ${response.status}`);
const fileContent = await response.text();
return fileContent;
};
(async () => {
const url = "https://dl.dropboxusercontent.com/scl/fi/2lmqo9xo14bo8466xb2ia/dros.3.txt?rlkey=kb3zt0gjnh9h843y20rkrcq4a&e=1&dl=0";
const url2 = "https://dl.dropbox.com/scl/fi/bpd0t21ypyo0nyv3svi14/dros.9.txt?rlkey=i24mzd3hb1zruq7w8eshel9kq&dl=0";
const url3 = "https://dl.dropbox.com/scl/fi/ha34hk0jdg8cj5i7va2lb/dros.26.txt?rlkey=duyjahmvxf64splqvpzndlup3&dl=0";
const fileContent = await fetchTsv(url);
const fileContent2 = await fetchTsv(url2);
const fileContent3 = await fetchTsv(url3);
const testChunk = parseTsv(fileContent, { center: true, normalize: true }); //~ parseTsv(data, center = true) ?
const testChunk2 = parseTsv(fileContent2, { center: true, normalize: true }); //~ parseTsv(data, center = true) ?
const testChunk3 = parseTsv(fileContent3, { center: true, normalize: true }); //~ parseTsv(data, center = true) ?
console.log(testChunk);
const urlTan2018 = "https://dl.dropboxusercontent.com/scl/fi/lzv3ba5paum6srhte4z2t/GSM3271406_pbmc_18.impute.3dg.txt?rlkey=dc7k1gg5ghv2v7dsl0gg1uoo9&dl=0";
const fileTan2018 = await fetchTsv(urlTan2018);
const tan2018Model = parse3dg(fileTan2018 , { center: true, normalize: true }); //~ parseTsv(data, center = true) ?
//~ API testing
//~ this config specifies how the 3D model will look
// Used for the de-emphasized rest of the model
const unselected_ViewConfig = ({
scale: 0.005,
coloring: "constant",
color: "#a3a3a3",
links: false,
});
// Used for highlighted region
const selected_viewConfig = ({
scale: 0.02,
coloring: "constant",
color: "orange",
mark: "box",
links: true,
});
const num = testChunk.bins.length;
const sineWave = (amplitude, frequency, length) => Array.from({ length }, (_, i) => amplitude * Math.sin(frequency * i));
const sineValues = sineWave(100, 0.2, num);
const viewConfig = ({
scale: {
values: sineValues,
min: -100,
max: 100,
scaleMin: 0.01,
scaleMax: 0.03,
},
links: false,
mark: "sphere",
color: {
values: sineValues,
min: 0,
max: 100,
colorScale: "viridis",
},
});
//~ create a scene
let chromatinScene = initScene();
chromatinScene = addChunkToScene(chromatinScene, testChunk, viewConfig);
// chromatinScene = addModelToScene(chromatinScene, tan2018Model, viewConfig);
// const [selectedPartA, selectionA] = get(tan2018Model, "1(pat)");
// const selectedModelA = {
// parts: [selectedPartA],
// };
// chromatinScene = addModelToScene(chromatinScene, tan2018Model, unselected_ViewConfig);
// chromatinScene = addModelToScene(chromatinScene, selectedModelA, selected_viewConfig);
const [renderer, canvas] = display(chromatinScene, { alwaysRedraw: true, withHUD: true});
//~ add canvas to the page
let appEl = document.querySelector('#app');
if (canvas) {
appEl.appendChild(canvas);
}
const elem = document.querySelector('#screenshot');
elem.addEventListener('click', () => {
renderer.render();
canvas.toBlob((blob) => {
saveBlob(blob, `screencapture-${canvas.width}x${canvas.height}.png`);
});
});
const saveBlob = (function() {
const a = document.createElement('a');
document.body.appendChild(a);
a.style.display = 'none';
return function saveData(blob, fileName) {
const url = window.URL.createObjectURL(blob);
a.href = url;
a.download = fileName;
a.click();
};
}());
})();
</script>
</body>
</html>