-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
123 lines (112 loc) · 2.65 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
<html>
<head>
<meta charset="UTF-8">
<title>Averagine Model</title>
<style>
* {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
color: dimgrey;
}
h1, h2, h3, h4, h5, h6 {
color: darkcyan;
}
body, header, main, footer {
width: 100%;
margin: 0;
padding: 0;
}
div.header, div.main, div.footer {
box-sizing: border-box;
width: 100%;
max-width: 960px;
min-width: 320px;
margin: 0 auto;
padding: 4px;
}
div.header {
height: 60px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
}
div.main {
min-height: 600px;
padding: 16px;
}
div.footer {
height: 40px;
display: flex;
flex-direction: row;
justify-content: space-around;
align-items: center;
}
div.header a, div.footer a {
text-decoration: none;
}
div.header img {
height: 100%;
}
canvas, input {
width: 100%;
margin: 16px auto;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.2.1/chart.umd.min.js"></script>
<script src="./model.js"></script>
</head>
<body>
<header>
<div class="header">
<img src="fig/Averagine.svg" alt="logo"/><h1>Averagine Model</h1>
</div>
</header>
<main>
<div class="main">
<canvas id="canvas" width="600" height="400"></canvas>
<input type="range" id="mass" min="1" max="19999" value="10000" step="1" onchange="plot()">
</div>
</main>
<footer>
<div class="footer">
<span><a href="http://ctarn.io">http://ctarn.io</a></span>
<span>Copyright © Tarn Yeong Ching</span>
<span><a href="mailto:i@ctarn.io">i@ctarn.io</a></span>
</div>
</footer>
</body>
<script>
const ctx = document.getElementById("canvas").getContext("2d")
const chart = new Chart(ctx, {
type: "bar",
data: {datasets: [{backgroundColor: "darkcyan"}]},
options: {
plugins: {legend: {display: false}},
scales: {
x: {title: {display: true, text: "Mass (Da)"},},
y: {
title: {display: true, text: "Abundance"},
ticks: {callback: (value, index, ticks) => { return value + "%" }},
beginAtZero: true,
},
},
},
})
function plot() {
var mass = parseFloat(document.getElementById("mass").value)
var labels = []
var data = []
var v = V[Math.floor(mass / 10)]
for (var i = 0; i < v.length; ++i) {
labels.push(`#${i + 1}: ${mass + i}`)
data.push(v[i] * 100)
}
chart.data.datasets[0].data = data
chart.data.labels = labels
chart.update()
}
const args = new URLSearchParams(window.location.search);
document.getElementById("mass").value = args.has("mass") ? parseInt(args.get("mass")) : 10000
plot()
</script>
</html>