sandrider has asked for the wisdom of the Perl Monks concerning the following question:

Hi, I was wondering if it was possible to draw clickable venn diagrams in perl. Thanks.

Replies are listed 'Best First'.
Re: Drawing venn diagrams
by zentara (Cardinal) on Oct 24, 2005 at 13:50 UTC
    It depends what you want to do with the Venn diagram. The hard part will be detecting the overlapping region, because object tags have priority, and if your mouse is above an intersection, only the topmost (high priority object) will be seen.

    If you just want to make visualizations, and not worry about computing whether a point is in an overlapping area, you will probably want to use some sort of transparency. Tk is not very good at transparent objects, but there is an example in the "widget" demo. Tk::Zinc does a better job of transparency, and examples are in the #7 in the OpenGL section of the zinc-demo.

    I did notice in the Gnome2-Canvas-1.002 ( the very latest Perl-gtk2 ) demo, that they have transparency. If you run canvas.pl look for the beige oval, and drag it around. You can see through the color transparency. It could be the basis of pretty nice Venn diagram.


    I'm not really a human, but I play one on earth. flash japh
Re: Drawing venn diagrams
by blazar (Canon) on Oct 24, 2005 at 08:24 UTC
    "Draw", "cliccable"? Give us some context, man! Are you talking 'bout some GUI? Web environment? A hint, a clue...
      I want a venn diagram that is in jpg format so i can use it to show some results over the web
Re: Drawing venn diagrams
by zentara (Cardinal) on Oct 25, 2005 at 13:29 UTC
    This kind of interested me for my example snippet collection, so here are a couple of Tk Venn diagrams, which demonstrate some of the problems you will need to overcome.

    First, is an example where the colors obscure one another. You need the -fill option, in order for the mouse bindings to work.


    I'm not really a human, but I play one on earth. flash japh
      I thru (sic) in a balloon too, to make it seem like a party. :-)
      Hmm...about the balloon. I can't seem to find the Tk::CanvasBalloon module. When I try to run your code, I get "Can't find module...". I thought "hmm...must not have it installed", so I fired up cpanp to pull it down. No dice there, either. Is it part of some larger distribution or something?

      thor

      Feel the white light, the light within
      Be your own disciple, fan the sparks of will
      For all of us waiting, your kingdom will come

        Yeah, it's one of eserte's(Slaven Rezsic) modules. Its at CanvasBalloon It makes balloons easier on a Canvas.

        I'm not really a human, but I play one on earth. flash japh
Re: Drawing venn diagrams
by Anonymous Monk on Oct 24, 2005 at 06:36 UTC

    Yes.

    As almost anything else, you can do it in Perl.

Re: Drawing venn diagrams
by zentara (Cardinal) on Oct 26, 2005 at 21:29 UTC
    Well to "round out the selection", here is a Zinc example.

    I'm not really a human, but I play one on earth. flash japh
Re: Drawing venn diagrams
by zentara (Cardinal) on Oct 25, 2005 at 20:20 UTC
    Well I also ripped apart the Gnome-Canvas2 demo, to show how nice it can work on Perl-Gtk2. You may need the latest Perl/Gtk2 for this to work, it's what I used. It is draggable, uses the anti-aliased canvas, zoom, and has semi-transparency. I still don't see how the transparency works, it just does. If anyone can enlighten me, please do.

    I'm not really a human, but I play one on earth. flash japh
      Just in case anyone is looking for answers, here is how the transpparency works in Gtk2. It is from 'muppet', the Perl/Gtk2 master.

      Return-path: <scott@asofyet.org> > I can manipulate the "fill_color_rgba" hex number to > give me a few different semi-transparent ellipses, but > can anyone explain how the hex numbering actually works to > produce the semi-transparent effect? The RGBA numbers are 32-bit values composed of one-byte-per-channel for red, green, blue, and alpha (0xrrggbbaa). The alpha value is the "opacity", and this is used to describe how much of the source color is blended with the destination color to create the output color according to this formula: alpha_pct = alpha / 255.0 destination red' = source red * alpha_pct + dest red * (1.0 - alpha_pct) destination green' = source green * alpha_pct + dest green * (1.0 - alpha_pct) destination blue' = source blue * alpha_pct + dest blue * (1.0 - alpha_pct) An alpha value of 0xff is 255, which is 100% of the source color, which is a traditional "source-copy" operation. An alpha value of 25% means the output color is composed of 25% of the source color and 75% of the color already existing at the destination. The actual color you'll get as a result of the opacity value, therefore, depends on what you're blending it with. On a light background, a lower opacity makes the color lighter, on a dark background, a lower opacity makes the color darker, over red it gets redder, etc. This is implemented using client-side blitting of microtiles in libart. To get proper alpha blending, you need full-resolution color data, so it must be done on 24-bit RGB values -- dithered colors don't work --- so it happens on the client side, using XPutImage to transfer the full RGB to the X server. > The canvas demo, is set up, to allow you to choose a normal > (not anti-aliased) example, which does it on the basis of using a > stiple. > It's alot uglier, but it is always how I thought it was done, > coming from > Tk. Stippling is a form of halftoning, which is how you approximate colors on a device that can't actually reproduce them. By having a stipple pattern that displays every other dot, you get effectively 50% of the input color, and the background shows through. No alpha blending occurs --- it's the equivalent of alpha=100%. And, yes, this is uglier than alpha blending, but tends to be much faster, as it can be performed on the X server. The Tk canvas pretty much predates widespread use of alpha blending; old hardware had a hard time with it, because it requires keeping full-color copies of the various components to be blended. As an aside, cairo does everything in an alpha space, and is much more efficient at it than libart. Part of the big fuss about the new compositing-based X servers is that they can do alpha blending on the server side.

      I'm not really a human, but I play one on earth. flash japh
A reply falls below the community's threshold of quality. You may see it by logging in.