Skip to content

Commit

Permalink
Fix data removal when group cardinality ≤ 1.
Browse files Browse the repository at this point in the history
Fixes #90.
  • Loading branch information
jasondavies committed Sep 10, 2013
1 parent 60169ab commit d3b8bb6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions crossfilter.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(function(exports){
crossfilter.version = "1.3.1";
crossfilter.version = "1.3.2";
function crossfilter_identity(d) {
return d;
}
Expand Down Expand Up @@ -1008,7 +1008,7 @@ function crossfilter() {
}

function removeData() {
for (var i = 0, j = 0; i < n; ++i) {
if (groupIndex) for (var i = 0, j = 0; i < n; ++i) {
if (filters[i]) {
if (i !== j) groupIndex[j] = groupIndex[i];
++j;
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.1",
"version": "1.3.2",
"description": "Fast multidimensional filtering for coordinated views.",
"keywords": [
"square",
Expand Down
2 changes: 1 addition & 1 deletion src/crossfilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ function crossfilter() {
}

function removeData() {
for (var i = 0, j = 0; i < n; ++i) {
if (groupIndex) for (var i = 0, j = 0; i < n; ++i) {
if (filters[i]) {
if (i !== j) groupIndex[j] = groupIndex[i];
++j;
Expand Down
12 changes: 11 additions & 1 deletion test/crossfilter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,14 @@ suite.addBatch({
data.foo.evenOdd = data.foo.group(function(value) { return Math.floor(value / 2); });
return data;
},
"removing a record works for a group with cardinality one": function(data) {
data.add([{foo: 1}, {foo: 1.1}, {foo: 1.2}]);
data.foo.filter(1.1);
data.remove();
data.foo.filterAll();
data.remove();
assert.deepEqual(data.foo.top(Infinity), []);
},
"removing a record updates dimension": function(data) {
data.add([{foo: 1}, {foo: 2}]);
data.foo.filterExact(1);
Expand All @@ -918,8 +926,10 @@ suite.addBatch({
data.add([{foo: 1}, {foo: 2}, {foo: 3}]);
data.foo.filter(2);
data.remove();
data.foo.filter(null);
data.foo.filterAll();
assert.deepEqual(data.foo.top(Infinity), [{foo: 3}, {foo: 1}]);
data.remove();
assert.deepEqual(data.foo.top(Infinity), []);
}
}
}
Expand Down

0 comments on commit d3b8bb6

Please sign in to comment.