Skip to Content
Soundor Components
Components

Plot overview

Compose a canvas chart for responses and measurements.

Use Plot for line, area, bar, step, point and band series on linear or log axes, with draggable markers for editing. Plot draws the data it is given; analysis and other DSP belong in the plug-in.

import { Plot, formatters } from '@soundor/components';
import { useState } from 'react';

const response = Array.from({ length: 96 }, (_, i): [number, number] => {
  const hz = 20 * 1000 ** (i / 95);
  const gain =
    12 / (1 + (hz / 1800) ** 2 / 3) -
    4 +
    5 * Math.exp(-((Math.log10(hz) - 2.4) ** 2 / 0.05));
  return [hz, gain];
});

export default function Demo() {
  const [point, setPoint] = useState<readonly [number, number]>([1800, 4]);
  return (
    <Plot width={420} height={190} title="Response">
      <Plot.XAxis
        domain={[20, 20_000]}
        scale="log"
        ticks="decades"
        format={formatters.frequency}
      />
      <Plot.YAxis domain={[-24, 24]} format={formatters.decibels} />
      <Plot.Grid />
      <Plot.Area label="EQ" points={response} baseline={0} extend />
      <Plot.Marker x={point[0]} y={point[1]} label="1" onMove={setPoint} />
      <Plot.Readout />
    </Plot>
  );
}
plot.tsx, running in the web runtime.Source
import { Plot, formatters } from '@soundor/components';

<Plot width={440} height={220} title="Response">
  <Plot.XAxis domain={[20, 20_000]} scale="log" format={formatters.frequency} />
  <Plot.YAxis domain={[-24, 24]} format={formatters.decibels} />
  <Plot.Grid />
  <Plot.Area source={inputSpectrum} opacity={0.2} />
  <Plot.Line points={response} />
  <Plot.HorizontalLine value={0} />
  {bands.map((band) => (
    <Plot.Marker
      key={band.id}
      x={band.frequency}
      y={band.gain}
      onMove={([hz, db]) => moveBand(band.id, hz, db)}
    />
  ))}
  <Plot.Readout />
</Plot>;

Only what you put in is drawn. A single Plot.Line inside Plot is enough to draw a chart. Without a declared axis, that dimension spans the extent of the series' static data (or 0 to 1) and draws no line or labels.

Parts

PageWhat it covers
Axes and guidesPlot.XAxis, Plot.YAxis, Plot.Grid, Plot.HorizontalLine, Plot.VerticalLine, and Plot.FrequencyKeyboard.
SeriesPlot.Line, Plot.Area, Plot.Steps, Plot.Bars, Plot.Points, Plot.Band, Plot.Legend, Plot.Readout, and live sources.
EditingPlot.Marker, custom overlays, background input, selection, and grouped movement.
ExamplesInteractive EQ, spectrum, levels, compressor, envelope, waveform, and automation demos.

Order and composition

Parts are ordinary React components and belong inside Plot. Your own components can render them, including conditionally or in a map:

<Plot width={440} height={220}>
  <FrequencyAxis />
  <GainAxis />
  {showSpectrum && <Spectrum />}
  <EQResponse />
  <EQBands bands={bands} />
</Plot>

The grid is drawn beneath the series. Series are drawn in tree order, first at the bottom. Markers and guides are drawn over the series in their own order, on the same canvas. Custom views can be layered over that canvas.

Accessibility

The plot is announced as an image with its accessibilityLabel (or its title). Describe what it shows, and provide important values as text or controls. See marker keyboard behavior and Keyboard and accessibility.

Props

Prop

Type

Plot is built from the chart helpers.

On this page