UNPKG

@rongmz/trading-charts

Version:

This is a d3 based charting library for stocks and finance world. If the question is, why another chart library? - Coz, I find no "open-source" library fits my requirements.

146 lines (145 loc) 4.38 kB
export type TsOLHCVCandle = [string, number, number, number, number, number]; export type TsValue = { ts: string; v: number; }; export type CandlePlotData = { o: number; h: number; l: number; c: number; }; export type PlotData = CandlePlotData | number; export declare const CLASS_SUBGRAPH = "rongmz_subgraph"; export declare const DEAFULT_ZOOM_LEVEL = 0.8; export declare const MIN_ZOOM_POINTS = 3; export declare const X_AXIS_HEIGHT_PX = 25; export interface ChartConfig { [yScaleId: string]: SubGraphConfig; } export interface SubGraphConfig { [plotName: string]: PlotConfig; } export type PlotLineType = 'solid-line' | 'dashed-line' | 'dotted-line'; export type ValueExtractor<T> = (data: TsOLHCVCandle | TsValue | any) => T; export interface PlotConfig { type: PlotLineType | 'area' | 'candle' | 'bar' | 'var-bar'; dataId: string; tsValue: ValueExtractor<Date>; data: ValueExtractor<PlotData>; baseY?: number | ValueExtractor<number>; colorBaseY?: string; color?: string | (ValueExtractor<string>); areaColor?: string; } export interface GraphData { [dataId: string]: (TsOLHCVCandle | TsValue | any)[]; } export interface DataMat { ts: Date; data: { [scaleId: string]: { [plotName: string]: { d: PlotData; color: string; baseY?: number; }; }; }; } export type GraphDataMat = DataMat[]; export interface SubGraphSettings { title: string; titleFontSize: string; titlePlacement: 'top-left' | 'top-center' | 'top-right'; titleFontColor: string; yScaleTitle: string; yScaleTickCount: number; yScaleFormat: string; crossHairYScaleFormat: string; yScalePaddingPct: number; legendPosition: 'top-left' | 'top-right'; legendFontSize: string; legendMargin: [number, number, number] | number; legendFormat: string; lineWidth: number; scaleSectionRatio: number; deltaHeight: number; colorPallet: string[]; } export interface ChartSettings extends SubGraphSettings { width: number; height: number; plotSectionRatio: number; graphSeparatorColor: string; crossHairWidth: number; crossHairColor: string; crossHairContrastColor: string; background: string; gridLinesType: 'none' | 'vert' | 'horiz' | 'both'; gridLinesColor: string | [string, string]; xGridInterval: number; xScaleFormat: string; xScaleCrossHairFormat: string; xScalePadding: number; scaleLineColor: string; scaleFontColor: string; scaleFontSize: string; watermarkText: string; zoomLevel: number; wheelZoomSensitivity: number; annotationLineWidth: number; annotationFontSize: string; subGraph: { [scaleId: string]: Partial<SubGraphSettings>; }; } export declare const LightThemeChartSettings: Partial<ChartSettings>; export declare const DarkThemeChartSettings: Partial<ChartSettings>; export declare const debug: (...msg: any[]) => void; export declare const log: (...msg: any[]) => void; export declare const warn: (...msg: any[]) => void; export declare const error: (...msg: any[]) => void; export type Interpolator<K, V> = (t: K) => V; export interface CanvasMap { [scaleId: string]: d3.Selection<HTMLCanvasElement, any, any, any>; } export interface ScaleRowMap { [scaleId: string]: d3.Selection<HTMLTableCellElement, any, any, any>[]; } export interface MouseDownPosition { x: number; y: number; dx?: number; dy?: number; scaleId: string; } export interface MousePosition { x: number; y: number; scaleId: string; } export declare const getLineDash: (type: 'solid' | 'dashed' | 'dotted') => number[]; export interface YCoordinateMap<T> { [range: string]: T; } export interface D3YScaleMap { [scaleId: string]: d3.ScaleLinear<number, number>; } export type ZoomPanType = 'zoom' | 'pan'; export type ZoomPanListenerType = () => void; export declare const EVENT_ZOOM = "onzoom"; export declare const EVENT_PAN = "onpan"; export type AnnotationType = 'xRange' | 'xSingle' | 'flag' | 'rect'; export interface Annotation { type: AnnotationType; scaleId?: string; text: string; color: string; areaColor: string; textColor: string; x: Date[]; y: number[]; direction: 'up' | 'down'; showXValue?: boolean; }