Skip to content

DistributionPlot ​

Histogram with optional overlay curve for density or cumulative distribution.

Demo ​

Usage ​

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

<DistributionPlot data={distributionData} width={500} height={350} />

Data Type — DistributionData ​

FieldTypeRequiredDescription
bins{ start, end, count }[]yesHistogram bins
overlay{ x[], y[] }noOverlay curve
modestringno'histogram' | 'density' | 'cumulative'

Props ​

PropTypeDefaultDescription
dataDistributionData—Primary data prop
widthnumber—SVG width
heightnumber—SVG height
xLabelstring—X-axis label
yLabelstring—Y-axis label
colorstring—Bar color

Example — Constructing Data ​

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

const data: DistributionData = {
  bins: Array.from({ length: 30 }, (_, i) => {
    const start = i * 2;
    const end = start + 2;
    // Normal-ish distribution centered at 30
    const mid = start + 1;
    const count = Math.round(100 * Math.exp(-((mid - 30) ** 2) / 200));
    return { start, end, count };
  }),
  overlay: {
    x: Array.from({ length: 100 }, (_, i) => i * 0.6),
    y: Array.from({ length: 100 }, (_, i) => {
      const x = i * 0.6;
      return 100 * Math.exp(-((x - 30) ** 2) / 200);
    }),
  },
};

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