benfred / venn.js

Area proportional Venn and Euler diagrams in JavaScript
MIT License
1.04k stars 218 forks source link

Support for intesection of 3 sets? #92

Closed guy4261 closed 7 years ago

guy4261 commented 7 years ago

Hi,

Is intersection of 3 sets supported? It seems from my experiments that it isn't - am I missing something? Here's a modified simple.html I used to test my assumption:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Simple venn.js example</title>
<style>
body {
    font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
    font-size: 14px;
}
</style>
</head>

<body>
    <div id="venn"></div>
</body>

<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="venn.js"></script>
<script>
// define sets and set set intersections
var sets = [ {sets: ['A'], size: 12},
             {sets: ['B'], size: 12},
             {sets: ['C'], size: 12},
             {sets: ['A','B', 'C'], size: 2}];

var chart = venn.VennDiagram();
d3.select("#venn").datum(sets).call(chart);

</script>
</html>

Thanks,

g.

benfred commented 7 years ago

Right now we are assuming that if you leave out the size information for any pair of sets, that the desired size between those sets is 0: https://github.com/benfred/venn.js/commit/050d9adf9c2bd85c98374d25c93cedc524e2bbf7#diff-677d382da9f8d81f61d50af24f937b32R74

Adding the missing pair-wise set intersection data should make this work:

var sets = [ {sets: ['A'], size: 12},
             {sets: ['B'], size: 12},
             {sets: ['C'], size: 12},
             {sets: ['A','B',], size: 2},
             {sets: ['B','C',], size: 2},
             {sets: ['A','C',], size: 2},
             {sets: ['A','B',], size: 2}];

var chart = venn.VennDiagram();
d3.select("#venn").datum(sets).call(chart);