Skip to content

Commit

Permalink
Fill background of begin time and end time text
Browse files Browse the repository at this point in the history
Ensures that the text is readable even when it overlaps with another segment
  • Loading branch information
thequilo committed Sep 4, 2024
1 parent 76a1b49 commit 0094c1a
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions meeteval/viz/visualize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2021,11 +2021,25 @@ class CanvasPlot {
context.fillStyle = "gray";
context.textAlign = "center";
context.textBaseline = "bottom";
context.fillText(`begin time: ${d.start_time.toFixed(2)}`, d.x + d.width / 2, this.plot.y(d.start_time) - 3);
{
const text = `begin time: ${d.start_time.toFixed(2)}`;
const textMetrics = context.measureText(text);
context.fillStyle = "#eee";
context.fillRect(d.x + d.width / 2 - textMetrics.width / 2 - 3, this.plot.y(d.start_time), textMetrics.width + 6, - (textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent));
context.fillStyle = "gray";
context.fillText(text, d.x + d.width / 2, this.plot.y(d.start_time) - 1);
}

// Write end time below end marker
context.textBaseline = "top";
context.fillText(`end time: ${d.end_time.toFixed(2)}`, d.x + d.width / 2, this.plot.y(d.end_time) + 3);
{
context.textBaseline = "top";
const text = `end time: ${d.end_time.toFixed(2)}`;
const textMetrics = context.measureText(text);
context.fillStyle = "#eee";
context.fillRect(d.x + d.width / 2 - textMetrics.width / 2 - 3, this.plot.y(d.end_time), textMetrics.width + 6, (textMetrics.fontBoundingBoxAscent + textMetrics.fontBoundingBoxDescent));
context.fillStyle = "gray";
context.fillText(`end time: ${d.end_time.toFixed(2)}`, d.x + d.width / 2, this.plot.y(d.end_time) + 2);
}
}
}

Expand Down

0 comments on commit 0094c1a

Please sign in to comment.