UNPKG

@devexperts/dxcharts-lite

Version:
143 lines (142 loc) 6.71 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 { BehaviorSubject } from 'rxjs'; import { CanvasBoundsContainer } from '../canvas/canvas-bounds-container'; import { FullChartConfig } from '../chart.config'; import { ChartModel } from '../components/chart/chart.model'; import { PaneManager } from '../components/pane/pane-manager.component'; import { CanvasInputListenerComponent } from '../inputlisteners/canvas-input-listener.component'; import { CandleHover, CandleHoverProducerPart } from '../model/candle-hover'; import { ChartBaseElement } from '../model/chart-base-element'; import { CompareSeriesHover, CompareSeriesHoverProducerPart } from '../model/compare-series-hover'; import { DateTimeFormatter } from '../model/date-time.formatter'; import { ScaleModel } from '../model/scale.model'; import VisualCandle from '../model/visual-candle'; import { CrossEvent, CrossEventProducerComponent } from './cross-event-producer.component'; import { TimeZoneModel } from '../model/time-zone.model'; import { MainCanvasTouchHandler } from './main-canvas-touch.handler'; export interface BaseHover { readonly x: number; readonly y: number; readonly timestamp: number; readonly timeFormatted: string; readonly paneId: string; } export interface HoverParts { readonly candleHover: CandleHover | undefined; readonly compareSeriesHover: CompareSeriesHover[]; [key: string]: unknown; } export interface Hover extends BaseHover, HoverParts { } export interface HoverProducerPart<T = unknown> { getData(hover: BaseHover): T | undefined; } export interface HoverProducerParts { candleHover: CandleHoverProducerPart; compareSeriesHover: CompareSeriesHoverProducerPart; [key: string]: HoverProducerPart; } /** * Produces the Hover event. * Hover is used for displaying values in legend and NOT related to displaying cross tool. */ export declare class HoverProducerComponent extends ChartBaseElement { private crossEventProducer; private scale; private config; private chartModel; private canvasInputListener; private canvasBoundsContainer; private paneManager; private timeZoneModel; private mainCanvasTouchHandler; private formatterFactory; hoverSubject: BehaviorSubject<Hover | null>; get hover(): Hover | null; longTouchActivatedSubject: BehaviorSubject<boolean>; private hoverProducerParts; xFormatter: DateTimeFormatter; constructor(crossEventProducer: CrossEventProducerComponent, scale: ScaleModel, config: FullChartConfig, chartModel: ChartModel, canvasInputListener: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, paneManager: PaneManager, timeZoneModel: TimeZoneModel, mainCanvasTouchHandler: MainCanvasTouchHandler, formatterFactory: (format: string) => (timestamp: number) => string); /** * This method is responsible for activating the chart hover functionality. It subscribes to several observables to * update the hover when the chart is updated or when the user interacts with it. It also handles special behavior * for mobile devices, such as disabling panning and showing the cross tool on long touch. * * @protected * @memberof ChartHover * @returns {void} */ protected doActivate(): void; /** * Recalculates the cross tool X formatter. * @function * @private * @returns {void} */ private recalculateCrossToolXFormatter; /** * Creates a hover object from a VisualCandle object. * @param {VisualCandle} candle - The VisualCandle object to create the hover from. * @returns {Hover | undefined} - The created hover object or undefined if the input is invalid. */ private createHoverFromCandle; /** * Creates a hover object based on the provided x and y coordinates. * @param {number} x - The x coordinate of the hover. * @param {number} y - The y coordinate of the hover. * @param {string} uuid * @returns {Hover | undefined} - The hover object or undefined if there are no candles in the chart model. * @todo Check if uuid is still useful here. */ createHover(x: number, y: number, uuid: string): Hover | undefined; /** * Creates a hover from a VisualCandle object and fires it. * @param {VisualCandle} candle - The VisualCandle object to create the hover from. */ createAndFireHoverFromCandle(candle: VisualCandle): void; /** * Update current hover using a VisualCandle and fires it. * @param {VisualCandle} candle - The VisualCandle object to create the hover from. */ updateHover(candle: VisualCandle): void; /** * Creates a hover element at the specified coordinates and fires it with the option to show the cross tool * @param {CrossEvent} [x,y] - The coordinates where the hover element will be created * @param {boolean} [showCrossTool=true] - Whether to show the cross tool or not * @returns {void} */ createAndFireHover([x, y, uuid]: CrossEvent): void; /** * Private method that handles the hover event. If a hover event is provided, it sets the last hover to the provided hover. * If the device is mobile and the cross tool type is not 'none', it sets the active candle to the hovered candle only when a long tap is detected. * The showCrossToolOverride is set to true only when a long tap is detected on mobile devices, otherwise it is set to the value of showCrossTool parameter. * Finally, it fires the EVENT_HOVER event with the provided hover and showCrossToolOverride. * If no hover event is provided, it fires the EVENT_CLOSE_HOVER event. * * @param {Hover} [hover] - The hover event to handle. * @returns {void} */ private fireHover; /** * Fires the last hover update if there is a last cross. */ fireLastCross(): void; /** * Registers a hover producer part with the given id. * * @param {string} id - The id of the hover producer part. * @param {HoverProducerPart} hoverProducerPart - The hover producer part to register. * @returns {void} */ registerHoverProducerPart(id: string, hoverProducerPart: HoverProducerPart): void; /** * Removes a hover producer part from the hoverProducerParts object. * @param {string} id - The id of the hover producer part to be removed. * @returns {void} */ unregisterHoverProducerPart(id: string): void; }