Skip to main content

Debug

The interaction library provides several utilities for debugging visualizations. These are useful when building custom components or troubleshooting rendering issues.

Debug Mode

Enable debug mode on the InteractionManager to visualize the viewBox and other internal state:

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

const manager = new InteractionManager({
canvas: document.querySelector('canvas'),
debug: true, // Shows viewBox border and additional info
});

When debug mode is enabled:

  • A red border appears around the actual viewBox
  • Grid lines become more visible
  • Component bounding boxes are highlighted

Viewport Info

Display current viewport information including coordinates and zoom level:

import { DebugInfo } from '@wangyaoshen/locus-interaction';

const debugInfo = new DebugInfo({
position: [10, 10],
showViewport: true,
showMousePosition: true,
precision: 2,
});

manager.registerComponent(debugInfo);

Transform Widget

A debugging tool for testing transformations on components:

import { TransformWidget } from '@wangyaoshen/locus-interaction';

const widget = new TransformWidget({
children: [myShape],
showHandles: true,
showCenter: true,
});

manager.registerComponent(widget);

The transform widget allows you to:

  • Drag to translate
  • Rotate using corner handles
  • Scale using edge handles

Props

DebugInfo Props

NameTypeDefaultDescription
positionVector2[10, 10]Display position
showViewportbooleantrueShow viewport bounds
showMousePositionbooleantrueShow mouse coordinates
precisionnumber3Decimal precision
fontSizenumber12Text font size
colorstring'#666'Text color

TransformWidget Props

NameTypeDefaultDescription
childrenComponent[]-Components to transform
showHandlesbooleantrueShow transform handles
showCenterbooleantrueShow center point
handleSizenumber8Handle size
handleColorstring'#2196F3'Handle color