@devexperts/dxcharts-lite
Version:
31 lines (30 loc) • 1.36 kB
JavaScript
/*
* Copyright (C) 2019 - 2025 Devexperts Solutions IE Limited
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
import { calculateSymbolHeight, calculateTextWidth } from '../../utils/canvas/canvas-font-measure-tool.utils';
export class TextDrawer {
constructor(config) {
this.config = config;
}
draw(ctx, allPoints, model, hitTestDrawerConfig) {
ctx.save();
allPoints.forEach((points, idx) => {
var _a;
const config = model.getPaintConfig(idx);
ctx.fillStyle = (_a = hitTestDrawerConfig.color) !== null && _a !== void 0 ? _a : config.color;
const font = config.lineWidth + 'px ' + this.config.components.yAxis.fontFamily;
ctx.font = font;
points.forEach(p => {
const text = model.getTextForPoint(p);
const textWidth = calculateTextWidth(text, ctx, font);
const textHeight = calculateSymbolHeight(font, ctx);
const x = model.view.toX(p.centerUnit) - textWidth / 2;
const y = model.view.toY(p.close) + textHeight;
ctx.fillText(text, x, y);
});
});
ctx.restore();
}
}