Skip to content

Commit 4a42fdc

Browse files
committed
More spectro enhancements
1 parent dba5ad3 commit 4a42fdc

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

scripts/spectrogram.php

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ function applyText(text,x,y,opacity) {
105105
if(opacity < 0.2) {
106106
opacity = 0.2;
107107
}
108+
CTX.textAlign = "center";
108109
CTX.fillStyle = "rgba(255, 255, 255, "+opacity+")";
109110
CTX.font = '15px Roboto Flex';
110111
//fitTextOnCanvas(text,"Roboto Flex",document.body.querySelector('canvas').scrollHeight * 0.35)
@@ -134,18 +135,34 @@ function loadDetectionIfNewExists() {
134135
timeDiff = (d2-d1)/1000;
135136

136137
// stagger Y placement if a new bird
137-
if(split[i].split(",")[1] != lastbird) {
138-
if(add >= 60) {
139-
add = 0
138+
if(split[i].split(",")[1] != lastbird || split[i].split(",")[1].length > 15) {
139+
if(add >= 80) {
140+
add -= 40;
140141
} else {
141142
add += 20;
142143
}
144+
145+
if(parseFloat(add + document.body.querySelector('canvas').height * 0.50) > document.body.querySelector('canvas').height || parseFloat(add + document.body.querySelector('canvas').height * 0.50) <= 0) {
146+
add = 0;
147+
}
143148
}
144149

145150
// Date csv file was created + relative detection time of bird + mic delay
146151
secago = Math.abs(timeDiff) - split[i].split(",")[0] - 6.8;
147-
console.log(Math.abs(timeDiff) + " - " + split[i].split(",")[0] + " - 6.8");
148-
applyText(split[i].split(",")[1],document.body.querySelector('canvas').width - ((parseInt(secago))*avgfps), ((document.body.querySelector('canvas').height * 0.50) + add ), split[i].split(",")[2])
152+
153+
x = document.body.querySelector('canvas').width - ((parseInt(secago))*avgfps);
154+
// if the text is too close to the right side of the canvas and will be cut off, wait 3 seconds before adding text
155+
if(x > document.body.querySelector('canvas').width - (3*avgfps)) {
156+
setTimeout(function (split,i,x) {
157+
console.log(split[i])
158+
console.log("originally at "+x+", now waiting 2 sec and at "+(x-(3*avgfps)))
159+
applyText(split[i].split(",")[1],(x - (3*avgfps)), ((document.body.querySelector('canvas').height * 0.50) + add ), split[i].split(",")[2]);
160+
}, 2000, split, i, x)
161+
} else {
162+
applyText(split[i].split(",")[1],x, ((document.body.querySelector('canvas').height * 0.50) + add ), split[i].split(",")[2])
163+
}
164+
165+
149166
lastbird = split[i].split(",")[1]
150167
}
151168

0 commit comments

Comments
 (0)