import { Node } from '../../types/Node'; import { Point } from '../../types/Point'; import { ShapeStyle } from '../../styles/ShapeStyle'; import { Renderer } from '../Renderer'; abstract class ShapeRenderer extends Renderer { static defaultFill = 'white'; static defaultStroke = '#333333'; static defaultStrokeDash = null; static defaultStrokeWidth = 1.5; // Nodes to render protected _nodes: Node[]; // Styling fill: string | null; stroke: string | null; strokeDash: number[] | null; strokeWidth: number | null; protected constructor (style?: ShapeStyle) { super(); this._nodes = []; this.fill = ShapeRenderer.defaultFill; this.stroke = ShapeRenderer.defaultStroke; this.strokeDash = ShapeRenderer.defaultStrokeDash; this.strokeWidth = ShapeRenderer.defaultStrokeWidth; if (style) { if (style.fill !== undefined) this.fill = style.fill; if (style.stroke !== undefined) this.stroke = style.stroke; if (style.strokeDash !== undefined) this.strokeDash = style.strokeDash.slice(); if (style.strokeWidth !== undefined) this.strokeWidth = style.strokeWidth; } } abstract containsPoint (node: Node, x: number, y: number, scale?: number): boolean; abstract intersect (angle: number): Point; abstract selfLoopPoints (node: Node): Point[]; nodes (): Node[]; nodes (points: Node[]): this; nodes (points?: Node[]): Node[] | this { return arguments.length ? (this._nodes = points!, this) : this._nodes; } protected _doStrokeAndFill(context: CanvasRenderingContext2D) { if (this.strokeDash) context.setLineDash(this.strokeDash); if (this.strokeWidth !== null) context.lineWidth = this.strokeWidth; if (this.fill) { context.fillStyle = this.fill; context.fill(); } if (this.stroke && this.strokeWidth) { context.strokeStyle = this.stroke; context.stroke(); } } } export { ShapeRenderer }