Skip to content

ts options & data #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 39 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e3b20dd
src/options
Fil Jul 26, 2022
17fcc95
src/data.ts & src/options.ts
Fil Jul 26, 2022
bcb3ec9
checkpoint -- still errors
Jul 27, 2022
c0bbfd7
clean up arrayify and valueof
Fil Jul 27, 2022
ed68179
"p25" | "p95" | pXX with the &{} trick
Fil Jul 27, 2022
911aaba
ts error unit test
Fil Jul 27, 2022
ad0bac4
add tsd for type tests
Jul 29, 2022
f283574
snapshot passing
Jul 29, 2022
94ab948
more tests and cleanup
Jul 30, 2022
b986115
cleanup valueof
Jul 30, 2022
0d5f5de
tweak
Jul 30, 2022
74eedbe
remove comment
Jul 30, 2022
562d444
Merge branch 'fil/ts-options' into duane/ts-options
Fil Jul 30, 2022
9c0fe20
all green!
Fil Jul 30, 2022
a8f86cf
wording in data.ts
Fil Jul 30, 2022
85d62cb
a color option can be null
Fil Jul 30, 2022
1066fde
cleaner
Fil Jul 31, 2022
239eb99
tighten accessor vs coloraccessor
Fil Jul 31, 2022
c9df5af
typo
Fil Jul 31, 2022
1132c6d
clean
Fil Jul 31, 2022
2ec38b4
clean
Fil Aug 1, 2022
1a65c55
cleaner
Fil Aug 1, 2022
b0473bd
some tests
Aug 1, 2022
db0fc80
A TODO on identity; simplify
Fil Aug 2, 2022
772d339
map and arrayify types and tests
Aug 2, 2022
c627fae
fixes
Aug 2, 2022
c6c27b7
fixes
Fil Aug 2, 2022
1a3bbbd
wrong path
Fil Aug 2, 2022
eb2fe7b
update imports of assert to be compatible with es modules and add tes…
Aug 2, 2022
c60f1f8
separate tsconfig for tests
Aug 2, 2022
50772c9
simplify
Fil Aug 4, 2022
402ce87
clean
Fil Aug 4, 2022
9bf27a3
more granular types for valueof, arrayify, map
Aug 4, 2022
6d85f4f
should fail ci
Aug 4, 2022
ed5dddd
should pass ci
Aug 4, 2022
7880218
an overload was missing for maybeZ
Fil Aug 4, 2022
d2eb106
prettier
Fil Aug 4, 2022
bcda2ae
use one-letter variables for overload defs
Fil Aug 8, 2022
67bdef9
format the comments
Fil Aug 8, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"no-sparse-arrays": 0,
"no-unexpected-multiline": 0,
"@typescript-eslint/no-empty-function": 0,
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-this-alias": 0,
"@typescript-eslint/no-unused-vars": ["error", {"ignoreRestSiblings": true}]
}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"test": "yarn test:typecheck && yarn test:lint && yarn test:mocha",
"test:mocha": "mkdir -p test/output && mocha --conditions=mocha 'test/**/*-test.*' 'test/plot.js'",
"test:lint": "eslint src test",
"test:typecheck": "tsc --noEmit",
"test:typecheck": "tsc --noEmit && tsc --noEmit -p test/tsconfig.json",
"prepublishOnly": "rm -rf dist && rollup -c && tsc",
"postpublish": "git push && git push --tags",
"dev": "vite"
Expand Down Expand Up @@ -63,6 +63,7 @@
"prettier": "^2.7.1",
"rollup": "2",
"rollup-plugin-terser": "7",
"tsd": "^0.22.0",
"tslib": "^2.4.0",
"typescript": "^4.6.4",
"typescript-module-alias": "^1.0.2",
Expand Down
94 changes: 94 additions & 0 deletions src/data.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/**
* Values are associated to screen encodings (positions, colors…) via scales.
*/
export type Value = number | string | Date | boolean | null | undefined;

/**
* A data point with values attached to field names; typically, a row from a
* tabular dataset.
*/
export type Row = Record<string, Value>;

/**
* A single Datum is often a Value, a Row, or an array of values; if a Row,
* possible field names can be inferred from its keys to define accessors; if an
* array, typical accessors are indices, and length, expressed as strings
*/
export type Datum = Row | Value | Value[];
export type FieldNames<T> = T extends Row
? keyof T
: T extends Value[]
? // eslint-disable-next-line @typescript-eslint/ban-types
"length" | "0" | "1" | "2" | (string & {})
: never;

/**
* The marks data; typically an array of Datum, but can also be defined as an
* iterable compatible with Array.from.
*/
export type Data<T extends Datum> = ArrayLike<T> | Iterable<T> | TypedArray;

/**
* An array or typed array constructor, or any class that implements Array.from
*/
export type ArrayType = ArrayConstructor | TypedArrayConstructor;

/**
* The data is then arrayified, and a range of indices is computed, serving as
* pointers into the columnar representation of each channel
*/
export type DataArray<T extends Datum> = T[] | TypedArray;

/**
* A series is an array of indices, used to group data into classes (e.g.,
* groups and facets)
*/
export type index = number; // integer
export type Series = index[] | Uint32Array;
export type Facets = Series[];

export type NumericArray = number[] | TypedArray;
export type ValueArray = NumericArray | Value[];

/**
* Typed arrays are preserved through arrayify
*/
export type TypedArray =
| Int8Array
| Uint8Array
| Int16Array
| Uint16Array
| Int32Array
| Uint32Array
| Uint8ClampedArray
| Float32Array
| Float64Array;

export type TypedArrayConstructor =
| Int8ArrayConstructor
| Uint8ArrayConstructor
| Int16ArrayConstructor
| Uint16ArrayConstructor
| Int32ArrayConstructor
| Uint32ArrayConstructor
| Uint8ClampedArrayConstructor
| Float32ArrayConstructor
| Float64ArrayConstructor;

export type Constructor<T extends TypedArray> = T extends Int8Array
? Int8ArrayConstructor
: T extends Uint8Array
? Uint8ArrayConstructor
: T extends Int16Array
? Int16ArrayConstructor
: T extends Int32Array
? Int32ArrayConstructor
: T extends Uint32Array
? Uint32ArrayConstructor
: T extends Uint8ClampedArray
? Uint8ClampedArrayConstructor
: T extends Float32Array
? Float32ArrayConstructor
: T extends Float64Array
? Float64ArrayConstructor
: never;
Loading