Skip to content

ChromatogramViewer

HPLC/FPLC chromatogram with multiple traces, peak annotations, fraction markers, and dual Y-axes.

Demo

Usage

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

<ChromatogramViewer data={chromData} width={600} height={350} />

Data Type — ChromData

FieldTypeRequiredDescription
tracesChromTrace[]yesSignal traces
peaksChromPeak[]noDetected peaks
fractionsChromFraction[]noCollected fractions
xLabelstringnoX-axis label

Props

PropTypeDefaultDescription
dataChromDataPrimary data prop
widthnumber600SVG width
heightnumber350SVG height
showPeaksbooleantrueShow peak labels
showFractionsbooleantrueShow fraction markers

Example — Constructing Data

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

const data: ChromData = {
  traces: [
    {
      name: 'UV 280nm',
      x: Array.from({ length: 200 }, (_, i) => i * 0.15),
      y: Array.from({ length: 200 }, (_, i) => {
        const x = i * 0.15;
        return 20 * Math.exp(-((x - 8) ** 2) / 1.5) +
          80 * Math.exp(-((x - 12) ** 2) / 2) +
          5 * Math.exp(-((x - 18) ** 2) / 3);
      }),
      unit: 'mAU',
    },
    {
      name: '% Buffer B',
      x: Array.from({ length: 200 }, (_, i) => i * 0.15),
      y: Array.from({ length: 200 }, (_, i) => Math.min(100, Math.max(0, (i - 50) * 0.8))),
      yAxis: 'right',
      color: '#ff7f00',
      unit: '%B',
    },
  ],
  fractions: [
    { name: 'F1', start: 6, end: 10, color: '#4daf4a' },
    { name: 'F2', start: 10, end: 15, color: '#e41a1c' },
    { name: 'F3', start: 16, end: 20, color: '#377eb8' },
  ],
  xLabel: 'Volume (mL)',
};

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