plot icon indicating copy to clipboard operation
plot copied to clipboard

tree value

Open Fil opened this issue 3 years ago • 4 comments

Use root.count or root.sum and expose a node:value somehow

(From https://github.com/observablehq/plot/pull/841)

Fil avatar May 11 '22 15:05 Fil

Being able to preprocess the tree with a function that gets passed the root node might be a more general solution than specifically calling count or sum (eg. maybe the user wants to do something more involved using a particular traversal).

The API already exposes the tree node objects as nodes if you use the { node: d => ... } form for an option value so I don't think this would involve a bigger commitment to the d3 tree representation than already exists.

yurivish avatar May 11 '22 15:05 yurivish

I suppose that if we define a value option it could accept built-ins ("sum" and "count") as well as a more generic function.

Fil avatar May 11 '22 15:05 Fil

I also have a use case for filtering nodes by their computed value and only laying out the filtered nodes. (This behaves differently from the current filter option, and can't be accomplished by filtering the data since it needs tree information)

The basic idea is that I want to compute the sum/value on the full tree, but then filter display to only the "significant" nodes.

Right now I'm making my own tree and putting the values in a lookup map that's indexed by node.id (the partial path), which works as a fully general workaround, though it does require computing the tree twice.

I wonder if there is a related/more general kind of use case for post-processing density mark bin data (both as examples of wanting to modify the intermediate data representation). Maybe they could share a common design pattern for accessing/modifying the computed data before it's plotted.

yurivish avatar May 11 '22 15:05 yurivish

a D3 example https://observablehq.com/@john-guerra/tree-value

Fil avatar Jun 10 '22 06:06 Fil