Skip to content

ScatterPlot ​

XY scatter plot with optional gates, log scales, and point labels.

Demo ​

Usage ​

svelte
<script>
  import { ScatterPlot } from '@molbiohive/hatchlings';
</script>

<ScatterPlot data={scatterData} width={500} height={400} />

Data Type — ScatterData ​

FieldTypeRequiredDescription
pointsDataPoint[]yesData points
axes{ x, y }noAxis labels
gatesGate[]noGating regions

Props ​

PropTypeDefaultDescription
dataScatterData—Primary data prop
widthnumber—SVG width
heightnumber—SVG height
logXboolean—Log X scale
logYboolean—Log Y scale
pointSizenumber—Point radius

Example — Constructing Data ​

ts
import type { ScatterData } from '@molbiohive/hatchlings';

const data: ScatterData = {
  points: Array.from({ length: 100 }, (_, i) => {
    const s1 = Math.sin(i * 127.1) * 43758.5453;
    const s2 = Math.sin(i * 269.5) * 43758.5453;
    const r1 = s1 - Math.floor(s1);
    const r2 = s2 - Math.floor(s2);
    const x = r1 * 10;
    const y = x * 0.8 + (r2 - 0.5) * 3;
    return { x, y, label: i % 20 === 0 ? `Sample ${i}` : undefined };
  }),
  axes: { x: 'Expression (log2)', y: 'Enrichment (fold)' },
};

This is the data powering the demo above. See docs/data/charts.ts for the full source.