class List
Native Array of groups with various added methods and properties. Methods described below.
class Value
Supergroup Lists are composed of Values which are String or Number objects representing group values. Methods described below.
exported function supergroup.group(recs, dim, opts)
Parameters:
recs must be an Array of Objects.
(list of records to be grouped)
dim must be a string or Function.
(either the property name to group by or a function returning a group by string or number)
opts is optional and must be an Object.
opts.childProp must be a String and has a default value of 'children'.
(If group ends up being hierarchical, this will be the property name of any children)
opts.excludeValues is optional and must be an Array of Strings.
(to exlude specific group values)
opts.preListRecsHook is optional and must be a function.
(run recs through this function before continuing processing)
opts.dimName is optional and must be a function.
(defaults to the value of dim
. If dim
is a function, the dimName will be ugly.)
Returns an Array of Values
(enhanced with all the List methods Avaailable as _.supergroup, Underscore mixin)
The original records in this group are stored as an Array in the records property (should probably be a getter method).
val.records is enhanced with Underscore methods for convenience, but also with the supergroup method that's been mixed in to Underscore. So you can group this specific subset like: val.records.supergroup on FIX!!!!!!
pointless without recursion
if group has children, can search down the tree
memberof enlightenedData
e.addUnderscoreMethods = function(arr) {
_(e.underscoreMethodsToAddToArrays).each(function(methodName) {
if (_(arr).has(methodName)) return;
Object.defineProperty(arr, methodName, {
value: function() {
var part = _.partial(_[methodName], arr);
var result = part.apply(null, _.toArray(arguments));
if (_.isArray(result)) e.addListMethods(result);
return result;
}});
});
return arr;
};
e.underscoreMethodsToAddToArrays = [
"each",
"map",
"reduce",
"find",
"filter",
"reject",
"all",
"every",
"any",
"some",
"contains",
"invoke",
"pluck",
"where",
"findWhere",
"max",
"min",
"shuffle",
"sortBy",
"groupBy",
"countBy",
"sortedIndex",
"size",
"first",
"initial",
"last",
"rest",
"compact",
"flatten",
"without",
"uniq",
"union",
"intersection",
"difference",
"zip",
"unzip",
//"object",
"indexOf",
"lastIndexOf",
"chain",
"result"
];</span>
Enhance arrays with {@link http://underscorejs.org/ Underscore} functions that work on arrays.
Parameters:
Returns an Array
(now enhanced Now can call Underscore functions as methods on the array, and if the return value is an array, it will also be enhanced.)
and Returns a whatever the underscore function would return
Example:
`enlightenedData.addUnderscoreMethods(['a','bb','ccc']) .pluck('length') . group.where({foo:bar}).invoke('baz')
didn't make this yet, just copied from above Value.prototype.descendants = function(level) { var ret = [this]; if (level !== 0 && this[childProp] && (!level || this.depth < level)) ret = .flatten(.map(this[childProp], function(c) { return c.leafNodes(level); }), true); return makeList(ret); };
var delim = opts.delim || '/';
return (this.parent ?
this.parent.namePath(_.extend({},opts,{notLeaf:true})) : '') +
((opts.noRoot && this.depth===0) ? '' :
(this + (opts.notLeaf ? delim : ''))
)
CHANGING -- HOPE THIS DOESN'T BREAK STUFF (pedigree isn't documented yet)
memberof supergroup
Summarize records by a dimension
Parameters:
Records must be a list.
(to be summarized)
Dimension must be a numericDim.
(to summarize by)
memberof supergroup
Compare groups across two similar root notes
Parameters:
* **... must be a from.**
* **... must be a to.**
* **... must be a dim.**
* **... must be an opts.**<br/>(used by treelike and some earlier code)
memberof supergroup
Compare two groups by a dimension
Parameters:
* **... must be an A.**
* **... must be a B.**
* **... must be a dim.**
memberof supergroup
Concatenate two Values into a new one (??)
Parameters:
* **... must be a from.**
* **... must be a to.**
memberof supergroup
Sometimes a List gets turned into a standard array, e.g., through slicing or sorting or filtering. addListMethods turns it back into a List
List
would be a constructor if IE10 supported
__proto__, so it pretends to be one instead.
Parameters:
Register as a named module with AMD.
supergroup.js
Author: Sigfried Gold
License: MIT
usage examples at http://sigfried.github.io/blog/supergroup