Data

Datasets as an environment reads them: a column resolved to numbers, dates, periods or categories, the axis presets over them, and a series entry.

@internote/canvas-sdk48 exports

#Functions

asInterval
packages/canvas-sdk/src/data/values.ts:37
A refined interval whose ends are already plain numbers, or null.
(value: unknown): IntervalValue | null
boundColumnCells
packages/canvas-sdk/src/data/columns.ts:124
The cells of a bound column, or null when the value is not a binding or the rows are not here.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): string[] | null
buildTimeSeries
packages/canvas-sdk/src/data/time-series.ts:38
Group three parallel columns — key, period, value — into a series.
(
    datasets: Record<string, ChalkDataset> | undefined,
    keysBinding: unknown,
    valuesBinding: unknown,
    periodBinding: unknown,
): TimeSeries | null
categoryPosition
packages/canvas-sdk/src/data/categories.ts:132
The position (1-based) a name takes on a categorical axis, or null where the axis has no such name.
(axis: CategoricalAxis, text: string): number | null
columnKindOf
packages/canvas-sdk/src/data/columns.ts:100
The kind every non-blank cell shares; text when they do not.
(cells: string[]): ColumnKind
complexValueOf
packages/canvas-sdk/src/data/columns.ts:85
A complex literal as its real and imaginary parts, or null when the cell is not one.
(cell: string): { re: number; im: number; } | null

Reads D39's written form: 4+2i, 2i+4, -i, 3.5j. A bare real is a complex number with no imaginary part.

datasetColumnKind
packages/canvas-sdk/src/data/resolve-column.ts:61
How the column a binding names reads as a whole, or null when the value is not a column binding or the dataset has not arrived.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): ColumnKind | null
datasetPeriodKind
packages/canvas-sdk/src/data/resolve-column.ts:139
The kind of period a column holds — years, dates, months, weekdays, hours, weeks (periods.ts) — or null where its cells share no kind.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): PeriodKind | null
dateValueOf
packages/canvas-sdk/src/data/columns.ts:56
An ISO date as a fractional year — the number a date plots at.
(cell: string): number | null
discreteAxis
packages/canvas-sdk/src/data/categories.ts:120
The discrete NUMERIC axis for a set of values: sorted ascending, duplicates dropped, each stop named by the number it is.
(values: number[], ticks?: string[]): CategoricalAxis

The names are the canonical string forms, so everything that reads an axis by name goes on working; values is what the matching and the ticks use. The caller decides the ticks — a graph prints them through its own numeric formatter, which knows about π, decades and dates.

formatPeriod
packages/canvas-sdk/src/data/periods.ts:134
Formats a scrubber position back into a label for the reader, such as Mar, 09:30 or 2024-W12; the inverse of periodValueOf.
(value: number, kind: PeriodKind, step?: number): string
freeParams
packages/canvas-sdk/src/data/values.ts:97
Free identifiers of a refined parametised expression — the letters an environment may offer the reader as parameters.
(value: unknown): string[]
isAxisPresetName
packages/canvas-sdk/src/data/categories.ts:55
Whether name is one of the AXIS_PRESETS, matched exactly (lower case).
(name: string): name is AxisPresetName
isCategoricalAxis
packages/canvas-sdk/src/data/categories.ts:173
Whether an axis is ruled in names.
(axis: { kind?: string; } | null | undefined): axis is CategoricalAxis
isDateEntry
packages/canvas-sdk/src/data/columns.ts:157
Whether a value is a DateEntry.
(value: unknown): value is DateEntry
isGeometryDataset
packages/canvas-sdk/src/data/attachments.ts:43
Whether a dataset is boundary geometry rather than a table.
(dataset: ChalkDataset): boolean

The compiler marks one with format: 'geojson', and only .geojson is an admitted extension — the extension IS the format declaration, so the name is checked too and the two can never disagree. .json is deliberately not accepted: a GeoJSON in a .json file should fail when it is attached, naming the extension it needs, rather than at load with a parse error from whatever tried to read it.

parseCsv
packages/canvas-sdk/src/data/attachments.ts:64
Parse a CSV into header + rows.
(text: string): CsvRows

Deliberately minimal and deliberately not a dependency: RFC 4180 quoting (doubled "" inside a quoted field, delimiters and newlines inside quotes), CRLF, and nothing else. Cells stay strings — a dataset is columns of strings and the receiving attribute's type does the parsing.

periodIsWorded
packages/canvas-sdk/src/data/period-format.ts:74
Whether a kind is written as words or notation — set as text, not as a number.
(kind: PeriodKind | null): boolean
periodKindOf
packages/canvas-sdk/src/data/periods.ts:66
Returns the PeriodKind every non-blank cell in a column shares, or null if they do not all match one kind.
(cells: string[]): PeriodKind | null
periodKindOfFormat
packages/canvas-sdk/src/data/period-format.ts:66
The kind a written format: names, or null for auto — which is not a kind but a deferral, and the caller decides it from the data.
(raw: unknown): PeriodKind | null
periodsOf
packages/canvas-sdk/src/data/time-series.ts:104
The distinct periods a column holds, ascending — what a scrubber's range and natural stops are read from.
(
    datasets: Record<string, ChalkDataset> | undefined,
    periodBinding: unknown,
): number[]
periodValueOf
packages/canvas-sdk/src/data/periods.ts:85
Converts a cell to the number a scrubber positions it at: a date as a fractional year, a month as 1 to 12, and so on.
(cell: string, kind: PeriodKind): number
presetAxis
packages/canvas-sdk/src/data/categories.ts:99
The categorical axis for a preset, with its short ticks.
(name: AxisPresetName): CategoricalAxis
resolveAttachedDatasets
packages/canvas-sdk/src/data/attachments.ts:135
The document's datasets with every attached CSV filled in from files.
(
    datasets: Record<string, ChalkDataset> | undefined,
    files: AttachedFiles,
): Record<string, ChalkDataset>

Returns the input unchanged when there is nothing to do — no attachments, or the files have not arrived — so the host does not hand environments a new object identity on every render for no reason. A dataset whose file is missing keeps its bare src: the column then resolves to null, exactly as it did before the attachment landed, rather than to an invented empty table that would render as a silently blank chart.

resolveCategoricalColumn
packages/canvas-sdk/src/data/resolve-column.ts:125
Returns the dataset column a binding names as positions on a categorical axis, or null if the value is not a column binding.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
    axis: CategoricalAxis,
): number[] | null
resolveColumn
packages/canvas-sdk/src/data/resolve-column.ts:42
The column a binding names, as the strings the dataset holds — or null.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): string[] | null
resolveInterval
packages/canvas-sdk/src/data/values.ts:51
Evaluates an interval whose ends may be expressions, such as [0, 0.46 / s], at the current parameter values.
(value: unknown, params: Record<string, number>): IntervalValue | null
resolveNumber
packages/canvas-sdk/src/data/values.ts:70
Evaluates a value that may be a number, an expression or a date to a number, at the current parameter values, or returns fallback.
(value: unknown, params: Record<string, number>, fallback?: number): number
resolveNumericColumn
packages/canvas-sdk/src/data/resolve-column.ts:107
Returns the dataset column a binding names as numbers, or null if the value is not a column binding.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): number[] | null
resolvePeriodColumn
packages/canvas-sdk/src/data/resolve-column.ts:154
A period column for a time scrubber, on its kind's number line: years and numbers as themselves, ISO dates as fractional years, month and weekday names as their positions (1 = January, 1 = Monday), HH:MM as hours, YYYY-Www as fractional years by the week.
(
    datasets: Record<string, ChalkDataset> | undefined,
    value: unknown,
): number[] | null
seriesAt
packages/canvas-sdk/src/data/time-series.ts:77
Every key's value at a moment, interpolating between the two periods that bracket it — so a reader who stops at 1995 sees half way between the 1990 and 2000 rows rather than nothing at all.
(series: TimeSeries, at: number): Map<string, number>

A key whose own series starts late or ends early holds its nearest reading rather than vanishing: a gap in one country's record should not punch a hole in the map at every other country's expense.

seriesAxis
packages/canvas-sdk/src/data/categories.ts:107
The categorical axis for a written list of names; each tick writes its name.
(names: string[]): CategoricalAxis
seriesEntryFreeVars
packages/canvas-sdk/src/data/columns.ts:185
Returns the names of the parameters a series entry's expression depends on, or an empty list for a non-expression entry.
(entry: unknown): string[]
seriesEntryLabel
packages/canvas-sdk/src/data/columns.ts:174
Returns the text label for a series entry, as a categorical axis would show it, or null for an entry that has none.
(entry: unknown): string | null
seriesEntryReading
packages/canvas-sdk/src/data/columns.ts:210
Which reading an entry offers an auto axis.
numberlabel

Red is R·e·d to the expression parser and a colour to a reader; the refiner keeps both and the axis decides. Written out, an entry is a NUMBER when it is a literal, a date, or an expression whose every letter is a parameter the environment declares, and a NAME otherwise — so a, b beside parameter(var: a) and parameter(var: b) is two numbers, and beside nothing is two categories.

#Constants

AXIS_PRESETS
packages/canvas-sdk/src/data/categories.ts:41
The months and weekdays axes, full names with their three-letter ticks.
Record<AxisPresetName, AxisPreset>
PARAMETER_FORMATS
packages/canvas-sdk/src/data/period-format.ts:40
The written vocabulary of format:, in the order the docs should list it.
readonly ["auto", "numbers", "dates", "months", "weekdays", "hours", "weeks"]

#Interfaces

AxisPreset
packages/canvas-sdk/src/data/categories.ts:31
The names a built-in categorical axis matches and the ticks it writes.
namesRequired
The full names, in order — what a cell is matched against.
string[]
ticksRequired
What the ticks write.
string[]
CategoricalAxis
packages/canvas-sdk/src/data/categories.ts:60
An axis ruled in names.
kindRequired
Discriminates a categorical axis from a NumericAxis.
'categories'
namesRequired
The names, in order; position i + 1 is names[i].
string[]
preset
The preset the names came from, when they came from one; it lets a cell match by its three-letter form.
monthsweekdays
stops
A DISCRETE NUMERIC axis: the names are numbers, and these are the numbers they are.
number[]

Everything about the axis's shape is a categorical axis's — the stops stand at 1…n whatever the gaps between the values are, the window is half a step beyond each end, nothing snaps it to a grid step or grows it for the aspect, and a continuous mark is refused on it. What differs is the reading: a cell is matched as a NUMBER (so 800, 800.0 and a column holding either land on the same stop), the stops are sorted ascending rather than kept in the order they were met, and each tick is printed by the numeric formatter instead of writing its own text.

Which is the axis a heatmap of a factorial grid wants: five loads and four speeds, one cell apiece, labelled 2…6 and 800…2000 with nothing invented in between.

Named stops and not values, though the numbers are what the axis holds: a NumericAxis already has a values, and it is the KIND of number written there (numbers, radians, dates). Two fields of one name on the two halves of ResolvedAxis, one a string and one a list, is a mistake waiting for whoever reaches for axis.values without narrowing first.

ticksRequired
What each tick writes — the short form for a preset, the name itself otherwise.
string[]
CsvRows
packages/canvas-sdk/src/data/attachments.ts:49
A CSV's header and body, cells left as strings.
columnsRequired
The header row's cells, in order.
string[]
rowsRequired
Every row after the header, each a list of cells in column order.
string[][]
DateEntry
packages/canvas-sdk/src/data/columns.ts:149
A date literal in a series or at a place on an axis — its text, and the year it plots at.
dateRequired
The date as written, 2024-03-15 or 2024-03.
string
valueRequired
The fractional year it plots at; see dateValueOf.
number
IntervalValue
packages/canvas-sdk/src/data/values.ts:29
A span with both ends resolved to numbers.
endRequired
Where it ends; may be lower than start on a reversed axis.
number
startRequired
Where the span begins.
number
TimeSeries
packages/canvas-sdk/src/data/time-series.ts:25
Long-format rows grouped for reading at a moment.
byKeyRequired
key → period → value. Keys are the join column's cells, verbatim.
Map<string, Map<number, number>>
periodsRequired
The periods present, ascending and deduplicated.
number[]

#Types

AttachedFiles
packages/canvas-sdk/src/data/attachments.ts:31
The uploaded text files an internote carries, by name.
Record<string, string> | null | undefined
AxisPresetName
packages/canvas-sdk/src/data/categories.ts:26
A built-in categorical axis an author can name in <axis> format:.
monthsweekdays
ColumnKind
packages/canvas-sdk/src/data/columns.ts:38
How a dataset column reads.
numericdatecomplextext

numeric when every non-blank cell is a number, date when every one is an ISO date (2024-03-15 or 2024-03, nothing locale-dependent), complex when every one is a complex literal that is not a plain number, and text otherwise — which is what a column of names is, and what a categorical axis reads.

ParameterFormat
packages/canvas-sdk/src/data/period-format.ts:51
What a parameter's format: may say: how the reader reads its values, or auto to decide from the bound data.
monthsweekdaysautonumbersdateshoursweeks
PeriodKind
packages/canvas-sdk/src/data/period-format.ts:37
What kind of time-like value a column holds, such as date or month, which decides how a scrubber steps through it and labels it.
numberdatemonthweekdayhourweek

Last updated