NetiPlot

Background Shapes

Background shapes are decorative or structural elements rendered behind the graph. Pass them via the shapes prop.

Shape definition — NetiPlotShapeDefinition

FieldTypeRequiredDescription
idstringUnique identifier
shapestringShape type: 'rect', 'circle', 'ellipse', 'image', or custom
xnumberLeft edge position in graph coordinates
ynumberTop edge position in graph coordinates
widthnumberWidth in graph coordinates
heightnumberHeight in graph coordinates
sizenumberShorthand for square shapes (sets both width and height)
styleNetiPlotShapeStyleVisual properties
visiblebooleanHide without removing (default true)
noEditbooleanPrevent resize/move handles
noClickbooleanSuppress click events
boundsIgnorebooleanExclude from fit-to-view bounds calculation

Shape style — NetiPlotShapeStyle

style?: {
  background?: string                        // fill colour
  border?: string | CanvasGradient          // stroke colour (alias: stroke, line)
  lineWidth?: number                         // stroke width in pixels
  fillColor?: string                         // alias for background (alias: fill)
  strokeColor?: string                       // alias for border
}

Example

const shapes: NetiPlotShapeDefinition[] = [
  {
    id: 'region-a',
    shape: 'rect',
    x: 50, y: 50,
    width: 300, height: 200,
    style: {
      background: 'rgba(59, 130, 246, 0.1)',
      border: '#3b82f6',
      lineWidth: 1,
    },
  },
  {
    id: 'zone',
    shape: 'circle',
    x: 400, y: 200,
    size: 120,
    style: { background: 'rgba(16, 185, 129, 0.15)' },
    noEdit: true,
  },
]

Shape interaction

Enable shape editing (drag to move, handles to resize) via options:

options={{ interaction: { allowShapeInteraction: true } }}

Shape move and resize events fire as 'shapeUpdate' on the onMouse callback.

Custom shape drawing

Use shapeDrawingFunction to fully control how a shape is rendered. See Custom drawing.