@devexperts/dxcharts-lite
Version:
162 lines (161 loc) • 7.65 kB
TypeScript
/*
* 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 { Subject } from 'rxjs';
import { CanvasBoundsContainer } from '../../canvas/canvas-bounds-container';
import { CursorHandler } from '../../canvas/cursor.handler';
import { YAxisWidthContributor } from '../../canvas/y-axis-bounds.container';
import { BarType, FullChartColors, FullChartConfig, YAxisAlign, YAxisConfig, YAxisLabelAppearanceType, YAxisLabelMode, YAxisLabelType } from '../../chart.config';
import EventBus from '../../events/event-bus';
import { CanvasInputListenerComponent } from '../../inputlisteners/canvas-input-listener.component';
import { PriceMovement } from '../../model/candle-series.model';
import { CanvasModel } from '../../model/canvas.model';
import { ChartBaseElement } from '../../model/chart-base-element';
import { DataSeriesType } from '../../model/data-series.config';
import { DataSeriesModel } from '../../model/data-series.model';
import { ScaleModel } from '../../model/scale.model';
import { PriceAxisType } from '../labels_generator/numeric-axis-labels.generator';
import { ChartPanComponent } from '../pan/chart-pan.component';
import { VisualYAxisLabel, YAxisLabelsProvider } from './price_labels/y-axis-labels.model';
import { YAxisScaleHandler } from './y-axis-scale.handler';
import { YAxisModel } from './y-axis.model';
import { HitTestCanvasModel } from '../../model/hit-test-canvas.model';
import { ChartResizeHandler } from '../../inputhandlers/chart-resize.handler';
export type LabelColorResolver = (priceMovement: PriceMovement, colors: FullChartColors) => string;
/**
* Y axis component. Contains all Y axis related logic.
*/
export declare class YAxisComponent extends ChartBaseElement {
private eventBus;
private config;
private canvasModel;
scale: ScaleModel;
private canvasInputListeners;
private canvasBoundsContainer;
private chartPanComponent;
private cursors;
paneUUID: string;
extentIdx: number;
private hitTestCanvasModel;
private chartResizeHandler;
private labelsColorByChartTypeMap;
yAxisScaleHandler: YAxisScaleHandler;
model: YAxisModel;
axisTypeSetSubject: Subject<PriceAxisType>;
axisAlignSetSubject: Subject<YAxisAlign>;
axisAlignMovedSubject: Subject<YAxisAlign>;
readonly state: YAxisConfig;
constructor(eventBus: EventBus, config: FullChartConfig, canvasModel: CanvasModel, scale: ScaleModel, canvasInputListeners: CanvasInputListenerComponent, canvasBoundsContainer: CanvasBoundsContainer, chartPanComponent: ChartPanComponent, cursors: CursorHandler, valueFormatter: (value: number) => string, dataSeriesProvider: () => DataSeriesModel | undefined, paneUUID: string, extentIdx: number, hitTestCanvasModel: HitTestCanvasModel, chartResizeHandler: ChartResizeHandler, initialState?: YAxisConfig);
setExtentIdx(extentIdx: number): void;
/**
* Registers default label color resolvers for different chart types.
* @private
* @function
* @name registerDefaultLabelColorResolver
* @returns {void}
*/
private registerDefaultLabelColorResolvers;
protected doActivate(): void;
updateCursor(): void;
/**
* Updates labels visual appearance on canvas
*/
updateOrderedLabels(adjustYAxisWidth?: boolean): void;
/**
* Registers a label color resolver for a specific chart type.
*
* @param {BarType} chartType - The type of chart for which the label color resolver is being registered.
* @param {LabelColorResolver} resolver - The function that will be used to resolve the color of the labels for the specified chart type.
* @returns {void}
*/
registerLabelColorResolver(chartType: BarType, resolver: LabelColorResolver): void;
/**
* Returns a function that resolves the color for a label based on the type of data series.
* @param {DataSeriesType} candlesType - The type of data series.
* @returns {Function} - A function that resolves the color for a label.
* If there is no color mapping for the given data series type, it returns the default color resolver function.
*/
getLabelsColorResolver(candlesType: DataSeriesType): LabelColorResolver;
/**
* You can add a custom labels provider for additional labels on YAxis (like for drawings, symbol last price, studies, etc..)
* @param groupName - a group in which labels position recalculation algorithm will be applied, usually it's subchart name
* @param provider
* @param id
*/
registerYAxisLabelsProvider(provider: YAxisLabelsProvider, groupName?: string, id?: string): string;
/**
* An easier way to manage custom y-axis labels, than y-axis labels providers.
* However, overlapping avoidance is not supported
* @param name
* @param label
*/
addSimpleYAxisLabel(name: string, label: VisualYAxisLabel): void;
/**
* @param name
*/
deleteSimpleYAxisLabel(name: string): void;
getAxisType(): PriceAxisType;
/**
* Unregister a Y axis labels provider from the specified group.
* @param {string} groupName - The name of the group from which to unregister the provider. Defaults to LabelsGroups.MAIN.
* @param {string} id - The ID of the provider to unregister.
* @returns {string} - The ID of the unregistered provider.
*/
unregisterYAxisLabelsProvider(groupName: string | undefined, id: string): string;
getBounds(): import("../../model/bounds.model").Bounds;
/**
* If custom pane has y-axis it has to register width contributor to correctly calculate overall y-axis width.
* @param contributor
*/
registerYAxisWidthContributor(contributor: YAxisWidthContributor): void;
/**
* Sets the type of axis: percent, regular or logarithmic.
* @param type - the type of axis
*/
setAxisType(type: PriceAxisType): void;
/**
* Change YAxis position to left or to right
* @param align
*/
setYAxisAlign(align: YAxisAlign): void;
/**
* Controls visibility of the y-axis (additionally disable/enable component)
*/
setVisible(isVisible: boolean): void;
/**
* If visible, when you can see the y-axis on the chart
*/
isVisible(): boolean;
/**
* Controls lockPriceToBarRatio of the y-axis
*/
setLockPriceToBarRatio(value?: boolean): void;
/**
* Changes the visual type of particular label.
* @param type - label type
* @param mode - visual mode
*/
changeLabelMode(type: YAxisLabelType, mode: YAxisLabelMode): void;
/**
* Changes the visual type of particular label.
* @param type - label type
* @param mode - visual mode
*/
changeLabelAppearance(type: YAxisLabelType, mode: YAxisLabelAppearanceType): void;
/**
* Sets the inverse price scale mode. Inverts Y axis vertically.
* Inversion also works for candles, drawings and overlay studies.
* @param inverse - true or false
*/
togglePriceScaleInverse(inverse?: boolean): void;
/**
* Changes the visibility of the labels' descriptions.
* @param {boolean} descVisibility - A boolean value indicating whether the descriptions should be visible or not.
* @returns {void}
*/
changeLabelsDescriptionVisibility(descVisibility: boolean): void;
setDblClickCallback: (cb: () => void) => () => void;
setDblTapCallback: (cb: () => void) => () => void;
}