GithubHelp home page GithubHelp logo

Comments (3)

syntagmatic avatar syntagmatic commented on April 26, 2024

This seems too magical to be worth it, at least from the perspective of transitioning from version 3. There will be considerable confusion about hierarchy formats because of issues like d3/d3-collection#3

The d3.hierarchy API is useful to encounter and read about, so explicitly declaring it is good for now.

The automatic boxing probably can't work both with code that uses the existing d3.nest (key/values) and the flare.json (name/children) structures... or can it?

from d3-hierarchy.

mbostock avatar mbostock commented on April 26, 2024

I don’t think you’d want automatic boxing to allow the children to be defined using the values property by default. That would imply d3.hierarchy would allow either, as well, and that seems unnecessary and difficult to implement cleanly.

If we changed d3.nest according to d3/d3-collection#3, old code like this:

var entries = nest.entries(data);
var root = d3.hierarchy({values: entries}, function(d) { return d.values; });
root.sum(function(d) { return d.values; });
treemap(root);

Could be changed to this:

var entries = nest.entries(data);
var root = treemap({children: entries});

In other words:

  • You don’t need to specify a children accessor to d3.hierarchy because the default one is now compatible with d3.nest.
  • You don’t need to pass the result of nest.entries to d3.hierarchy because the hierarchy layout (treemap) automatically does that if the input isn’t a d3.hierarchy instance.
  • You don’t need to call hierarchy.sum, either, because the hierarchy layout automatically does that if the input isn’t a d3.hierarchy instance.
  • You don’t have the confusion of entry.values referring to either the children values or the rolled-up value because nest.rollup replaces the leaf entries with {key, value} objects.

Now, you could just take d3/d3-collection#3 by itself and not allow autoboxing, in which case you’d need to say this:

var entries = nest.entries(data);
var root = d3.hierarchy({children: entries});
root.sum(function(d) { return d.value; });
treemap(root);

That’s still an improvement in my view. If you just changed the behavior of nest.rollup, then it’d be:

var entries = nest.entries(data);
var root = d3.hierarchy({values: entries}, function(d) { return d.values; });
root.sum(function(d) { return d.value; });
treemap(root);

Which I guess is still slightly better because it avoids the entry.value vs. entry.values confusion, but I still think it’d be nice to use entry.children instead of entry.values.

You could also support autoboxing but reject d3/d3-collection#3, in which case the example here would remain unchanged since d3.nest wouldn’t be able to take advantage of autoboxing. But autoboxing would still help if you had hierarchical JSON data and you just wanted the default behavior in regards to sorting.

from d3-hierarchy.

mbostock avatar mbostock commented on April 26, 2024

Okay, I think I’m against autoboxing in that: it doesn’t introduce the d3.hierarchy API (and violates parsimony); it requires specifying default behavior in all hierarchy layouts; and it’s not useful in the case where you have tabular data and need to use d3.stratify.

from d3-hierarchy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.