ECG test
by Yamamila
HTML
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/flot/0.8.3/jquery.flot.js"></script>
<div id="placeholder" style="min-height:300px">
</div>
<br>
<button id='button'>
<font color=red>
Sem Adrenalina
</font>
</button>
JavaScript
$(function() {
// info for graph2
instant = 5;
high = -45;
frequency = 15;
updateInterval = 70;
var data1 = [], data2 = [], totalPoints = 300;
function getRandomData() {
// original j flot randon data, nao precisamos neste exemplo..
}
function getRandomData2() {
// se adrenalina ON sobre o grafico
if(isRunning==true){
high=high-.25;
frequency=frequency+.25;
}
if(high<-80){ // esse eh o limite superior
high=-80;
frequency=35;
}
if (data2.length > 0)
data2 = data2.slice(1);
while (data2.length < totalPoints) {
instant = instant - frequency;
if (instant < high) {
instant = (high * -1);
}
instantShow = instant;
if (instantShow < 20) {
instantShow = 20;
}
data2.push(instantShow);
}
var res = [];
for (var i = 0; i < data2.length; ++i) {
res.push([i, data2[i]])
}
//console.log(data2);
return res;
}
//
// Set up the control widget
$("#updateInterval").val(updateInterval).change(function() {
var v = $(this).val();
if (v && !isNaN(+v)) {
updateInterval = +v;
if (updateInterval < 1) {
updateInterval = 1;
} else if (updateInterval > 2000) {
updateInterval = 2000;
}
$(this).val("" + updateInterval);
}
});
var plot = $.plot("#placeholder", [{
data: getRandomData()
}, {
data: getRandomData2()
}], {
series: {
shadowSize: 0
},
yaxis: {
min: 0,
max: 100
},
xaxis: {
show: false
}
});
//
// function update() { plot.setData([getRandomData()]);
function update() {
plot.setData([{
data: getRandomData()
}, {
data: getRandomData2()
}]);
plot.draw();
setTimeout(update, updateInterval);
}
update();
});
//
// buttons
//
var isRunning = false;
document.getElementById('button').onclick =...