Venn diagram like trees

I ran into the problem of representing a Venn diagram as a tree structure for processing information as XML.

Does anyone have an elegant way to do this, or maybe some sharp observations?

Please note that I cannot process individual elements in sets. The diagrams will illustrate situations equivalent to “Only 20 students, of which 5 play sports, 8 play chess and 3 do both.”

+4
source share
2 answers

From your description, I understand that you are talking about working with aggregate data (score for each set), and not with discrete elements. Therefore, based on this assumption, I would first consider how another code base represents Venn diagrams (Google diagram API)

The Google Chart API presents Venn diagrams using seven values. I extracted the following descriptions from it: http://code.google.com/apis/chart/image/docs/gallery/venn_charts.html

  • The first three values ​​determine the sizes of the three circles: A, B, and C. For a chart with two circles, specify zero for the third value.
  • The fourth value indicates the size of the intersection of A and B.
  • The fifth value indicates the size of the intersection of A and C. For a chart with two circles, do not specify a value here.
  • The sixth value indicates the size of the intersection of B and C. For a chart with two circles, do not enter a value here.
  • The seventh value determines the size of the common intersection of A, B, and C. For a chart with two circles, do not specify a value here.

We can use the same approach to represent your problem domain in XML:

<venn_diagram item_type="Students" item_count="20"> <set_a name="Play Sports" item_count="5"/> <set_b name="Play Chess" item_count="8"/> <set_a_and_b name="Play Both" item_count="3"/> </venn_diagram> 

With this information, you know enough to draw a diagram.

+1
source

As others have noted, it is not clear what you need to know, but you have provided some of what you need to know. Note that Venn diagrams present data in a way that is similar to the Disjunctive Normal Form for Boolean operators. That is, the Universe is a union of disjoint sets defined by the intersection of sets and their compliments. For example, with sets A, B, and C, you get the following counts (where a single quote means “compliment”):

 ABC ABC' A B'C A B'C' A'B C A'B C' A'B'C A'B'C' 

You may notice that these are binary values ​​above set names. So, basically, if you have a Venn diagram between N sets, you need to know the number 2 ^ n. From this you can restore all the necessary information. (for example, “A” is an ABC union ABC union “AB'C AB'C union”)

From there, representing as an XML file is just an exercise - you need to know how many sets, their name and for each nonzero intersection their count and which sets are complemented at the intersection. (You can store more explicitly if you want, but XML is already very concise.)

Hope this helps - even if it's late!

+1
source

Source: https://habr.com/ru/post/1340451/


All Articles