UNPKG

@devexperts/dxcharts-lite

Version:
56 lines (55 loc) 1.78 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 { clipToBounds } from '../../utils/canvas/canvas-drawing-functions.utils'; export const candleTypesList = [ 'candle', 'bar', 'line', 'area', 'scatterPlot', 'hollow', 'histogram', 'baseline', 'trend', ]; /** * A decorator for drawers, that draw something depending on visual candles */ export class CandleSeriesWrapper { constructor(drawer, config, chartBounds) { this.drawer = drawer; this.config = config; this.chartBounds = chartBounds; } draw(ctx, allPoints, model, hitTestDrawerConfig) { if (this.isChartTypeAllowed()) { this.beforeDraw(ctx); this.drawer.draw(ctx, allPoints, model, hitTestDrawerConfig); this.afterDraw(ctx, model); } } beforeDraw(ctx) { // by default we have clip to study underlay area if study is underlying // remove clip if study is underlying, because we need to color candles on main chart // in the end we have to restore original clip // if (!studySeries.overlaying) { ctx.restore(); ctx.save(); clipToBounds(ctx, this.chartBounds()); // } } isChartTypeAllowed() { return candleTypesList.includes(this.config.components.chart.type); } afterDraw(ctx, model) { // restore previous clip // if (!studySeries.overlaying) { ctx.restore(); ctx.save(); clipToBounds(ctx, model.scale.getBounds()); // } } }