Skip to main content

Interaction

This component is the entrypoint into rendering interactive visualizations. It provides a canvas-based environment for creating draggable points, lines, and other interactive elements.

import { InteractionManager, InteractivePoint } from '@wangyaoshen/locus-interaction';

const manager = new InteractionManager({
canvas: document.querySelector('canvas'),
});

const point = new InteractivePoint({
position: [250, 150],
color: '#E91E63',
radius: 16,
});

manager.registerComponent(point);

Sizing

The canvas size can be configured via the width and height options:

const manager = new InteractionManager({
canvas: document.querySelector('canvas'),
width: 500,
height: 300,
});

Pan and Zoom

Enable panning and zooming for the canvas:

const manager = new InteractionManager({
canvas: document.querySelector('canvas'),
pan: true,
zoom: { min: 0.5, max: 2 },
});

Props

NameTypeDefaultDescription
canvasHTMLCanvasElement-The canvas element to use
widthnumber500Canvas width
heightnumber300Canvas height
panbooleantrueEnable mouse/touch panning
zoomboolean | { min: number; max: number }falseEnable zooming
backgroundColorstring'transparent'Canvas background color
gridSizenumber50Grid line spacing
showGridbooleantrueShow background grid

Available Components

Explore the display components available: