Skip to content

Commit

Permalink
Remove stale groups on data removal.
Browse files Browse the repository at this point in the history
Previously, groups would never be removed even if the values that
created them were removed.

Fixes #91.
  • Loading branch information
jasondavies committed Sep 12, 2013
1 parent 86b1660 commit ac1de20
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 13 deletions.
32 changes: 27 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.3";
crossfilter.version = "1.3.4";
function crossfilter_identity(d) {
return d;
}
Expand Down Expand Up @@ -1008,11 +1008,33 @@ function crossfilter() {
}

function removeData() {
if (groupIndex) for (var i = 0, j = 0; i < n; ++i) {
if (filters[i]) {
if (i !== j) groupIndex[j] = groupIndex[i];
++j;
if (groupIndex) {
var oldK = k,
oldGroups = groups,
seenGroups = crossfilter_index(oldK, oldK);

// Filter out non-matches by copying matching group index entries to
// the beginning of the array.
for (var i = 0, j = 0; i < n; ++i) {
if (filters[i]) {
seenGroups[groupIndex[j] = groupIndex[i]] = 1;
++j;
}
}

// Reassemble groups including only those groups that were referred
// to by matching group index entries. Note the new group index in
// seenGroups.
groups = [], k = 0;
for (i = 0; i < oldK; ++i) {
if (seenGroups[i]) {
seenGroups[i] = k++;
groups.push(oldGroups[i]);
}
}

// Reindex the group index using seenGroups to find the new index.
for (var i = 0; i < j; ++i) groupIndex[i] = seenGroups[groupIndex[i]];
}
}

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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "crossfilter",
"version": "1.3.3",
"version": "1.3.4",
"description": "Fast multidimensional filtering for coordinated views.",
"keywords": [
"square",
Expand Down
Loading

0 comments on commit ac1de20

Please sign in to comment.