Pezh commited on
Commit
9b9e8e7
·
verified ·
1 Parent(s): 96a9585

Create script.js

Browse files
Files changed (1) hide show
  1. script.js +59 -0
script.js ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // Get the canvas element
2
+ const canvas = document.getElementById('ecg-canvas');
3
+ const ctx = canvas.getContext('2d');
4
+
5
+ // Set the canvas dimensions
6
+ canvas.width = 400;
7
+ canvas.height = 100;
8
+
9
+ // Define the ECG data
10
+ const ecgData = [
11
+ { time: 0, value: 0 },
12
+ { time: 100, value: 10 },
13
+ { time: 200, value: 20 },
14
+ { time: 300, value: 30 },
15
+ { time: 400, value: 40 },
16
+ { time: 500, value: 50 },
17
+ { time: 600, value: 60 },
18
+ { time: 700, value: 70 },
19
+ { time: 800, value: 80 },
20
+ { time: 900, value: 90 },
21
+ { time: 1000, value: 100 }
22
+ ];
23
+
24
+ // Define the beat data
25
+ const beatData = [
26
+ { time: 0, value: 0 },
27
+ { time: 333, value: 33 },
28
+ { time: 66, value: 66 },
29
+ { time: 99, value: 99 }
30
+ ];
31
+
32
+ // Draw the ECG graph
33
+ function drawECG() {
34
+ ctx.clearRect(0, 0, canvas.width, canvas.height);
35
+ ctx.beginPath();
36
+ ctx.moveTo(0, canvas.height / 2);
37
+ for (let i = 0; i < ecgData.length; i++) {
38
+ const point = ecgData[i];
39
+ ctx.lineTo(point.time, point.value);
40
+ }
41
+ ctx.lineTo(canvas.width, canvas.height / 2);
42
+ ctx.stroke();
43
+ }
44
+
45
+ // Draw the beat markers
46
+ function drawBeats() {
47
+ ctx.beginPath();
48
+ for (let i = 0; i < beatData.length; i++) {
49
+ const beat = beatData[i];
50
+ ctx.fillStyle = 'red';
51
+ ctx.fillRect(beat.time, canvas.height / 2, 5, 5);
52
+ }
53
+ }
54
+
55
+ // Show the ECG graph and beat markers
56
+ document.getElementById('show-button').addEventListener('click', function() {
57
+ drawECG();
58
+ drawBeats();
59
+ });