candlestick-to-png
Version:
Lightweight library to draw an array of candles into a canvas and render it as png file.
162 lines (161 loc) • 4.5 kB
TypeScript
import { LamboCandle, Move } from "./models";
export interface CandleStickGraphOptions {
wantLines: boolean;
wantCandles: boolean;
zoom: number;
zoomSpeed: number;
wantTrades: boolean;
wantSMA: boolean;
wantEMA: boolean;
wantRSI: boolean;
granularity: number;
wantMACD: boolean;
wantBollingerBands: boolean;
wantGrid: boolean;
wantStats: boolean;
triangleSize: number;
lineWidth: number;
lineWidthGreen: number;
lineWidthRed: number;
wantSideMarksMove: boolean;
baseFontName: string;
}
export interface CandleStickColors {
gridColor: string;
gridTextColor: string;
lineColor: string;
mouseHoverTextColor: string;
greenColor: string;
redColor: string;
greenHoverColor: string;
redHoverColor: string;
mouseHoverBackgroundColor: string;
growLineColor: string;
blackColor: string;
whiteColor: string;
yellowColor: string;
purpleColor: string;
purpleColorTransparent: string;
yellowColorTransparent: string;
debugLineColor: string;
whiteColorTrasparent: string;
blueColor: string;
greenAreaColor: string;
redAreaColor: string;
greenAreaColorIntens: string;
redAreaColorIntes: string;
whiteColorMoreTrasparent: string;
logoColor: string;
}
export declare class CandleStickGraph {
private options;
private canvas;
private context;
private candlesticks;
private selectedCandleStick;
private moves;
private drops;
private rightCandlesOffset;
private curRightCandleOffset;
private dragInfo;
private colorInfo;
private width;
private height;
private candleWidth;
private marginLeft;
private marginRight;
private marginTop;
private marginBottom;
private yStart;
private yEnd;
private yRange;
private yPixelRange;
private xStart;
private xEnd;
private xRange;
private xPixelRange;
private xGridCells;
private yGridCells;
private b_drawMouseOverlay;
private mousePosition;
private xMouseHover;
private yMouseHover;
private hoveredCandlestickID;
private leftAxis;
private rightAxis;
private getIncreaseMsg;
private readonly GENERAL_FONT_SIZE;
private readonly TEXT_FONT_SIZE;
constructor(options: CandleStickGraphOptions | undefined);
toCandleStick(candle: LamboCandle): CandleStick;
reset(): void;
clean(): void;
apply(options: CandleStickGraphOptions | undefined): void;
applyColors(options: CandleStickColors): void;
private _initCanvas;
initCanvasHeadless(canvas: HTMLCanvasElement): void;
initCanvas(canvas: HTMLCanvasElement, canvasId?: string): void;
private bindCanvasListeners;
private static getFont;
private areSelectedCandlesNotNull;
draw: () => void;
private calculateCandleWidth;
private getSelectedCandleStick;
private drawRectangleWithText;
private drawSmallRectangleWithText;
private drawMoves;
private drawSideMarksMove;
private drawDrops;
private drawLines;
private drawOverAreas;
private drawCandlesAndValuatePoints;
private drawPriceLine;
private drawTimeLine;
private drawInfoLabel;
addTrade(move: Move): this;
addCandlestick: (candlestick: CandleStick, adaptZoom: boolean) => void;
concatCandleSticks(canvasCandleSticks: CandleStick[], adaptZoom?: boolean): this;
private mouseMove;
private mouseUp;
private mouseDown;
private mouseDrag;
private mouseOut;
private mouseWheel;
private drawGrid;
private calculateYRange;
private calculateXRange;
private yToPixelCoords;
private xToPixelCoords;
private yToValueCoords;
private xToValueCoords;
private drawLine;
private fillRect;
private fillRectRounded;
private fillPolygon;
private drawTriangleUp;
private drawTriangleDown;
private drawRect;
private formatDate;
private roundPriceValue;
private lineIntersect;
cleanCandleSticks(): void;
private setLineWidth;
private resetLineWidth;
private calculateSma;
private calculateEma;
private calculateTrix;
private calculateRsi;
private drawMACD;
private calculateBollingerBands;
private drawBollingRangeArea;
private formatDateNoHours;
private drawStatsLabel;
private drawLogo;
}
export interface CandleStick {
timestamp: number;
open: number;
close: number;
high: number;
low: number;
}