@ac-kit/model-dataset 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/LICENSE +28 -0
  2. package/README.md +87 -0
  3. package/dist/frame/column.d.ts +24 -0
  4. package/dist/frame/column.d.ts.map +1 -0
  5. package/dist/frame/column.js +12 -0
  6. package/dist/frame/column.js.map +1 -0
  7. package/dist/frame/data-frame-builder.d.ts +44 -0
  8. package/dist/frame/data-frame-builder.d.ts.map +1 -0
  9. package/dist/frame/data-frame-builder.js +106 -0
  10. package/dist/frame/data-frame-builder.js.map +1 -0
  11. package/dist/frame/data-frame.d.ts +161 -0
  12. package/dist/frame/data-frame.d.ts.map +1 -0
  13. package/dist/frame/data-frame.js +251 -0
  14. package/dist/frame/data-frame.js.map +1 -0
  15. package/dist/frame/field.d.ts +125 -0
  16. package/dist/frame/field.d.ts.map +1 -0
  17. package/dist/frame/field.js +17 -0
  18. package/dist/frame/field.js.map +1 -0
  19. package/dist/frame/format-field.d.ts +27 -0
  20. package/dist/frame/format-field.d.ts.map +1 -0
  21. package/dist/frame/format-field.js +63 -0
  22. package/dist/frame/format-field.js.map +1 -0
  23. package/dist/geo/geometry.d.ts +45 -0
  24. package/dist/geo/geometry.d.ts.map +1 -0
  25. package/dist/geo/geometry.js +2 -0
  26. package/dist/geo/geometry.js.map +1 -0
  27. package/dist/index.d.ts +9 -0
  28. package/dist/index.d.ts.map +1 -0
  29. package/dist/index.js +9 -0
  30. package/dist/index.js.map +1 -0
  31. package/dist/quantity/number-format.d.ts +10 -0
  32. package/dist/quantity/number-format.d.ts.map +1 -0
  33. package/dist/quantity/number-format.js +2 -0
  34. package/dist/quantity/number-format.js.map +1 -0
  35. package/dist/quantity/unit.d.ts +30 -0
  36. package/dist/quantity/unit.d.ts.map +1 -0
  37. package/dist/quantity/unit.js +26 -0
  38. package/dist/quantity/unit.js.map +1 -0
  39. package/package.json +58 -0
package/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2024-2026 Anthony Champagne and contributors
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package/README.md ADDED
@@ -0,0 +1,87 @@
1
+ # @ac-kit/model-dataset
2
+
3
+ Self-describing tabular data: a `DataFrame` of named, typed columns, plus the
4
+ vocabulary that says what each column means.
5
+
6
+ A frame carries its schema as **data** — field name, measurement scale, unit,
7
+ number format, and which direction counts as an improvement. That is what lets a
8
+ renderer decide what it can draw, or how to format a cell, without being told by
9
+ the producer.
10
+
11
+ ```ts
12
+ import { dataFrameFromRows } from "@ac-kit/model-dataset";
13
+
14
+ const frame = dataFrameFromRows(
15
+ [
16
+ { name: "case", kind: "nominal", title: "case" },
17
+ {
18
+ name: "medianMs",
19
+ kind: "quantitative",
20
+ title: "median",
21
+ unit: { symbol: "s", scale: -3 },
22
+ direction: "lower-is-better",
23
+ format: { maximumFractionDigits: 3 },
24
+ },
25
+ ],
26
+ [
27
+ ["parse", 1.204],
28
+ ["stringify", 0.917],
29
+ ],
30
+ );
31
+ ```
32
+
33
+ ## What it is for
34
+
35
+ One frame, many outputs. `@ac-kit/format-csv`, `@ac-kit/format-markdown` and
36
+ `@ac-kit/format-monospace` each render the same frame, and because formatting
37
+ comes from the field rather than from each renderer, the same number reads the
38
+ same way everywhere. `@ac-kit/model-chart` describes plots over the same shape.
39
+
40
+ ## Contents
41
+
42
+ | Group | Exports |
43
+ | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
44
+ | Frame | `DataFrame`, `FrameMeta`, `dataFrameFromRows`, `dataFrameFromColumns`, `dataFrameRow`, `dataFrameColumn`, `dataFrameField`, `dataFrameFieldIndex`, `dataFrameSelectFields`, `dataFrameWithField` |
45
+ | Incremental | `DataFrameBuilder` — append rows as they arrive, rewrite them as better answers come in |
46
+ | Schema | `FieldDescriptor`, `FieldKind`, `FieldDirection`, `isNumericField`, `isCategoricalField` |
47
+ | Cells | `Value`, `Column`, `columnCell` |
48
+ | Formatting | `createFieldFormatter`, `formatFieldValue`, `fieldTitle`, `NumberFormatSpec` |
49
+ | Quantities | `Unit`, `DIMENSIONLESS` |
50
+ | Geometry | `Geometry` and its GeoJSON (RFC 7946) members |
51
+
52
+ ## Columnar, with row-shaped entry points
53
+
54
+ Storage is one array per field, because that is how the data is read — a chart
55
+ scans one field end-to-end to find its domain — and because a complete numeric
56
+ column can then be a `Float64Array` rather than a boxed array.
57
+
58
+ Rows are still how data is written: `dataFrameFromRows` for a one-shot build,
59
+ `DataFrameBuilder` for the incremental case, `dataFrameRow` to read one back.
60
+ There is only ever one representation; the row-shaped API is a view onto it.
61
+
62
+ A producer that computes a whole series at a time rather than a record at a time
63
+ reaches for `dataFrameFromColumns` instead, which stores the arrays it is given
64
+ by reference. Sampled data arrives that way, and routing it through the
65
+ row-major path would box every value only to transpose it back.
66
+
67
+ Only `DataFrameBuilder.build()` packs complete numeric columns into a typed
68
+ array — it owns its values and knows when they are final. `dataFrameFromRows`
69
+ stores what it was given.
70
+
71
+ ## No `interval` field kind
72
+
73
+ A span is two fields — `binStart`/`binEnd`, `startedAt`/`endedAt`,
74
+ `medianLowMs`/`medianHighMs` — bound together by an `x`/`x2` encoding in
75
+ `@ac-kit/model-chart`. That keeps every column scalar, and therefore
76
+ typed-array-capable, and means a histogram, a Gantt row and a confidence band
77
+ need no special container.
78
+
79
+ ## Direction belongs to the field, not the unit
80
+
81
+ `latencyMs` and `batteryLifeMs` share a unit and disagree about which way is
82
+ better, so `direction` sits on `FieldDescriptor`. `Unit` is a dimension and a
83
+ scale, nothing more.
84
+
85
+ See the
86
+ [generated API docs](https://anthochamp.github.io/node-essentials/api/model-dataset/)
87
+ for the full reference.
@@ -0,0 +1,24 @@
1
+ import type { Geometry } from "../geo/geometry.js";
2
+ /**
3
+ * One cell. `null` is absent, not zero and not empty.
4
+ *
5
+ * Numbers and bigints are unformatted: a renderer applies the owning field's
6
+ * format, so the same value reads identically in every output medium.
7
+ */
8
+ export type Value = string | number | bigint | boolean | Geometry | null;
9
+ /**
10
+ * One field's values, in row order.
11
+ *
12
+ * A typed array is the canonical form for a complete, null-free numeric field:
13
+ * it stores eight bytes per value with no boxing, which a boxed array cannot do
14
+ * because it is heterogeneous by definition. A field that is still filling in,
15
+ * or that has gaps, uses the boxed form; `DataFrameBuilder` chooses.
16
+ */
17
+ export type Column = Float64Array | Int32Array | Value[];
18
+ /**
19
+ * One cell, whichever representation the column uses.
20
+ *
21
+ * @returns The value, or `null` when `rowIndex` is out of range.
22
+ */
23
+ export declare function columnCell(column: Column, rowIndex: number): Value;
24
+ //# sourceMappingURL=column.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.d.ts","sourceRoot":"","sources":["../../src/frame/column.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;GAKG;AACH,MAAM,MAAM,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,GAAG,IAAI,CAAC;AAEzE;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,GAAG,YAAY,GAAG,UAAU,GAAG,KAAK,EAAE,CAAC;AAEzD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,KAAK,CAKlE"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * One cell, whichever representation the column uses.
3
+ *
4
+ * @returns The value, or `null` when `rowIndex` is out of range.
5
+ */
6
+ export function columnCell(column, rowIndex) {
7
+ if (rowIndex < 0 || rowIndex >= column.length) {
8
+ return null;
9
+ }
10
+ return column[rowIndex] ?? null;
11
+ }
12
+ //# sourceMappingURL=column.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"column.js","sourceRoot":"","sources":["../../src/frame/column.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAc,EAAE,QAAgB;IAC1D,IAAI,QAAQ,GAAG,CAAC,IAAI,QAAQ,IAAI,MAAM,CAAC,MAAM,EAAE,CAAC;QAC/C,OAAO,IAAI,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC;AACjC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import type { Value } from "./column.js";
2
+ import type { DataFrame, FrameMeta } from "./data-frame.js";
3
+ import type { FieldDescriptor } from "./field.js";
4
+ /**
5
+ * Fills a frame in row by row, and lets a row already written be rewritten.
6
+ *
7
+ * This is the incremental path: a live view knows the schema before the first
8
+ * observation arrives, appends a placeholder row when one starts, and
9
+ * overwrites it as better answers come in. A partially-filled frame renders as
10
+ * readily as a complete one — the unwritten cells are simply `null`.
11
+ */
12
+ export declare class DataFrameBuilder {
13
+ private meta_?;
14
+ private readonly fields_;
15
+ private readonly columns_;
16
+ private readonly indexByName_;
17
+ private rowCount_;
18
+ constructor(fields: readonly FieldDescriptor[], meta_?: FrameMeta | undefined);
19
+ get rowCount(): number;
20
+ /**
21
+ * Appends a row, padding missing trailing cells with `null`.
22
+ *
23
+ * @returns The new row's index, for a later {@link setCell}.
24
+ */
25
+ appendRow(row?: readonly Value[]): number;
26
+ /**
27
+ * Overwrites a row already appended. Rows between the last one and `rowIndex`
28
+ * are created empty.
29
+ */
30
+ setRow(rowIndex: number, row: readonly Value[]): void;
31
+ /** @throws {UnknownFieldError} When no field carries that name. */
32
+ setCell(rowIndex: number, fieldName: string, value: Value): void;
33
+ setMeta(meta: FrameMeta): void;
34
+ /**
35
+ * Snapshots the rows written so far. O(r × f).
36
+ *
37
+ * Complete numeric columns are packed into a `Float64Array`; anything with a
38
+ * gap or a non-numeric cell stays boxed. The result shares no storage with
39
+ * the builder, so building again after more rows is safe.
40
+ */
41
+ build(): DataFrame;
42
+ private growTo_;
43
+ }
44
+ //# sourceMappingURL=data-frame-builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-frame-builder.d.ts","sourceRoot":"","sources":["../../src/frame/data-frame-builder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAmBlD;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAQ3B,OAAO,CAAC,KAAK,CAAC;IAPf,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAY;IACrC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAsB;IACnD,OAAO,CAAC,SAAS,CAAK;IAEtB,YACC,MAAM,EAAE,SAAS,eAAe,EAAE,EAC1B,KAAK,CAAC,EAAE,SAAS,YAAA,EAOzB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED;;;;OAIG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,SAAS,KAAK,EAAE,GAAG,MAAM,CAOxC;IAED;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,SAAS,KAAK,EAAE,GAAG,IAAI,CAKpD;IAED,mEAAmE;IACnE,OAAO,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAO/D;IAED,OAAO,CAAC,IAAI,EAAE,SAAS,GAAG,IAAI,CAE7B;IAED;;;;;;OAMG;IACH,KAAK,IAAI,SAAS,CAoBjB;IAED,OAAO,CAAC,OAAO;CAKf"}
@@ -0,0 +1,106 @@
1
+ import { UnknownFieldError } from "./data-frame.js";
2
+ import { isNumericField } from "./field.js";
3
+ /** Whether a column is complete, all-numeric, and so worth packing. */
4
+ function isPackable_(field, values) {
5
+ if (!isNumericField(field)) {
6
+ return false;
7
+ }
8
+ for (let index = 0; index < values.length; index++) {
9
+ if (typeof values[index] !== "number") {
10
+ return false;
11
+ }
12
+ }
13
+ return true;
14
+ }
15
+ /**
16
+ * Fills a frame in row by row, and lets a row already written be rewritten.
17
+ *
18
+ * This is the incremental path: a live view knows the schema before the first
19
+ * observation arrives, appends a placeholder row when one starts, and
20
+ * overwrites it as better answers come in. A partially-filled frame renders as
21
+ * readily as a complete one — the unwritten cells are simply `null`.
22
+ */
23
+ export class DataFrameBuilder {
24
+ meta_;
25
+ fields_;
26
+ columns_;
27
+ indexByName_;
28
+ rowCount_ = 0;
29
+ constructor(fields, meta_) {
30
+ this.meta_ = meta_;
31
+ this.fields_ = [...fields];
32
+ this.columns_ = fields.map(() => []);
33
+ this.indexByName_ = new Map(fields.map((field, index) => [field.name, index]));
34
+ }
35
+ get rowCount() {
36
+ return this.rowCount_;
37
+ }
38
+ /**
39
+ * Appends a row, padding missing trailing cells with `null`.
40
+ *
41
+ * @returns The new row's index, for a later {@link setCell}.
42
+ */
43
+ appendRow(row) {
44
+ const rowIndex = this.rowCount_;
45
+ for (let index = 0; index < this.columns_.length; index++) {
46
+ this.columns_[index][rowIndex] = row?.[index] ?? null;
47
+ }
48
+ this.rowCount_++;
49
+ return rowIndex;
50
+ }
51
+ /**
52
+ * Overwrites a row already appended. Rows between the last one and `rowIndex`
53
+ * are created empty.
54
+ */
55
+ setRow(rowIndex, row) {
56
+ this.growTo_(rowIndex + 1);
57
+ for (let index = 0; index < this.columns_.length; index++) {
58
+ this.columns_[index][rowIndex] = row[index] ?? null;
59
+ }
60
+ }
61
+ /** @throws {UnknownFieldError} When no field carries that name. */
62
+ setCell(rowIndex, fieldName, value) {
63
+ const fieldIndex = this.indexByName_.get(fieldName);
64
+ if (fieldIndex === undefined) {
65
+ throw new UnknownFieldError(fieldName);
66
+ }
67
+ this.growTo_(rowIndex + 1);
68
+ this.columns_[fieldIndex][rowIndex] = value;
69
+ }
70
+ setMeta(meta) {
71
+ this.meta_ = meta;
72
+ }
73
+ /**
74
+ * Snapshots the rows written so far. O(r × f).
75
+ *
76
+ * Complete numeric columns are packed into a `Float64Array`; anything with a
77
+ * gap or a non-numeric cell stays boxed. The result shares no storage with
78
+ * the builder, so building again after more rows is safe.
79
+ */
80
+ build() {
81
+ const columns = this.columns_.map((values, index) => {
82
+ const field = this.fields_[index];
83
+ const slice = values.slice(0, this.rowCount_);
84
+ if (!isPackable_(field, slice)) {
85
+ return slice;
86
+ }
87
+ const packed = new Float64Array(this.rowCount_);
88
+ for (let rowIndex = 0; rowIndex < this.rowCount_; rowIndex++) {
89
+ packed[rowIndex] = slice[rowIndex];
90
+ }
91
+ return packed;
92
+ });
93
+ return {
94
+ fields: [...this.fields_],
95
+ columns,
96
+ rowCount: this.rowCount_,
97
+ ...(this.meta_ === undefined ? {} : { meta: this.meta_ }),
98
+ };
99
+ }
100
+ growTo_(rowCount) {
101
+ while (this.rowCount_ < rowCount) {
102
+ this.appendRow();
103
+ }
104
+ }
105
+ }
106
+ //# sourceMappingURL=data-frame-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-frame-builder.js","sourceRoot":"","sources":["../../src/frame/data-frame-builder.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,uEAAuE;AACvE,SAAS,WAAW,CACnB,KAAsB,EACtB,MAAwB;IAExB,IAAI,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC;QAC5B,OAAO,KAAK,CAAC;IACd,CAAC;IACD,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QACpD,IAAI,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,QAAQ,EAAE,CAAC;YACvC,OAAO,KAAK,CAAC;QACd,CAAC;IACF,CAAC;IACD,OAAO,IAAI,CAAC;AACb,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,gBAAgB;IAQnB,KAAK;IAPG,OAAO,CAAoB;IAC3B,QAAQ,CAAY;IACpB,YAAY,CAAsB;IAC3C,SAAS,GAAG,CAAC,CAAC;IAEtB,YACC,MAAkC,EAC1B,KAAiB;qBAAjB,KAAK;QAEb,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,MAAM,CAAC,CAAC;QAC3B,IAAI,C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C,CAAC,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;SACzD,CAAC;IACH,CAAC;IAEO,OAAO,CAAC,QAAgB;QAC/B,OAAO,IAAI,CAAC,SAAS,GAAG,QAAQ,EAAE,CAAC;YAClC,IAAI,CAAC,SAAS,EAAE,CAAC;QAClB,CAAC;IACF,CAAC;CACD"}
@@ -0,0 +1,161 @@
1
+ import type { Column, Value } from "./column.js";
2
+ import type { FieldDescriptor } from "./field.js";
3
+ /** Frame-level presentation metadata: what a title or a caption would say. */
4
+ export type FrameMeta = {
5
+ title?: string;
6
+ description?: string;
7
+ /** Rendered below the data. Free-form; callers own the meaning. */
8
+ footnotes?: string[];
9
+ /** Producer-defined, opaque to every renderer. */
10
+ attributes?: Record<string, unknown>;
11
+ };
12
+ /**
13
+ * A relation: named, typed columns of equal length.
14
+ *
15
+ * Columnar because that is how it is read — a renderer scans one field
16
+ * end-to-end to find a domain, then maps it — and because a complete numeric
17
+ * column can then be a typed array rather than a boxed one. Rows are reached
18
+ * through {@link dataFrameRow}, and built through {@link dataFrameFromRows} or
19
+ * `DataFrameBuilder`.
20
+ *
21
+ * `columns` is parallel to `fields`: `columns[i]` holds `fields[i]`'s values.
22
+ */
23
+ export type DataFrame = {
24
+ /** Machine name, for joining several frames or naming an output file. */
25
+ name?: string;
26
+ fields: FieldDescriptor[];
27
+ columns: Column[];
28
+ rowCount: number;
29
+ meta?: FrameMeta;
30
+ };
31
+ /** A row carrying more cells than the frame has fields. */
32
+ export declare class DataFrameShapeError extends Error {
33
+ readonly rowIndex: number;
34
+ readonly fieldCount: number;
35
+ readonly cellCount: number;
36
+ constructor(rowIndex: number, fieldCount: number, cellCount: number);
37
+ }
38
+ /** A field name that the frame does not declare. */
39
+ export declare class UnknownFieldError extends Error {
40
+ readonly fieldName: string;
41
+ constructor(fieldName: string);
42
+ }
43
+ /**
44
+ * Position of a field within the frame, or `-1`.
45
+ *
46
+ * O(n) in the field count, which is small; a caller resolving many names should
47
+ * build its own index once instead of calling this in a loop.
48
+ */
49
+ export declare function findDataFrameFieldIndexByName(frame: DataFrame, name: string): number;
50
+ /**
51
+ * One field's descriptor, looked up by name.
52
+ *
53
+ * O(f) in the field count. Use {@link findDataFrameFieldIndexByName} when a
54
+ * missing field is expected rather than exceptional.
55
+ *
56
+ * @throws {UnknownFieldError} When no field carries that name.
57
+ */
58
+ export declare function getDataFrameFieldByName(frame: DataFrame, name: string): FieldDescriptor;
59
+ /**
60
+ * One field's values, looked up by name.
61
+ *
62
+ * O(f) in the field count. The column is shared, not copied.
63
+ *
64
+ * @throws {UnknownFieldError} When no field carries that name.
65
+ */
66
+ export declare function getDataFrameColumnByName(frame: DataFrame, name: string): Column;
67
+ /**
68
+ * One row, in field order. Out-of-range indices yield an all-`null` row.
69
+ *
70
+ * O(f) in the field count — one indexed read per column, not a scan.
71
+ */
72
+ export declare function dataFrameRow(frame: DataFrame, rowIndex: number): Value[];
73
+ /**
74
+ * Builds a frame from row-major input, which is what hand-written data and most
75
+ * producers naturally have.
76
+ *
77
+ * O(r × f). Short rows are padded with `null`. Columns are stored as given,
78
+ * never packed into a typed array — `DataFrameBuilder` is the path that packs,
79
+ * because it owns its values and knows when they are complete.
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * const frame = dataFrameFromRows(
84
+ * [
85
+ * { name: "city", kind: "nominal" },
86
+ * { name: "population", kind: "quantitative" },
87
+ * ],
88
+ * [
89
+ * ["Lyon", 522_250],
90
+ * ["Nantes", 320_732],
91
+ * ],
92
+ * );
93
+ * frame.rowCount; // 2
94
+ * ```;
95
+ *
96
+ * @param rows One array per row, in field order.
97
+ * @throws {DataFrameShapeError} When a row is longer than the field list.
98
+ */
99
+ export declare function dataFrameFromRows(fields: readonly FieldDescriptor[], rows: readonly (readonly Value[])[], meta?: FrameMeta): DataFrame;
100
+ /** Columns that do not line up with the field list, or with each other. */
101
+ export declare class DataFrameColumnShapeError extends Error {
102
+ readonly fieldCount: number;
103
+ readonly columnLengths: number[];
104
+ constructor(fieldCount: number, columnLengths: number[]);
105
+ }
106
+ /**
107
+ * Builds a frame from columns already in hand — the counterpart of
108
+ * {@link dataFrameFromRows}, for a producer that computes a whole series at a
109
+ * time rather than a record at a time.
110
+ *
111
+ * O(f) in the field count: columns are stored by reference, never copied or
112
+ * repacked, so a caller that already built a `Float64Array` keeps it. That is
113
+ * also the reason to prefer this over {@link dataFrameFromRows} for sampled data
114
+ * — the row-major path boxes every value and then transposes it.
115
+ *
116
+ * @example
117
+ * ```ts
118
+ * const frame = dataFrameFromColumns(
119
+ * [
120
+ * { name: "x", kind: "quantitative" },
121
+ * { name: "y", kind: "quantitative" },
122
+ * ],
123
+ * [Float64Array.from([0, 1, 2]), Float64Array.from([0, 1, 4])],
124
+ * );
125
+ * frame.rowCount; // 3
126
+ * ```;
127
+ *
128
+ * @param fields One descriptor per column, in column order.
129
+ * @param columns Parallel to `fields`, all of the same length.
130
+ * @throws {DataFrameColumnShapeError} When the column count differs from the
131
+ * field count, or the columns are not all the same length.
132
+ */
133
+ export declare function dataFrameFromColumns(fields: readonly FieldDescriptor[], columns: readonly Column[], meta?: FrameMeta): DataFrame;
134
+ /**
135
+ * A frame carrying only the named fields, in the order given — the projection a
136
+ * table renderer applies to choose and order its columns.
137
+ *
138
+ * O(n × f) in the requested and declared field counts. Columns are shared with
139
+ * the source frame, not copied.
140
+ *
141
+ * @throws {UnknownFieldError} When a name is not declared by the frame.
142
+ */
143
+ export declare function dataFrameSelectFields(frame: DataFrame, names: readonly string[]): DataFrame;
144
+ /**
145
+ * A frame carrying only the fields that hold at least one non-`null` cell.
146
+ *
147
+ * O(r × f) worst case, less when a column has an early non-`null`. Columns are
148
+ * shared with the source frame, not copied. Applied by the caller and never by
149
+ * a renderer: a stable schema is sometimes the point, as it is for CSV
150
+ * headers.
151
+ */
152
+ export declare function dataFrameDropEmptyFields(frame: DataFrame): DataFrame;
153
+ /**
154
+ * A copy of the frame with one more column, computed per row.
155
+ *
156
+ * O(r × cost of `compute`). This is how a derived quantity — a ratio to the
157
+ * fastest row, a share of a total, a rank — becomes a field, so a table and a
158
+ * chart read it the same way instead of each recomputing it.
159
+ */
160
+ export declare function dataFrameWithField(frame: DataFrame, field: FieldDescriptor, compute: (frame: DataFrame, rowIndex: number) => Value): DataFrame;
161
+ //# sourceMappingURL=data-frame.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-frame.d.ts","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAEjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,8EAA8E;AAC9E,MAAM,MAAM,SAAS,GAAG;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mEAAmE;IACnE,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,kDAAkD;IAClD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACrC,CAAC;AAEF;;;;;;;;;;GAUG;AACH,MAAM,MAAM,SAAS,GAAG;IACvB,yEAAyE;IACzE,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,eAAe,EAAE,CAAC;IAC1B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,SAAS,CAAC;CACjB,CAAC;AAEF,2DAA2D;AAC3D,qBAAa,mBAAoB,SAAQ,KAAK;IAE5C,QAAQ,CAAC,QAAQ,EAAE,MAAM;IACzB,QAAQ,CAAC,UAAU,EAAE,MAAM;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM;IAH3B,YACU,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,MAAM,EAM1B;CACD;AAED,oDAAoD;AACpD,qB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SAAS,CAoBX;AAED;;;;;;;GAOG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,SAAS,GAAG,SAAS,CAoBpE;AAWD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CACjC,KAAK,EAAE,SAAS,EAChB,KAAK,EAAE,eAAe,EACtB,OAAO,EAAE,CAAC,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,KAAK,KAAK,GACpD,SAAS,CAWX"}
@@ -0,0 +1,251 @@
1
+ import { columnCell } from "./column.js";
2
+ /** A row carrying more cells than the frame has fields. */
3
+ export class DataFrameShapeError extends Error {
4
+ rowIndex;
5
+ fieldCount;
6
+ cellCount;
7
+ constructor(rowIndex, fieldCount, cellCount) {
8
+ super(`Row ${rowIndex} has ${cellCount} cells, expected at most ${fieldCount}`);
9
+ this.rowIndex = rowIndex;
10
+ this.fieldCount = fieldCount;
11
+ this.cellCount = cellCount;
12
+ this.name = "DataFrameShapeError";
13
+ }
14
+ }
15
+ /** A field name that the frame does not declare. */
16
+ export class UnknownFieldError extends Error {
17
+ fieldName;
18
+ constructor(fieldName) {
19
+ super(`No field named "${fieldName}"`);
20
+ this.fieldName = fieldName;
21
+ this.name = "UnknownFieldError";
22
+ }
23
+ }
24
+ /**
25
+ * Position of a field within the frame, or `-1`.
26
+ *
27
+ * O(n) in the field count, which is small; a caller resolving many names should
28
+ * build its own index once instead of calling this in a loop.
29
+ */
30
+ export function findDataFrameFieldIndexByName(frame, name) {
31
+ return frame.fields.findIndex((field) => field.name === name);
32
+ }
33
+ /**
34
+ * One field's descriptor, looked up by name.
35
+ *
36
+ * O(f) in the field count. Use {@link findDataFrameFieldIndexByName} when a
37
+ * missing field is expected rather than exceptional.
38
+ *
39
+ * @throws {UnknownFieldError} When no field carries that name.
40
+ */
41
+ export function getDataFrameFieldByName(frame, name) {
42
+ const index = findDataFrameFieldIndexByName(frame, name);
43
+ if (index === -1) {
44
+ throw new UnknownFieldError(name);
45
+ }
46
+ return frame.fields[index];
47
+ }
48
+ /**
49
+ * One field's values, looked up by name.
50
+ *
51
+ * O(f) in the field count. The column is shared, not copied.
52
+ *
53
+ * @throws {UnknownFieldError} When no field carries that name.
54
+ */
55
+ export function getDataFrameColumnByName(frame, name) {
56
+ const index = findDataFrameFieldIndexByName(frame, name);
57
+ if (index === -1) {
58
+ throw new UnknownFieldError(name);
59
+ }
60
+ return frame.columns[index];
61
+ }
62
+ /**
63
+ * One row, in field order. Out-of-range indices yield an all-`null` row.
64
+ *
65
+ * O(f) in the field count — one indexed read per column, not a scan.
66
+ */
67
+ export function dataFrameRow(frame, rowIndex) {
68
+ const row = Array.from({ length: frame.columns.length });
69
+ for (let index = 0; index < frame.columns.length; index++) {
70
+ row[index] = columnCell(frame.columns[index], rowIndex);
71
+ }
72
+ return row;
73
+ }
74
+ /**
75
+ * Builds a frame from row-major input, which is what hand-written data and most
76
+ * producers naturally have.
77
+ *
78
+ * O(r × f). Short rows are padded with `null`. Columns are stored as given,
79
+ * never packed into a typed array — `DataFrameBuilder` is the path that packs,
80
+ * because it owns its values and knows when they are complete.
81
+ *
82
+ * @example
83
+ * ```ts
84
+ * const frame = dataFrameFromRows(
85
+ * [
86
+ * { name: "city", kind: "nominal" },
87
+ * { name: "population", kind: "quantitative" },
88
+ * ],
89
+ * [
90
+ * ["Lyon", 522_250],
91
+ * ["Nantes", 320_732],
92
+ * ],
93
+ * );
94
+ * frame.rowCount; // 2
95
+ * ```;
96
+ *
97
+ * @param rows One array per row, in field order.
98
+ * @throws {DataFrameShapeError} When a row is longer than the field list.
99
+ */
100
+ export function dataFrameFromRows(fields, rows, meta) {
101
+ const columns = fields.map(() => Array.from({ length: rows.length }));
102
+ for (let rowIndex = 0; rowIndex < rows.length; rowIndex++) {
103
+ const row = rows[rowIndex];
104
+ if (row.length > fields.length) {
105
+ throw new DataFrameShapeError(rowIndex, fields.length, row.length);
106
+ }
107
+ for (let fieldIndex = 0; fieldIndex < fields.length; fieldIndex++) {
108
+ columns[fieldIndex][rowIndex] = row[fieldIndex] ?? null;
109
+ }
110
+ }
111
+ return {
112
+ fields: [...fields],
113
+ columns,
114
+ rowCount: rows.length,
115
+ ...(meta === undefined ? {} : { meta }),
116
+ };
117
+ }
118
+ /** Columns that do not line up with the field list, or with each other. */
119
+ export class DataFrameColumnShapeError extends Error {
120
+ fieldCount;
121
+ columnLengths;
122
+ constructor(fieldCount, columnLengths) {
123
+ super(`Expected ${fieldCount} columns of equal length, got ${columnLengths.length} of lengths [${columnLengths.join(", ")}]`);
124
+ this.fieldCount = fieldCount;
125
+ this.columnLengths = columnLengths;
126
+ this.name = "DataFrameColumnShapeError";
127
+ }
128
+ }
129
+ /**
130
+ * Builds a frame from columns already in hand — the counterpart of
131
+ * {@link dataFrameFromRows}, for a producer that computes a whole series at a
132
+ * time rather than a record at a time.
133
+ *
134
+ * O(f) in the field count: columns are stored by reference, never copied or
135
+ * repacked, so a caller that already built a `Float64Array` keeps it. That is
136
+ * also the reason to prefer this over {@link dataFrameFromRows} for sampled data
137
+ * — the row-major path boxes every value and then transposes it.
138
+ *
139
+ * @example
140
+ * ```ts
141
+ * const frame = dataFrameFromColumns(
142
+ * [
143
+ * { name: "x", kind: "quantitative" },
144
+ * { name: "y", kind: "quantitative" },
145
+ * ],
146
+ * [Float64Array.from([0, 1, 2]), Float64Array.from([0, 1, 4])],
147
+ * );
148
+ * frame.rowCount; // 3
149
+ * ```;
150
+ *
151
+ * @param fields One descriptor per column, in column order.
152
+ * @param columns Parallel to `fields`, all of the same length.
153
+ * @throws {DataFrameColumnShapeError} When the column count differs from the
154
+ * field count, or the columns are not all the same length.
155
+ */
156
+ export function dataFrameFromColumns(fields, columns, meta) {
157
+ const lengths = columns.map((column) => column.length);
158
+ const rowCount = lengths[0] ?? 0;
159
+ if (columns.length !== fields.length ||
160
+ lengths.some((length) => length !== rowCount)) {
161
+ throw new DataFrameColumnShapeError(fields.length, lengths);
162
+ }
163
+ return {
164
+ fields: [...fields],
165
+ columns: [...columns],
166
+ rowCount,
167
+ ...(meta === undefined ? {} : { meta }),
168
+ };
169
+ }
170
+ /**
171
+ * A frame carrying only the named fields, in the order given — the projection a
172
+ * table renderer applies to choose and order its columns.
173
+ *
174
+ * O(n × f) in the requested and declared field counts. Columns are shared with
175
+ * the source frame, not copied.
176
+ *
177
+ * @throws {UnknownFieldError} When a name is not declared by the frame.
178
+ */
179
+ export function dataFrameSelectFields(frame, names) {
180
+ const fields = [];
181
+ const columns = [];
182
+ for (const name of names) {
183
+ const index = findDataFrameFieldIndexByName(frame, name);
184
+ if (index === -1) {
185
+ throw new UnknownFieldError(name);
186
+ }
187
+ fields.push(frame.fields[index]);
188
+ columns.push(frame.columns[index]);
189
+ }
190
+ return {
191
+ ...(frame.name === undefined ? {} : { name: frame.name }),
192
+ fields,
193
+ columns,
194
+ rowCount: frame.rowCount,
195
+ ...(frame.meta === undefined ? {} : { meta: frame.meta }),
196
+ };
197
+ }
198
+ /**
199
+ * A frame carrying only the fields that hold at least one non-`null` cell.
200
+ *
201
+ * O(r × f) worst case, less when a column has an early non-`null`. Columns are
202
+ * shared with the source frame, not copied. Applied by the caller and never by
203
+ * a renderer: a stable schema is sometimes the point, as it is for CSV
204
+ * headers.
205
+ */
206
+ export function dataFrameDropEmptyFields(frame) {
207
+ const fields = [];
208
+ const columns = [];
209
+ for (let index = 0; index < frame.fields.length; index++) {
210
+ const column = frame.columns[index];
211
+ if (!hasValue_(column, frame.rowCount)) {
212
+ continue;
213
+ }
214
+ fields.push(frame.fields[index]);
215
+ columns.push(column);
216
+ }
217
+ return {
218
+ ...(frame.name === undefined ? {} : { name: frame.name }),
219
+ fields,
220
+ columns,
221
+ rowCount: frame.rowCount,
222
+ ...(frame.meta === undefined ? {} : { meta: frame.meta }),
223
+ };
224
+ }
225
+ function hasValue_(column, rowCount) {
226
+ for (let rowIndex = 0; rowIndex < rowCount; rowIndex++) {
227
+ if (columnCell(column, rowIndex) !== null) {
228
+ return true;
229
+ }
230
+ }
231
+ return false;
232
+ }
233
+ /**
234
+ * A copy of the frame with one more column, computed per row.
235
+ *
236
+ * O(r × cost of `compute`). This is how a derived quantity — a ratio to the
237
+ * fastest row, a share of a total, a rank — becomes a field, so a table and a
238
+ * chart read it the same way instead of each recomputing it.
239
+ */
240
+ export function dataFrameWithField(frame, field, compute) {
241
+ const values = Array.from({ length: frame.rowCount });
242
+ for (let rowIndex = 0; rowIndex < frame.rowCount; rowIndex++) {
243
+ values[rowIndex] = compute(frame, rowIndex);
244
+ }
245
+ return {
246
+ ...frame,
247
+ fields: [...frame.fields, field],
248
+ columns: [...frame.columns, values],
249
+ };
250
+ }
251
+ //# sourceMappingURL=data-frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-frame.js","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAiCzC,2DAA2D;AAC3D,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAEnC,QAAQ;IACR,UAAU;IACV,SAAS;IAHnB,YACU,QAAgB,EAChB,UAAkB,EAClB,SAAiB;QAE1B,KAAK,CACJ,OAAO,QAAQ,QAAQ,SAAS,4BAA4B,UAAU,EAAE,CACxE,CAAC;wBANO,QAAQ;0BACR,UAAU;yBACV,SAAS;QAKlB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACnC,CAAC;CACD;AAED,oDAAoD;AACpD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACtB,SAAS;IAA9B,YAAqB,SAAiB;QACrC,KAAK,CAAC,mBAAmB,SAAS,GAAG,CAAC,CAAC;yBADnB,SAAS;QAE7B,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;IACjC,CAAC;CACD;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC5C,KAAgB,EAChB,IAAY;IAEZ,OAAO,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,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AG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;KACzD,CAAC;AACH,CAAC;AAED,SAAS,SAAS,CAAC,MAAc,EAAE,QAAgB;IAClD,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC;QACxD,IAAI,UAAU,CAAC,MAAM,EAAE,QAAQ,CAAC,KAAK,IAAI,EAAE,CAAC;YAC3C,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IACD,OAAO,KAAK,CAAC;AACd,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAgB,EAChB,KAAsB,EACtB,OAAsD;IAEtD,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAQ,EAAE,MAAM,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC;IAC7D,KAAK,IAAI,QAAQ,GAAG,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC,QAAQ,EAAE,QAAQ,EAAE,EAAE,CAAC;QAC9D,MAAM,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED,OAAO;QACN,GAAG,KAAK;QACR,MAAM,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;QAChC,OAAO,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,MAAM,CAAC;KACnC,CAAC;AACH,CAAC"}
@@ -0,0 +1,125 @@
1
+ import type { NumberFormatSpec } from "../quantity/number-format.js";
2
+ import type { Unit } from "../quantity/unit.js";
3
+ /**
4
+ * A field's measurement scale — what operations on its values are meaningful,
5
+ * and therefore which visual channels it may drive.
6
+ *
7
+ * This is the type system a renderer reasons with: it never inspects a cell to
8
+ * decide how to draw a field.
9
+ */
10
+ export type FieldKind =
11
+ /** Unordered categories. Equality only. */
12
+ "nominal"
13
+ /** Ordered categories, with no distance between them. */
14
+ | "ordinal"
15
+ /** Continuous; differences and ratios are meaningful. */
16
+ | "quantitative"
17
+ /** Instants on a time axis. */
18
+ | "temporal"
19
+ /** Wraps at a period: an angle, a compass bearing, a time of day. */
20
+ | "cyclic"
21
+ /** A shape in a coordinate reference system. */
22
+ | "geometry"
23
+ /** An opaque key. Joinable, never plotted. */
24
+ | "identifier";
25
+ /**
26
+ * Which way is an improvement for a measured quantity.
27
+ *
28
+ * A property of the quantity, not of its unit — `latencyMs` and `batteryLifeMs`
29
+ * share a unit and disagree here.
30
+ */
31
+ export type FieldDirection = "lower-is-better" | "higher-is-better" | "neutral";
32
+ type FieldCommon = {
33
+ /** Machine key, unique within a frame. Referenced by encodings and joins. */
34
+ name: string;
35
+ /** Human label. Falls back to `name` when absent. */
36
+ title?: string;
37
+ /** Longer prose for a tooltip, a legend caption or a screen reader. */
38
+ description?: string;
39
+ /** Whether the column may contain `null`. Default `true`. */
40
+ nullable?: boolean;
41
+ /**
42
+ * Literal text wrapped around the formatted value, never around a `null`
43
+ * cell's placeholder.
44
+ *
45
+ * Opaque: a `"±"` prefix does not make the value a magnitude, and a `"%"`
46
+ * suffix does not scale it — the producer guarantees that. These exist
47
+ * because `Intl.NumberFormatOptions` can express neither `±` nor `×`.
48
+ */
49
+ prefix?: string;
50
+ suffix?: string;
51
+ };
52
+ type NumericFieldCommon = FieldCommon & {
53
+ unit?: Unit;
54
+ format?: NumberFormatSpec;
55
+ direction?: FieldDirection;
56
+ /**
57
+ * Name of the field holding this one's uncertainty, as a half-width around it
58
+ * — the error bar a chart would draw, the `±` column a table would print.
59
+ *
60
+ * Points from the value to its uncertainty rather than the reverse, so a
61
+ * renderer that ignores uncertainty simply never follows the link, and a
62
+ * value with several candidate spreads still names the one that qualifies it.
63
+ * Use `lower`/`upper` bound fields instead where the interval is asymmetric.
64
+ */
65
+ uncertaintyField?: string;
66
+ };
67
+ export type NominalFieldDescriptor = FieldCommon & {
68
+ kind: "nominal";
69
+ };
70
+ export type OrdinalFieldDescriptor = FieldCommon & {
71
+ kind: "ordinal";
72
+ /** Category order. Absent means order of first appearance. */
73
+ domain?: readonly string[];
74
+ };
75
+ export type QuantitativeFieldDescriptor = NumericFieldCommon & {
76
+ kind: "quantitative";
77
+ };
78
+ export type TemporalFieldDescriptor = NumericFieldCommon & {
79
+ kind: "temporal";
80
+ /**
81
+ * How an instant reads as text. Numeric cells are epoch milliseconds. Absent
82
+ * leaves the choice to the renderer.
83
+ */
84
+ dateFormat?: Intl.DateTimeFormatOptions;
85
+ };
86
+ export type CyclicFieldDescriptor = NumericFieldCommon & {
87
+ kind: "cyclic";
88
+ /** Value at which the scale wraps: `360` for degrees, `24` for hours. */
89
+ period: number;
90
+ };
91
+ export type GeometryFieldDescriptor = FieldCommon & {
92
+ kind: "geometry";
93
+ /**
94
+ * Coordinate reference system identifier, e.g. `"EPSG:4326"`. Absent means
95
+ * WGS 84, which is what GeoJSON fixes for interchange.
96
+ */
97
+ crs?: string;
98
+ };
99
+ export type IdentifierFieldDescriptor = FieldCommon & {
100
+ kind: "identifier";
101
+ };
102
+ /**
103
+ * One column's name, measurement scale and presentation metadata.
104
+ *
105
+ * A frame's schema is data, inspectable at runtime — which is what lets a
106
+ * renderer decide what it can draw without being told.
107
+ *
108
+ * There is deliberately no `interval` kind: a span is two fields plus an
109
+ * `x`/`x2` encoding, which keeps every column scalar and typed-array-capable. A
110
+ * histogram is `binStart`/`binEnd`/`count`; a Gantt row is
111
+ * `startedAt`/`endedAt`.
112
+ */
113
+ export type FieldDescriptor = NominalFieldDescriptor | OrdinalFieldDescriptor | QuantitativeFieldDescriptor | TemporalFieldDescriptor | CyclicFieldDescriptor | GeometryFieldDescriptor | IdentifierFieldDescriptor;
114
+ /**
115
+ * Whether a field's values support arithmetic, and so can drive a continuous
116
+ * scale.
117
+ */
118
+ export declare function isNumericField(field: FieldDescriptor): field is QuantitativeFieldDescriptor | TemporalFieldDescriptor | CyclicFieldDescriptor;
119
+ /**
120
+ * Whether a field's values form a discrete set, and so map to a band or a
121
+ * colour list.
122
+ */
123
+ export declare function isCategoricalField(field: FieldDescriptor): field is NominalFieldDescriptor | OrdinalFieldDescriptor;
124
+ export {};
125
+ //# sourceMappingURL=field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../../src/frame/field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,MAAM,SAAS;AACpB,2CAA2C;AACzC,SAAS;AACX,yDAAyD;GACvD,SAAS;AACX,yDAAyD;GACvD,cAAc;AAChB,+BAA+B;GAC7B,UAAU;AACZ,qEAAqE;GACnE,QAAQ;AACV,gDAAgD;GAC9C,UAAU;AACZ,8CAA8C;GAC5C,YAAY,CAAC;AAEhB;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,SAAS,CAAC;AAEhF,KAAK,WAAW,GAAG;IAClB,6EAA6E;IAC7E,IAAI,EAAE,MAAM,CAAC;IACb,qDAAqD;IACrD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uEAAuE;IACvE,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,kBAAkB,GAAG,WAAW,GAAG;IACvC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,SAAS,CAAC,EAAE,cAAc,CAAC;IAC3B;;;;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Ae,GACpB,KAAK,IAAI,sBAAsB,GAAG,sBAAsB,CAE1D"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Whether a field's values support arithmetic, and so can drive a continuous
3
+ * scale.
4
+ */
5
+ export function isNumericField(field) {
6
+ return (field.kind === "quantitative" ||
7
+ field.kind === "temporal" ||
8
+ field.kind === "cyclic");
9
+ }
10
+ /**
11
+ * Whether a field's values form a discrete set, and so map to a band or a
12
+ * colour list.
13
+ */
14
+ export function isCategoricalField(field) {
15
+ return field.kind === "nominal" || field.kind === "ordinal";
16
+ }
17
+ //# sourceMappingURL=field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"field.js","sourceRoot":"","sources":["../../src/frame/field.ts"],"names":[],"mappings":"AAiIA;;;GAGG;AACH,MAAM,UAAU,cAAc,CAC7B,KAAsB;IAKtB,OAAO,CACN,KAAK,CAAC,IAAI,KAAK,cAAc;QAC7B,KAAK,CAAC,IAAI,KAAK,UAAU;QACzB,KAAK,CAAC,IAAI,KAAK,QAAQ,CACvB,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CACjC,KAAsB;IAEtB,OAAO,KAAK,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC;AAC7D,CAAC"}
@@ -0,0 +1,27 @@
1
+ import type { Value } from "./column.js";
2
+ import type { FieldDescriptor } from "./field.js";
3
+ export type FormatFieldOptions = {
4
+ /** Passed to `Intl`. Absent uses the runtime default. */
5
+ locale?: string | string[];
6
+ /** Text for a `null` cell. Default `""`. */
7
+ nullText?: string;
8
+ };
9
+ /** A field's human label, falling back to its machine name. */
10
+ export declare function fieldTitle(field: FieldDescriptor): string;
11
+ /**
12
+ * A reusable formatter for one field's cells.
13
+ *
14
+ * Built once per column, never per cell: constructing an `Intl.NumberFormat`
15
+ * costs far more than using one, and a table renderer calls this per row.
16
+ *
17
+ * @returns A function mapping any cell of that field to display text.
18
+ */
19
+ export declare function createFieldFormatter(field: FieldDescriptor, options?: FormatFieldOptions): (value: Value) => string;
20
+ /**
21
+ * One cell as display text.
22
+ *
23
+ * Convenient for a one-off; use {@link createFieldFormatter} whenever a whole
24
+ * column is being rendered.
25
+ */
26
+ export declare function formatFieldValue(value: Value, field: FieldDescriptor, options?: FormatFieldOptions): string;
27
+ //# sourceMappingURL=format-field.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-field.d.ts","sourceRoot":"","sources":["../../src/frame/format-field.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,MAAM,MAAM,kBAAkB,GAAG;IAChC,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAC3B,4CAA4C;IAC5C,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,+DAA+D;AAC/D,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,MAAM,CAEzD;AAOD;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CACnC,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,CAW1B;AAoCD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,MAAM,CAER"}
@@ -0,0 +1,63 @@
1
+ /** A field's human label, falling back to its machine name. */
2
+ export function fieldTitle(field) {
3
+ return field.title ?? field.name;
4
+ }
5
+ /** A geometry has no meaningful `toString`, so it reports its shape kind. */
6
+ function plainText_(value) {
7
+ return typeof value === "object" ? value.type : String(value);
8
+ }
9
+ /**
10
+ * A reusable formatter for one field's cells.
11
+ *
12
+ * Built once per column, never per cell: constructing an `Intl.NumberFormat`
13
+ * costs far more than using one, and a table renderer calls this per row.
14
+ *
15
+ * @returns A function mapping any cell of that field to display text.
16
+ */
17
+ export function createFieldFormatter(field, options) {
18
+ const nullText = options?.nullText ?? "";
19
+ const format = createUnaffixedFormatter_(field, nullText, options?.locale);
20
+ const prefix = field.prefix ?? "";
21
+ const suffix = field.suffix ?? "";
22
+ if (prefix === "" && suffix === "") {
23
+ return format;
24
+ }
25
+ return (value) => value === null ? nullText : `${prefix}${format(value)}${suffix}`;
26
+ }
27
+ function createUnaffixedFormatter_(field, nullText, locale) {
28
+ if (field.kind === "temporal") {
29
+ const dateFormat = new Intl.DateTimeFormat(locale, field.dateFormat);
30
+ return (value) => {
31
+ if (value === null) {
32
+ return nullText;
33
+ }
34
+ if (typeof value === "number" || typeof value === "bigint") {
35
+ return dateFormat.format(Number(value));
36
+ }
37
+ return plainText_(value);
38
+ };
39
+ }
40
+ if (field.kind === "quantitative" || field.kind === "cyclic") {
41
+ const numberFormat = new Intl.NumberFormat(locale, field.format);
42
+ return (value) => {
43
+ if (value === null) {
44
+ return nullText;
45
+ }
46
+ if (typeof value === "number" || typeof value === "bigint") {
47
+ return numberFormat.format(value);
48
+ }
49
+ return plainText_(value);
50
+ };
51
+ }
52
+ return (value) => (value === null ? nullText : plainText_(value));
53
+ }
54
+ /**
55
+ * One cell as display text.
56
+ *
57
+ * Convenient for a one-off; use {@link createFieldFormatter} whenever a whole
58
+ * column is being rendered.
59
+ */
60
+ export function formatFieldValue(value, field, options) {
61
+ return createFieldFormatter(field, options)(value);
62
+ }
63
+ //# sourceMappingURL=format-field.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-field.js","sourceRoot":"","sources":["../../src/frame/format-field.ts"],"names":[],"mappings":"AAUA,+DAA+D;AAC/D,MAAM,UAAU,UAAU,CAAC,KAAsB;IAChD,OAAO,KAAK,CAAC,KAAK,IAAI,KAAK,CAAC,IAAI,CAAC;AAClC,CAAC;AAED,6EAA6E;AAC7E,SAAS,UAAU,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AAC,KAAK,CAAC,CAAC,CAAC;YACzC,CAAC;YACD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACH,CAAC;IAED,IAAI,KAAK,CAAC,IAAI,KAAK,cAAc,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC9D,MAAM,YAAY,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QACjE,OAAO,CAAC,KAAK,EAAE,EAAE;YAChB,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;gBACpB,OAAO,QAAQ,CAAC;YACjB,CAAC;YACD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC5D,OAAO,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACnC,CAAC;YACD,OAAO,UAAU,CAAC,KAAK,CAAC,CAAC;QAC1B,CAAC,CAAC;IACH,CAAC;IAED,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AACnE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAC/B,KAAY,EACZ,KAAsB,EACtB,OAA4B;IAE5B,OAAO,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * A position in a coordinate reference system, as `[x, y]` — longitude first
3
+ * for a geographic CRS, matching GeoJSON (RFC 7946 §3.1.1). A third element is
4
+ * elevation.
5
+ */
6
+ export type GeoPosition = readonly [number, number] | readonly [number, number, number];
7
+ export type GeoPoint = {
8
+ type: "Point";
9
+ coordinates: GeoPosition;
10
+ };
11
+ export type GeoMultiPoint = {
12
+ type: "MultiPoint";
13
+ coordinates: readonly GeoPosition[];
14
+ };
15
+ export type GeoLineString = {
16
+ type: "LineString";
17
+ coordinates: readonly GeoPosition[];
18
+ };
19
+ export type GeoMultiLineString = {
20
+ type: "MultiLineString";
21
+ coordinates: readonly (readonly GeoPosition[])[];
22
+ };
23
+ /** First ring is the exterior; any further rings are holes. */
24
+ export type GeoPolygon = {
25
+ type: "Polygon";
26
+ coordinates: readonly (readonly GeoPosition[])[];
27
+ };
28
+ export type GeoMultiPolygon = {
29
+ type: "MultiPolygon";
30
+ coordinates: readonly (readonly (readonly GeoPosition[])[])[];
31
+ };
32
+ export type GeoGeometryCollection = {
33
+ type: "GeometryCollection";
34
+ geometries: readonly Geometry[];
35
+ };
36
+ /**
37
+ * A shape in a coordinate reference system, in GeoJSON's geometry vocabulary
38
+ * (RFC 7946 §3.1).
39
+ *
40
+ * The CRS itself is not carried here: RFC 7946 fixes it to WGS 84 for
41
+ * interchange, and a dataset using another one declares it once on the geometry
42
+ * field rather than on every cell.
43
+ */
44
+ export type Geometry = GeoPoint | GeoMultiPoint | GeoLineString | GeoMultiLineString | GeoPolygon | GeoMultiPolygon | GeoGeometryCollection;
45
+ //# sourceMappingURL=geometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../../src/geo/geometry.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,MAAM,WAAW,GACpB,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,GACzB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AAErC,MAAM,MAAM,QAAQ,GAAG;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,WAAW,EAAE,WAAW,CAAA;CAAE,CAAC;AACnE,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,SAAS,WAAW,EAAE,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,aAAa,GAAG;IAC3B,IAAI,EAAE,YAAY,CAAC;IACnB,WAAW,EAAE,SAAS,WAAW,EAAE,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,kBAAkB,GAAG;IAChC,IAAI,EAAE,iBAAiB,CAAC;IACxB,WAAW,EAAE,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC;AACF,+DAA+D;AAC/D,MAAM,MAAM,UAAU,GAAG;IACxB,IAAI,EAAE,SAAS,CAAC;IAChB,WAAW,EAAE,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC;CACjD,CAAC;AACF,MAAM,MAAM,eAAe,GAAG;IAC7B,IAAI,EAAE,cAAc,CAAC;IACrB,WAAW,EAAE,SAAS,CAAC,SAAS,CAAC,SAAS,WAAW,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;CAC9D,CAAC;AACF,MAAM,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,oBAAoB,CAAC;IAC3B,UAAU,EAAE,SAAS,QAAQ,EAAE,CAAC;CAChC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GACjB,QAAQ,GACR,aAAa,GACb,aAAa,GACb,kBAAkB,GAClB,UAAU,GACV,eAAe,GACf,qBAAqB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=geometry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"geometry.js","sourceRoot":"","sources":["../../src/geo/geometry.ts"],"names":[],"mappings":""}
@@ -0,0 +1,9 @@
1
+ export * from "./frame/column.js";
2
+ export * from "./frame/data-frame-builder.js";
3
+ export * from "./frame/data-frame.js";
4
+ export * from "./frame/field.js";
5
+ export * from "./frame/format-field.js";
6
+ export * from "./geo/geometry.js";
7
+ export * from "./quantity/number-format.js";
8
+ export * from "./quantity/unit.js";
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export * from "./frame/column.js";
2
+ export * from "./frame/data-frame-builder.js";
3
+ export * from "./frame/data-frame.js";
4
+ export * from "./frame/field.js";
5
+ export * from "./frame/format-field.js";
6
+ export * from "./geo/geometry.js";
7
+ export * from "./quantity/number-format.js";
8
+ export * from "./quantity/unit.js";
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,+BAA+B,CAAC;AAC9C,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * How a renderer should turn a numeric cell into text.
3
+ *
4
+ * A subset of `Intl.NumberFormatOptions`, so a renderer applies it by handing
5
+ * it straight to `Intl.NumberFormat` rather than reimplementing formatting.
6
+ * Restricted to the members that are meaningful without a locale decision and
7
+ * that every output medium can honour.
8
+ */
9
+ export type NumberFormatSpec = Pick<Intl.NumberFormatOptions, "style" | "unit" | "unitDisplay" | "notation" | "useGrouping" | "minimumFractionDigits" | "maximumFractionDigits" | "minimumSignificantDigits" | "maximumSignificantDigits" | "signDisplay">;
10
+ //# sourceMappingURL=number-format.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-format.d.ts","sourceRoot":"","sources":["../../src/quantity/number-format.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAClC,IAAI,CAAC,mBAAmB,EACtB,OAAO,GACP,MAAM,GACN,aAAa,GACb,UAAU,GACV,aAAa,GACb,uBAAuB,GACvB,uBAAuB,GACvB,0BAA0B,GAC1B,0BAA0B,GAC1B,aAAa,CACf,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=number-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number-format.js","sourceRoot":"","sources":["../../src/quantity/number-format.ts"],"names":[],"mappings":""}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A quantity's unit and scale, shared by every renderer that needs to label an
3
+ * axis or a column without knowing what produced the numbers.
4
+ *
5
+ * Carries no notion of "better": nanoseconds are lower-is-better for latency
6
+ * and higher-is-better for battery life, so direction belongs to the measured
7
+ * quantity ({@link FieldDescriptor}), not to the dimension it is measured in.
8
+ */
9
+ export type Unit = {
10
+ /** Base unit symbol: `"s"`, `"B"`, `"op/s"`, `"°C"`, `"1"` for dimensionless. */
11
+ symbol: string;
12
+ /** Values are expressed in `symbol × 10^scale`. `-3` is milli, `-9` is nano. */
13
+ scale: number;
14
+ };
15
+ /** The dimensionless unit, for counts, ratios and indices. */
16
+ export declare const DIMENSIONLESS: Unit;
17
+ /** Seconds, for a duration reported at its base scale. */
18
+ export declare const SECOND: Unit;
19
+ /** Milliseconds — seconds carried at milli scale, not a unit of their own. */
20
+ export declare const MILLISECOND: Unit;
21
+ /** Microseconds. */
22
+ export declare const MICROSECOND: Unit;
23
+ /** Nanoseconds. */
24
+ export declare const NANOSECOND: Unit;
25
+ /** Bytes, for sizes and allocation counts. */
26
+ export declare const BYTE: Unit;
27
+ /** Operations per second, for throughput. */
28
+ export declare const OPERATIONS_PER_SECOND: Unit;
29
+ export declare function unitLabel(unit: Unit): string;
30
+ //# sourceMappingURL=unit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit.d.ts","sourceRoot":"","sources":["../../src/quantity/unit.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,IAAI,GAAG;IAClB,iFAAiF;IACjF,MAAM,EAAE,MAAM,CAAC;IACf,gFAAgF;IAChF,KAAK,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,8DAA8D;AAC9D,eAAO,MAAM,aAAa,EAAE,IAAgC,CAAC;AAE7D,0DAA0D;AAC1D,eAAO,MAAM,MAAM,EAAE,IAAgC,CAAC;AAEtD,8EAA8E;AAC9E,eAAO,MAAM,WAAW,EAAE,IAAiC,CAAC;AAE5D,oBAAoB;AACpB,eAAO,MAAM,WAAW,EAAE,IAAiC,CAAC;AAE5D,mBAAmB;AACnB,eAAO,MAAM,UAAU,EAAE,IAAiC,CAAC;AAE3D,8CAA8C;AAC9C,eAAO,MAAM,IAAI,EAAE,IAAgC,CAAC;AAEpD,6CAA6C;AAC7C,eAAO,MAAM,qBAAqB,EAAE,IAAmC,CAAC;AAWxE,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAE5C"}
@@ -0,0 +1,26 @@
1
+ /** The dimensionless unit, for counts, ratios and indices. */
2
+ export const DIMENSIONLESS = { symbol: "1", scale: 0 };
3
+ /** Seconds, for a duration reported at its base scale. */
4
+ export const SECOND = { symbol: "s", scale: 0 };
5
+ /** Milliseconds — seconds carried at milli scale, not a unit of their own. */
6
+ export const MILLISECOND = { symbol: "s", scale: -3 };
7
+ /** Microseconds. */
8
+ export const MICROSECOND = { symbol: "s", scale: -6 };
9
+ /** Nanoseconds. */
10
+ export const NANOSECOND = { symbol: "s", scale: -9 };
11
+ /** Bytes, for sizes and allocation counts. */
12
+ export const BYTE = { symbol: "B", scale: 0 };
13
+ /** Operations per second, for throughput. */
14
+ export const OPERATIONS_PER_SECOND = { symbol: "op/s", scale: 0 };
15
+ const SI_PREFIXES = {
16
+ [-9]: "n",
17
+ [-6]: "µ",
18
+ [-3]: "m",
19
+ [0]: "",
20
+ [3]: "k",
21
+ [6]: "M",
22
+ };
23
+ export function unitLabel(unit) {
24
+ return `${SI_PREFIXES[unit.scale] ?? `e${unit.scale}`}${unit.symbol}`;
25
+ }
26
+ //# sourceMappingURL=unit.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unit.js","sourceRoot":"","sources":["../../src/quantity/unit.ts"],"names":[],"mappings":"AAeA,8DAA8D;AAC9D,MAAM,CAAC,MAAM,aAAa,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAE7D,0DAA0D;AAC1D,MAAM,CAAC,MAAM,MAAM,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEtD,8EAA8E;AAC9E,MAAM,CAAC,MAAM,WAAW,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;AAE5D,oBAAoB;AACpB,MAAM,CAAC,MAAM,WAAW,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;AAE5D,mBAAmB;AACnB,MAAM,CAAC,MAAM,UAAU,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,EAAE,CAAC;AAE3D,8CAA8C;AAC9C,MAAM,CAAC,MAAM,IAAI,GAAS,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAEpD,6CAA6C;AAC7C,MAAM,CAAC,MAAM,qBAAqB,GAAS,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC;AAExE,MAAM,WAAW,GAAqC;IACrD,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG;IACT,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG;IACT,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG;IACT,CAAC,CAAC,CAAC,EAAE,EAAE;IACP,CAAC,CAAC,CAAC,EAAE,GAAG;IACR,CAAC,CAAC,CAAC,EAAE,GAAG;CACR,CAAC;AAEF,MAAM,UAAU,SAAS,CAAC,IAAU;IACnC,OAAO,GAAG,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;AACvE,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "@ac-kit/model-dataset",
3
+ "version": "0.1.0",
4
+ "description": "Self-describing tabular data: a DataFrame of named, typed columns, plus the vocabulary that says what each column means.",
5
+ "keywords": [
6
+ "dataframe",
7
+ "dataset",
8
+ "schema",
9
+ "tabular"
10
+ ],
11
+ "homepage": "https://anthochamp.github.io/node-essentials/api/model-dataset/",
12
+ "bugs": {
13
+ "url": "https://github.com/anthochamp/node-essentials/issues"
14
+ },
15
+ "license": "BSD-3-Clause",
16
+ "author": "Anthony Champagne <dev@anthonychampagne.fr>",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "git+https://github.com/anthochamp/node-essentials.git",
20
+ "directory": "packages/model-dataset"
21
+ },
22
+ "files": [
23
+ "dist"
24
+ ],
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.js",
28
+ "exports": {
29
+ ".": "./dist/index.js"
30
+ },
31
+ "publishConfig": {
32
+ "main": "./dist/index.js",
33
+ "exports": {
34
+ ".": "./dist/index.js"
35
+ },
36
+ "access": "public"
37
+ },
38
+ "scripts": {
39
+ "compile": "tsc -p ./tsconfig.build.json -outDir dist",
40
+ "compile:check": "tsc -noEmit -p ./tsconfig.json",
41
+ "clean": "rimraf dist",
42
+ "build": "yarn clean && yarn compile",
43
+ "test": "yarn run -T vitest run",
44
+ "prepack": "yarn build"
45
+ },
46
+ "devDependencies": {
47
+ "@ac-kit/tsconfig": "0.1.0",
48
+ "@ac-kit/typedoc-config": "0.1.0",
49
+ "@ac-kit/vitest-config": "0.1.0",
50
+ "@typescript/native": "typescript@7.0.2",
51
+ "rimraf": "6.1.3",
52
+ "typedoc": "0.28.20",
53
+ "typescript": "@typescript/typescript6@6.0.2"
54
+ },
55
+ "engines": {
56
+ "node": ">=24"
57
+ }
58
+ }