benfred / venn.js

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

venn.js Cannot read property 'circle' of null #70

Closed logust79 closed 8 years ago

logust79 commented 8 years ago

I have this dataset (a bit long, attach at the bottom), where it causes venn.js Cannot read property 'circle' of null error. at arcArea += circleArea(arc.circle.radius, arc.width); I printed out the buggy loop data, it looks something like this: innerPoints = [{...parentIndex: [0, 2]...}, {...parentIndex: [1, 2]...}, {...parentIndex: [0, 2]...}, {...parentIndex: [1, 2]...}, {...parentIndex: [1, 3]...}, {...parentIndex: [1, 3]...} When it decides to nest-loop the first and last element of the list, it can't find matching index and arc will end up with null, causing the arcArea += circleArea(arc.circle.radius, arc.width); to fail. A quick fix is to add a conditional to avoid updating arcArea when arc is null, although I have no clue if this breaks the mathematics. Can you please have a look at this? Many thanks. The dataset


var sets = [{ sets: ['a'], size: 226},
            { sets: ['b'], size: 733},
            { sets: ['c'], size: 279},
            { sets: ['d'], size: 332},
            { sets: ['e'], size: 244},
            { sets: ['f'], size: 650},
            { sets: ['a','b'], size: 214},
            { sets: ['a','c'], size: 119},
            { sets: ['a','d'], size: 187},
            { sets: ['a','e'], size: 155},
            { sets: ['a','f'], size: 186},
            { sets: ['b','c'], size: 202},
            { sets: ['b','d'], size: 332},
            { sets: ['b','e'], size: 244},
            { sets: ['b','f'], size: 415},
            { sets: ['c','d'], size: 127},
            { sets: ['c','e'], size: 103},
            { sets: ['c','f'], size: 191},
            { sets: ['d','e'], size: 244},
            { sets: ['d','f'], size: 222},
            { sets: ['e','f'], size: 149},
            { sets: ['a','b','c'], size: 117},
            { sets: ['a','b','d'], size: 187},
            { sets: ['a','b','e'], size: 155},
            { sets: ['a','b','f'], size: 179},
            { sets: ['a','c','d'], size: 116},
            { sets: ['a','c','e'], size: 100},
            { sets: ['a','c','f'], size: 104},
            { sets: ['a','d','e'], size: 155},
            { sets: ['a','d','f'], size: 170},
            { sets: ['a','e','f'], size: 139},
            { sets: ['b','c','d'], size: 127},
            { sets: ['b','c','e'], size: 103},
            { sets: ['b','c','f'], size: 171},
            { sets: ['b','d','e'], size: 244},
            { sets: ['b','d','f'], size: 222},
            { sets: ['b','e','f'], size: 149},
            { sets: ['c','d','e'], size: 103},
            { sets: ['c','d','f'], size: 109},
            { sets: ['c','e','f'], size: 88},
            { sets: ['d','e','f'], size: 149},
            { sets: ['a','b','c','d'], size: 116},
            { sets: ['a','b','c','e'], size: 100},
            { sets: ['a','b','c','f'], size: 103},
            { sets: ['a','b','d','e'], size: 155},
            { sets: ['a','b','d','f'], size: 170},
            { sets: ['a','b','e','f'], size: 139},
            { sets: ['a','c','d','e'], size: 100},
            { sets: ['a','c','d','f'], size: 103},
            { sets: ['a','c','e','f'], size: 97},
            { sets: ['a','d','e','f'], size: 139},
            { sets: ['b','c','d','e'], size: 103},
            { sets: ['b','c','d','f'], size: 109},
            { sets: ['b','c','e','f'], size: 88},
            { sets: ['b','d','e','f'], size: 149},
            { sets: ['c','d','e','f'], size: 88},
            { sets: ['a','b','c','d','e'], size: 100},
            { sets: ['a','b','c','d','f'], size: 103},
            { sets: ['a','b','c','e','f'], size: 87},
            { sets: ['a','b','d','e','f'], size: 139},
            { sets: ['a','c','d','e','f'], size: 87},
            { sets: ['b','c','d','e','f'], size: 88},
            { sets: ['a','b','c','d','e','f'], size: 87},

            ]
benfred commented 8 years ago

This seems to be caused when multiple circles intersect at nearly the same point - causing issues with the code that tries to figure out the intersection area. In your case this point occurs with the 'a', 'd', 'e', 'f' circles:

screen shot 2016-05-14 at 4 41 59 pm.

The last commit should fix https://github.com/benfred/venn.js/commit/1792850b4d0dd732b31e9fa27f68426ca8053cb5

logust79 commented 8 years ago

Excellent work! Thank you very much!