Usage

import { Board } from "@niuee/board";

// however you prefer to get a canvas element that is already in the DOM
const canvasElement = document.querySelector("canvas") as HTMLCanvasElement;
const board = new Board(canvasElement);

const stepFn = board.getStepFunction();
const context = board.getContext();

function step(timestamp: number){
stepFn(timestamp);
// do other stuff after the board has stepped
//.
//.
//.
}

Alternatively you can import the board class as from a subdirectory; this shaves the bundle size a bit but not a lot though. As the board is the overall entry point for the library.

import { Board } from "@niuee/board/boardify";

Constructors

Properties

  • get height(): number

    Returns number

  • set height(height: number): void

    This is in sync with the canvas height and the camera view port height. This is not the board's height. If the limitEntireViewPort is set to true, the min zoom level is updated based on the height.

    Parameters

    • height: number

    Returns void

  • get width(): number

    Returns number

  • set width(width: number): void

    This is in sync with the canvas width and the camera view port width. This is not the board's width. If the limitEntireViewPort is set to true, the min zoom level is updated based on the width of the canvas.

    Parameters

    • width: number

    Returns void

Accessors

  • get alignCoordinateSystem(): boolean

    Returns boolean

  • set alignCoordinateSystem(align: boolean): void

    This is an attribute that determines if the coordinate system should be aligned with the one of the HTML canvas element. The default is true. If you set this to true, the coordinate system will be aligned with the one of the HTML canvas element. If you change this value during runtime, you should update the context to be aligned with the new coordinate system. (just call board.context again)

    Parameters

    • align: boolean

    Returns void

  • get fullScreen(): boolean

    Determines if the board should be full screen. If this is set to true, the width and height of the board will be set to the window's inner width and inner height respectively, and the width and height of the board will resize with the window.

    Returns boolean

  • set fullScreen(value: boolean): void

    Parameters

    • value: boolean

    Returns void

  • get limitEntireViewPort(): boolean

    Returns boolean

  • set limitEntireViewPort(value: boolean): void

    Determines the behavior of the camera when the camera is at the edge of the boundaries. If set to true, the entire view port would not move beyond the boundaries. If set to false, only the center of the camera is bounded by the boundaries.

    Parameters

    • value: boolean

    Returns void

  • get maxHalfTransHeight(): number

    The max translation height of the camera. This is the maximum distance the camera can move in the vertical direction.

    Returns number

  • get maxHalfTransWidth(): number

    The max translation width of the camera. This is the maximum distance the camera can move in the horizontal direction.

    Returns number

Methods

  • Converts a point from window coordinates to world coordinates.

    Parameters

    • clickPointInWindow: Point

      The point in window coordinates to convert.

    Returns Point

    The converted point in world coordinates.

  • Add an camera movement event listener. The events are "pan", "zoom", and "rotate". There's also an "all" event that will be triggered when any of the above events are triggered.

    Type Parameters

    Parameters

    • eventName: K

      The event name to listen for. The events are "pan", "zoom", and "rotate".

    • callback: (event: CameraEventMap[K], cameraState: CameraState) => void

      The callback function to call when the event is triggered. The event provided to the callback is different for the different events.

    Returns UnSubscribe

    The converted point in world coordinates.

  • This is the step function that is called in the animation frame. This function is responsible for updating the canvas context and the camera state.

    Parameters

    • timestamp: number

    Returns void

Helper Methods

  • This function sets the max translation width of the camera while fixing the minimum x boundary.

    Parameters

    • value: number

    Returns void

  • This function sets the max translation width of the camera while fixing the minimum x boundary.

    Parameters

    • value: number

    Returns void

LifeCycle

  • This function is used to set up the board. It adds all the event listeners and starts the resize observer and the attribute observer.

    Returns void

  • This function is used to clean up the board. It removes all the event listeners and disconnects the resize observer and the attribute observer.

    Returns void