Skip to content

Commit 900d148

Browse files
simplify comment and code
the comment was mostly describing invariants for replacing group.top() with group.all() + computeOrderedGroups + slice (9d07086) slice's second parameter has a reasonable default for #1184
1 parent 947c381 commit 900d148

File tree

1 file changed

+4
-23
lines changed

1 file changed

+4
-23
lines changed

src/cap-mixin.js

+4-23
Original file line numberDiff line numberDiff line change
@@ -50,36 +50,17 @@ dc.capMixin = function (_chart) {
5050
return _chart.valueAccessor()(d, i);
5151
};
5252

53-
/**
54-
* Base function orders by crossfilter's group.all.
55-
* This returns all groups, in ascending order, by value.
56-
*
57-
* This function is expected to return items in the same direction,
58-
* ascending but the N biggest where N is cap.
59-
*
60-
* Since computeOrderedGroups is using crossfilter's quicksort, the
61-
* sorted items will always be in ascending order.
62-
*
63-
* This means if we cap, we need to take from N to the end of the array.
64-
*
65-
* Index
66-
* 0-------N-------length
67-
*
68-
* Value
69-
* small -> big
70-
*
71-
*/
53+
// return N biggest groups, where N is the cap, sorted in ascending order.
7254
_chart.data(function (group) {
7355
if (_cap === Infinity) {
7456
return _chart._computeOrderedGroups(group.all());
7557
} else {
76-
var topRows = group.all(); // ordered by crossfilter group order (default value)
77-
78-
topRows = _chart._computeOrderedGroups(topRows); // re-order using ordering (default key)
58+
var topRows = group.all(); // in key order
59+
topRows = _chart._computeOrderedGroups(topRows); // re-order using ordering (defaults to key)
7960

8061
if (_cap) {
8162
var start = Math.max(0, topRows.length - _cap);
82-
topRows = topRows.slice(start, topRows.length);
63+
topRows = topRows.slice(start);
8364
}
8465

8566
if (_othersGrouper) {

0 commit comments

Comments
 (0)