Options
All
  • Public
  • Public/Protected
  • All
Menu
classdesc

The main class of the PlotBoilerplate.

requires

Vertex

requires

Line

requires

Vector

requires

Polygon

requires

PBImage

requires

VEllipse

requires

Circle

requires

MouseHandler

requires

KeyHandler

requires

VertexAttr

requires

CubicBezierCurve

requires

BezierPath

requires

Drawable

requires

DrawConfig

requires

IHooks

requires

PBParams

requires

Triangle

requires

drawutils

requires

drawutilsgl

requires

SVGSerializable

requires

XYCoords

requires

XYDimension

Hierarchy

  • PlotBoilerplate

Index

Constructors

constructor

Properties

canvas

canvas: HTMLCanvasElement | SVGElement
member

{HTMLCanvasElement}

memberof

PlotBoilerplate

instance

canvasSize

canvasSize: XYDimension
member

{XYDimension}

memberof

PlotBoilerplate

instance

config

config: Config
member

{Config}

memberof

PlotBoilerplate

instance

console

console: Console
member

{Console}

memberof

PlotBoilerplate

instance

ctx

ctx: CanvasRenderingContext2D | WebGLRenderingContext | undefined
member

{CanvasRenderingContext2D|WebGLRenderingContext}

memberof

PlotBoilerplate

deprecated
instance

draggedElements

draggedElements: Array<IDraggable>
member

{Array}

memberof

PlotBoilerplate

instance

draw

draw: DrawLib<void>
member

{drawutils|drawutilsgl|drawutilssvg}

memberof

PlotBoilerplate

instance

drawConfig

drawConfig: DrawConfig
member

{DrawConfig}

memberof

PlotBoilerplate

instance

drawables

drawables: Array<Drawable>
member

{Array}

memberof

PlotBoilerplate

instance

eventCatcher

eventCatcher: HTMLElement

The event catcher might be a different element positioned over the actual canvas.

member

{HTMLElement}

memberof

PlotBoilerplate

instance

fill

fill: DrawLib<void>
member

{drawutils|drawutilsgl|drawutilssvg}

memberof

PlotBoilerplate

instance

grid

grid: Grid
member

{Grid}

memberof

PlotBoilerplate

instance

hooks

hooks: IHooks
member

{IHooks}

memberof

PlotBoilerplate

instance

Private keyHandler

keyHandler: KeyHandler | undefined
member

{KeyHandler|undefined}

memberof

PlotBoilerplate

instance

paths

paths: Array<BezierPath>
member

{Array}

memberof

PlotBoilerplate

instance

Private renderTime

renderTime: number = 0

A discrete timestamp to identify single render cycles. Note that using system time milliseconds is not a safe way to identify render frames, as on modern powerful machines multiple frames might be rendered within each millisecond.

member

{number}

memberof

plotboilerplate

instance

selectPolygon

selectPolygon: Polygon | null
member

{Poylgon}

memberof

PlotBoilerplate

instance

vertices

vertices: Array<Vertex>
member

{Array}

memberof

PlotBoilerplate

instance

Static Readonly DEFAULT_CANVAS_HEIGHT

DEFAULT_CANVAS_HEIGHT: number = 768
constant

{number}

Static Readonly DEFAULT_CANVAS_WIDTH

DEFAULT_CANVAS_WIDTH: number = 1024
constant

{number}

Static Readonly DEFAULT_CLICK_TOLERANCE

DEFAULT_CLICK_TOLERANCE: number = 8
constant

{number}

Static Readonly DEFAULT_TOUCH_TOLERANCE

DEFAULT_TOUCH_TOLERANCE: number = 32
constant

{number}

Static Private Draggable

Draggable: (Anonymous class) = class {static VERTEX: string = "vertex";item: any;typeName: string;vindex: number; // Vertex-indexpindex: number; // Point-index (on path)pid: number; // Point-ID (on curve)cindex: number; // Curve-indexconstructor(item: any, typeName: string) {this.item = item;this.typeName = typeName;}isVertex() {return this.typeName == PlotBoilerplate.Draggable.VERTEX;}setVIndex(vindex: number): IDraggable {this.vindex = vindex;return this;}}

A wrapper class for draggable items (mostly vertices).

Methods

Private _handleColor

  • _handleColor(h: Vertex, color: string): string

Private _setToRetina

  • _setToRetina(): void
  • This function sets the canvas resolution to factor 2.0 (or the preferred pixel ratio of your device) for retina displays. Please not that in non-GL mode this might result in very slow rendering as the canvas buffer size may increase.

    method

    _setToRetina

    instance
    memberof

    PlotBoilerplate

    Returns void

add

  • Add a drawable object.

    This must be either:

     * a Vertex
     * a Line
     * a Vector
     * a VEllipse
     * a VEllipseSector
     * a Circle
     * a Polygon
     * a Triangle
     * a BezierPath
     * a BPImage
    
    method

    add

    instance
    memberof

    PlotBoilerplate

    Parameters

    • drawable: Drawable | Array<Drawable>

      The drawable (of one of the allowed class instance) to add.

    • Optional redraw: boolean

    Returns void

adjustOffset

  • adjustOffset(redraw?: boolean): void
  • Re-adjust the configured offset depending on the current canvas size and zoom (scaleX and scaleY).

    method

    adjustOffset

    Parameters

    • Optional redraw: boolean

      [optional] If set the canvas will redraw with the new offset (default=false).

    Returns void

Private clear

  • clear(): void
  • This function clears the canvas with the configured background color.

    This function is usually only used internally.

    method

    clear

    instance
    memberof

    PlotBoilerplate

    Returns void

Private clearSelection

  • clearSelection(redraw?: boolean): this
  • Clear the selection.

    This function is usually only used internally.

    method

    clearSelection

    instance
    memberof

    PlotBoilerplate

    Parameters

    • Optional redraw: boolean

    Returns this

    this

createGUI

  • Creates a control GUI (a dat.gui instance) for this plot boilerplate instance.

    method

    createGUI

    instance
    memberof

    PlotBoilerplate

    Parameters

    Returns GUI

drawAll

  • drawAll(renderTime: number, draw: DrawLib<any>, fill: DrawLib<any>): void
  • Draw all: drawables, grid, select-polygon and vertices.

    method

    drawAll

    instance
    memberof

    PlotBoilerplate

    Parameters

    Returns void

drawDrawable

  • Draw the given drawable.

    This function is usually only used internally.

    method

    drawDrawable

    instance
    memberof

    PlotBoilerplate

    Parameters

    • d: Drawable

      The drawable to draw.

    • renderTime: number

      The current render time. It will be used to distinct already draw vertices from non-draw-yet vertices.

    • draw: DrawLib<any>

      The drawing library to use to draw lines.

    • fill: DrawLib<any>

      The drawing library to use to fill areas.

    Returns void

drawDrawables

  • drawDrawables(renderTime: number, draw: DrawLib<any>, fill: DrawLib<any>): void
  • Draw all drawables.

    This function is usually only used internally.

    method

    drawDrawables

    instance
    memberof

    PlotBoilerplate

    Parameters

    • renderTime: number

      The current render time. It will be used to distinct already draw vertices from non-draw-yet vertices.

    • draw: DrawLib<any>

      The drawing library to use to draw lines.

    • fill: DrawLib<any>

      The drawing library to use to fill areas.

    Returns void

Private drawGrid

  • drawGrid(draw: DrawLib<any>): void
  • Draw the grid with the current config settings.

    This function is usually only used internally.

    method

    drawGrid

    instance
    memberof

    PlotBoilerplate

    Parameters

    • draw: DrawLib<any>

      The drawing library to use to draw lines.

    Returns void

Private drawOrigin

  • drawOrigin(draw: DrawLib<any>): void
  • Draw the origin with the current config settings.

    This function is usually only used internally.

    method

    drawOrigin

    instance
    memberof

    PlotBoilerplate

    Parameters

    • draw: DrawLib<any>

      The drawing library to use to draw lines.

    Returns void

Private drawSelectPolygon

  • drawSelectPolygon(draw: DrawLib<any>): void
  • Draw the select-polygon (if there is one).

    This function is usually only used internally.

    method

    drawSelectPolygon

    instance
    memberof

    PlotBoilerplate

    Parameters

    Returns void

Private drawVertices

  • drawVertices(renderTime: number, draw: DrawLib<any>): void
  • Draw all vertices that were not yet drawn with the given render time.

    This function is usually only used internally.

    method

    drawVertices

    instance
    memberof

    PlotBoilerplate

    Parameters

    • renderTime: number

      The current render time. It is used to distinct already draw vertices from non-draw-yet vertices.

    • draw: DrawLib<any>

    Returns void

fitToView

  • fitToView(bounds: Bounds): void
  • Set the current zoom and draw offset to fit the given bounds.

    This method currently restores the aspect zoom ratio.

    Parameters

    Returns void

Private getAvailableContainerSpace

getDraggedElementCount

  • getDraggedElementCount(): number
  • Determine if any elements are currently being dragged (on mouse move or touch move).

    method

    getDraggedElementCount

    instance
    memberof

    PlotBoilerplate

    Returns number

    The number of elements that are currently being dragged.

Private getFProp

  • getFProp(elem: HTMLElement | SVGElement, propName: string): number
  • Internal helper function used to get 'float' properties from elements. Used to determine border withs and paddings that were defined using CSS.

    Parameters

    • elem: HTMLElement | SVGElement
    • propName: string

    Returns number

getVertexNear

  • getVertexNear(pixelPosition: XYCoords, pixelTolerance: number): Vertex | undefined
  • Find the vertex near the given position.

    The position is the absolute vertex position, not the x-y-coordinates on the canvas.

    Parameters

    • pixelPosition: XYCoords
    • pixelTolerance: number

      A radius around the position to include into the search. Note that the tolerance will be scaled up/down when zoomed.

    Returns Vertex | undefined

    The vertex near the given position or undefined if none was found there.

Private handleClick

Private installInputListeners

  • installInputListeners(): void

Private locatePointNear

  • (Helper) Locates the point (index) at the passed position. Using an internal tolerance of 7 pixels.

    The result is an object { type : 'bpath', pindex, cindex, pid }

    Returns false if no point is near the passed position.

    method

    locatePointNear

    Parameters

    • point: XYCoords

      The polygonal selection area.

    • Optional tolerance: number

    Returns IDraggable | null

    Or false if none found.

Private mouseDownHandler

Private mouseDragHandler

  • The mouse-drag handler.

    It moves selected elements around or performs the panning if the ctrl-key if hold down.

    method

    mouseDragHandler.

    Parameters

    Returns void

Private mouseUpHandler

Private mouseWheelHandler

redraw

  • redraw(): void
  • Trigger redrawing of all objects.

    Usually this function is automatically called when objects change.

    method

    redraw

    instance
    memberof

    PlotBoilerplate

    Returns void

remove

  • remove(drawable: Drawable | Array<Drawable>, redraw?: boolean, removeWithVertices?: boolean): void
  • Remove a drawable object.

    This must be either:

     * a Vertex
     * a Line
     * a Vector
     * a VEllipse
     * a Circle
     * a Polygon
     * a BezierPath
     * a BPImage
     * a Triangle
    
    method

    remove

    instance
    memberof

    PlotBoilerplate

    Parameters

    • drawable: Drawable | Array<Drawable>

      The drawable (of one of the allowed class instance) to remove.

    • Optional redraw: boolean
    • Optional removeWithVertices: boolean

    Returns void

removeAll

  • removeAll(keepVertices?: boolean): void
  • Remove all elements.

    If you want to keep the vertices, pass true.

    method

    removeAll

    instance
    memberof

    PlotBoilerplate

    Parameters

    • Optional keepVertices: boolean

    Returns void

removeVertex

  • removeVertex(vert: Vertex, redraw?: boolean): void
  • Remove a vertex from the vertex list.

    method

    removeVertex

    instance
    memberof

    PlotBoilerplate

    Parameters

    • vert: Vertex

      The vertex to remove.

    • Optional redraw: boolean

    Returns void

resizeCanvas

  • resizeCanvas(): void
  • This function resizes the canvas to the required settings (toggles fullscreen).

    This function is usually only used internally but feel free to call it if resizing required.

    method

    resizeCanvas

    instance
    memberof

    PlotBoilerplate

    Returns void

revertMousePosition

  • revertMousePosition(x: number, y: number): XYCoords
  • Revert a transformed mouse position back to canvas coordinates.

    This is the inverse function of transformMousePosition.

    method

    revertMousePosition

    instance
    memberof

    PlotBoilerplate

    Parameters

    • x: number

      The x component of the position to revert.

    • y: number

      The y component of the position to revert.

    Returns XYCoords

    The canvas coordinates for the given position.

saveFile

  • saveFile(): void

selectVerticesInPolygon

  • selectVerticesInPolygon(polygon: Polygon): void
  • Add all vertices inside the polygon to the current selection.

    method

    selectVerticesInPolygon

    instance
    memberof

    PlotBoilerplate

    Parameters

    • polygon: Polygon

      The polygonal selection area.

    Returns void

setConsole

  • setConsole(con: Console): void
  • Set the console for this instance.

    method

    setConsole

    instance
    memberof

    PlotBoilerplate

    Parameters

    • con: Console

      The new console object (default is globalThis.console).

    Returns void

Private setOffset

Private setZoom

  • setZoom(zoomFactorX: number, zoomFactorY: number, interactionPos: Vertex): void
  • Set a new zoom value (and re-adjust the draw offset).

    Note: the function will not trigger any redraws.

    Parameters

    • zoomFactorX: number

      The new horizontal zoom value.

    • zoomFactorY: number

      The new vertical zoom value.

    • interactionPos: Vertex

      The position of mouse/touch interaction.

    Returns void

transformMousePosition

  • transformMousePosition(x: number, y: number): XYCoords
  • Transforms the given x-y-(mouse-)point to coordinates respecting the view offset and the zoom settings.

    method

    transformMousePosition

    instance
    memberof

    PlotBoilerplate

    Parameters

    • x: number

      The x position relative to the canvas.

    • y: number

      The y position relative to the canvas.

    Returns XYCoords

    A simple object

    { x : Number, y : Number }
    with the transformed coordinates.

Private updateCSSscale

  • updateCSSscale(): void
  • Update the CSS scale for the canvas depending onf the cssScale{X,Y} settings.

    This function is usually only used inernally.

    method

    updateCSSscale

    instance
    memberof

    PlotBoilerplate

    Returns void

viewport

Static Private _saveFile

  • This function opens a save-as file dialog and – once an output file is selected – stores the current canvas contents as an SVG image.

    It is the default hook for saving files and can be overwritten.

    method

    _saveFile

    instance
    memberof

    PlotBoilerplate

    Parameters

    Returns void

Object literals

Static utils

utils: object

A set of helper functions.

enableBezierPathAutoAdjust

  • enableBezierPathAutoAdjust(bezierPath: BezierPath): void
  • Installs vertex listeners to the path's vertices so that controlpoints move with their path points when dragged.

    Bézier path points with attr.bezierAutoAdjust==true will have their two control points audo-updated if moved, too (keep path connections smooth).

    Parameters

    • bezierPath: BezierPath

      The path to use auto-adjustment for.

    Returns void

safeMergeByKeys

  • safeMergeByKeys<KeyType, ValueType>(base: Record<KeyType, ValueType>, extension: Record<KeyType, ValueType>): Record<KeyType, ValueType>
  • Merge the elements in the 'extension' object into the 'base' object based on the keys of 'base'.

    Type parameters

    • KeyType: string | number | symbol

    • ValueType

    Parameters

    • base: Record<KeyType, ValueType>
    • extension: Record<KeyType, ValueType>

    Returns Record<KeyType, ValueType>

    base extended by the new attributes.

setCSSscale

  • setCSSscale(element: HTMLElement | SVGElement, scaleX: number, scaleY: number): void

fetch

fetch: object

bool

  • bool(obj: any, key: string, fallback: boolean | null): any
  • A helper function to the the object property boolean value specified by the given key.

    Parameters

    • obj: any
    • key: string

      The key of the object property (the name).

    • fallback: boolean | null

      A default value if the key does not exist.

    Returns any

func

  • func(obj: any, key: string, fallback: ((...args: any[]) => any) | null): any
  • A helper function to the the object property function-value specified by the given key.

    Parameters

    • obj: any
    • key: string

      The key of the object property (the name).

    • fallback: ((...args: any[]) => any) | null

      A default value if the key does not exist.

    Returns any

num

  • num(obj: any, key: string, fallback: number): any
  • A helper function to the the object property numeric value specified by the given key.

    Parameters

    • obj: any
    • key: string

      The key of the object property (the name).

    • fallback: number

      A default value if the key does not exist.

    Returns any

val

  • val(obj: any, key: string, fallback: any): any
  • A helper function to the the object property value specified by the given key.

    Parameters

    • obj: any
    • key: string

      The key of the object property (the name).

    • fallback: any

      A default value if the key does not exist.

    Returns any

Legend

  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Private property
  • Private method
  • Static property
  • Static method

Generated using TypeDoc