GithubHelp home page GithubHelp logo

Comments (9)

mbostock avatar mbostock commented on April 27, 2024

Perhaps nest.entries should create {key, children} by default, too. Then it would be default-compatible with d3.hierarchy.

from d3-collection.

syntagmatic avatar syntagmatic commented on April 27, 2024

I think it's best to keep the behavior of d3.nest as it is-- at least key/values for the internal node keys. It's a simple, successful function with many examples and tutorials out there.

The referenced issue could resolved with a new convenience function in d3-hierarchy that has an API similar d3.nest but returns a hierarchy object. The new function would be a sibling to stratify.

from d3-collection.

mbostock avatar mbostock commented on April 27, 2024

I don’t want to introduce a new operator; that’s a pretty big addition to the API when there’s already a reasonable way to turn the result of nest.entries into a d3.hierarchy. We’re just talking about turning this:

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

Into this:

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

Or, if we just change the behavior of nest.rollup and don’t adopt entry.children:

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

Name changes are the most trivial of incompatibilities. We shouldn’t needlessly rename things, but if changing entry.values to entry.children makes things easier, it might be worth it. Certainly there are a lot of other API changes in D3 4.0 that I believe are worth it; we shouldn’t needlessly bind ourselves to past API decisions if we’ve learned something since.

It is interesting to consider whether d3.nest should return a d3.hierarchy instance directly. That would suggest moving d3.nest to the d3-hierarchy module, or perhaps better, moving d3.hierarchy and d3.stratify into d3-collection (since these are just operations on data and not hierarchical layouts). That would offer some nice improvements, like addressing #4 because d3.hierarchy provides visit methods, but you also lose something because nests are specialized hierarchies where each child is uniquely identified by a string key. It’s sometimes convenient to represent them as nested maps.

So, I feel like it’s worth considering renaming entry.values to entry.children (and having nest.rollup replace entry.children with entry.value), but I’m not currently in favor of more substantial changes.

from d3-collection.

mbostock avatar mbostock commented on April 27, 2024

I’ve implemented both approaches in #6 and #7. I guess I’m leaning towards #6 to be conservative now.

from d3-collection.

mbostock avatar mbostock commented on April 27, 2024

Merged #6.

from d3-collection.

PatriciaW43 avatar PatriciaW43 commented on April 27, 2024

I'm having problems with d3.nest. Sometimes rollup returns key/value and sometimes key/values. It appears that the first time it is invoked it results in key/values then key/value. This means that the program works correctly the first time but then it returns key/value and fails.

from d3-collection.

mbostock avatar mbostock commented on April 27, 2024

@PatriciaW43 nest.rollup always produces leaf entries with entry.value rather than entry.values. Please see my guide on reporting an issue.

from d3-collection.

PatriciaW43 avatar PatriciaW43 commented on April 27, 2024

I wasn't sure how to report an issue so I created a Gist at gist:fe81b673a90a3cd5f32b7aceca9559c0

from d3-collection.

bplmp avatar bplmp commented on April 27, 2024

For me nest.rollup is also producing entry.values on leaf entries.

See this example, which is linked from d3-collection's readme: http://bl.ocks.org/phoebebright/raw/3176159/

var nested_data = d3.nest()
.key(function(d) { return d.status; })
.key(function(d) { return d.priority; })
.rollup(function(leaves) { return leaves.length; })
.entries(csv_data);

Returns:

[
   {
      "key": "Complete",
      "values": [
         {
            "key": "MUST",
            "values": 5
         },
         {
            "key": "SHOULD",
            "values": 5
         },
         {
            "key": "COULD",
            "values": 1
         }
      ]
   },
   {
      "key": "In Progress",
      "values": [
         {
            "key": "MUST",
            "values": 6
         },
         {
            "key": "SHOULD",
            "values": 1
         },
         {
            "key": "WISH",
            "values": 1
         }
      ]
   },
   {
      "key": "Not Started",
      "values": [
         {
            "key": "MUST",
            "values": 9
         },
         {
            "key": "SHOULD",
            "values": 3
         },
         {
            "key": "COULD",
            "values": 3
         },
         {
            "key": "WISH",
            "values": 1
         }
      ]
   }
]

from d3-collection.

Related Issues (19)

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.