-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLDL_cholesterol_graph.html
More file actions
218 lines (181 loc) · 6.54 KB
/
LDL_cholesterol_graph.html
File metadata and controls
218 lines (181 loc) · 6.54 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>12/09/2024</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
background-color: #f4f4f4;
color: #333;
line-height: 1.6;
}
h1, h2 {
color: #2c3e50;
}
img {
max-width: 100%;
height: auto;
display: block;
margin: 10px 0;
}
.container {
max-width: 800px;
margin: 0 auto;
background: #fff;
padding: 20px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
p {
margin: 10px 0;
}
a {
color: #3498db;
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
/* Ensure canvas is scrollable on smaller screens */
.canvas-container {
width: 100%;
overflow-x: auto; /* Horizontal scroll for smaller devices */
margin-bottom: 20px;
border: 1px solid #ddd;
background: #f9f9f9;
padding: 10px;
}
canvas {
display: block;
margin: 0 auto;
border: 1px solid black;
}
@media (max-width: 768px) {
body {
margin: 10px;
}
.container {
padding: 10px;
}
h1 {
font-size: 24px;
}
h2 {
font-size: 18px;
}
}
</style>
<script type="text/javascript" id="MathJax-script" async
src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js"></script>
</head>
<body>
<div class="container">
Back to <a href="index">Homepage</a>
<h1>iBlog</h1>
<h2>12/09/2024</h2>
<p>
On 09/16/2021, I was prescribed Atorvastatin and have since been taking one 10MG tablet per day.
</p>
<div class="canvas-container">
<canvas id="cholesterolGraph" width="800" height="400"></canvas>
</div>
<script>
const canvas = document.getElementById('cholesterolGraph');
const ctx = canvas.getContext('2d');
const data = [
{ date: "2013-04-16", cholesterol: 103 },
{ date: "2015-04-01", cholesterol: 113 },
{ date: "2020-02-13", cholesterol: 160 },
{ date: "2021-09-16", cholesterol: 263 },
{ date: "2022-09-19", cholesterol: 154 },
{ date: "2023-10-20", cholesterol: 135 },
{ date: "2024-12-05", cholesterol: 159 },
];
const cholesterols = data.map(d => d.cholesterol);
const minCholesterol = Math.min(...cholesterols);
const maxCholesterol = Math.max(...cholesterols);
function map(value, minInput, maxInput, minOutput, maxOutput) {
return ((value - minInput) / (maxInput - minInput)) * (maxOutput - minOutput) + minOutput;
}
function drawTitle() {
ctx.font = "20px Arial";
ctx.textAlign = "center";
ctx.fillStyle = "black";
ctx.fillText("LDL Cholesterol Levels Over Time", canvas.width / 2, 30);
}
function drawAxes() {
ctx.beginPath();
ctx.moveTo(50, 350);
ctx.lineTo(50, 50);
ctx.moveTo(50, 350);
ctx.lineTo(750, 350);
ctx.stroke();
ctx.font = "16px Arial";
ctx.textAlign = "center";
ctx.fillText("Date", 400, 390);
ctx.save();
ctx.translate(20, 200);
ctx.rotate(-Math.PI / 2);
ctx.fillText("LDL Cholesterol Level", 0, 0);
ctx.restore();
}
function drawGridAndLabels() {
ctx.font = "12px Arial";
ctx.fillStyle = "black";
const totalPoints = data.length;
const xSpacing = (750 - 50) / (totalPoints - 1);
data.forEach((point, index) => {
const x = 50 + index * xSpacing;
ctx.fillText(point.date, x, 370);
ctx.beginPath();
ctx.moveTo(x, 350);
ctx.lineTo(x, 50);
ctx.strokeStyle = "#ddd";
ctx.stroke();
});
for (let i = minCholesterol; i <= maxCholesterol; i += 10) {
const y = map(i, minCholesterol, maxCholesterol, 350, 50);
if (y >= 50 && y <= 350) {
ctx.fillText(i, 40, y + 5);
ctx.beginPath();
ctx.moveTo(50, y);
ctx.lineTo(750, y);
ctx.strokeStyle = "#ddd";
ctx.stroke();
}
}
}
function plotData() {
const totalPoints = data.length;
const xSpacing = (750 - 50) / (totalPoints - 1);
data.forEach((point, index) => {
const x = 50 + index * xSpacing;
const y = map(point.cholesterol, minCholesterol, maxCholesterol, 350, 50);
ctx.beginPath();
ctx.arc(x, y, 3, 0, 2 * Math.PI);
ctx.fillStyle = "blue";
ctx.fill();
if (index > 0) {
const prevX = 50 + (index - 1) * xSpacing;
const prevY = map(data[index - 1].cholesterol, minCholesterol, maxCholesterol, 350, 50);
ctx.beginPath();
ctx.moveTo(prevX, prevY);
ctx.lineTo(x, y);
ctx.strokeStyle = "blue";
ctx.stroke();
}
});
}
drawTitle();
drawAxes();
drawGridAndLabels();
plotData();
</script>
<p>End of blog. Thank you for reading!</p>
Back to <a href="index">Homepage</a><br><br>
© 2024. This work by Isaiah Keating is openly licensed via <a href="https://creativecommons.org/licenses/by-sa/4.0/">CC BY-SA 4.0</a>
</div>
</body>
</html>