UNPKG

@devexperts/dxcharts-lite

Version:
61 lines (60 loc) 2.47 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 { HIT_TEST_ID_RANGE } from '../../model/hit-test-canvas.model'; import { flatMap } from '../../utils/array.utils'; export class PaneHitTestController { constructor(panes, canvasModel) { this.panes = panes; this.canvasModel = canvasModel; // used in hit test for creating series this.dataSeriesIdCounter = HIT_TEST_ID_RANGE.DATA_SERIES[0]; this.getNewDataSeriesHitTestId = () => { return this.dataSeriesIdCounter++; }; } /** * Returns an array with two numbers representing the range of IDs for data series. * @returns {Array<number>} An array with two numbers representing the range of IDs for data series. */ getIdRange() { return HIT_TEST_ID_RANGE.DATA_SERIES; } get allDataSeries() { return flatMap(flatMap(Object.values(this.panes), c => c.yExtentComponents), p => Array.from(p.dataSeries)); } /** * Looks up a data series by its ID. * * @param {number} id - The ID of the data series to look up. * @returns {DataSeriesModel | undefined} - The data series with the given ID, or undefined if it does not exist. */ lookup(id) { const result = this.allDataSeries.find(d => d.htId === id); return result; } /** * Changes the hovered property of all data series to true if their id matches the id of the provided model. * @param {DataSeriesModel | null} model - The model to compare the id with. * @returns {void} */ onHover(model) { this.allDataSeries.forEach(d => (d.highlighted = d.htId === (model === null || model === void 0 ? void 0 : model.htId))); this.canvasModel.fireDraw(); } onMouseDown(model) { model && this.handleYExtentDragStart(model); } onMouseUp() { this.handleYExtentDragEnd(); } handleYExtentDragStart(model) { Object.values(this.panes).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.deactivate())); model.extentComponent.dragNDrop.activate(); } handleYExtentDragEnd() { Object.values(this.panes).forEach(p => p.yExtentComponents.forEach(y => y.dragNDrop.activate())); } }