@ac-kit/model-dataset 0.1.0 → 0.3.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.
- package/CHANGELOG.md +85 -0
- package/README.md +26 -3
- package/dist/frame/column.d.ts +54 -0
- package/dist/frame/column.d.ts.map +1 -1
- package/dist/frame/column.js +160 -0
- package/dist/frame/column.js.map +1 -1
- package/dist/frame/data-frame-builder.js.map +1 -1
- package/dist/frame/data-frame.d.ts +10 -0
- package/dist/frame/data-frame.d.ts.map +1 -1
- package/dist/frame/data-frame.js +34 -0
- package/dist/frame/data-frame.js.map +1 -1
- package/dist/frame/data-grid.d.ts +64 -0
- package/dist/frame/data-grid.d.ts.map +1 -0
- package/dist/frame/data-grid.js +97 -0
- package/dist/frame/data-grid.js.map +1 -0
- package/dist/frame/format-field.d.ts +5 -0
- package/dist/frame/format-field.d.ts.map +1 -1
- package/dist/frame/format-field.js +47 -3
- package/dist/frame/format-field.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +11 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# @ac-kit/model-dataset
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b4fe43: `columnRowsToFloat64Array(out, column, rows, from, to)` copies the cells at
|
|
8
|
+
`rows[from … to)` of a column into `out` as numbers, one group's values read
|
|
9
|
+
through a grouping's index array, without allocating: cells map as in
|
|
10
|
+
`columnToFloat64Array`, and a row outside the column gives `NaN`.
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [0b4fe43]
|
|
15
|
+
- Updated dependencies [0b4fe43]
|
|
16
|
+
- Updated dependencies [0b4fe43]
|
|
17
|
+
- Updated dependencies [0b4fe43]
|
|
18
|
+
- Updated dependencies [0b4fe43]
|
|
19
|
+
- Updated dependencies [0b4fe43]
|
|
20
|
+
- Updated dependencies [0b4fe43]
|
|
21
|
+
- Updated dependencies [0b4fe43]
|
|
22
|
+
- Updated dependencies [0b4fe43]
|
|
23
|
+
- Updated dependencies [0b4fe43]
|
|
24
|
+
- Updated dependencies [0b4fe43]
|
|
25
|
+
- Updated dependencies [0b4fe43]
|
|
26
|
+
- Updated dependencies [0b4fe43]
|
|
27
|
+
- Updated dependencies [0b4fe43]
|
|
28
|
+
- Updated dependencies [0b4fe43]
|
|
29
|
+
- Updated dependencies [0b4fe43]
|
|
30
|
+
- Updated dependencies [0b4fe43]
|
|
31
|
+
- @ac-kit/core@0.13.0
|
|
32
|
+
|
|
33
|
+
## 0.2.0
|
|
34
|
+
|
|
35
|
+
### Minor Changes
|
|
36
|
+
|
|
37
|
+
- 34e8cfa: `DataGrid` describes a dense scalar field over a regular lattice, addressed by
|
|
38
|
+
position: `columns` and `rows`, a row-major `Float64Array` of values (rows
|
|
39
|
+
top-first, `NaN` for a missing cell), a `start` and `step` per axis, and a field
|
|
40
|
+
descriptor for each axis and for the values. `dataGrid` checks it and returns it
|
|
41
|
+
as given — the value count must be `columns × rows`, steps finite and non-zero,
|
|
42
|
+
fields numeric — and throws a `DataGridShapeError` otherwise. `isDataGrid` tells
|
|
43
|
+
a grid from a `DataFrame` by the full grid shape, so a frame carrying a `values`
|
|
44
|
+
property is still a frame.
|
|
45
|
+
- 34e8cfa: New helpers for reading columns; the only runtime dependency is `@ac-kit/core`
|
|
46
|
+
(`describeValue`, for error messages):
|
|
47
|
+
|
|
48
|
+
- `compareValues(a, b)` is a total order over cells: numbers (a bigint compared
|
|
49
|
+
with a number exactly), then `NaN`, strings by code unit, booleans
|
|
50
|
+
(`false` before `true`), geometries by type name, and `null` last.
|
|
51
|
+
- `columnToFloat64Array(out, column)` fills `out` with the column's numbers
|
|
52
|
+
(`null`, `NaN` and non-numbers become `NaN`, a bigint is rounded) and throws
|
|
53
|
+
`RangeError` when the lengths differ.
|
|
54
|
+
- `columnFiniteExtent(column, sign?)` returns `[low, high]` over finite numbers,
|
|
55
|
+
skipping `null`, `NaN` and, with `sign` `1` or `-1`, values that are not
|
|
56
|
+
strictly positive or negative; `undefined` when none remain.
|
|
57
|
+
- `dataFrameTakeRows(frame, rows)` gathers rows in the order given; typed
|
|
58
|
+
arrays stay typed, and an invalid index throws `RangeError`.
|
|
59
|
+
- `dataFrameFromDataGrid(grid)` returns one row per cell, row-major, with the
|
|
60
|
+
fields `x`, `y` and the grid's value (`NaN` becomes `null`).
|
|
61
|
+
- `FormatFieldOptions.timeZone` formats temporal cells in that IANA zone when
|
|
62
|
+
the field's `dateFormat` names none; the `dateFormat`'s other options are
|
|
63
|
+
read as `Intl` reads them, inherited and getter-backed ones included.
|
|
64
|
+
|
|
65
|
+
Error messages for a wrong-kind argument now describe it with `describeValue`
|
|
66
|
+
from `@ac-kit/core` instead of the former ad-hoc wording.
|
|
67
|
+
|
|
68
|
+
### Patch Changes
|
|
69
|
+
|
|
70
|
+
- Updated dependencies [34e8cfa]
|
|
71
|
+
- Updated dependencies [34e8cfa]
|
|
72
|
+
- Updated dependencies [34e8cfa]
|
|
73
|
+
- Updated dependencies [34e8cfa]
|
|
74
|
+
- Updated dependencies [34e8cfa]
|
|
75
|
+
- Updated dependencies [34e8cfa]
|
|
76
|
+
- Updated dependencies [34e8cfa]
|
|
77
|
+
- Updated dependencies [34e8cfa]
|
|
78
|
+
- Updated dependencies [34e8cfa]
|
|
79
|
+
- Updated dependencies [34e8cfa]
|
|
80
|
+
- Updated dependencies [34e8cfa]
|
|
81
|
+
- Updated dependencies [34e8cfa]
|
|
82
|
+
- Updated dependencies [34e8cfa]
|
|
83
|
+
- Updated dependencies [34e8cfa]
|
|
84
|
+
- Updated dependencies [34e8cfa]
|
|
85
|
+
- @ac-kit/core@0.12.0
|
package/README.md
CHANGED
|
@@ -44,8 +44,10 @@ same way everywhere. `@ac-kit/model-chart` describes plots over the same shape.
|
|
|
44
44
|
| Frame | `DataFrame`, `FrameMeta`, `dataFrameFromRows`, `dataFrameFromColumns`, `dataFrameRow`, `dataFrameColumn`, `dataFrameField`, `dataFrameFieldIndex`, `dataFrameSelectFields`, `dataFrameWithField` |
|
|
45
45
|
| Incremental | `DataFrameBuilder` — append rows as they arrive, rewrite them as better answers come in |
|
|
46
46
|
| Schema | `FieldDescriptor`, `FieldKind`, `FieldDirection`, `isNumericField`, `isCategoricalField` |
|
|
47
|
-
|
|
|
48
|
-
|
|
|
47
|
+
| Grid | `DataGrid`, `DataGridAxis`, `dataGrid`, `isDataGrid`, `DataGridShapeError` — a dense scalar field over a regular lattice, addressed by position |
|
|
48
|
+
| Cells | `Value`, `Column`, `columnCell`, `compareValues` (total order), `columnToFloat64Array`, `columnRowsToFloat64Array` (one group's rows), `columnFiniteExtent` (optionally positive or negative values only) |
|
|
49
|
+
| Rows | `dataFrameTakeRows` (gather rows, typed arrays stay typed), `dataFrameFromDataGrid` (one row per cell: `x`, `y`, `value`; `NaN` becomes `null`) |
|
|
50
|
+
| Formatting | `createFieldFormatter`, `formatFieldValue` (`FormatFieldOptions.timeZone` for temporal cells), `fieldTitle`, `NumberFormatSpec` |
|
|
49
51
|
| Quantities | `Unit`, `DIMENSIONLESS` |
|
|
50
52
|
| Geometry | `Geometry` and its GeoJSON (RFC 7946) members |
|
|
51
53
|
|
|
@@ -68,6 +70,27 @@ Only `DataFrameBuilder.build()` packs complete numeric columns into a typed
|
|
|
68
70
|
array — it owns its values and knows when they are final. `dataFrameFromRows`
|
|
69
71
|
stores what it was given.
|
|
70
72
|
|
|
73
|
+
## A grid is not a relation
|
|
74
|
+
|
|
75
|
+
A raster or a surface reads a `DataGrid`: one `Float64Array` of `columns × rows`
|
|
76
|
+
values, row-major with rows top-first and `NaN` for a missing cell, plus a
|
|
77
|
+
`start` and `step` per axis. Position gives x and y, so nothing else is stored.
|
|
78
|
+
`dataGrid` checks the shape and the field kinds; `isDataGrid` tells a grid from
|
|
79
|
+
a frame.
|
|
80
|
+
|
|
81
|
+
```ts
|
|
82
|
+
import { dataGrid } from "@ac-kit/model-dataset";
|
|
83
|
+
|
|
84
|
+
const elevation = dataGrid({
|
|
85
|
+
columns: 2,
|
|
86
|
+
rows: 2,
|
|
87
|
+
values: Float64Array.of(10, 12, 11, Number.NaN),
|
|
88
|
+
x: { start: 0.5, step: 1, field: { name: "easting", kind: "quantitative" } },
|
|
89
|
+
y: { start: 1.5, step: 1, field: { name: "northing", kind: "quantitative" } },
|
|
90
|
+
value: { name: "elevation", kind: "quantitative", unit: { symbol: "m" } },
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
71
94
|
## No `interval` field kind
|
|
72
95
|
|
|
73
96
|
A span is two fields — `binStart`/`binEnd`, `startedAt`/`endedAt`,
|
|
@@ -83,5 +106,5 @@ better, so `direction` sits on `FieldDescriptor`. `Unit` is a dimension and a
|
|
|
83
106
|
scale, nothing more.
|
|
84
107
|
|
|
85
108
|
See the
|
|
86
|
-
[generated API docs](https://anthochamp.
|
|
109
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/model-dataset/)
|
|
87
110
|
for the full reference.
|
package/dist/frame/column.d.ts
CHANGED
|
@@ -21,4 +21,58 @@ export type Column = Float64Array | Int32Array | Value[];
|
|
|
21
21
|
* @returns The value, or `null` when `rowIndex` is out of range.
|
|
22
22
|
*/
|
|
23
23
|
export declare function columnCell(column: Column, rowIndex: number): Value;
|
|
24
|
+
/**
|
|
25
|
+
* A total order over cells, for sorting and for ordering discrete domains.
|
|
26
|
+
*
|
|
27
|
+
* Numbers first (a bigint is compared with a number exactly, `-0` equals `0`),
|
|
28
|
+
* then `NaN`, then strings by UTF-16 code unit, then booleans (`false` before
|
|
29
|
+
* `true`), then geometries by type name, then `null`. Two cells that compare
|
|
30
|
+
* `0` are equal for ordering purposes only (`1n` and `1`).
|
|
31
|
+
*
|
|
32
|
+
* O(1) (O(length) for strings).
|
|
33
|
+
*
|
|
34
|
+
* @returns A negative number, zero or a positive number.
|
|
35
|
+
*/
|
|
36
|
+
export declare function compareValues(a: Value, b: Value): number;
|
|
37
|
+
/**
|
|
38
|
+
* Copies a column into a `Float64Array`.
|
|
39
|
+
*
|
|
40
|
+
* `null`, `NaN` and non-numeric cells (strings, booleans, geometries) become
|
|
41
|
+
* `NaN`; a bigint becomes the nearest `Number` (rounded).
|
|
42
|
+
*
|
|
43
|
+
* O(n), no allocation.
|
|
44
|
+
*
|
|
45
|
+
* @param out Receives the values, and is returned.
|
|
46
|
+
* @throws {RangeError} When `out.length` differs from `column.length`.
|
|
47
|
+
*/
|
|
48
|
+
export declare function columnToFloat64Array<T extends Float64Array>(out: T, column: Column): T;
|
|
49
|
+
/**
|
|
50
|
+
* Copies the cells at `rows[from … to)` of a column into `out[0 … to − from)`:
|
|
51
|
+
* one group's values, read through a grouping's index array, as numbers.
|
|
52
|
+
*
|
|
53
|
+
* Cells map as in {@link columnToFloat64Array}; a row outside the column gives
|
|
54
|
+
* `NaN`, as {@link columnCell} gives `null`. The rest of `out` is untouched, so
|
|
55
|
+
* a scratch buffer sized by the largest group serves every group.
|
|
56
|
+
*
|
|
57
|
+
* O(to − from), no allocation.
|
|
58
|
+
*
|
|
59
|
+
* @param out Receives the values, and is returned.
|
|
60
|
+
* @param rows Row indices into `column`, not modified.
|
|
61
|
+
* @param from First position in `rows`. Default `0`.
|
|
62
|
+
* @param to End position in `rows`, excluded. Default `rows.length`.
|
|
63
|
+
* @throws {RangeError} When `from` and `to` are not integers with `0 ≤ from ≤
|
|
64
|
+
* to ≤ rows.length`, or `out` is shorter than `to − from`.
|
|
65
|
+
*/
|
|
66
|
+
export declare function columnRowsToFloat64Array<T extends Float64Array>(out: T, column: Column, rows: ArrayLike<number>, from?: number, to?: number): T;
|
|
67
|
+
/**
|
|
68
|
+
* The smallest and largest finite number of a column, or `undefined` when it
|
|
69
|
+
* holds none.
|
|
70
|
+
*
|
|
71
|
+
* Skips `null`, `NaN`, infinities and non-numeric cells; a bigint counts as its
|
|
72
|
+
* rounded `Number`. `sign` keeps only strictly positive (`1`) or strictly
|
|
73
|
+
* negative (`-1`) values, which is the domain of a logarithmic scale.
|
|
74
|
+
*
|
|
75
|
+
* O(n), no allocation beyond the result.
|
|
76
|
+
*/
|
|
77
|
+
export declare function columnFiniteExtent(column: Column, sign?: 1 | -1): readonly [low: number, high: number] | undefined;
|
|
24
78
|
//# sourceMappingURL=column.d.ts.map
|
|
@@ -1 +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"}
|
|
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;AAoBD;;;;;;;;;;;GAWG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,GAAG,MAAM,CA8BxD;AASD;;;;;;;;;;GAUG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,YAAY,EAC1D,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,MAAM,GACZ,CAAC,CAcH;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,YAAY,EAC9D,GAAG,EAAE,CAAC,EACN,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,SAAS,CAAC,MAAM,CAAC,EACvB,IAAI,SAAI,EACR,EAAE,GAAE,MAAoB,GACtB,CAAC,CA2BH;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CACjC,MAAM,EAAE,MAAM,EACd,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GACX,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,GAAG,SAAS,CAmBlD"}
|
package/dist/frame/column.js
CHANGED
|
@@ -9,4 +9,164 @@ export function columnCell(column, rowIndex) {
|
|
|
9
9
|
}
|
|
10
10
|
return column[rowIndex] ?? null;
|
|
11
11
|
}
|
|
12
|
+
function valueRank_(value) {
|
|
13
|
+
if (value === null) {
|
|
14
|
+
return 5;
|
|
15
|
+
}
|
|
16
|
+
switch (typeof value) {
|
|
17
|
+
case "number":
|
|
18
|
+
return Number.isNaN(value) ? 1 : 0;
|
|
19
|
+
case "bigint":
|
|
20
|
+
return 0;
|
|
21
|
+
case "string":
|
|
22
|
+
return 2;
|
|
23
|
+
case "boolean":
|
|
24
|
+
return 3;
|
|
25
|
+
default:
|
|
26
|
+
return 4;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* A total order over cells, for sorting and for ordering discrete domains.
|
|
31
|
+
*
|
|
32
|
+
* Numbers first (a bigint is compared with a number exactly, `-0` equals `0`),
|
|
33
|
+
* then `NaN`, then strings by UTF-16 code unit, then booleans (`false` before
|
|
34
|
+
* `true`), then geometries by type name, then `null`. Two cells that compare
|
|
35
|
+
* `0` are equal for ordering purposes only (`1n` and `1`).
|
|
36
|
+
*
|
|
37
|
+
* O(1) (O(length) for strings).
|
|
38
|
+
*
|
|
39
|
+
* @returns A negative number, zero or a positive number.
|
|
40
|
+
*/
|
|
41
|
+
export function compareValues(a, b) {
|
|
42
|
+
const rankA = valueRank_(a);
|
|
43
|
+
const rankB = valueRank_(b);
|
|
44
|
+
if (rankA !== rankB) {
|
|
45
|
+
return rankA - rankB;
|
|
46
|
+
}
|
|
47
|
+
switch (rankA) {
|
|
48
|
+
case 0: {
|
|
49
|
+
const left = a;
|
|
50
|
+
const right = b;
|
|
51
|
+
if (left < right) {
|
|
52
|
+
return -1;
|
|
53
|
+
}
|
|
54
|
+
return left > right ? 1 : 0;
|
|
55
|
+
}
|
|
56
|
+
case 2:
|
|
57
|
+
case 4: {
|
|
58
|
+
const left = rankA === 2 ? a : a.type;
|
|
59
|
+
const right = rankA === 2 ? b : b.type;
|
|
60
|
+
if (left < right) {
|
|
61
|
+
return -1;
|
|
62
|
+
}
|
|
63
|
+
return left > right ? 1 : 0;
|
|
64
|
+
}
|
|
65
|
+
case 3:
|
|
66
|
+
return Number(a) - Number(b);
|
|
67
|
+
default:
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
function cellToNumber_(value) {
|
|
72
|
+
if (typeof value === "number") {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
return typeof value === "bigint" ? Number(value) : Number.NaN;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Copies a column into a `Float64Array`.
|
|
79
|
+
*
|
|
80
|
+
* `null`, `NaN` and non-numeric cells (strings, booleans, geometries) become
|
|
81
|
+
* `NaN`; a bigint becomes the nearest `Number` (rounded).
|
|
82
|
+
*
|
|
83
|
+
* O(n), no allocation.
|
|
84
|
+
*
|
|
85
|
+
* @param out Receives the values, and is returned.
|
|
86
|
+
* @throws {RangeError} When `out.length` differs from `column.length`.
|
|
87
|
+
*/
|
|
88
|
+
export function columnToFloat64Array(out, column) {
|
|
89
|
+
if (out.length !== column.length) {
|
|
90
|
+
throw new RangeError(`Output length ${out.length} differs from column length ${column.length}`);
|
|
91
|
+
}
|
|
92
|
+
if (Array.isArray(column)) {
|
|
93
|
+
for (let index = 0; index < column.length; index++) {
|
|
94
|
+
out[index] = cellToNumber_(column[index]);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
out.set(column);
|
|
99
|
+
}
|
|
100
|
+
return out;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Copies the cells at `rows[from … to)` of a column into `out[0 … to − from)`:
|
|
104
|
+
* one group's values, read through a grouping's index array, as numbers.
|
|
105
|
+
*
|
|
106
|
+
* Cells map as in {@link columnToFloat64Array}; a row outside the column gives
|
|
107
|
+
* `NaN`, as {@link columnCell} gives `null`. The rest of `out` is untouched, so
|
|
108
|
+
* a scratch buffer sized by the largest group serves every group.
|
|
109
|
+
*
|
|
110
|
+
* O(to − from), no allocation.
|
|
111
|
+
*
|
|
112
|
+
* @param out Receives the values, and is returned.
|
|
113
|
+
* @param rows Row indices into `column`, not modified.
|
|
114
|
+
* @param from First position in `rows`. Default `0`.
|
|
115
|
+
* @param to End position in `rows`, excluded. Default `rows.length`.
|
|
116
|
+
* @throws {RangeError} When `from` and `to` are not integers with `0 ≤ from ≤
|
|
117
|
+
* to ≤ rows.length`, or `out` is shorter than `to − from`.
|
|
118
|
+
*/
|
|
119
|
+
export function columnRowsToFloat64Array(out, column, rows, from = 0, to = rows.length) {
|
|
120
|
+
if (!Number.isInteger(from) ||
|
|
121
|
+
!Number.isInteger(to) ||
|
|
122
|
+
from < 0 ||
|
|
123
|
+
from > to ||
|
|
124
|
+
to > rows.length) {
|
|
125
|
+
throw new RangeError(`[${from}, ${to}) is not a range of the ${rows.length} rows`);
|
|
126
|
+
}
|
|
127
|
+
if (out.length < to - from) {
|
|
128
|
+
throw new RangeError(`Output length ${out.length} is shorter than the ${to - from} rows`);
|
|
129
|
+
}
|
|
130
|
+
if (Array.isArray(column)) {
|
|
131
|
+
for (let position = from; position < to; position++) {
|
|
132
|
+
out[position - from] = cellToNumber_(column[rows[position]] ?? null);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else {
|
|
136
|
+
for (let position = from; position < to; position++) {
|
|
137
|
+
out[position - from] = column[rows[position]] ?? Number.NaN;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* The smallest and largest finite number of a column, or `undefined` when it
|
|
144
|
+
* holds none.
|
|
145
|
+
*
|
|
146
|
+
* Skips `null`, `NaN`, infinities and non-numeric cells; a bigint counts as its
|
|
147
|
+
* rounded `Number`. `sign` keeps only strictly positive (`1`) or strictly
|
|
148
|
+
* negative (`-1`) values, which is the domain of a logarithmic scale.
|
|
149
|
+
*
|
|
150
|
+
* O(n), no allocation beyond the result.
|
|
151
|
+
*/
|
|
152
|
+
export function columnFiniteExtent(column, sign) {
|
|
153
|
+
let low = Number.POSITIVE_INFINITY;
|
|
154
|
+
let high = Number.NEGATIVE_INFINITY;
|
|
155
|
+
for (let index = 0; index < column.length; index++) {
|
|
156
|
+
const number = cellToNumber_(column[index]);
|
|
157
|
+
if (!Number.isFinite(number)) {
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
if (sign === 1 ? number <= 0 : sign === -1 && number >= 0) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
if (number < low) {
|
|
164
|
+
low = number;
|
|
165
|
+
}
|
|
166
|
+
if (number > high) {
|
|
167
|
+
high = number;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return low <= high ? [low, high] : undefined;
|
|
171
|
+
}
|
|
12
172
|
//# sourceMappingURL=column.js.map
|
package/dist/frame/column.js.map
CHANGED
|
@@ -1 +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"}
|
|
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;AAED,SAAS,UAAU,CAAC,KAAY;IAC/B,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACpB,OAAO,CAAC,CAAC;IACV,CAAC;IACD,QAAQ,OAAO,KAAK,EAAE,CAAC;QACtB,KAAK,QAAQ;YACZ,OAAO,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACpC,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC;QACV,KAAK,QAAQ;YACZ,OAAO,CAAC,CAAC;QACV,KAAK,SAAS;YACb,OAAO,CAAC,CAAC;QACV;YACC,OAAO,CAAC,CAAC;IACX,CAAC;AACF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,aAAa,CAAC,CAAQ,EAAE,CAAQ;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AAC,CAAC,CAAC;QAEH,OAAO;YACN,MAAM,EAAE,CAAC,GAAG,IAAI,CAAC,OAAO,CAAC;YACzB,OAAO;YACP,QAAQ,EAAE,IAAI,CAAC,SAAS;YACxB,GAAG,CAAC,IAAI,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,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"}
|
|
@@ -150,6 +150,16 @@ export declare function dataFrameSelectFields(frame: DataFrame, names: readonly
|
|
|
150
150
|
* headers.
|
|
151
151
|
*/
|
|
152
152
|
export declare function dataFrameDropEmptyFields(frame: DataFrame): DataFrame;
|
|
153
|
+
/**
|
|
154
|
+
* A frame holding the given rows, in the given order (repeats allowed): a
|
|
155
|
+
* filter, a sort or a facet's subset.
|
|
156
|
+
*
|
|
157
|
+
* O(k × f) for k rows and f fields. Each column is gathered into a new one of
|
|
158
|
+
* the same kind: a typed array stays a typed array of its type.
|
|
159
|
+
*
|
|
160
|
+
* @throws {RangeError} When an index is not an integer in `[0, rowCount)`.
|
|
161
|
+
*/
|
|
162
|
+
export declare function dataFrameTakeRows(frame: DataFrame, rows: Int32Array | readonly number[]): DataFrame;
|
|
153
163
|
/**
|
|
154
164
|
* A copy of the frame with one more column, computed per row.
|
|
155
165
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-frame.d.ts","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-frame.d.ts","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAA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E,QAAQ,EAAE,MAAM,KAAK,KAAK,GACpD,SAAS,CAWX"}
|
package/dist/frame/data-frame.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describeValue } from "@ac-kit/core";
|
|
1
2
|
import { columnCell } from "./column.js";
|
|
2
3
|
/** A row carrying more cells than the frame has fields. */
|
|
3
4
|
export class DataFrameShapeError extends Error {
|
|
@@ -230,6 +231,39 @@ function hasValue_(column, rowCount) {
|
|
|
230
231
|
}
|
|
231
232
|
return false;
|
|
232
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* A frame holding the given rows, in the given order (repeats allowed): a
|
|
236
|
+
* filter, a sort or a facet's subset.
|
|
237
|
+
*
|
|
238
|
+
* O(k × f) for k rows and f fields. Each column is gathered into a new one of
|
|
239
|
+
* the same kind: a typed array stays a typed array of its type.
|
|
240
|
+
*
|
|
241
|
+
* @throws {RangeError} When an index is not an integer in `[0, rowCount)`.
|
|
242
|
+
*/
|
|
243
|
+
export function dataFrameTakeRows(frame, rows) {
|
|
244
|
+
for (let index = 0; index < rows.length; index++) {
|
|
245
|
+
const row = rows[index];
|
|
246
|
+
if (!Number.isInteger(row) || row < 0 || row >= frame.rowCount) {
|
|
247
|
+
throw new RangeError(`Row index ${describeValue(row)} at position ${index} is outside [0, ${frame.rowCount})`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const columns = frame.columns.map((column) => {
|
|
251
|
+
const taken = Array.isArray(column)
|
|
252
|
+
? Array.from({ length: rows.length })
|
|
253
|
+
: new column.constructor(rows.length);
|
|
254
|
+
for (let index = 0; index < rows.length; index++) {
|
|
255
|
+
taken[index] = column[rows[index]];
|
|
256
|
+
}
|
|
257
|
+
return taken;
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
...(frame.name === undefined ? {} : { name: frame.name }),
|
|
261
|
+
fields: frame.fields,
|
|
262
|
+
columns,
|
|
263
|
+
rowCount: rows.length,
|
|
264
|
+
...(frame.meta === undefined ? {} : { meta: frame.meta }),
|
|
265
|
+
};
|
|
266
|
+
}
|
|
233
267
|
/**
|
|
234
268
|
* A copy of the frame with one more column, computed per row.
|
|
235
269
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-frame.js","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-frame.js","sourceRoot":"","sources":["../../src/frame/data-frame.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,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,IAAI,KAAK,IAAI,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB,CACtC,KAAgB,EAChB,IAAY;IAEZ,MAAM,KAAK,GAAG,6BAA6B,CAAC,K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AAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAE,CAAU,CAAC;QAC9C,CAAC;QACD,OAAO,KAAK,CAAC;IACd,CAAC,CAAC,CAAC;IAEH,OAAO;QACN,GAAG,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC;QACzD,MAAM,EAAE,KAAK,CAAC,MAAM;QACpB,OAAO;QACP,QAAQ,EAAE,IAAI,CAAC,MAAM;QACrB,GAAG,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;;;;;;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,64 @@
|
|
|
1
|
+
import type { DataFrame } from "./data-frame.js";
|
|
2
|
+
import type { FieldDescriptor } from "./field.js";
|
|
3
|
+
/** Where the cell centres of one lattice axis lie, and in which units. */
|
|
4
|
+
export type DataGridAxis = {
|
|
5
|
+
/** Centre of the first cell. */
|
|
6
|
+
readonly start: number;
|
|
7
|
+
/** Distance between neighbouring centres; negative runs the axis backwards. */
|
|
8
|
+
readonly step: number;
|
|
9
|
+
/** Describes the axis' values: its unit, title and number format. */
|
|
10
|
+
readonly field: FieldDescriptor;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A dense scalar field over a regular lattice, addressed by position.
|
|
14
|
+
*
|
|
15
|
+
* Not a relation: every cell holds one value of one field, and x and y follow
|
|
16
|
+
* from the cell's column and row, so nothing but the values is stored. A raster
|
|
17
|
+
* or a surface reads this; a table of observations stays a {@link DataFrame}.
|
|
18
|
+
*
|
|
19
|
+
* Cell `(column, row)` lies at `x.start + column * x.step` and `y.start + row *
|
|
20
|
+
* y.step`, and holds `values[row * columns + column]`.
|
|
21
|
+
*/
|
|
22
|
+
export type DataGrid = {
|
|
23
|
+
/** Machine name, for naming the grid among a chart's sources. */
|
|
24
|
+
readonly name?: string;
|
|
25
|
+
readonly columns: number;
|
|
26
|
+
readonly rows: number;
|
|
27
|
+
/** Row-major, rows top-first; `NaN` for a missing cell. */
|
|
28
|
+
readonly values: Float64Array;
|
|
29
|
+
readonly x: DataGridAxis;
|
|
30
|
+
readonly y: DataGridAxis;
|
|
31
|
+
/** Describes the values: their unit, title and number format. */
|
|
32
|
+
readonly value: FieldDescriptor;
|
|
33
|
+
};
|
|
34
|
+
/** A grid whose dimensions, steps, values or fields are inconsistent. */
|
|
35
|
+
export declare class DataGridShapeError extends Error {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Builds a grid, checking that it is a lattice.
|
|
40
|
+
*
|
|
41
|
+
* Stores `values` by reference, like `dataFrameFromColumns`.
|
|
42
|
+
*
|
|
43
|
+
* @throws {DataGridShapeError} When `columns` or `rows` is not a non-negative
|
|
44
|
+
* safe integer, `values` does not hold exactly `columns * rows` cells, an
|
|
45
|
+
* axis `start` is not finite or its `step` is zero or not finite, or a field
|
|
46
|
+
* is not numeric (quantitative, temporal or cyclic).
|
|
47
|
+
*/
|
|
48
|
+
export declare function dataGrid(grid: DataGrid): DataGrid;
|
|
49
|
+
/**
|
|
50
|
+
* A grid as a relation with one row per cell, row-major: fields `x`, `y` and
|
|
51
|
+
* `value` (the grid's three descriptors), cell centres computed from `start`
|
|
52
|
+
* and `step`, a missing (`NaN`) value as `null`.
|
|
53
|
+
*
|
|
54
|
+
* O(cells). The `x` and `y` columns are `Float64Array`s; the value column is a
|
|
55
|
+
* `Float64Array` when no cell is missing and a boxed array otherwise.
|
|
56
|
+
*/
|
|
57
|
+
export declare function dataFrameFromDataGrid(grid: DataGrid): DataFrame;
|
|
58
|
+
/**
|
|
59
|
+
* Whether a chart source is a grid rather than a frame.
|
|
60
|
+
*
|
|
61
|
+
* O(1).
|
|
62
|
+
*/
|
|
63
|
+
export declare function isDataGrid(source: DataFrame | DataGrid): source is DataGrid;
|
|
64
|
+
//# sourceMappingURL=data-grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-grid.d.ts","sourceRoot":"","sources":["../../src/frame/data-grid.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAGlD,0EAA0E;AAC1E,MAAM,MAAM,YAAY,GAAG;IAC1B,gCAAgC;IAChC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+EAA+E;IAC/E,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;CAChC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,QAAQ,GAAG;IACtB,iEAAiE;IACjE,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,2DAA2D;IAC3D,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC;IACzB,iEAAiE;IACjE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;CAChC,CAAC;AAEF,yEAAyE;AACzE,qBAAa,kBAAmB,SAAQ,KAAK;IAC5C,YAAY,OAAO,EAAE,MAAM,EAG1B;CACD;AAED;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,QAAQ,CA8CjD;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAyB/D;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,GAAG,MAAM,IAAI,QAAQ,CAU3E"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { describeValue } from "@ac-kit/core";
|
|
2
|
+
import { isNumericField } from "./field.js";
|
|
3
|
+
/** A grid whose dimensions, steps, values or fields are inconsistent. */
|
|
4
|
+
export class DataGridShapeError extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.name = "DataGridShapeError";
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Builds a grid, checking that it is a lattice.
|
|
12
|
+
*
|
|
13
|
+
* Stores `values` by reference, like `dataFrameFromColumns`.
|
|
14
|
+
*
|
|
15
|
+
* @throws {DataGridShapeError} When `columns` or `rows` is not a non-negative
|
|
16
|
+
* safe integer, `values` does not hold exactly `columns * rows` cells, an
|
|
17
|
+
* axis `start` is not finite or its `step` is zero or not finite, or a field
|
|
18
|
+
* is not numeric (quantitative, temporal or cyclic).
|
|
19
|
+
*/
|
|
20
|
+
export function dataGrid(grid) {
|
|
21
|
+
for (const [label, count] of [
|
|
22
|
+
["columns", grid.columns],
|
|
23
|
+
["rows", grid.rows],
|
|
24
|
+
]) {
|
|
25
|
+
if (!Number.isSafeInteger(count) || count < 0) {
|
|
26
|
+
throw new DataGridShapeError(`"${label}" must be a non-negative safe integer, got ${describeValue(count)}`);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
if (grid.values.length !== grid.columns * grid.rows) {
|
|
30
|
+
throw new DataGridShapeError(`Expected ${grid.columns} × ${grid.rows} = ${grid.columns * grid.rows} values, got ${grid.values.length}`);
|
|
31
|
+
}
|
|
32
|
+
for (const [label, axis] of [
|
|
33
|
+
["x", grid.x],
|
|
34
|
+
["y", grid.y],
|
|
35
|
+
]) {
|
|
36
|
+
if (!Number.isFinite(axis.start)) {
|
|
37
|
+
throw new DataGridShapeError(`Axis ${label}: "start" must be finite, got ${describeValue(axis.start)}`);
|
|
38
|
+
}
|
|
39
|
+
if (!Number.isFinite(axis.step) || axis.step === 0) {
|
|
40
|
+
throw new DataGridShapeError(`Axis ${label}: "step" must be finite and non-zero, got ${describeValue(axis.step)}`);
|
|
41
|
+
}
|
|
42
|
+
if (!isNumericField(axis.field)) {
|
|
43
|
+
throw new DataGridShapeError(`Axis ${label}: field "${axis.field.name}" is ${axis.field.kind}, expected a numeric kind`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (!isNumericField(grid.value)) {
|
|
47
|
+
throw new DataGridShapeError(`Value field "${grid.value.name}" is ${grid.value.kind}, expected a numeric kind`);
|
|
48
|
+
}
|
|
49
|
+
return grid;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* A grid as a relation with one row per cell, row-major: fields `x`, `y` and
|
|
53
|
+
* `value` (the grid's three descriptors), cell centres computed from `start`
|
|
54
|
+
* and `step`, a missing (`NaN`) value as `null`.
|
|
55
|
+
*
|
|
56
|
+
* O(cells). The `x` and `y` columns are `Float64Array`s; the value column is a
|
|
57
|
+
* `Float64Array` when no cell is missing and a boxed array otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export function dataFrameFromDataGrid(grid) {
|
|
60
|
+
const cellCount = grid.columns * grid.rows;
|
|
61
|
+
const xs = new Float64Array(cellCount);
|
|
62
|
+
const ys = new Float64Array(cellCount);
|
|
63
|
+
let missing = false;
|
|
64
|
+
for (let row = 0; cellCount > 0 && row < grid.rows; row++) {
|
|
65
|
+
const y = grid.y.start + row * grid.y.step;
|
|
66
|
+
for (let column = 0; column < grid.columns; column++) {
|
|
67
|
+
const index = row * grid.columns + column;
|
|
68
|
+
xs[index] = grid.x.start + column * grid.x.step;
|
|
69
|
+
ys[index] = y;
|
|
70
|
+
missing ||= Number.isNaN(grid.values[index]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const values = missing
|
|
74
|
+
? Array.from(grid.values, (value) => (Number.isNaN(value) ? null : value))
|
|
75
|
+
: grid.values.slice();
|
|
76
|
+
return {
|
|
77
|
+
...(grid.name === undefined ? {} : { name: grid.name }),
|
|
78
|
+
fields: [grid.x.field, grid.y.field, grid.value],
|
|
79
|
+
columns: [xs, ys, values],
|
|
80
|
+
rowCount: cellCount,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Whether a chart source is a grid rather than a frame.
|
|
85
|
+
*
|
|
86
|
+
* O(1).
|
|
87
|
+
*/
|
|
88
|
+
export function isDataGrid(source) {
|
|
89
|
+
const candidate = source;
|
|
90
|
+
return (candidate.values instanceof Float64Array &&
|
|
91
|
+
typeof candidate.columns === "number" &&
|
|
92
|
+
typeof candidate.rows === "number" &&
|
|
93
|
+
typeof candidate.x === "object" &&
|
|
94
|
+
typeof candidate.y === "object" &&
|
|
95
|
+
typeof candidate.value === "object");
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=data-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-grid.js","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,EAAE,EAAE,MAAM,CAAC;QACzB,QAAQ,EAAE,SAAS;KACnB,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAA4B;IACtD,MAAM,SAAS,GAAG,MAAkD,CAAC;IACrE,OAAO,CACN,SAAS,CAAC,MAAM,YAAY,YAAY;QACxC,OAAO,SAAS,CAAC,OAAO,KAAK,QAAQ;QACrC,OAAO,SAAS,CAAC,IAAI,KAAK,QAAQ;QAClC,OAAO,SAAS,CAAC,CAAC,KAAK,QAAQ;QAC/B,OAAO,SAAS,CAAC,CAAC,KAAK,QAAQ;QAC/B,OAAO,SAAS,CAAC,KAAK,KAAK,QAAQ,CACnC,CAAC;AACH,CAAC"}
|
|
@@ -5,6 +5,11 @@ export type FormatFieldOptions = {
|
|
|
5
5
|
locale?: string | string[];
|
|
6
6
|
/** Text for a `null` cell. Default `""`. */
|
|
7
7
|
nullText?: string;
|
|
8
|
+
/**
|
|
9
|
+
* IANA time zone for temporal cells, used when the field's `dateFormat` names
|
|
10
|
+
* none. Absent uses the runtime default.
|
|
11
|
+
*/
|
|
12
|
+
timeZone?: string;
|
|
8
13
|
};
|
|
9
14
|
/** A field's human label, falling back to its machine name. */
|
|
10
15
|
export declare function fieldTitle(field: FieldDescriptor): string;
|
|
@@ -1 +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,
|
|
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;IAClB;;;OAGG;IACH,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,CAgB1B;AAyFD;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,eAAe,EACtB,OAAO,CAAC,EAAE,kBAAkB,GAC1B,MAAM,CAER"}
|
|
@@ -16,7 +16,7 @@ function plainText_(value) {
|
|
|
16
16
|
*/
|
|
17
17
|
export function createFieldFormatter(field, options) {
|
|
18
18
|
const nullText = options?.nullText ?? "";
|
|
19
|
-
const format = createUnaffixedFormatter_(field, nullText, options?.locale);
|
|
19
|
+
const format = createUnaffixedFormatter_(field, nullText, options?.locale, options?.timeZone);
|
|
20
20
|
const prefix = field.prefix ?? "";
|
|
21
21
|
const suffix = field.suffix ?? "";
|
|
22
22
|
if (prefix === "" && suffix === "") {
|
|
@@ -24,9 +24,53 @@ export function createFieldFormatter(field, options) {
|
|
|
24
24
|
}
|
|
25
25
|
return (value) => value === null ? nullText : `${prefix}${format(value)}${suffix}`;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
// Every `Intl.DateTimeFormat` option, in the order ECMA-402 reads them. Each
|
|
28
|
+
// is read once with an ordinary `Get`, as `Intl` does: own, inherited and
|
|
29
|
+
// getter-backed options alike, a getter seeing the caller's object as `this`.
|
|
30
|
+
const DATE_TIME_FORMAT_OPTION_NAMES_ = [
|
|
31
|
+
"localeMatcher",
|
|
32
|
+
"calendar",
|
|
33
|
+
"numberingSystem",
|
|
34
|
+
"hour12",
|
|
35
|
+
"hourCycle",
|
|
36
|
+
"timeZone",
|
|
37
|
+
"weekday",
|
|
38
|
+
"era",
|
|
39
|
+
"year",
|
|
40
|
+
"month",
|
|
41
|
+
"day",
|
|
42
|
+
"dayPeriod",
|
|
43
|
+
"hour",
|
|
44
|
+
"minute",
|
|
45
|
+
"second",
|
|
46
|
+
"fractionalSecondDigits",
|
|
47
|
+
"timeZoneName",
|
|
48
|
+
"formatMatcher",
|
|
49
|
+
"dateStyle",
|
|
50
|
+
"timeStyle",
|
|
51
|
+
];
|
|
52
|
+
function withTimeZone_(options, timeZone) {
|
|
53
|
+
if (timeZone === undefined || options === undefined) {
|
|
54
|
+
return timeZone === undefined ? options : { timeZone };
|
|
55
|
+
}
|
|
56
|
+
if (options.timeZone !== undefined) {
|
|
57
|
+
return options;
|
|
58
|
+
}
|
|
59
|
+
const merged = { timeZone };
|
|
60
|
+
for (const name of DATE_TIME_FORMAT_OPTION_NAMES_) {
|
|
61
|
+
if (name === "timeZone") {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const value = options[name];
|
|
65
|
+
if (value !== undefined) {
|
|
66
|
+
merged[name] = value;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return merged;
|
|
70
|
+
}
|
|
71
|
+
function createUnaffixedFormatter_(field, nullText, locale, timeZone) {
|
|
28
72
|
if (field.kind === "temporal") {
|
|
29
|
-
const dateFormat = new Intl.DateTimeFormat(locale, field.dateFormat);
|
|
73
|
+
const dateFormat = new Intl.DateTimeFormat(locale, withTimeZone_(field.dateFormat, timeZone));
|
|
30
74
|
return (value) => {
|
|
31
75
|
if (value === null) {
|
|
32
76
|
return nullText;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"format-field.js","sourceRoot":"","sources":["../../src/frame/format-field.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"format-field.js","sourceRoot":"","sources":["../../src/frame/format-field.ts"],"names":[],"mappings":"AAeA,+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,CAAC,KAA2B;IAC9C,OAAO,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AAC/D,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CACnC,KAAsB,EACtB,OAA4B;IAE5B,MAAM,QAAQ,GAAG,OAAO,EAAE,QAAQ,IAAI,EAAE,CAAC;IACzC,MAAM,MAAM,GAAG,yBAAyB,CACvC,KAAK,EACL,QAAQ,EACR,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,QAAQ,CACjB,CAAC;IAEF,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC;IAClC,MAAM,MAAM,GAAG,KAAK,CAAC,MAAM,IAAI,EAAE,CAAC;IAClC,IAAI,MAAM,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QACpC,OAAO,MAAM,CAAC;IACf,CAAC;IACD,OAAO,CAAC,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H,MAAM,UAAU,gBAAgB,CAC/B,KAAY,EACZ,KAAsB,EACtB,OAA4B;IAE5B,OAAO,oBAAoB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;AACpD,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./frame/column.js";
|
|
2
2
|
export * from "./frame/data-frame-builder.js";
|
|
3
3
|
export * from "./frame/data-frame.js";
|
|
4
|
+
export * from "./frame/data-grid.js";
|
|
4
5
|
export * from "./frame/field.js";
|
|
5
6
|
export * from "./frame/format-field.js";
|
|
6
7
|
export * from "./geo/geometry.js";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from "./frame/column.js";
|
|
2
2
|
export * from "./frame/data-frame-builder.js";
|
|
3
3
|
export * from "./frame/data-frame.js";
|
|
4
|
+
export * from "./frame/data-grid.js";
|
|
4
5
|
export * from "./frame/field.js";
|
|
5
6
|
export * from "./frame/format-field.js";
|
|
6
7
|
export * from "./geo/geometry.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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"}
|
|
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,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,cAAc,yBAAyB,CAAC;AACxC,cAAc,mBAAmB,CAAC;AAClC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,oBAAoB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ac-kit/model-dataset",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Self-describing tabular data: a DataFrame of named, typed columns, plus the vocabulary that says what each column means.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dataframe",
|
|
@@ -8,15 +8,15 @@
|
|
|
8
8
|
"schema",
|
|
9
9
|
"tabular"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://anthochamp.
|
|
11
|
+
"homepage": "https://anthochamp.pages.grenadine.io/node-essentials/api/model-dataset/",
|
|
12
12
|
"bugs": {
|
|
13
|
-
"url": "https://
|
|
13
|
+
"url": "https://git.grenadine.io/anthochamp/node-essentials/issues"
|
|
14
14
|
},
|
|
15
15
|
"license": "BSD-3-Clause",
|
|
16
16
|
"author": "Anthony Champagne <dev@anthonychampagne.fr>",
|
|
17
17
|
"repository": {
|
|
18
18
|
"type": "git",
|
|
19
|
-
"url": "git+https://
|
|
19
|
+
"url": "git+https://git.grenadine.io/anthochamp/node-essentials.git",
|
|
20
20
|
"directory": "packages/model-dataset"
|
|
21
21
|
},
|
|
22
22
|
"files": [
|
|
@@ -43,12 +43,17 @@
|
|
|
43
43
|
"test": "yarn run -T vitest run",
|
|
44
44
|
"prepack": "yarn build"
|
|
45
45
|
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@ac-kit/core": "^0.13.0"
|
|
48
|
+
},
|
|
46
49
|
"devDependencies": {
|
|
50
|
+
"@ac-kit/math-random": "0.4.1",
|
|
47
51
|
"@ac-kit/tsconfig": "0.1.0",
|
|
48
52
|
"@ac-kit/typedoc-config": "0.1.0",
|
|
49
|
-
"@ac-kit/vitest-config": "0.
|
|
53
|
+
"@ac-kit/vitest-config": "0.2.0",
|
|
54
|
+
"@types/web": "^0.0.367",
|
|
50
55
|
"@typescript/native": "typescript@7.0.2",
|
|
51
|
-
"rimraf": "6.1.
|
|
56
|
+
"rimraf": "6.1.4",
|
|
52
57
|
"typedoc": "0.28.20",
|
|
53
58
|
"typescript": "@typescript/typescript6@6.0.2"
|
|
54
59
|
},
|