Skip to content

Commit

Permalink
Fix reindex and group listeners on data removal.
Browse files Browse the repository at this point in the history
There was a bug where the new index was not always being copied.  In
addition, the updateMany/updateOne/null behaviour, was not being updated
for groups on data removal.
  • Loading branch information
jasondavies committed Sep 13, 2013
1 parent ac1de20 commit d3b2e4a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 15 deletions.
24 changes: 19 additions & 5 deletions crossfilter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(exports){
crossfilter.version = "1.3.4";
crossfilter.version = "1.3.5";
function crossfilter_identity(d) {
return d;
}
Expand Down Expand Up @@ -699,7 +699,8 @@ function crossfilter() {
function removeData(reIndex) {
for (var i = 0, j = 0, k; i < n; ++i) {
if (filters[k = index[i]]) {
if (i !== j) values[j] = values[i], index[j] = reIndex[k];
if (i !== j) values[j] = values[i];
index[j] = reIndex[k];
++j;
}
}
Expand Down Expand Up @@ -1008,7 +1009,7 @@ function crossfilter() {
}

function removeData() {
if (groupIndex) {
if (k > 1) {
var oldK = k,
oldGroups = groups,
seenGroups = crossfilter_index(oldK, oldK);
Expand All @@ -1033,8 +1034,21 @@ function crossfilter() {
}
}

// Reindex the group index using seenGroups to find the new index.
for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
if (k > 1) {
// Reindex the group index using seenGroups to find the new index.
for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
} else {
groupIndex = null;
}
filterListeners[filterListeners.indexOf(update)] = k > 1
? (reset = resetMany, update = updateMany)
: k === 1 ? (reset = resetOne, update = updateOne)
: reset = update = crossfilter_null;
} else if (k === 1) {
for (var i = 0; i < n; ++i) if (filters[i]) return;
groups = [], k = 0;
filterListeners[filterListeners.indexOf(update)] =
update = reset = crossfilter_null;
}
}

Expand Down
2 changes: 1 addition & 1 deletion crossfilter.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d3b2e4a

Please sign in to comment.