Skip to content

Add select transforms. - #190

Merged
mbostock merged 4 commits into
mainfrom
mbostock/select
Mar 4, 2021
Merged

mbostock merged 4 commits into
mainfrom
mbostock/select

Conversation

@mbostock

@mbostock mbostock commented Mar 4, 2021

Copy link
Copy Markdown
Member

Introduces new transforms for pulling out individual values from the data, while being z- and facet-aware.

@mbostock
mbostock requested a review from Fil March 4, 2021 19:14
@mbostock

mbostock commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

I thought about naming these Plot.selectFirst, Plot.selectLast, Plot.selectMinX etc. Let me know if you prefer that additional verbosity.

@Fil

Fil commented Mar 4, 2021

Copy link
Copy Markdown
Contributor

I guess Plot.selectFirst etc. might help discoverability.

@mbostock

mbostock commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

Okay, I adopted the longer names.

@mbostock

mbostock commented Mar 4, 2021

Copy link
Copy Markdown
Member Author

I’m feeling pretty good about this and will merge but let me know if you have any objections or suggestions! Thanks.

@mbostock
mbostock merged commit 91afdcf into main Mar 4, 2021
@mbostock
mbostock deleted the mbostock/select branch March 4, 2021 20:46
@Fil

Fil commented Mar 5, 2021

Copy link
Copy Markdown
Contributor

It's working great, and I like the way it anticipates multiple values. To test this out and make it more extensible I've tried to export Plot.select.

Then for example, I can select a few values to label a line chart:

    Plot.text(data, {
      transform: Plot.select(I => d3.range(50, I.length, 100), null, {}),
      x: "date",
      y: "value",
   })

the null and {} are unfortunate in this case (since I don't need any channel to work with), so maybe we could make the third argument optional.

I could also detect n local maxima, etc., by adding my own functions.

If we do export it, the function should probably be called differently, to avoid confusion with d3.select. Note that it's a filter (#138), in a somewhat raw form. A signature like Plot.selectFilter((I, V) => …, {...options, key: accessor}) might be easier to use than (I, V) => …, "key", options.

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.

2 participants