UNPKG

@devexperts/dxcharts-lite

Version:
46 lines (45 loc) 1.68 kB
/* * Copyright (C) 2019 - 2026 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/. */ /* * Copyright (C) 2019 - 2024 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 { EVENT_DRAW } from '../../events/events'; /** * Custom labels on X axis. */ export class XAxisLabelsModel extends ChartBaseElement { constructor(eventBus, labelProviders) { super(); this.eventBus = eventBus; this.labelProviders = labelProviders; this.labels = []; this.initModel(); /** * TODO refactor this, should NOT be recalculated on each DRAW, rather coordinates should be updated in drawer * @doc-tags refactor */ this.addSubscription(this.eventBus.on(EVENT_DRAW, () => this.recalculateLabels())); } /** * Initializes the model by recalculating the labels. */ initModel() { this.recalculateLabels(); } /** * Recalculates the labels by clearing the existing labels and adding new labels from the label providers. * @returns {void} */ recalculateLabels() { this.labels = []; for (const provider of this.labelProviders) { this.labels.push(...provider.getUnorderedLabels()); } } }