Options
All
  • Public
  • Public/Protected
  • All
Menu

Class HTML5Canvas

Hierarchy

Implements

Index

Constructors

constructor

  • new HTML5Canvas(element: HTMLCanvasElement): HTML5Canvas

Properties

Private _clickedElement

_clickedElement: DiagramElement<any> | null

Protected _ctx

_ctx: CanvasRenderingContext2D

Private _element

_element: HTMLCanvasElement

Private _isMoving

_isMoving: boolean

Private _startedX

_startedX: number

Private _startedY

_startedY: number

Accessors

background

  • get background(): string | any
  • set background(value: string | any): void

cursor

diagram

  • get diagram(): Diagram | null
  • set diagram(val: Diagram | null): void

grid

  • get grid(): boolean
  • set grid(val: boolean): void

gridX

  • get gridX(): number

gridY

  • get gridY(): number

height

  • get height(): number

hoveredElement

offsetX

  • get offsetX(): number

offsetY

  • get offsetY(): number

selectedElements

width

  • get width(): number

zoom

  • get zoom(): number
  • set zoom(value: number): void

zoomHeight

  • get zoomHeight(): number

zoomWidth

  • get zoomWidth(): number

Methods

addSelection

clearSelection

  • clearSelection(): void

clipRectangle

  • clipRectangle(bounds: Bounds): void

deleteSelection

drawLine

drawRectangle

  • drawRectangle(bounds: Bounds): void

drawSimpleLine

  • drawSimpleLine(x1: number, y1: number, x2: number, y2: number, stroke: Stroke): void

drawText

  • drawText(text: string, x: number, y: number, font: Font, maxWidth?: undefined | number, hAlign?: TextAlign, vAlign?: Baseline): void
  • Draws a text

    Parameters

    • text: string

      The text to draw

    • x: number

      The text X position

    • y: number

      The text Y position

    • font: Font

      The font to use

    • Optional maxWidth: undefined | number

      The maximum width of the text

    • Default value hAlign: TextAlign = "left"

      The horizontal alignment

    • Default value vAlign: Baseline = "middle"

      The vertical alignment

    Returns void

Private extractNewEdgeWaypoint

  • extractNewEdgeWaypoint(edge: Edge<any>, px: number, py: number): void
  • Extracts a new edge waypoint

    Parameters

    • edge: Edge<any>

      The edge who receives the new waypoint

    • px: number

      X position

    • py: number

      Y position

    Returns void

fillRectangle

generateImage

  • generateImage(zoom: number, format?: string, quality?: undefined | number): string
  • Generates an image data URL from the canvas

    Parameters

    • zoom: number

      The zoom factor used for the generated image

    • Default value format: string = "image/png"

      The format as mime type. By default this is image/png

    • Optional quality: undefined | number

      If JPEG, a quality can be specified

    Returns string

    A data URL covering the image data

generatePDF

  • generatePDF(zoom: number): string
  • Generates an SVG data URL from the canvas

    Parameters

    • zoom: number

      The zoom factor used for the generated image

    Returns string

    A data URL covering the image data

generateSVG

  • generateSVG(zoom: number): string
  • Generates an SVG data URL from the canvas

    Parameters

    • zoom: number

      The zoom factor used for the generated image

    Returns string

    A data URL covering the image data

getElementByPosition

  • getElementByPosition(x: number, y: number): DiagramElement<any> | null

Protected getElementCoordinates

  • getElementCoordinates(target: DiagramElement<any>): [number, number]

getHandleByPosition

  • getHandleByPosition(x: number, y: number): Handle | null

Protected invalidate

  • invalidate(): void

isSelected

labelLine

  • labelLine(line: Line, font: Font, label: string, position?: number): void

measureTextWidth

  • measureTextWidth(text: string, font: Font): number

moveElement

  • moveElement(element: DiagramElement<any>, dx: number, dy: number): void

moveOffset

  • moveOffset(dx: number, dy: number): void

onContextMenu

  • onContextMenu(event: Event): void

onKeyPress

  • onKeyPress(event: KeyboardEvent): void

onLeftClick

  • onLeftClick(clickedElement: DiagramElement<any> | null, event: MouseEvent): void
  • Handles a left click in the canvas

    Parameters

    • clickedElement: DiagramElement<any> | null

      The clicked element or null, if no element was hit

    • event: MouseEvent

      The mouse event triggered

    Returns void

onMiddleClick

  • onMiddleClick(clickedElement: DiagramElement<any> | null, event: MouseEvent): void
  • Handles a middle click in the canvas

    Parameters

    • clickedElement: DiagramElement<any> | null

      The clicked element or null, if no element was hit

    • event: MouseEvent

      The mouse event triggered

    Returns void

onMouseDown

  • onMouseDown(event: MouseEvent): void
  • Handles when a mouse button is pushed down on the canvas

    Parameters

    • event: MouseEvent

    Returns void

onMouseMove

  • onMouseMove(event: MouseEvent): void
  • Handles when a mouse is moved over the canvas

    Parameters

    • event: MouseEvent

    Returns void

onMouseUp

  • onMouseUp(event: MouseEvent): void
  • Handles when a mouse button is released on the canvas

    Parameters

    • event: MouseEvent

    Returns void

onMouseWheel

  • onMouseWheel(delta: number, x: number, y: number): void
  • Handles when the mouse wheel is scrolled over the canvas

    Parameters

    • delta: number
    • x: number
    • y: number

    Returns void

onRightClick

  • onRightClick(clickedElement: DiagramElement<any> | null, event: MouseEvent): void
  • Handles a right click in the canvas

    Parameters

    • clickedElement: DiagramElement<any> | null

      The clicked element or null, if no element was hit

    • event: MouseEvent

      The mouse event triggered

    Returns void

popCanvasStack

  • popCanvasStack(): void

pushCanvasStack

  • pushCanvasStack(): void

Protected render

  • render(): this

rerender

  • rerender(): this

resize

  • resize(width: number, height: number): this

Private snapToGrid

  • snapToGrid(px: number, py: number): [number, number]
  • Snaps coordinates to the grid

    Parameters

    • px: number

      Original X coordinate

    • py: number

      Original Y coordinate

    Returns [number, number]

    Coordinates on the grid

strokeRectangle

translate

  • translate(offset: Point): void

Protected updateHandles

zoom100

  • zoom100(x?: undefined | number, y?: undefined | number): void

Protected zoomCanvas

  • zoomCanvas(newZoom: number, x?: undefined | number, y?: undefined | number): void

zoomIn

  • zoomIn(x?: undefined | number, y?: undefined | number): void

zoomOut

  • zoomOut(x?: undefined | number, y?: undefined | number): void

Generated using TypeDoc