@devexperts/dxcharts-lite
Version:
175 lines (174 loc) • 8.43 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 { YExtentComponent } from '../components/pane/extent/y-extent-component';
import { DataSeriesYAxisLabelsProvider } from '../components/y_axis/price_labels/data-series-y-axis-labels.provider';
import { AtLeastOne } from '../utils/object.utils';
import { ChartBaseElement } from './chart-base-element';
import { DataSeriesView } from './data-series-view';
import { DataSeriesConfig, DataSeriesPaintConfig, DataSeriesType } from './data-series.config';
import { HighLowWithIndex, ScaleModel } from './scale.model';
import { HighLowProvider } from './scaling/auto-scale.model';
import { Index, Pixel, Unit, Viewable } from './scaling/viewport.model';
/**
* Properties are named in order to match VisualCandle interface
*/
export declare class VisualSeriesPoint {
centerUnit: Unit;
close: Unit;
constructor(centerUnit: Unit, close: Unit);
/**
* returns y coordinate in pixels
*/
y(viewable: Viewable): Pixel;
/**
* returns x coordinate in pixels
*/
x(viewable: Viewable): Pixel;
clone(): VisualSeriesPoint;
}
export interface DataSeriesPoint {
timestamp: number;
close: Unit;
}
export interface DataSeriesViewportIndexes {
dataIdxStart: Index;
dataIdxEnd: Index;
}
/**
* DataSeriesModel represents single time series chart.
* Usually data source is presented as a one-dimension array, but here it can be presented as two-dimension array
* If the data is presented as two-dim array when every data array will be drawn as a separate time-series
* For example, linear chart type will be drawn with gaps on the chart
*/
export declare class DataSeriesModel<D extends DataSeriesPoint = DataSeriesPoint, V extends VisualSeriesPoint = VisualSeriesPoint> extends ChartBaseElement {
extentComponent: YExtentComponent;
id: string;
htId: number;
parentId?: string | number | undefined;
name: string;
highlighted: boolean;
yAxisLabelProvider: DataSeriesYAxisLabelsProvider;
readonly config: DataSeriesConfig;
scale: ScaleModel;
view: DataSeriesView;
protected _dataPoints: D[][];
pricePrecisions: number[];
/**
* Should be used for paint tools like rectangular drawing or diff cloud
*/
linkedDataSeriesModels: DataSeriesModel<D, V>[];
highLowProvider: HighLowProvider;
get dataPoints2D(): D[][];
get dataPoints(): D[];
protected _dataPointsFlat: D[];
set dataPoints(points: D[][] | D[]);
protected _visualPoints: V[][];
protected _visualPointsFlat: V[];
dataIdxStart: Index;
dataIdxEnd: Index;
get visualPoints(): V[];
get visualPoints2D(): V[][];
set visualPoints(points: V[][] | V[]);
constructor(extentComponent: YExtentComponent, id: string, htId: number, parentId?: string | number | undefined, _config?: AtLeastOne<DataSeriesConfig>);
protected doActivate(): void;
/**
* Sets the data points and recalculates internal state
* @param {DataSeriesPoint[][] | DataSeriesPoint[]} points - The data points to set for the model. Can be an array of arrays or a single array.
* @returns {void}
*/
setDataPoints(points: D[][] | D[]): void;
/**
* Returns the paint configuration object for a specific series part, or the default paint configuration object
* if the specified series part is not defined in the current DataSeriesView configuration.
*
* @param {number} seriesPart - The index of the series part to get the paint configuration for.
* @returns {DataSeriesPaintConfig} The paint configuration object for the specified series part, or the default paint configuration object.
*/
getPaintConfig: (seriesPart: number) => DataSeriesPaintConfig;
protected _toVisualPoints(data: D[][]): V[][];
/**
* Moves the DataSeriesModel to the given extent.
* @param extent
*/
moveToExtent(extent: YExtentComponent): void;
/**
* Transforms the given array of data points of type D into an array of visual points of type V.
* Each visual point object contains a centerUnit property with the index of the point in the input array,
* and a close property with the close value of the point.
*
* @param {D[]} data - The array of data points to transform into visual points.
* @returns {V[]} An array of visual points, each with a centerUnit and close property.
*/
toVisualPoints(data: D[]): V[];
setType(type: DataSeriesType): void;
/**
* Recalculates the visual points of the DataSeriesView based on the current data points.
* The visual points are stored in the visualPoints property of the DataSeriesView.
* Should be called 1 time when data are set / updated to chart.
*/
recalculateVisualPoints(): void;
/**
* Recalculates the indexes of the start and end points of the data viewport,
* based on the current xStart and xEnd values of the scale model, or on the given xStart and xEnd parameters.
*
* @param {number} [xStart=this.scale.xStart] - The start value of the viewport on the x-axis. Defaults to the current xStart value of the scale model.
* @param {number} [xEnd=this.scale.xEnd] - The end value of the viewport on the x-axis. Defaults to the current xEnd value of the scale model.
*/
recalculateDataViewportIndexes(xStart?: number, xEnd?: number): void;
/**
* Calculates and returns the indexes of the start and end points of the data viewport,
* based on the given start and end units on the x-axis.
*
* @param {Unit} xStart - The start value of the viewport on the x-axis.
* @param {Unit} xEnd - The end value of the viewport on the x-axis.
* @returns {DataSeriesViewportIndexes} An object containing the calculated start and end indexes of the data viewport.
*/
calculateDataViewportIndexes(xStart: Unit, xEnd: Unit): DataSeriesViewportIndexes;
/**
* Formats the given numerical value using the default value formatter.
*
* @param {number} value - The numerical value to be formatted.
* @returns {string} The formatted value as a string.
*/
valueFormatter(value: number): string;
/**
* Returns the close value of the visual point at the given index, or 1 if the visual point is not defined.
* The index defaults to the data index start of the DataSeriesView.
*
* @param {number} [idx=this.dataIdxStart] - The index of the visual point to retrieve the close value for.
* @returns {Unit} The close value of the visual point at the given index, or 1 if the visual point is not defined.
*/
getBaseline: (idx?: number) => Unit;
/**
* Returns the string representation of the close value of the given visual point.
*
* @param {VisualSeriesPoint} point - The visual point to get the string representation of the close value for.
* @returns {string} The string representation of the close value of the given visual point.
*/
getTextForPoint: (point: VisualSeriesPoint) => string;
/**
* Returns a two-dimensional array of the visual points in the viewport of the DataSeriesView.
* The viewport range can be customized by providing start and end units on the x-axis.
* If start or end units are not provided, the current viewport range of the DataSeriesView is used.
*
* @param {number} [xStart] - The start value of the viewport range on the x-axis.
* @param {number} [xEnd] - The end value of the viewport range on the x-axis.
* @returns {V[][]} A two-dimensional array of the visual points in the viewport of the DataSeriesView.
*/
getSeriesInViewport(xStart?: number, xEnd?: number): V[][];
/**
* Returns last visible on the screen data series value
* @param seriesIndex
*/
getLastVisualSeriesPoint: () => V | undefined;
/**
* Return last overall data series value (even if not visible)
* @param seriesIndex
*/
getLastDataSeriesPoint: () => V | undefined;
}
export declare const calculateDataSeriesHighLow: (visualCandles: VisualSeriesPoint[]) => HighLowWithIndex;
export declare const defaultValueFormatter: (value: number) => string;