UNPKG

@devexperts/dxcharts-lite

Version:
44 lines (43 loc) 1.94 kB
/* * 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 { CandleSeriesModel } from '../../model/candle-series.model'; import { setLineWidth } from '../data-series.drawer'; import { flat } from '../../utils/array.utils'; export class LineDrawer { constructor(config) { this.config = config; } draw(ctx, points, candleSeries, hitTestDrawerConfig) { if (candleSeries instanceof CandleSeriesModel) { // @ts-ignore const visualCandles = flat(points); // TODO rework, make sure drawing is precise setLineWidth(ctx, this.config.lineWidth, candleSeries, hitTestDrawerConfig, this.config.selectedWidth); const lineTheme = candleSeries.colors.lineTheme; // make style changes outside loop to improve performance ctx.lineCap = 'round'; if (hitTestDrawerConfig.color) { ctx.strokeStyle = hitTestDrawerConfig.color; } for (let i = 1; i < visualCandles.length; i++) { const prev = visualCandles[i - 1]; const vc = visualCandles[i]; const direction = vc.name; if (!hitTestDrawerConfig.color) { ctx.strokeStyle = lineTheme[`${direction}Color`]; } const prevX = candleSeries.view.toX(prev.centerUnit); const prevY = candleSeries.view.toY(prev.close); const x = candleSeries.view.toX(vc.centerUnit); const y = candleSeries.view.toY(vc.close); ctx.beginPath(); ctx.moveTo(prevX, prevY); ctx.lineTo(x, y); ctx.stroke(); } } } }