Pikchr

how to draw venn diagrams like these
Login

how to draw venn diagrams like these

(1.1) Originally by emacsbliss with edits by drh on 2022-11-10 23:12:52 from 1.0 [source]

Hi,

wonder anyone can give some examples how to draw venn diagrams from this link?

thanks a lot!!

https://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

(2) By drh on 2022-11-11 00:27:41 in reply to 1.0 [link] [source]

The "intersection" Venn diagram looks like it might be tricky. The others similar simple enough but I don't know how (off hand) to do the intersection. I'll work on it when I get a chance...

(3.1) By Warren Young (wyoung) on 2022-11-13 09:02:43 edited from 3.0 in reply to 2 [link] [source]

Here's as close as I was able to get:

A B
IJA: circle invisible "A" bold fill white
IJB: circle invisible "B" bold fill white at IJA + (0.33, 0)
IJI: dot at IJA.n + (0.166, -0.06) invis
IJJ: dot at IJA.s + (0.166, +0.06) invis
     spline thin from IJI     \
        to IJB.w + (-0.05, 0) \
        to IJJ                \
        to IJJ                \
        to IJA.e + (+0.05, 0) \
        to IJI                \
        close fill firebrick
     circle at IJA
     circle at IJB
     dot at IJI color green
     dot at IJJ color green

(The green dots are merely to show where the IJI and IJJ reference points are, for sanity-checking.)

There are several problems:

  1. The current implementation of splines don't necessarily run through the points specified, but instead bypass them by some distance. This is a valid definition of "spline", but not the only one.

  2. I had to double the "to IJJ" bit to avoid a teardrop shape. This shows a nonideality in the language, where the starting point is treated differently than the others, resulting in a cusp at IJI but rounded shapes everywhere else.

  3. The current implementation misinterprets "spline invis fill red". Instead of a red-filled no-border spline, it becomes wholly invisible.

    (That's part of the reason why the inner section bulges: you're seeing overlapping border lines due to my need to settle for "thin".)

The hard-coded constants are merely due to my atrophied trig-fu. I really should have expressed them using expressions of the form "at A + (sin(X), cos(Y))", pinning the four key points using references to existing geometry: what I'm calling IJI and IJJ, plus the intermediate points at the "waist" of the inner piece.

(What do you call that inner shape, anyway? A half-rounded diamond? A double-ended teardrop? A supersonic airfoil?)

Rather than change the current definition of "spline", there are a number of ways we can provide for cases like this:

  • Per the OP's other thread, define "arc" to do what we want here. The command will need to be extended to allow a multi-point arc, because currently, "arc from A to B to C" is a syntax error at the third point.
  • Add a "thru" alternative to "to" which forces the path thru that point, rather than merely near it.

(6) By sam atman (mnemnion) on 2026-06-04 01:38:53 in reply to 3.1 [link] [source]

I know I'm late to the party here, but in the spirit of adding a few breadcrumbs to the trail:

The current implementation misinterprets "spline invis fill red". Instead of a red-filled no-border spline, it becomes wholly invisible.

That is what invis is supposed to do, it makes the object disappear. What you want is "spline color none fill red":

A B
IJA: circle invisible "A" bold fill white
IJB: circle invisible "B" bold fill white at IJA + (0.33, 0)
IJI: dot at IJA.n + (0.166, -0.06) invis
IJJ: dot at IJA.s + (0.166, +0.06) invis
     spline from IJI     \
        to IJB.w + (-0.05, 0) \
        to IJJ                \
        to IJJ                \
        to IJA.e + (+0.05, 0) \
        to IJI                \
        close color none fill firebrick
     circle at IJA
     circle at IJB
     dot at IJI color green
     dot at IJJ color green

(4.2) By Warren Young (wyoung) on 2022-11-13 09:42:05 edited from 4.1 in reply to 1.1 [link] [source]

Here's all the easy cases:

A B B A A B A B B A
VENNS: [
    /* RIGHT JOIN */
    RJA:  circle "A" bold fill white
    RJB:  circle "B" bold fill firebrick at RJA + (0.33, 0)
          circle at RJA

    /* LEFT JOIN */
    LJB:  circle "B" bold at RJB.s + (0, -0.4) fill white
    LJA:  circle "A" bold at RJA.s + (0, -0.4) fill firebrick
          circle at LJB

    /* OUTER JOIN */
    OJA:  circle "A" bold fill firebrick at LJA.s + (0, -0.4)
    OJB:  circle "B" bold fill firebrick at OJA + (0.33, 0)
          circle at OJA

    /* LEFT EXCLUDING JOIN */
    LEJA: circle "A" bold fill firebrick at OJA.s + (0, -0.4)
    LEJB: circle "B" bold fill white at OJB.s + (0, -0.4)
          circle at LEJA

    /* RIGHT EXCLUDING JOIN */
    REJB: circle "B" bold fill firebrick at LEJB.s + (0, -0.4)
    REJA: circle "A" bold fill white at LEJA.s + (0, -0.4)
          circle at REJB
]

box thin rad 0.03 fill lightgray \
    width VENNS.width+0.2 \
    height VENNS.height+0.2 \
    at VENNS.c behind VENNS

Click it to see the code and the comments. With the exception of the first two, they're in the same order as in the article because it was more convenient to draw them in this order. (You have to play games with the "behind" attribute to draw LEFT JOIN first.)

You have my partial attempt at INNER JOIN in post 3 above. The "OUTER excluding JOIN" diagram from your referenced page is missing for the same essential reason.

(5) By emacsbliss on 2022-11-18 21:58:24 in reply to 4.2 [link] [source]

awesome, thanks so much!!