Skip to content

dataset mark option#2295

Draft
Fil wants to merge 2 commits intomainfrom
fil/dataset
Draft

dataset mark option#2295
Fil wants to merge 2 commits intomainfrom
fil/dataset

Conversation

@Fil
Copy link
Copy Markdown
Contributor

@Fil Fil commented Mar 10, 2025

dataset

Plot.dot(olympians, {x: "weight", y: "height", dataset: Plot.identity})

@Fil Fil requested a review from mbostock March 10, 2025 10:31
Copy link
Copy Markdown
Member

@mbostock mbostock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, what is the motivation for this PR? Why is it useful to set data attributes in this context? Is it more than “advanced” uses? Is this desirable enough to merit a first-class feature, rather than say a render transform to set attributes?

And how often is it that you want to set a whole set of data attributes, derived from an object, rather than being more specific about what attributes you choose? It feels unlike Plot to have a channel whose values are objects, and allow different attributes if the objects are not homogeneous. And likewise there’s the complexity of dealing with primitive values (and the arbitrariness of data-value, and pulling out the channel label, etc.).

I’m wondering about a more precise design where you can set individual data attributes, say like so for data-name:

Plot.dot(athletes, {x: "weight", y: "height", dataset: {name: "name"}})

Or like so, which I think I prefer:

Plot.dot(athletes, {x: "weight", y: "height", "data-name": "name"})

The latter would require extracting the data-* options out of the mark options, but that seems doable. But in any case, I’d like to hear the rationale to justify adding such a feature.

@Fil Fil marked this pull request as draft April 3, 2026 09:10
@Fil
Copy link
Copy Markdown
Contributor Author

Fil commented Apr 3, 2026

I wanted to allow a trace back to the original data points, that is not expressed visually but allows machine inspection. This would be useful, for example, to implement custom interactions (say, to click on a geo feature and select all the values from that feature); it's the primary use case I had in mind. I agree with your comments though (both about motivation and implementation).

@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 3, 2026

Would D3’s approach of setting __data__ work better (or some other property)? We could avoid serialization if it’s just for programmatic access.

@Fil
Copy link
Copy Markdown
Contributor Author

Fil commented Apr 4, 2026

Setting __data__ allows to retrieve the original object, but you are right that in Plot this does not really exist as such, as we tend to favor columnar formats for channels. This convinces me that the automatic development of all properties is a bad idea (what happens if we pass an object that has very many properties, etc.).

An advantage of data-value is that it can be queried with CSS and with querySelectorAll. Needs more thinking wrt what the actual use cases are, but it's probably more constrained and modest than what is in this PR.

@mbostock
Copy link
Copy Markdown
Member

mbostock commented Apr 4, 2026

Querying with CSS is also available via the className and ariaLabel 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