Guest JuergenIch hab mir schon Canvas angeguggt - naja damit kann ich ja keinen Zeitstrahl zeichnen...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
#!/usr/bin/perl use strict; use warnings; use Tk; my $mw = tkinit( -title => 'timeline' ); my $c = $mw->Scrolled( Canvas => -scrollbars => 'soe', -width => 500, -height => 400, -background => 'white', )->pack( -fill => 'both', -expand => 1, )->Subwidget('scrolled'); my @data = ( time - 60 * 60 * 24 * 7 * 4, [ 'Anfang' ], time - 60 * 60 * 24 * 7 * 3, [ 'Termin', 'Termin 2' ], time - 60 * 60 * 24 * 7 * 2, [ 'Mitte' ], time - 60 * 60 * 24 * 7 * 1, [ 'Termin 3', 'Termin 4' ], time - 60 * 60 * 24 * 7 * 0, [ 'Ende' ], ); my $scrltop = $c->createTimeline( 0, 400, 500, 400, \@data, ); $c->configure( -scrollregion => [ -100, $scrltop-15, 600, 415 ] ); MainLoop; sub Tk::Canvas::createTimeline { my( $self, $x0, $y0, $x1, $y1, $data ) = @_; my $xstep = @$data > 2 ? ($x1 - $x0) / ($data->[-2] - $data->[0]) : die "Timeline: Not enough data specified!\n"; # create x-axe: $self->createLine( $x0, $y0, $x1, $y1, -fill => 'black', -arrow => 'last', ); my $scrltop = $y0; # plot data: for ( my $i = 0; $i < @$data; $i += 2 ) { my( $x, $y ) = @{$data}[$i,$i+1]; my $xpos = ($x - $data->[0]) * $xstep; # create x-axe-label: $self->createLine( $xpos, $y1, $xpos, $y1+3, -fill => 'black', ); $self->createText( $xpos, $y1+15 + ($i/2 % 2 ? 0 : 15), -anchor => 'center', -text => scalar localtime $x, -fill => 'black', ); # plot events: for ( my $j = 0; $j < @$y; $j++ ) { $self->createText( $xpos, $y1 - $j * 24 - ($i/2 % 2 ? 24 : 12), -anchor => 'center', -text => $y->[$j], -fill => 'black', ); } # for # update $scrltop: my $yh = $y1 - $#{$y} * 24 - ($i/2 % 2 ? 24 : 12); $scrltop = $yh if $yh < $scrltop; } # for # return top-coordinate: return $scrltop; } # Tk::Canva::createTimeline
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use strict; use Tk; use Tk::Canvas; my $mw = MainWindow->new(); # erstelle das canvas und einen pfeil mit der länge $length my $length = 300; my $canvas = $mw->Canvas(-bg => 'white')->pack(); $canvas->createLine( 0,200,$length,200, -arrowshape => [6,10,3], -width => 2, -arrow => 'last' ); fill($canvas); Tk::MainLoop(); sub fill{ my $widget = shift; my @dates = ([4,"Frisör"],[7,"Arzt"],[20,"Restaurant"]); my $unit = $length / 30; # teile die länge des zeitstrahles durch die anzahl der tage foreach my $date (@dates){ $widget->createText($unit*$date->[0],180, -text => $date->[1]); $widget->createText($unit*$date->[0],210, -text => $date->[0]); $widget->createLine($unit*$date->[0],190,$unit*$date->[0],200); } }