benfred/venn.js

Orientation order does not always sort lexicographically

jamand opened this issue · 1 comments

Hello. In order to compare multiple Venn diagrams I'd like to have a certain orientation order of the sets, e.g. using their id in lexicographic order.
I defined an order function as described in https://github.com/benfred/venn.js/blob/master/examples/orientation_order.html, but in some rare cases the order of the sets is reversed when changing the size of a set.
A minimal example where the sets are not lexicographically sorted (although they should be) can be found here:
http://jsfiddle.net/hvczy0LL/78/ (this also happens when unlike in the example two sets have a non-empty overlap).

Thanks for the bug report!

I can see an issue with orientationOrder and disjoint sets. I added some code to normalize the display of a venn diagram (example/test page here) so that algorithms starting from a random initial location produce output that looks the same. The orientationOrder parameter lets you define a custom sort order for this normalization inside of an non-disjoint cluster of items.

The problem is that orientationOrder only affects layout inside an overlapping cluster of circles, and doesn't currently do anything with disjoint sets like in your example. The reason is that orientationOrder is a function that specifies order for individual items, and with the disjoint clusters we need to order groups of items instead.

In your example each disjoint cluster only has one set - so should be relatively easy to fix (basically change this line https://github.com/benfred/venn.js/blob/master/src/layout.js#L574 to incorporate the sort order defined by orientationOrder instead of the size of the group of sets). For multiple sets we could use orientationOrder to order sets inside the cluster and then use the the first item in the sorted list to compare between clusters.

Do you have an example with this not working with two sets and a non-empty overlap? I think that should work right now