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

ts options & data #1008

wants to merge 39 commits into from

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Jul 26, 2022

data.ts

Documents the types of data that are expected by Marks, and the way they are handled internally (via valueof, arrayify, map…). Facets, groups &c are represented by a Series, an index into the columnar representation of the data.

options.ts

Plot.valueof and Plot.column get their JSDoc from the README

Type safety issues:

  • the field accessor might crash if the datum is not a generic object; it's a choice not to type-guard this (for performance)
  • the first and second accessors might crash if the datum is not an array; same

Duck-typing was interesting to type; I tried two methods:

export function isOptions(option: any): boolean {
  return isObject(option) && typeof (option as {transform: null}).transform !== "function";
}

export function isDomainSort(sort: any): boolean {
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
  return isObject(sort) && sort!.value === undefined && sort!.channel === undefined;
}

maybe the second version is better, esp. if we disabled @typescript-eslint/no-non-null-assertion on the whole project?

I'm still hesitating between the myriad ways one can specify an object. Let me know which one you prefer ( {[key: string]: any} over Record<<……>>)?

(Also a reminder to merge in cli, since we need the mv separate from the subsequent changes, rather than a file deletion+addition.)

(first part of #1005)

todo:

  • add a test for the crash of valueof(undefined, accessor function)

@Fil Fil requested review from duaneatat and mbostock July 26, 2022 16:03
@mbostock
Copy link
Member

Can we find a way to not duplicate the contents of the README? I really don’t want the documentation to be duplicated—it will almost immediately get out of sync and be burdensome to keep in sync. I think either the JSDoc should be automatically extracted from the README or, perhaps more likely, vice versa.

@duaneatat
Copy link
Contributor

@mbostock I'm working on that this week 👍

@Fil Fil mentioned this pull request Jul 27, 2022
@Fil Fil force-pushed the fil/ts-options branch from 4931ae0 to 6d5f7b9 Compare July 27, 2022 13:53
test valueof (null, ()=>{})
@Fil Fil force-pushed the fil/ts-options branch from 6d5f7b9 to c0bbfd7 Compare July 27, 2022 13:57
Fil added a commit that referenced this pull request Jul 27, 2022
Fil added a commit that referenced this pull request Jul 27, 2022
Fil added a commit that referenced this pull request Jul 31, 2022
context.ts

src/options

api.ts and options.ts

fix type formatAuto

scales/index

scales/schemes

scales/schemes.ts

src/stats

stats.ts

remove common.ts for now

symbols

symbols.ts

marks/marker

marker.ts; changing the API for marker

the second argument for markers has not been documented yet; changing it from *context* = {document} to *document*

style

style.ts

src/transforms/basic

transform/basic.ts

transform/identity

transforms/identity.ts

transforms/group

transforms/groups.ts

transforms/inset

transforms/inset.ts

transforms/map

transforms/map.ts

transforms/select

transforms/select.ts

transforms/stack

transforms/stack.ts

transforms/interval

transforms/interval.ts

transforms/normalize

transforms/normalize.ts

transforms/window

transforms/window.ts

transforms/bin

transforms/bin.ts

clean-up valueof, map

renames & clean-up on ValueAccessor

valueof cleaner

cleaner defs for data and columns

Add stack error messages when X or Z are missing and the specified order requires them

move data types to src/data.ts

too much typing

README documentation and links for Plot.column, Plot.valueof and Plot.transform (aka basic)

options.ts copied from 6b6aa86

keep in sync with #1008

follow #1008 on pXX

follow #1008

Datum can also be an array of values, with typical accessors being "length", "0", "1"…

more typings

basic.ts is working

transforms: identity, inset, interval, map

window, and a bit of progress on stack

normalize

select

stack

bin

group

markers and symbols

arrayify comes back

difficulty typing Trasnforms vs Initializer, because Plot.sort applies to either
@Fil Fil mentioned this pull request Aug 8, 2022
@Fil
Copy link
Contributor Author

Fil commented Aug 8, 2022

superseded by #1024

@Fil Fil closed this Aug 8, 2022
@Fil Fil deleted the fil/ts-options branch April 5, 2023 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants