@obliczeniowo/elementary
Version:
Library made in Angular version 19
166 lines (165 loc) • 6.55 kB
TypeScript
import { ColorType, Point2D } from '@obliczeniowo/elementary/classes';
import { Size } from '@obliczeniowo/elementary/resize-window';
export declare enum TextAlign {
LEFT = "left",
CENTER = "center",
RIGHT = "right",
JUSTIFY = "justify"
}
export declare enum TextBaseline {
ALPHABETIC = "alphabetic",
IDEOGRAPHIC = "ideographic",
BOTTOM = "bottom",
TOP = "top",
MIDDLE = "middle",
HANGING = "hanging"
}
export declare enum LinePattern {
NONE = 0,
DOTTED = 1,
DASHED = 2,
DASH_DOT = 3,
DISABLED = 4
}
export interface LinePatternDef {
strokeMiterlimit: number;
strokeDasharray: number[];
strokeDashoffset: number;
}
export interface Drawable {
draw: (ctx: DrawingContextInterface) => void;
}
/**
* Abstract class to easy cooperate and switch drawing context logic
*/
export declare abstract class DrawingContextInterface {
protected lastPoint: Point2D;
protected arrowScale: number;
/** optional data that can be set after call draw method */
lastSettings: {
text?: Size;
};
/**
* Some object required clear option before redraw (DrawingSvgInterface for example)
*/
abstract clear(): void;
abstract getTextDimension(text: string): {
width: number;
height: number;
};
/**
* Draw line
* @param startPoint start point
* @param endPoint end point
* @param stroke stroke width
* @param color stroke color as string in format #ffffff or Color object
* @param options specific for object under the hood object
*/
abstract drawLine(startPoint: Point2D, endPoint: Point2D, stroke: number, color: ColorType, options?: any): DrawingContextInterface;
/**
* Draw text
* @param text text to draw
* @param handlePosition handle position
* @param color color as string in format #ffffff or Color object
* @param angle rotate angle in radians
* @param options specific options for object under the hood
*/
abstract drawText(text: string, handlePosition: Point2D, color: ColorType, angle: number, options?: any): DrawingContextInterface;
/**
* Draw polyline using table of points
* @param points table of points
* @param stroke stroke width
* @param color stroke color as string in format #ffffff or Color object
* @param options specific for object under hood
*/
abstract drawPolyline(points: Point2D[], stroke: number, color: ColorType, options?: {
close?: boolean;
[key: string]: any;
}): DrawingContextInterface;
abstract drawPolygon(points: Point2D[], stroke: number, color: ColorType, fill: ColorType, options?: any): DrawingContextInterface;
/**
* Draw circle
* @param point center point
* @param ray ray
* @param stroke stroke width
* @param strokeColor stroke color as string in format #ffffff or Color object
* @param fillColor fill color as string in format #ffffff or Color object
* @param options options specific for object under the hood
*/
abstract drawCircle(point: Point2D, ray: number, stroke: number, strokeColor: ColorType, fillColor: ColorType, options?: any): DrawingContextInterface;
/**
* Draw pie
* @param center center
* @param rx rx
* @param ry ry (some object could not draw this correctly when rx !== ry)
* @param start start angle in radians
* @param end end angle in radians
* @param stroke stroke width
* @param strokeColor stroke color as string in format #ffffff or Color object
* @param fillColor fill color as string in format #ffffff or Color object
* @param options options specific for object under the hood
*/
abstract drawPie(center: Point2D, rx: number, ry: number, start: number, end: number, stroke: number, strokeColor: ColorType, fillColor: ColorType, options?: any): DrawingContextInterface;
/**
* Draw ellipse
* @param point center
* @param xRay x ray
* @param yRay y ray
* @param stroke stroke width
* @param strokeColor stroke color as string in format #ffffff or as Color object
* @param fillColor fill color as string in format #ffffff or as Color object
* @param options external options specific for different object under the hood
*/
abstract drawEllipse(point: Point2D, xRay: number, yRay: number, stroke: number, strokeColor: ColorType, fillColor: ColorType, options?: any): DrawingContextInterface;
/**
* Draw rectangle
* @param x coordinate
* @param y coordinate
* @param width rect width
* @param height rect height
* @param stroke stroke width
* @param strokeColor stroke color
* @param fillColor fill color
* @param options extra options (specific for object under the hood)
*/
abstract drawRect(x: number, y: number, width: number, height: number, stroke: number, strokeColor: ColorType, fillColor: ColorType, options?: any): DrawingContextInterface;
abstract lineTo(point: Point2D, stroke: number, color: ColorType): DrawingContextInterface;
/**
* Set font size
* @param fontSize font size
*/
abstract setFontSize(fontSize: number): DrawingContextInterface;
/** */
abstract getFontSize(): number;
/**
* Set text align flag
* @param align text align enum
*/
abstract setTextAlign(align: TextAlign): DrawingContextInterface;
/**
* Set text baseline
* @param textBaseline text baseline enum
*/
abstract setTextBaseline(textBaseline: TextBaseline): DrawingContextInterface;
/**
* Return text width of given text
*/
abstract getTextWidth(text: string): number;
group(options?: any): this;
endGroup(): this;
/**
* Set line pattern
* @param linePattern LinePattern enum or string or undefined to set default patterns
* @param linePatternDef to set own pattern definition
*/
abstract setLinePattern(linePattern: LinePattern | string | undefined, linePatternDef?: LinePatternDef): DrawingContextInterface;
moveTo(point: Point2D): this;
drawArrow(startPoint: Point2D, endPoint: Point2D, stroke: number, color: ColorType, drawArrow?: boolean, options?: any): this;
abstract getLineStrokeSize(size?: number): number;
abstract save(fileName: string): void;
/**
* Draw all kind of object that implements Drawable interface
* @param drawable table of object that implements Drawable interface
*/
draw(drawable: Drawable[]): this;
}