Skip to content

Graphs API

Import from nmrlink/graphs. Rendering does not modify raw samples or analysis results.

On this page

NMRGraphs

A browser view class. fid and fft are required destination elements; peak and status are optional text elements.

OptionDefaultMeaning
fid / fftRequiredDestination DOM elements
peak / statusnullPeak / analysis description text elements
displayEndMs10FID display end [ms]
frequencyLimitHz10000FFT ±display limit [Hz]; axis uses kHz
colors{}CSS colors for data1, data2 and fft
locale / labelsja / {}Language / partial text overrides
js
const graphs = new NMRGraphs({ fid: fidElement, fft: fftElement, locale: "en" });
graphs.show(record, analyzeMeasurement(record));
// When removing the view: graphs.dispose();

show(record, analysis) renders SVG. If analysis is omitted, it runs analyzeMeasurement with defaults. Height stays at 280 px while width follows the container. Resizing does not reacquire or reanalyze. clear() removes record references and the graphs; dispose() also disconnects the resize observer.

If evaluation of the analysis argument fails, the previous view remains. A rendering failure inside show clears the view and throws. Complete validation and analysis before passing the result to show.

createRecordPlots(record, options)

Returns { fid, fft, spectrum, peak } without a DOM; fid and fft are SVG strings. Options include width=720 (minimum 160), plus the same displayEndMs, frequencyLimitHz, colors, locale and labels as NMRGraphs. analysis defaults to the standard analysis; idPrefix is generated automatically. Manual prefixes must be unique within a page.

Response curve SVGs

FunctionRequired point fieldsAdditional options and axis
createFrequencyPlot(points, options)frequencyHz, nonnegative amplitudeSet frequency [kHz]
createPulsePlot(points, options)length, signed amplitudefit=null, mode=signed / magnitude; RF cycle count
createT1Plot(points, options)tau, signed signalfit=null, mode=signed / magnitude / quadrature; τ [ms]
createT2Plot(points, options)Positive tau, nonnegative signalfit=null; 2τ [ms]

All accept width=720, locale=ja and labels=, returning an SVG string at height 280 px with a minimum width of 160 px. Magnitude and quadrature modes require the corresponding point fields. T1 fits are drawn only in signed mode. Pulse, T1 and T2 axes start at zero without adding a measurement there. Callers handle responsive redraws.

Use results from fitPulseCalibration and fitT1 / fitT2 for fit. Pulse magnitude mode needs a magnitude fit. These curve functions do not accept colors.

locale, labels and colors

locale accepts ja (default) or en. NMRGraphs / createRecordPlots use title, xLabel and yLabel inside labels.fid and labels.fft. The four curve functions use those three keys directly in labels. Omitted strings use defaults; an empty string hides the text. title supplies both SVG title and aria-label.

js
const graphs = new NMRGraphs({
  fid: fidElement, fft: fftElement, locale: "en",
  labels: { fid: { xLabel: "Time [ms]" }, fft: { yLabel: "Amplitude [a.u.]" } },
  colors: { data1: "#176caa", data2: "#b34e25", fft: "#7c3aed" },
});

NMRGraphs also accepts fid.empty, fft.empty, peak.empty, peak.none, peak.outside, peak.value and status. peak.value placeholders are hz / outside; status placeholders are tailPoints / displayEndMs / startMs / endMs / window / frequencyLimitKHz. Strings are escaped as text, not interpreted as HTML. Unknown keys, placeholders, locales or non-string labels throw TypeError. Recreate the view to change languages.

Default colors are #176caa for data1 and fft, #b34e25 for data2. Band and axis colors stay fixed. Changing label text does not convert units.

Previews and copyable examples · PNG export · API index