function drawLabel(
context: CanvasRenderingContext2D,
label: LaidOutPriceAxisLabel,
width: number,
horizontalPixelRatio: number,
verticalPixelRatio: number,
): void {
const { colors } = getThemeStore();
const coordinate = Math.round(label.coordinate * verticalPixelRatio);
const labelHeight = Math.round(label.height * verticalPixelRatio);
const top = Math.round(coordinate - labelHeight / 2);
const horizontalPadding = Math.round(HORIZONTAL_PADDING * horizontalPixelRatio);
const backgroundColor = label.style === 'outlined' ? colors.chartBackground : label.color;
const textColor = label.style === 'outlined' ? label.color : getContrastTextColor(label.color);
context.fillStyle = backgroundColor;
context.fillRect(0, top, width, labelHeight);
if (label.style === 'outlined') {
const borderWidth = Math.max(1, Math.round(horizontalPixelRatio));
context.strokeStyle = label.color;
context.lineWidth = borderWidth;
context.strokeRect(
borderWidth / 2,
top + borderWidth / 2,
Math.max(0, width - borderWidth),
Math.max(0, labelHeight - borderWidth),
);
}
context.fillStyle = textColor;
const maxTextWidth = width - horizontalPadding * 2;
const text = fitText(context, label.text, maxTextWidth);
context.textAlign = 'center';
context.fillText(text, width / 2, coordinate);
}