Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add nest.mapValues as an alias for rollup.

Also, implement sortValues in terms of mapValues.
  • Loading branch information...
commit c8f5614d1b43915b57bd5567bd624daf1a5479f1 1 parent 1affcd2
Mike Bostock mbostock authored
Showing with 15 additions and 21 deletions.
  1. +6 −9 d3.v2.js
  2. +3 −3 d3.v2.min.js
  3. +6 −9 src/core/nest.js
15 d3.v2.js
View
@@ -317,14 +317,10 @@ d3.nest = function() {
var nest = {},
keys = [],
sortKeys = [],
- sortValues,
- rollup;
+ mapValues;
function map(array, depth) {
- if (depth >= keys.length) return rollup
- ? rollup.call(nest, array) : (sortValues
- ? array.sort(sortValues)
- : array);
+ if (depth >= keys.length) return mapValues ? mapValues.call(nest, array) : array;
var i = -1,
n = array.length,
@@ -391,12 +387,13 @@ d3.nest = function() {
// Specifies the order for leaf values.
// Applies to both maps and entries array.
nest.sortValues = function(order) {
- sortValues = order;
+ mapValues = function(array) { return array.sort(order); };
return nest;
};
- nest.rollup = function(f) {
- rollup = f;
+ nest.rollup =
+ nest.mapValues = function(_) {
+ mapValues = _;
return nest;
};
6 d3.v2.min.js
View
3 additions, 3 deletions not shown
15 src/core/nest.js
View
@@ -2,14 +2,10 @@ d3.nest = function() {
var nest = {},
keys = [],
sortKeys = [],
- sortValues,
- rollup;
+ mapValues;
function map(array, depth) {
- if (depth >= keys.length) return rollup
- ? rollup.call(nest, array) : (sortValues
- ? array.sort(sortValues)
- : array);
+ if (depth >= keys.length) return mapValues ? mapValues.call(nest, array) : array;
var i = -1,
n = array.length,
@@ -76,12 +72,13 @@ d3.nest = function() {
// Specifies the order for leaf values.
// Applies to both maps and entries array.
nest.sortValues = function(order) {
- sortValues = order;
+ mapValues = function(array) { return array.sort(order); };
return nest;
};
- nest.rollup = function(f) {
- rollup = f;
+ nest.rollup =
+ nest.mapValues = function(_) {
+ mapValues = _;
return nest;
};
Please sign in to comment.
Something went wrong with that request. Please try again.