UNPKG

@devexperts/dxcharts-lite

Version:
40 lines (39 loc) 2.45 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 { NumericYAxisLabelsGenerator } from './numeric-y-axis-labels.generator'; import { FancyYAxisLabelsModel } from './price_labels/y-axis-labels.model'; import { YAxisBaseLabelsModel } from './y-axis-base-labels.model'; export class YAxisModel extends ChartBaseElement { constructor(paneUUID, eventBus, state, canvasBoundsContainer, canvasModel, scale, valueFormatter, dataSeriesProvider, extentIdx, chartResizeHandler) { super(); this.paneUUID = paneUUID; this.state = state; this.canvasBoundsContainer = canvasBoundsContainer; this.extentIdx = extentIdx; this.labelsGenerator = new NumericYAxisLabelsGenerator(null, dataSeriesProvider, scale, valueFormatter, () => this.state.type, state.labelHeight); this.baseLabelsModel = new YAxisBaseLabelsModel(scale, this.labelsGenerator, this.canvasBoundsContainer, paneUUID, extentIdx); this.addChildEntity(this.baseLabelsModel); this.fancyLabelsModel = new FancyYAxisLabelsModel(eventBus, scale, canvasBoundsContainer, state, canvasModel, paneUUID, () => this.canvasBoundsContainer.updateYAxisWidths(), chartResizeHandler); this.addChildEntity(this.fancyLabelsModel); } doActivate() { const contributor = { getLargestLabel: () => { var _a; return ((_a = this.labelsGenerator.labelsCache.getLastCachedValue()) !== null && _a !== void 0 ? _a : []) .map(label => label.text) .concat(this.fancyLabelsModel.orderedLabels.flatMap(l => l.labels).map(l => l.labelText)) .reduce((maxLengthText, label) => (label.length > maxLengthText.length ? label : maxLengthText), ''); }, getYAxisIndex: () => this.extentIdx, getYAxisState: () => this.state, getPaneUUID: () => this.paneUUID, }; this.canvasBoundsContainer.yAxisBoundsContainer.registerYAxisWidthContributor(contributor); this.addSubscription(() => this.canvasBoundsContainer.yAxisBoundsContainer.removeYAxisWidthContributor(contributor)); } }