API reference

Engine namespaces

Every operation of the engine, grouped by namespace.

datasets

NameTypeDescription
importFiles(sources, options?)(sources: (File | FolderEntry)[], options?: ImportOptions) => Promise<ImportResult>Import files in order: delimited text and binary formats; { ids, errors, cancelled? }. Large files go out of core. options: signal (cancel), chooseChannels (asked for files with > 2,000 channels or an ambiguous structure), pickChannels (ask for every binary file).
warmImport(options?)(options?: { formats?: string[] }) => voidGet the next import ready: its worker starts now and, with 'hdf5' or 'mat' in formats, loads the HDF5 reader (4.8 MB, fetched once). One-shot: the next import uses it. Call it on idle, or when the user shows import intent (drag over, file picker); skip it when navigator.connection.saveData is set.
splitByRate(id)(id: string) => Promise<string[]>A combined multi-rate import as one dataset per group (read again from its file).
openAsTable(id)(id: string) => Promise<string[]>A file opened with one channel per tag (one row per sample) read again as its rows. Returns the new dataset ids.
openAsChannels(id)(id: string) => Promise<string[]>A long-form file opened as a table with openAsTable read again as one channel per tag (DatasetInfo.fromLong tells which datasets can). Returns the new dataset ids.
combine(id)(id: string) => Promise<string>Datasets split from one file, combined again.
chooseChannels(id, chooser)(id: string, chooser: ChannelChooser) => Promise<string[] | null>A binary import read again with the channels chooser returns (it starts from what was read); null when it cancels.
addColumns(input)(input: ColumnsInput) => stringAdd numeric columns as a dataset; returns its id. With bands (per column, lo and hi edges aligned with its rows) the charts shade that band under the column: how a reference's envelope is drawn. See Cycles.
replaceColumns(id, columns)(id: string, columns: Record<string, ArrayLike<number>>) => voidNew data for a dataset added with addColumns, in place: the columns passed are replaced (or added), the others kept. Same id, selection, colour, offset and laps; charts redraw on the next frame.
addText(text, name?)(text: string, name?: string) => Promise<string>Parse delimited text like an imported file. name defaults to 'dataset.csv'.
remove(id)(id: string) => voidRemove a dataset, its laps, colours and offsets.
clear()() => voidRemove every dataset; worksheets and charts stay.
configure(id, change)(id, { parseConfig?, beacon?, selectCycles?: 'all' | 'best' }) => Promise<void>Re-parse (in memory only) and/or split into cycles (beacon: BeaconConfig | null). selectCycles 'best' plots only the cycle with the lowest value (partial cycles ignored) instead of all.
setColor(id, color)(id: string, color: string | null) => voidColour of a dataset or lap; null restores the palette colour.
setOffset(id, x)(id: string, x: number) => voidX shift of a dataset or lap.
resetOffsets()() => voidClear every offset.
select(ids)(ids: string[]) => voidReplace the plotted ids (datasets, laps, live connections).
toggle(id)(id: string) => voidToggle one id; a dataset with laps toggles all of them.
selectAll() / deselectAll()() => voidSelect every dataset (laps included) / nothing.
raw(id)(id: string) => { rawText, data, parseConfig, kind, beacon }The parsed content of a dataset, for configuration dialogs and previews. For an imported file, rawText is only its first 256 KB.
columnBounds(column)(column: string) => Promise<{ min, max } | null>Min and max of a column across the plotted data (out-of-core, live and math channels included).

folders

NameTypeDescription
canPick()() => booleanWhether the native directory picker exists (Chrome, Edge).
pick()() => Promise<FolderEntry[] | null>Open the native directory picker; null when cancelled.
fromFileList(files)(files: FileList | File[]) => FolderEntry[]Entries from <input type="file" webkitdirectory>.
fromDataTransfer(dt)(dt: DataTransfer) => Promise<FolderEntry[]>Entries from a drop; folders are walked recursively.
tree(entries, rootName?)(entries: FolderEntry[], rootName?: string) => DirNodeA directory tree for a file picker.
isImportable(name)(name: string) => booleanTrue for delimited text, every binary format (MF4/MDF, EDF/BDF, XDF, TDMS, HDF5, MAT, COMTRADE, PQDIF, MCAP, ULog, MiniSEED, IRIG 106 Chapter 10, IENA, CCSDS), Parquet, Excel workbooks and their companion files (.dbc, .tdms_index, .dat).

worksheets

NameTypeDescription
add(name?)(name?: string) => stringAdd and activate a worksheet. Limit: worksheets.
rename(id, name)(id: string, name: string) => voidRename.
remove(id)(id: string) => voidRemove; the last worksheet cannot be removed (invalid_argument).
reorder(from, to)(from: number, to: number) => voidMove a worksheet by index.
activate(id)(id: string) => voidMake it the active worksheet and reset its zoom.
setXKey(id, key)(id: string, key: string) => voidChange the shared X column. Drops series on that column and clears zoom, offsets and colours.

charts

NameTypeDescription
add(kind, options?)(kind: ChartKind, { worksheetId?, title?, settings?, layout? }) => stringCreate a chart model. Limit: charts-per-worksheet.
update(id, patch)(id: string, patch: ChartSettingsPatch) => voidMerge settings; the kind cannot change.
replaceSettings(id, settings)(id: string, settings: PanelChartSettings) => voidReplace settings of the same kind.
rename(id, title)(id: string, title: string | null) => voidSet or clear the title.
setBackground(id, color)(id: string, color: string | null) => voidPlot background; null follows the theme.
remove(id)(id: string) => voidRemove the model; mounted views of it go blank.
get(id) / list(worksheetId?)ChartModel / ChartModel[]Read models.
setLayout, setLayouts, autoLayoutsee Worksheets and chartsStore or re-flow layout rectangles.
dragLayout(kind, rect, mode, dx, dy, board)(kind, rect, 'move' | 'resize' | ResizeEdge, dxPx, dyPx, { width, height }) => rectExported helper, not a charts method: the layout rectangle after dragging a chart to move or resize it on your grid. 'resize' moves the bottom-right corner; a ResizeEdge ('n', 'e', 's', 'w', 'nw', 'ne', 'sw', 'se') moves that side or corner, the opposite side staying put. Store the result with setLayout.
openWindow(id, options?)(id, { title?, width?, height?, left?, top?, mount? }) => ChartWindowShow the chart in its own browser window. Call it from a click. Without a size or position it opens where chart.window was recorded, if set. A position on another screen than the one showing the page needs the window-management permission of the browser (call getScreenDetails() first). Returns { window, controls, view, close(), on("close") }. Throws popup_blocked.
recordWindows()() => voidRecord in every chart where its own window is now (chart.window: screen position and size; null when in none), so the workbook saved next keeps it. Call it before a deliberate save: closing a window later does not change what was recorded. On open, offer to reopen those windows with openWindow, which puts each back where it was (one per click: browsers allow one popup per click).
addSeries(id, column?)(id: string, column?: string) => Promise<string | null>Multi-band only. Adds a series and fits its scale. Limit: channels-per-chart.
updateSeries(id, seriesId, patch)(id, seriesId, patch: Partial<PlotSeries>) => Promise<void>Patch a series; a new column re-fits the scale.
removeSeries, reorderSeries, autoScaleSeries(id, …) => …Remove, reorder (by series ids) or re-fit series.
mount(id, element, options?)(id: string, element: HTMLElement, options?: MountOptions) => ChartViewRender the chart. See ChartView.
setFonts(fonts)({ sans?, mono? }) => voidFont families for chart text; redraws mounted charts.
kinds() / label(kind)ChartKindInfo[] / stringChart kinds with labels, in menu order.

view

NameTypeDescription
setXRange(range, worksheetId?)(range: [number, number] | null, worksheetId?: string) => voidLinked X zoom of a worksheet (default: active).
resetZoom(worksheetId?)(worksheetId?: string) => voidFull range.
setCursorX(x, worksheetId?)(x: number | null, worksheetId?: string) => voidShared chart cursor of a worksheet (default: active), in X data units; null = none. Multiband charts set it on hover. Not saved, not undone, no change; fires cursorchange.
cursorX(worksheetId?)(worksheetId?: string) => number | nullThe current cursor X of a worksheet, or null.
setLiveWindow(seconds, worksheetId?)(seconds: number | null, worksheetId?: string) => voidScrolling window of a worksheet's live charts on a time axis (default: the active worksheet; null = everything). Each worksheet has its own, shared by its charts and saved with it. Default 30.

mathChannels

NameTypeDescription
create(input)(input: Partial<MathChannel> & { name, formula }) => MathChannelCreate a channel. Limit: math-channels.
update(id, patch)(id: string, patch: MathChannelPatch) => voidPatch name, units, formula, enabled or description.
remove(id)(id: string) => voidDelete.
importMany(channels)(channels: MathChannel[]) => Promise<MathChannel[]>Add several; returns those that fit within the limit.
importFile(file)(file: File) => Promise<{ channels, errors }>Import a JSON export.
exportBlob()() => BlobEvery channel as a JSON file.
preview(channel, worksheetId?)(channel: MathChannel, worksheetId?: string) => EvalResult | nullEvaluate against the plotted data; null when nothing is plotted.
sync(channels)(channels: MathChannel[]) => voidReplace the list with your store’s authoritative one.

live

NameTypeDescription
openLocal(name)(name: string) => LocalLiveStreamA stream fed by your page.
connect(stream, password)(stream: LiveStreamDescriptor, password: string) => Promise<void>Join an encrypted relay stream. Rejects with relay_unavailable or wrong_password.
disconnect(id)(id: string) => voidLeave a relay stream or close a local one.
rowCount(id)(id: string) => numberSamples buffered right now.
setSegmentAxis(id, cfg)(id: string, cfg: LiveSegmentAxis | null) => voidFollow the running cycle of a live connection. cfg: { cycle, axis, column, unit, replay?, onEvent? }. Every block runs the cycle rule (cycle, required) over the new samples and writes the open cycle's X on the alignment axis into the buffer as the computed column column, restarting at each cycle. replay also reports the cycles already in the buffer when it starts. onEvent fires on transitions only: open ({ tstart }) and close (the cycle, with its duration and flags; KPIs are not computed live). null stops it. See Cycles.

video

NameTypeDescription
sources()() => VideoSource[]Every camera the Camera panel can play: each live camera connection (kind: 'live', listed on its own; a camera's low layer is listed too, with lowOf naming its high camera, and the Camera panel picks the layer itself) and the sources you registered (kind: 'recorded'). Fires videochange when the list changes.
register(source)(source: VideoSource) => voidAdd a source, e.g. new RecordedVideoSource({ id, name, parentId, parentName?, recordingId, chunks, fetchChunk, open }): a camera recorded with a cloud recording, downloaded chunk by chunk as the panel seeks. id is the camera stream id, recordingId the data recording it was recorded with. A Camera panel whose worksheet shows that recording (a selected dataset with that info.meta.recordingId) plays it instead of the live camera. Replaces a source with the same id and recordingId.
unregister(id, recordingId?)(id: string, recordingId?: string) => voidRemove the registered sources of a camera (only that recording's when recordingId is given). Call it when you close the recording.

io

NameTypeDescription
exportWorkspace()() => Exported{ json, blob, filename }: envelope v2 (worksheets, active worksheet, the math channels they use, live window, lap settings; never data). Limit: workspaces-io.
exportWorkspaceEncrypted(password)(password: string) => Promise<Exported>A password-protected .kymo file (PBKDF2-SHA256 600k → AES-256-GCM). Limit: workspaces-io.
exportWorksheet(id?) / exportChart(id)(…) => ExportedOne worksheet (a .kymosh file) or chart, as json and blob.
parseFile(file)(file: File) => Promise<ParsedFile>What a file contains: type 'workspace' | 'worksheet' | 'chart' | 'encrypted' | 'error'.
importWorkspace(src, { password }?)(src, options?: { password?: string }) => Promise<{ worksheets: number; errors: string[] }>Replace every worksheet with a v1, v2 or encrypted (.kymo) file. Errors: password_required, wrong_password, bad_workspace.
toWorkbook()() => WorkbookBodyEnvelope v2 of the current analysis, for your own storage (not limited by workspaces-io).
openWorkbook(body)(body: unknown) => { worksheets: number; errors: string[] }Apply a v1/v2 body over the loaded data: its math channels join the session (renamed " (workbook)" on a clash).
importWorksheet(src)(src) => Promise<string>Append and activate a worksheet.
importChart(src, worksheetId?)(src, worksheetId?) => Promise<string>Add a chart to a worksheet.
hasWork()() => booleanWhether a workspace import would replace charts.
snapshot() / restore(snap)SnapshotDatasets, worksheets and selection, for rebuilding state in the same page.
reset()() => voidNo datasets, one blank worksheet. Live connections stay.

alerts

NameTypeDescription
setRules(rules)(rules: RuleDoc[]) => Array<RuleProblem & { ruleId: string }>Replace the rule set (kyr/1 documents). Invalid rules are refused and returned with their problems; past maxAlertRules the rest are left out and limit fires with alert-rules. See Alerts in the SDK.
rules()() => RuleDoc[]The rules in force.
state()() => RuleStateInfo[]Per rule and open file or stream: 'waiting' (with missing channel names), 'idle', 'pending', 'active', 'clearing', 'disabled' or 'not_applicable', and since (the onset).
evaluate(datasetId, { timeColumn, ruleIds? })Promise<AlertTransition[]>Run the rules over a loaded file from its first row; replaces that file’s marks.
clearMarks(targetId?)(targetId?: string) => voidRemove the marks of one file or stream, or all.

marks

NameTypeDescription
list()() => ChartMark[]Read-only spans from alert episodes: { id, ruleId, ruleName, severity, targetId, timeColumn, t0, t1 (null while open) }. Also getState().marks; the 'alert' event reports each transition.

data

NameTypeDescription
merged(worksheetId?)(worksheetId?: string) => Dataset | nullThe plotted datasets and live streams merged into one table, math channels materialised. For tables, previews and custom renderers.

Cycles

Cycle rules (v2): a start, an end and limits, built from conditions (compare, change, cross, reset, elapsed, clock, parent-start, parent-end, next-start, all, any). The same language as the app and the collector’s cycles:. See Cycles.

NameTypeDescription
new CycleSet(defs)(defs: Array<{ id, parentId, rule: CycleRule }>) => CycleSetCycles and their phases (a phase names its cycle in parentId) evaluated together. feed(t, col) takes samples in time order and returns the cycles and phases it closed, { definitionId, index, parentIndex?, tstart, tend, flags }; open() lists the running ones. Flags: late, too-long, too-short (from rule.limits).
engine.datasets.findCycles(id, defs, timeKey)(id: string, defs: Array<RuleDef & { kpis? }>, timeKey: string) => Promise<CycleFound[]>Any open dataset cut by the definitions, each found with its definition's KPIs by column name ('TIC201 max').
engine.datasets.addCycles(id, o)(id: string, o: { timeKey, defs, cycleId, found, pick, tables? }) => Promise<string[]>The picked cycles or phases as datasets with Cycle time (seconds since their start), then the cycles and phases tables. Returns the new ids.
engine.cycles.save(def) / remove(id)(def: Omit<CycleDefinition, "id"> & { id? }) => string / (id: string) => voidThe workbook's rule library (state.cycleRules), saved with the workbook. remove also removes a rule's phases.

Segments and references

Functions exported by @kymoscope/sdk for cycle rules and references. See Cycles for what they do in the app.

NameTypeDescription
new CycleSet(defs)(defs: RuleDef[]) => CycleSetCuts cycles and phases by cycle rules (the app's and the collector's rule language): defs are { id, parentId, rule }, a phase naming its cycle as parentId. feed(t, col) takes samples in time order (col: name → values) and returns the cycles and phases they closed, { definitionId, index, tstart, tend, flags }; open() lists the ones open now. CycleRunner runs one rule. NaN never changes a rule.
alignSegment(t, cols, tstart, axis)(t: Float64Array, cols: Map<string, Float64Array>, tstart: number, axis: AlignAxis) => AlignedSegmentA segment's samples on an alignment axis: elapsed (preroll_s), event (channel, op, value), cumulative (channel, integral?) or clock (tz).
buildReference(segs, channels, points)(segs: AlignedSegment[], channels: string[], points: number) => ReferenceCurvePer channel mean, σ, min, max and count on a grid of points (at most MAX_GRID = 8,000; channels × points at most MAX_BAND_CELLS = 131,072). One segment gives σ 0. Throws too_many_cells or empty.
bandEdges(c, k, band)(c: ReferenceChannel, k: number, band: 'sigma' | 'minmax') => { lo, hi }The band of a reference channel: mean ± k·σ, or min to max.
compareToReference(seg, ref, k, band?, minS?)(seg: AlignedSegment, ref: ReferenceCurve, k: number, band?: 'sigma' | 'minmax', minS?: number) => Comparisondelta per channel (value − reference mean), score (channels by z, highest first) and deviations (out-of-band runs; runs less than minS apart are joined, then shorter ones dropped). Deviations need ≥ 2 segments at a point: a single reference gives deltas and a score only.
encodeBand(ref, channels) / decodeBand(bytes, channels)(ref: ReferenceCurve, channels: string[]) => Uint8Array / (bytes: Uint8Array, channels: string[]) => ReferenceCurveA reference curve as compact bytes to store, and back.
referenceBands(ds, xKey, series, color?, offset?)(ds, xKey: string, series: PlotSeries[], color?: string, offset?: number) => MultibandEnvelope[]A dataset's bands (from addColumns) as chart envelopes, for custom renderers.