@obliczeniowo/elementary
Version:
Library made in Angular version 19
143 lines (142 loc) • 5.34 kB
TypeScript
import { MinMax } from '@obliczeniowo/elementary/math';
import { YAxisI } from './elements/y-axis-i';
import { DrawingContextInterface, LinePattern, TextAlign, Rect } from '@obliczeniowo/elementary/drawing';
import { DecimalPipe } from '@angular/common';
import { Subject } from 'rxjs';
import { Point2D, ColorType } from '@obliczeniowo/elementary/classes';
export declare enum PointType {
NONE = "none",
CIRCLE = "circle",
X = "x",
STAR = "star"
}
export interface BaseDrawingOptions {
/** color in format #rrggbb */
color?: ColorType;
stroke?: number;
linePattern?: LinePattern | string;
drawPoint?: PointType | string;
}
export interface AxisOptions extends BaseDrawingOptions {
arrow?: boolean;
dp?: number;
autoIncreaseDecrease?: boolean;
precision?: number;
display?: boolean;
}
export interface YAxisOptions extends AxisOptions {
textAlign?: TextAlign;
}
export interface GridOptions extends BaseDrawingOptions {
display?: boolean;
}
export interface LinearDiagram2DOptions {
displayCursor?: boolean;
xAxis?: AxisOptions;
yAxis?: YAxisOptions;
greed?: GridOptions;
set?: BaseDrawingOptions[];
xMinMax?: MinMax;
yMinMax?: MinMax;
}
export type DrawingPointFu = (point: Point2D, dc: DrawingContextInterface, stroke: number, color: ColorType, index: number, value: number) => void;
export declare class LinearDiagram2D {
protected static drawingPoints: Map<string, DrawingPointFu>;
protected options: LinearDiagram2DOptions;
/** min max for x */
protected xMinMax: MinMax;
/** min max for y */
protected yMinMax: MinMax;
/** */
protected yAxis: YAxisI;
/** */
protected xScale: number;
/** */
protected yScale: number;
protected xCursorLine: SVGPolylineElement;
protected yCursorLine: SVGPolylineElement;
protected xyCursor: SVGTextElement;
selectionRange?: MinMax;
/** diagram area rect (area where diagram data will be drawn) */
diagramArea: Rect;
pPoints: Point2D[][];
/** diagram title text */
title: string;
/** x label description */
xLabel: string;
/** y label description */
yLabel: string;
/** legend description table */
legend: string[];
/** pipe used for formatting x/y axis text */
decimalPipe: DecimalPipe;
/** */
xK: number;
/** */
yK: number;
redraw: Subject<void>;
onPointMouseOver: Subject<SVGGElement>;
onPointMouseOut: Subject<void>;
static registerDrawingPointFu(name: string, fu: DrawingPointFu): boolean;
/**
* Function that give you control over format of x axis values
* this function can be overridden let programmer use whatever he want
* @param x value on scale to draw
* @param xK x * pow(10, xK) - power of 10 that provide number into n.xxxx format
* @returns formatted string value of x scale
*/
xFormatter: (x: number, xK: number) => string;
set yFormatter(fu: (y: number, yK: number) => string);
/**
* set points vector and recalculate xMinMax & yMinMax values for diagram
*/
set points(points: Point2D[][]);
/**
* @param area diagram area
* @param points points vectors as table of Point2D
* @param options options settings for diagram (most of them override default one)
*/
constructor(area: Rect, points: Point2D[][], options?: LinearDiagram2DOptions);
protected normalizeMinMax(min: number, max: number): MinMax;
protected filterByRange(): Point2D[][];
/**
* Get min and max of x axis
* @returns return min & max for x axis
*/
getXMinMax(): MinMax;
/**
* Find minimum & maximum for y axis
* @returns MinMax interface of displayed values
*/
protected getYMinMax(): MinMax;
/**
* Convert point diagram pos to SVG pos
* @param point point to transform
* @param startPoint diagram start point
* @param xScale x scale
* @param yScale y scale
* @returns Point2D instance
*/
protected diagramPosToSVG(point: Point2D, startPoint: Point2D): Point2D;
protected svgPosToDiagram(point: Point2D, startPoint: Point2D, xScale: number, yScale: number): Point2D;
protected getDAxis(range: number, autoIncreaseDecrease: boolean, dp: number): number;
protected getDx(): number;
protected getDy(): number;
protected drawGreed(dc: DrawingContextInterface, startPoint: Point2D): void;
/**
* Calc scale elementary increase value with given precision
* @param value (max - min)
* @param precision integer number should be >= 0
* @returns scale elementary increase value
*/
protected recalcDScale(value: number, precision?: number): number;
protected drawXAxis(dc: DrawingContextInterface, startPoint: Point2D): number;
protected drawYAxis(dc: DrawingContextInterface, startPoint: Point2D): number;
protected drawLegend(dc: DrawingContextInterface): void;
protected drawVectors(dc: DrawingContextInterface, startPoint: Point2D): void;
draw(dc: DrawingContextInterface): void;
setOptions(options: LinearDiagram2DOptions | undefined): void;
drawCursor(mousePos: Point2D, svg: SVGGElement): void;
svgToDiagram(point: Point2D): Point2D;
protected getDrawPointFu(pointType: PointType | string): DrawingPointFu;
}