draw channel numbers separately

This commit is contained in:
Lewis Moten
2024-05-05 16:13:04 -04:00
parent 9a5f8a3e59
commit 5a5c013001

View File

@@ -972,6 +972,7 @@ function getTimePercent(time, newest) {
return ((newest - time) / duration); return ((newest - time) / duration);
} }
function drawChannelData() { function drawChannelData() {
const S = performance.now();
// return; // return;
const canvas = document.getElementById('received-channel-graph'); const canvas = document.getElementById('received-channel-graph');
const ctx = canvas.getContext('2d'); const ctx = canvas.getContext('2d');
@@ -1063,9 +1064,6 @@ function drawChannelData() {
} }
// for(let channelIndex = 0; channelIndex < channelCount; channelIndex++) {
// const [low, high] = channels[channelIndex];
// let top = channelHeight * channelIndex;
if(channelIndex % 8 === 0) { if(channelIndex % 8 === 0) {
ctx.strokeStyle = 'black'; ctx.strokeStyle = 'black';
ctx.lineWidth = 3; ctx.lineWidth = 3;
@@ -1074,22 +1072,26 @@ function drawChannelData() {
ctx.lineTo(width, top-1); ctx.lineTo(width, top-1);
ctx.stroke(); ctx.stroke();
} }
// channel number
ctx.font = `${channelHeight}px Arial`;
const size = ctx.measureText(channelIndex);
const textHeight = size.fontBoundingBoxAscent + size.fontBoundingBoxDescent;
const textTop = top + (channelHeight / 2) + (size.actualBoundingBoxAscent / 2);
// const textTop = top;//(top + (channelHeight / 2)) - (textHeight/2);
const hue = channelHue(channelIndex, channelCount);
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
ctx.fillText(channelIndex, 5, textTop);
} }
overlays.forEach(fn => fn()); overlays.forEach(fn => fn());
drawChannelNumbers(ctx, channelCount, channelHeight)
console.log('time', performance.now() - S);
}
function drawChannelNumbers(ctx, channelCount, channelHeight) {
let fontHeight = Math.min(24, channelHeight);
ctx.font = `${fontHeight}px Arial`;
ctx.textBaseline = 'middle';
ctx.fillStyle = 'rgba(0, 0, 0, .5)';
const maxDigits = (channelCount - 1).toString().length;
ctx.fillRect(0, 0, (fontHeight * maxDigits), channelHeight * channelCount);
for(let channelIndex = 0; channelIndex < channelCount; channelIndex++) {
let top = channelHeight * channelIndex;
let text = channelIndex.toString();
const textTop = top + (channelHeight / 2);
const hue = channelHue(channelIndex, channelCount);
ctx.fillStyle = `hsl(${hue}, 100%, 50%)`;
ctx.fillText(text, 5, textTop);
}
} }
function drawFrequencyData() { function drawFrequencyData() {
if(PAUSE) return; if(PAUSE) return;