Skip to content

Commit

Permalink
Treat missing intersection areas as disjoint
Browse files Browse the repository at this point in the history
Fix issue #42, detect missing
pairwise intersection areas and add them before optimizing
  • Loading branch information
benfred committed Sep 30, 2015
1 parent b77a12c commit 050d9ad
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 6 deletions.
30 changes: 27 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
{
"name": "venn.js",
"version": "0.2.0",
"author": "Ben Frederickson",
"version": "0.2.1",
"author": "Ben Frederickson <ben@benfrederickson.com> (http:/www.benfrederickson.com)",
"files": [
"venn.min.js",
"venn.js"
],
"url": "https://github.com/benfred/venn.js/issues",
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.9.1",
"grunt-contrib-concat": "~0.5.1",
"grunt-contrib-qunit": "~0.7.0",
"grunt-contrib-jshint": "~0.11.2"
}
},
"description": "Area Proportional Venn and Euler Diagrams",
"main": "venn.js",
"directories": {
"example": "examples",
"test": "tests"
},
"repository": {
"type": "git",
"url": "git+https://github.com/benfred/venn.js.git"
},
"keywords": [
"Venn",
"Euler"
],
"license": "MIT",
"bugs": {
"url": "https://github.com/benfred/venn.js/issues"
},
"homepage": "https://github.com/benfred/venn.js"
}
41 changes: 40 additions & 1 deletion src/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
var initialLayout = parameters.initialLayout || venn.bestInitialLayout;
var fmin = parameters.fmin || venn.fmin;

// add in missing pairwise areas as having 0 size
areas = addMissingAreas(areas);

// initial layout is done greedily
var circles = initialLayout(areas);

Expand Down Expand Up @@ -68,6 +71,41 @@
}, 0, r1 + r2);
};

/** Missing pair-wise intersection area data can cause problems:
treating as an unknown means that sets will be laid out overlapping,
which isn't what people expect. To reflect that we want disjoint sets
here, set the overlap to 0 for all missing pairwise set intersections */
function addMissingAreas(areas) {
areas = areas.slice();

// two circle intersections that aren't defined
var ids = [], pairs = {}, i, j, a, b;
for (i = 0; i < areas.length; ++i) {
var area = areas[i];
if (area.sets.length == 1) {
ids.push(area.sets[0]);
} else if (area.sets.length == 2) {
a = area.sets[0];
b = area.sets[1];
pairs[[a, b]] = true;
pairs[[b, a]] = true;
}
}
ids.sort(function(a, b) { return a > b; });

for (i = 0; i < ids.length; ++i) {
a = ids[i];
for (j = i + 1; j < ids.length; ++j) {
b = ids[j];
if (!([a, b] in pairs)) {
areas.push({'sets': [a, b],
'size': 0});
}
}
}
return areas;
}

/// Returns two matrices, one of the euclidean distances between the sets
/// and the other indicating if there are subset or disjoint set relationships
venn.getDistanceMatrices = function(areas, sets, setids) {
Expand Down Expand Up @@ -296,7 +334,8 @@
overlap.sort(sortOrder);

if (overlap.length === 0) {
throw "Need overlap information for set " + JSON.stringify( set );
// this shouldn't happen anymore with addMissingAreas
throw "ERROR: missing pairwise overlap information";
}

var points = [];
Expand Down
41 changes: 40 additions & 1 deletion venn.js
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ var venn = venn || {'version' : '0.2'};
var initialLayout = parameters.initialLayout || venn.bestInitialLayout;
var fmin = parameters.fmin || venn.fmin;

// add in missing pairwise areas as having 0 size
areas = addMissingAreas(areas);

// initial layout is done greedily
var circles = initialLayout(areas);

Expand Down Expand Up @@ -487,6 +490,41 @@ var venn = venn || {'version' : '0.2'};
}, 0, r1 + r2);
};

/** Missing pair-wise intersection area data can cause problems:
treating as an unknown means that sets will be laid out overlapping,
which isn't what people expect. To reflect that we want disjoint sets
here, set the overlap to 0 for all missing pairwise set intersections */
function addMissingAreas(areas) {
areas = areas.slice();

// two circle intersections that aren't defined
var ids = [], pairs = {}, i, j, a, b;
for (i = 0; i < areas.length; ++i) {
var area = areas[i];
if (area.sets.length == 1) {
ids.push(area.sets[0]);
} else if (area.sets.length == 2) {
a = area.sets[0];
b = area.sets[1];
pairs[[a, b]] = true;
pairs[[b, a]] = true;
}
}
ids.sort(function(a, b) { return a > b; });

for (i = 0; i < ids.length; ++i) {
a = ids[i];
for (j = i + 1; j < ids.length; ++j) {
b = ids[j];
if (!([a, b] in pairs)) {
areas.push({'sets': [a, b],
'size': 0});
}
}
}
return areas;
}

/// Returns two matrices, one of the euclidean distances between the sets
/// and the other indicating if there are subset or disjoint set relationships
venn.getDistanceMatrices = function(areas, sets, setids) {
Expand Down Expand Up @@ -715,7 +753,8 @@ var venn = venn || {'version' : '0.2'};
overlap.sort(sortOrder);

if (overlap.length === 0) {
throw "Need overlap information for set " + JSON.stringify( set );
// this shouldn't happen anymore with addMissingAreas
throw "ERROR: missing pairwise overlap information";
}

var points = [];
Expand Down
Loading

0 comments on commit 050d9ad

Please sign in to comment.