@obliczeniowo/elementary
Version:
Library made in Angular version 20
296 lines (288 loc) • 12.1 kB
TypeScript
import * as i0 from '@angular/core';
import { OnDestroy, TemplateRef, AfterViewInit, AfterContentInit, Renderer2, ElementRef, EventEmitter } from '@angular/core';
import { Subject, Subscription } from 'rxjs';
import { MinMax } from '@obliczeniowo/elementary/math';
import * as i4 from '@angular/common';
import { DecimalPipe } from '@angular/common';
import { Point2D, ColorType } from '@obliczeniowo/elementary/classes';
import { TextAlign, DrawingContextInterface, Rect, LinePattern, DrawingSvgInterface } from '@obliczeniowo/elementary/drawing';
import { OblFileService } from '@obliczeniowo/elementary/files';
import * as i5 from '@obliczeniowo/elementary/buttons';
import * as i6 from '@obliczeniowo/elementary/text-pipes';
import * as i7 from '@obliczeniowo/elementary/input';
import * as i8 from '@obliczeniowo/elementary/numeric-pipes';
/**
* Create hover over element on obl-linear-diagram-2d element by ng-content
*
* example with own template
*
* <obl-linear-diagram-2d [points]="points">
* <ng-template #xyTemplate let-x="x" let-y="y">
* <div class="xy-template">
* <div>x = {{ x | number: '0.5-5' }}</div>
* <div>y = {{ y | number: '0.5-5' }}</div>
* </div>
* </ng-template>
* </obl-linear-diagram-2d>
*/
declare class DiagramPointHoverComponent implements OnDestroy {
x: number;
y: number;
private pOnMouseOver?;
set onMouseOver(value: Subject<SVGGElement> | undefined);
private pOnMouseOut?;
set onMouseOut(value: Subject<void> | undefined);
over: '' | 'none';
top: number;
left: number;
xyTemplate: TemplateRef<any>;
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<DiagramPointHoverComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<DiagramPointHoverComponent, "obl-diagram-point-hover", never, {}, {}, ["xyTemplate"], ["*"], false, never>;
}
declare abstract class YAxisI {
protected textAlign: TextAlign;
/** pipe used for formatting x/y axis text */
decimalPipe: DecimalPipe;
/**
* Function that give you control over format of y axis values
* this function can be overrided let programmer use whatever he want
* @param y value on scale to draw
* @param yK y * pow(10, yK) - power of 10 that provide number into n.xxxx format
* @returns formatted string value of y scale
*/
yFormatter: (y: number, yK: number) => string;
abstract draw(dc: DrawingContextInterface, startPoint: Point2D, startScale: Point2D, dY: number, minMax: MinMax, yScale: number, yK: number, diagramArea: Rect, yLabel: string, yOptions?: AxisOptions): number;
}
declare enum PointType {
NONE = "none",
CIRCLE = "circle",
X = "x",
STAR = "star"
}
interface BaseDrawingOptions {
/** color in format #rrggbb */
color?: ColorType;
stroke?: number;
linePattern?: LinePattern | string;
drawPoint?: PointType | string;
}
interface AxisOptions extends BaseDrawingOptions {
arrow?: boolean;
dp?: number;
autoIncreaseDecrease?: boolean;
precision?: number;
display?: boolean;
}
interface YAxisOptions extends AxisOptions {
textAlign?: TextAlign;
}
interface GridOptions extends BaseDrawingOptions {
display?: boolean;
}
interface LinearDiagram2DOptions {
displayCursor?: boolean;
xAxis?: AxisOptions;
yAxis?: YAxisOptions;
greed?: GridOptions;
set?: BaseDrawingOptions[];
xMinMax?: MinMax;
yMinMax?: MinMax;
}
type DrawingPointFu = (point: Point2D, dc: DrawingContextInterface, stroke: number, color: ColorType, index: number, value: number) => void;
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;
}
declare class LinearDiagram2DComponent implements OnDestroy, AfterViewInit, AfterContentInit {
protected renderer: Renderer2;
protected dc: DrawingSvgInterface;
protected diagram2d?: LinearDiagram2D;
protected mousePos: Point2D;
protected selectArea?: Rect;
readonly width = 800;
readonly height = 528;
diagram: ElementRef<SVGSVGElement>;
legend: i0.InputSignal<string[]>;
points: i0.InputSignal<Point2D[][]>;
xFormatter: i0.InputSignal<((x: number) => string) | undefined>;
yFormatter: i0.InputSignal<((x: number) => string) | undefined>;
private pOptions;
get options(): LinearDiagram2DOptions;
set options(value: LinearDiagram2DOptions);
protected pLabels: {
x: string;
y: string;
title: string;
};
set labels(labels: {
x: string;
y: string;
title: string;
});
diagramPointHover: DiagramPointHoverComponent;
protected subscriptions: Subscription[];
constructor(renderer: Renderer2);
ngOnDestroy(): void;
ngAfterContentInit(): void;
ngAfterViewInit(): void;
pdf(): void;
draw(dc?: DrawingContextInterface): void;
move(event: MouseEvent): void;
keyup(event: MouseEvent): void;
left(): void;
right(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<LinearDiagram2DComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<LinearDiagram2DComponent, "obl-linear-diagram-2d", never, { "legend": { "alias": "legend"; "required": false; "isSignal": true; }; "points": { "alias": "points"; "required": false; "isSignal": true; }; "xFormatter": { "alias": "xFormatter"; "required": false; "isSignal": true; }; "yFormatter": { "alias": "yFormatter"; "required": false; "isSignal": true; }; "options": { "alias": "options"; "required": false; }; "labels": { "alias": "labels"; "required": false; }; }, {}, ["diagramPointHover"], ["*"], false, never>;
}
interface ArrayFilterOption {
value: number;
min?: number;
max?: number;
step?: number;
}
type ArrayFiltersOptions = {
[option: string]: ArrayFilterOption;
};
interface ArrayFilterModel {
filter: (data: Point2D[], options: {
[option: string]: any;
}) => Point2D[];
options: ArrayFiltersOptions;
}
interface ValueDesc {
value: number;
min?: number;
max?: number;
steep?: number;
}
type FiltersOptions = {
[filter: string]: ArrayFiltersOptions;
};
declare class DiagramDataFilterComponent {
protected file: OblFileService;
protected models: {
[name: string]: ArrayFilterModel;
};
protected _filters: FiltersOptions;
protected selected?: string;
protected lastData?: Point2D[];
set filters(filters: FiltersOptions);
get filters(): FiltersOptions;
translations: {
[en: string]: string;
};
allow?: string[];
filtersChanged: EventEmitter<FiltersOptions>;
constructor(file: OblFileService);
filtering(data: Point2D[]): Point2D[];
protected remove(name: string): void;
protected changed(): void;
protected compare: (f: any, s: any) => number;
protected download(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<DiagramDataFilterComponent, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<DiagramDataFilterComponent, "obl-diagram-data-filter", never, { "filters": { "alias": "filters"; "required": false; }; "translations": { "alias": "translations"; "required": false; }; "allow": { "alias": "allow"; "required": false; }; }, { "filtersChanged": "filtersChanged"; }, never, ["*"], false, never>;
}
declare class LinearDiagramModule {
static ɵfac: i0.ɵɵFactoryDeclaration<LinearDiagramModule, never>;
static ɵmod: i0.ɵɵNgModuleDeclaration<LinearDiagramModule, [typeof LinearDiagram2DComponent, typeof DiagramPointHoverComponent, typeof DiagramDataFilterComponent], [typeof i4.CommonModule, typeof i5.ButtonsModule, typeof i6.TextPipesModule, typeof i7.InputModule, typeof i8.AbsPipe, typeof i8.MinPipe], [typeof LinearDiagram2DComponent, typeof DiagramPointHoverComponent, typeof DiagramDataFilterComponent]>;
static ɵinj: i0.ɵɵInjectorDeclaration<LinearDiagramModule>;
}
export { DiagramDataFilterComponent, DiagramPointHoverComponent, LinearDiagram2D, LinearDiagram2DComponent, LinearDiagramModule, PointType };
export type { ArrayFilterModel, ArrayFilterOption, ArrayFiltersOptions, AxisOptions, BaseDrawingOptions, DrawingPointFu, FiltersOptions, GridOptions, LinearDiagram2DOptions, ValueDesc, YAxisOptions };