in reply to Drawing venn diagrams

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.

#!/usr/bin/perl use warnings; use strict; use Tk; my $mw = MainWindow->new(); # first create a canvas widget my $canvas = $mw->Canvas(width => 300, height => 200)->pack(); my $one = $canvas->createOval(55, 20, 200, 190, -fill => 'blue', -outline=>'blue', -tags => ['blue'], ); my $two = $canvas->createOval(105, 20, 250, 190, -fill => 'red', -outline=>'red', -tags => ['red'], ); my $ebutton = $mw->Button(-text => 'Exit', -command => 'Tk::exit')->pack(); $canvas->Tk::bind("<Motion>", [ \&print_xy, Ev('x'), Ev('y') ]); MainLoop(); sub print_xy { my ($canv, $x, $y) = @_; #trick to simulate a 1 point rectangular area my (@current) = $canvas->find('overlapping', $x, $y, $x, $y); foreach my $id(@current){ print $canvas->gettags($id),' '; } print "\n"; } __END__

So a way to get around this, in Tk, is to use a transparent stipple. This is still clunky compared to semi-transparency allowed in Zinc or perl-gtk. I thru in a balloon too, to make it seem like a party. :-)

#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::CanvasBalloon; # the -stipple=>'transparent' option will still # allow the bindings to work, but you can see the overlap # See Chapter 17 of Mastering Perl/Tk my $mw = MainWindow->new(); # first create a canvas widget my $canvas = $mw->Canvas(width => 300, height => 200)->pack(); #create a balloon my $msg = ''; my $balloon = $mw->CanvasBalloon( -initwait => 0, ); my $one = $canvas->createOval(55, 20, 200, 190, -fill => 'blue', -outline=>'blue', -tags => ['blue'], -stipple => 'transparent', ); my $two = $canvas->createOval(105, 20, 250, 190, -fill => 'red', -outline=>'red', -tags => ['red'], -stipple => 'transparent', ); $balloon->attach($canvas, ['blue','red'], -balloonmsg => $msg, ); my $ebutton = $mw->Button(-text => 'Exit', -command => 'Tk::exit')->pack(); $canvas->Tk::bind("<Motion>", [ \&print_xy, Ev('x'), Ev('y') ]); MainLoop(); sub print_xy { my ($canv, $x, $y) = @_; my @tags =(); #trick to find overlapping objects, just use x1 = x and y1 = y #to get a rectangular region of 1 point my (@current) = $canvas->find('overlapping', $x, $y, $x, $y); foreach my $id(@current){ push @tags, $canvas->gettags($id); } $msg = join ' ', @tags; $balloon->Popup($msg); } __END__

I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: Drawing venn diagrams
by thor (Priest) on Oct 25, 2005 at 15:03 UTC
    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