# Class "Plot": constructor, methods, destructor, global class data,
# Because a Plot object is a composite widget all the Composite base
# class methods and advertised widgets are available to you.
# Advertised Plot widgets: canvas, entry, PostScript_button, view_button.
use vars qw
/$VERSION @ISA/;
$VERSION = '3.013'; # $Id: //depot/Tk8/demos/demos/widget_lib/Plot.pm#13 $
Construct Tk
::Widget
'Plot';
# -title_color => 'Brown',
# -inactive_highlight => 'Skyblue2',
# -active_highlight => 'red',
# Plot composite widget constructor.
$cw->SUPER::Populate
($args);
delete $args->{-title_color
},
delete $args->{-inactive_highlight
},
delete $args->{-active_highlight
},
my %pinfo; # plot information hash
my $plot_font = '-*-Helvetica-Medium-R-Normal--*-180-*-*-*-*-*-*';
-cursor
=> 'top_left_arrow',
$cw->Advertise('canvas' => $c);
$c->pack(-side
=> 'top', -fill
=> 'x');
$c->createLine(100, 250, 400, 250, -width
=> 2);
$c->createLine(100, 250, 100, 50, -width
=> 2);
$c->createText(225, 20, -text
=> 'A Simple Plot', -font
=> $plot_font,
my($i, $x, $y, $point, $item);
for($i = 0; $i <= 10; $i++) {
$c->createLine($x, 250, $x, 245, -width
=> 2);
$c->createText($x, 254, -text
=> 10 * $i, -anchor
=> 'n',
for ($i = 0; $i <= 5; $i++) {
$c->createLine(100, $y, 105, $y, -width
=> 2);
$c->createText(96, $y, -text
=> $i * 50.0, -anchor
=> 'e',
foreach $point ([12, 56], [20, 94], [33, 98], [32, 120], [61, 180],
$x = 100 + (3 * ${$point}[0]);
$y = 250 - (4 * ${$point}[1]) / 5;
$item = $c->createOval($x-6, $y-6, $x+6, $y+6, -width
=> 1,
-outline
=> 'black', -fill
=> $ih);
$c->addtag('point', 'withtag', $item);
$c->bind('point', '<Any-Enter>' => [sub{shift->itemconfigure(@_)},
'current', -fill
=> $ah]);
$c->bind('point', '<Any-Leave>' => [sub{shift->itemconfigure(@_)},
'current', -fill
=> $ih]);
$c->bind('point', '<1>' => [sub {plot_down
(@_)}, \
%pinfo]);
$c->bind('point', '<ButtonRelease-1>' => sub {shift->dtag('selected')});
$c->CanvasBind('<B1-Motion>' => [sub {plot_move
(@_)}, \
%pinfo]);
$c->CanvasBind('<2>' => [sub {area_down
(@_)}, \
%pinfo]);
$c->CanvasBind('<B2-Motion>' => [sub {area_move
(@_)}, \
%pinfo]);
my $w_prcmd = $cw->Entry(
-textvariable
=> \
$pinfo{'prcmd'},
$cw->Advertise('entry' => $w_prcmd);
my $w_print = $cw->Button(
-text
=> 'Print in PostScript Format',
-command
=> [\
&area_save
, $c, \
%pinfo],
$cw->Advertise('PostScript_button' => $w_print);
$w_prcmd->bind('<Return>' => [$w_print => 'invoke']);
my $w_view = $cw->Button(
-text
=> 'View Composite Plot Widget',
-command
=> [\
&::view_widget_code
,
Tk
->findINC('demos/widget_lib/Plot.pm'),
$cw->Advertise('view_button' => $w_view);
} # end Populate, Plot constructor
my($x, $y) = ($e->x, $e->y);
eval {local $SIG{'__DIE__'}; $w->delete('area');};
my($x, $y) = ($e->x, $e->y);
if($x != $pinfo->{'areaX1'} && $y != $pinfo->{'areaY1'}) {
eval {local $SIG{'__DIE__'}; $w->delete('area');};
$w->addtag('area','withtag',$w->createRectangle($pinfo->{'areaX1'},
$pinfo->{'areaY1'},$x,$y));
my($x1, $x2, $y1, $y2, $a);
if($pinfo->{'areaX2'} != -1) {
@
$pinfo{'areaX1', 'areaX2', 'areaY1', 'areaY2'}; # slice !
($x1, $x2) = @
$pinfo{'areaX2', 'areaX1'} if $x2 <= $x1;
($y1, $y2) = @
$pinfo{'areaY2', 'areaY1'} if $y2 <= $y1;
$a = $w->postscript('-x' => $x1, '-y' => $y1,
-width
=> $x2 - $x1, -height
=> $y2 - $y1);
open(LPR
, "| $pinfo->{'prcmd'}");
my($x, $y) = ($e->x, $e->y);
$w->addtag('selected', 'withtag', 'current');
my($x, $y) = ($e->x, $e->y);
$w->move('selected', $x-$pinfo->{'lastX'}, $y-$pinfo->{'lastY'});