Class CandyGraph

Hierarchy

  • CandyGraph

Constructors

Properties

canvas: HTMLCanvasElement
commandsByCoords: Map<string, Map<Function, NamedDrawCommands>> = ...
scope: DrawCommand<DefaultContext, {}>

Methods

  • Clears the entire CandyGraph canvas.

    Examples

    Clear the canvas to solid white.

    cg.clear([1, 1, 1, 1]);
    

    Clear the canvas to blue.

    cg.clear([0, 0, 1, 1]);
    

    Clear the canvas to zero alpha for compositing with the page.

    const cg = new CandyGraph({ alpha: true });
    cg.clear([0, 0, 0, 0]);

    Parameters

    • color: [number, number, number, number]

    Returns void

  • Copies the contents of the CandyGraph canvas to another canvas. Returns the HTMLCanvasElement that was copied to.

    Parameters

    • sourceViewport: Viewport

      The Viewport of the CandyGraph canvas that will be copied from.

    • Optional destinationCanvas: HTMLCanvasElement

      The canvas that will be copied to. If not provided, one will be created with the dimensions of destinationViewport.

    • Optional destinationViewport: Viewport

      If not provided, one will be created that is positioned at [0, 0] and with the width and height of sourceViewport.

    Returns HTMLCanvasElement

  • Destroys the underlying regl instance and renders this CandyGraph instance unusable.

    Returns void

  • Renders the given Renderable(s) to the given Viewport with the provided CoordinateSystem.

    Example

    // Create a viewport.
    const viewport = { x: 0, y: 0, width: 384, height: 384 };

    // Create a coordinate system.
    const coords = new CartesianCoordinateSystem(
    new LinearScale([0, 1], [32, viewport.width - 16]),
    new LinearScale([0, 1], [32, viewport.height - 16])
    );

    // Render a line segment to the viewport.
    cg.render(coords, viewport, new LineSegments(cg, [0, 0, 1, 1]));

    // Render a couple more line segments to the viewport.
    cg.render(coords, viewport, [new LineSegments(cg, [0.5, 0, 0.5, 1]), new LineSegments(cg, [0, 1, 1, 0])]);

    Parameters

    Returns void

Generated using TypeDoc