UNPKG

@devexperts/dxcharts-lite

Version:
89 lines (88 loc) 3.89 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 { BehaviorSubject, combineLatest } from 'rxjs'; import { filter } from 'rxjs/operators'; import { ChartBaseElement } from '../model/chart-base-element'; import { isMobile } from '../utils/device/browser.utils'; export class CrossEventProducerComponent extends ChartBaseElement { constructor(canvasInputListener, canvasBoundsContainer) { super(); this.canvasInputListener = canvasInputListener; this.canvasBoundsContainer = canvasBoundsContainer; this.panesSubscriptions = {}; this.crossSubject = new BehaviorSubject(null); // mobile specific crosstool hover and touch info this.crossToolHover = null; this.crossToolTouchInfo = { fixed: { x: 0, y: 0 }, temp: { x: 0, y: 0 }, isSet: false, isCommonTap: false, }; } doActivate() { super.doActivate(); } /** * Emits a null value to the `cross` subject, effectively closing the current cross. */ fireCrossClose() { this.crossSubject.next(null); } /** * Unsubscribes from the mouse over event for a specific pane. * @param {string} uuid - The unique identifier of the pane. * @returns {void} */ unsubscribeMouseOver(uuid) { var _a; (_a = this.panesSubscriptions[uuid]) === null || _a === void 0 ? void 0 : _a.unsubscribe(); } /** * Subscribes to mouse over event on canvas elements. * @param {string} uuid - Unique identifier for the subscription. * @param {string[]} canvasElementNames - Array of canvas element names to subscribe to. * @param {HitBoundsTestOptionsPartial} [options] - Optional hit bounds test options. * @returns {Subscription} - Returns a subscription object. */ subscribeMouseOver(uuid, canvasElementNames, options) { const hts = canvasElementNames.map(canvasElementName => this.canvasBoundsContainer.getBoundsHitTest(canvasElementName, options)); const hitTest = (x, y) => hts.some(ht => ht(x, y)); return this.subscribeMouseOverHT(uuid, hitTest); } /** * Subscribes to mouse over event on a hit test area identified by uuid. * @param {string} uuid - The unique identifier of the hit test area. * @param {HitBoundsTest} hitTest - The hit test area. * @returns {Subscription} - The subscription object. */ subscribeMouseOverHT(uuid, hitTest) { const move$ = this.canvasInputListener.observeMouseMoveDocument(); const mouseEnter$ = this.canvasInputListener.observeMouseEnter(hitTest); let closeHoverFired = false; const subscription = combineLatest([move$, mouseEnter$]) .pipe(filter(([, enter]) => !closeHoverFired || (closeHoverFired && enter))) .subscribe(([point, enter]) => { if (enter) { const cross = [point.x, point.y, uuid]; this.crossSubject.next(cross); closeHoverFired = false; } // crosstool should be hidden if hovering nonpane only on desktop if (!enter && !isMobile()) { this.crossSubject.next(null); closeHoverFired = true; } }); this.panesSubscriptions[uuid] = subscription; return () => subscription.unsubscribe(); } }