@devexperts/dxcharts-lite
Version:
46 lines (45 loc) • 1.79 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 { clipToBounds } from '../utils/canvas/canvas-drawing-functions.utils';
/***
* HitTest Chart drawer. It's used to draw hit test for chart types on the hit-test canvas.
*/
export class HTDataSeriesDrawer {
constructor(seriesDrawers, canvasModel, paneManager, drawPredicate = () => true) {
this.seriesDrawers = seriesDrawers;
this.canvasModel = canvasModel;
this.paneManager = paneManager;
this.drawPredicate = drawPredicate;
}
draw() {
if (this.drawPredicate()) {
const ctx = this.canvasModel.ctx;
this.paneManager.yExtents.forEach(comp => {
ctx.save();
clipToBounds(ctx, comp.getBounds());
comp.dataSeries.forEach(series => this.drawSeries(ctx, series));
ctx.restore();
});
}
}
drawSeries(ctx, series) {
if (series.config.visible) {
const paintTool = series.config.type;
const drawer = this.seriesDrawers[paintTool];
if (drawer) {
const drawConfig = {
color: this.canvasModel.idToColor(series.htId),
hoverWidth: 7,
};
// +- 1 to correctly draw points which are partly inside bounds
drawer.draw(ctx, series.getSeriesInViewport(series.scale.xStart - 1, series.scale.xEnd + 1), series, drawConfig);
}
}
}
getCanvasIds() {
return [this.canvasModel.canvasId];
}
}