diff --git a/frontend/src/lib/uPlotLib/getUplotChartOptions.ts b/frontend/src/lib/uPlotLib/getUplotChartOptions.ts index 09e3ce4815..a86c1ee49c 100644 --- a/frontend/src/lib/uPlotLib/getUplotChartOptions.ts +++ b/frontend/src/lib/uPlotLib/getUplotChartOptions.ts @@ -136,7 +136,18 @@ export const getUPlotChartOptions = ({ if (threshold.thresholdLabel) { const text = threshold.thresholdLabel; const textX = plotRight - ctx.measureText(text).width - 20; - const textY = yPos - 15; + + const canvasHeight = ctx.canvas.height; + const yposHeight = canvasHeight - yPos; + const isHeightGreaterThan90Percent = canvasHeight * 0.9 < yposHeight; + + // Adjust textY based on the condition + let textY; + if (isHeightGreaterThan90Percent) { + textY = yPos + 15; // Below the threshold line + } else { + textY = yPos - 15; // Above the threshold line + } ctx.fillStyle = threshold.thresholdColor || 'red'; ctx.fillText(text, textX, textY); }