UNPKG

@devexperts/dxcharts-lite

Version:
68 lines (67 loc) 3.52 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 { ChartBaseElement } from '../../model/chart-base-element'; import { createCandlesOffsetProvider } from '../chart/data-series.high-low-provider'; import { volumeFormatter } from './volumes.formatter'; class SeparateVolumesComponent extends ChartBaseElement { constructor(chartComponent, config, volumesModel, paneManager) { super(); this.chartComponent = chartComponent; this.config = config; this.volumesModel = volumesModel; this.paneManager = paneManager; if (config.components.volumes.showSeparately) { this.activateSeparateVolumes(); } } doActivate() { super.doActivate(); this.addRxSubscription(this.chartComponent.chartModel.candlesUpdatedSubject.subscribe(() => { var _a, _b; return !((_a = this.pane) === null || _a === void 0 ? void 0 : _a.scale.isViewportValid()) && ((_b = this.pane) === null || _b === void 0 ? void 0 : _b.scale.doAutoScale(true)); })); this.addRxSubscription(this.volumesModel.volumeMax.subscribe(() => { var _a; return (_a = this.pane) === null || _a === void 0 ? void 0 : _a.scale.doAutoScale(); })); } /** * Activates the separate volumes feature. * If the pane component for separate volumes does not exist, it creates a new pane with the specified UUID and options. * It then sets the high-low provider for the volumes scale model and does an auto scale. * A new VolumesDrawer is created and added to the drawing manager with the specified parameters. */ activateSeparateVolumes() { if (this.paneManager.panes[SeparateVolumesComponent.UUID] === undefined) { const precision = 1; const volumePane = this.paneManager.createPane(SeparateVolumesComponent.UUID, { paneFormatters: { regular: (value) => volumeFormatter(value, precision), }, useDefaultHighLow: false, increment: 1, }); this.pane = volumePane; volumePane.mainExtent.yAxis.setAxisType('regular'); const { scale: scaleModel } = volumePane; const volumesHighLowProvider = createCandlesOffsetProvider(() => ({ top: 10, bottom: 0, left: 0, right: 0, visible: true }), this.volumesModel.highLowProvider); scaleModel.autoScaleModel.setHighLowProvider('volumes', volumesHighLowProvider); scaleModel.doAutoScale(true); } } /** * Deactivates the separate volumes feature by removing the separate volumes pane, deleting the scale model, and removing the underlay volumes area drawer. */ deactiveSeparateVolumes() { this.paneManager.removePane(SeparateVolumesComponent.UUID); delete this.pane; } /** * Converts a pixel value from the Y-axis of the scale model to the corresponding data value. * @param {Pixel} y - The pixel value to convert. * @returns {Unit} - The corresponding data value. */ fromY(y) { var _a, _b; return (_b = (_a = this.pane) === null || _a === void 0 ? void 0 : _a.scale.fromY(y)) !== null && _b !== void 0 ? _b : 0; } } SeparateVolumesComponent.UUID = 'volumes'; export { SeparateVolumesComponent };