line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Tk::GraphItems::LabeledConnector; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
Tk::GraphItems::LabeledConnector - Display edges of relation-graphs on a Tk::Canvas |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Tk::GraphItems::TextBox; |
12
|
|
|
|
|
|
|
require Tk::GraphItems::LabeledConnector; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my $conn = Tk::GraphItems::LabeledConnector->new( |
16
|
|
|
|
|
|
|
source => $a_TextBox, |
17
|
|
|
|
|
|
|
target => $another_TextBox, |
18
|
|
|
|
|
|
|
label => 'labeltext' |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
$conn->colour( 'red' ); |
21
|
|
|
|
|
|
|
$conn->arrow( 'both' ); |
22
|
|
|
|
|
|
|
$conn->width( 2 ); |
23
|
|
|
|
|
|
|
$conn->detach; |
24
|
|
|
|
|
|
|
$conn = undef; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Tk::GraphItems::LabeledConnector extends Tk::GraphItems::Connector with a 'label' option. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 METHODS |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
B supports the following additional methods: |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=over 4 |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=item B source => $a_GraphItems-Node, |
41
|
|
|
|
|
|
|
target => $a_GraphItems-NodeB, |
42
|
|
|
|
|
|
|
label => 'label text' |
43
|
|
|
|
|
|
|
colour => $a_TkColour, |
44
|
|
|
|
|
|
|
width => $width_pixels, |
45
|
|
|
|
|
|
|
arrow => $where, |
46
|
|
|
|
|
|
|
autodestroy => $bool<)> |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Create a new LabeledConnector instance and display it on the Canvas of 'source' and 'target'. See Tk::GraphItems::Connector for details. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=item B |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Sets the labels text to $labeltext, if the argument is given. Returns the current label, if called without an argument. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=back |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SEE ALSO |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Documentation of Tk::GraphItems::Connector |
62
|
|
|
|
|
|
|
Documentation of Tk::GraphItems::TextBox |
63
|
|
|
|
|
|
|
Examples in Tk/GraphItems/Examples |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 AUTHOR |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
Christoph Lamprecht, ch.l.ngre@online.de |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Copyright (C) 2008 by Christoph Lamprecht |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
74
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.7 or, |
75
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=cut |
79
|
1
|
|
|
1
|
|
23
|
use 5.008; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
125
|
|
80
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
1
|
|
|
1
|
|
7
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
29
|
|
84
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
34
|
|
85
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
719
|
|
86
|
|
|
|
|
|
|
require Tk::GraphItems::Connector; |
87
|
|
|
|
|
|
|
our @ISA = ('Tk::GraphItems::Connector'); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub initialize{ |
90
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
my %args = @_; |
92
|
0
|
|
0
|
|
|
|
my $labeltext = delete ($args{label}) || ''; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
my $can = $args{source}->get_canvas; |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
eval{$self->{label_id} = $can->createText(10,10, |
|
0
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
-text => $labeltext, |
98
|
|
|
|
|
|
|
-anchor => 'w')}; |
99
|
0
|
0
|
|
|
|
|
if ($@) { |
100
|
0
|
|
|
|
|
|
croak "Connector creation failed: $@"; |
101
|
|
|
|
|
|
|
} |
102
|
0
|
|
|
|
|
|
$self->SUPER::initialize(%args); |
103
|
0
|
|
|
|
|
|
$self->adjust_label; |
104
|
0
|
|
|
|
|
|
return $self; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub label{ |
108
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
109
|
0
|
|
|
|
|
|
my $can = $self->get_canvas; |
110
|
0
|
0
|
|
|
|
|
if (@_) { |
111
|
0
|
|
|
|
|
|
$can->itemconfigure($self->{label_id},-text=>$_[0]); |
112
|
0
|
|
|
|
|
|
return $self; |
113
|
|
|
|
|
|
|
} else { |
114
|
0
|
|
|
|
|
|
return $can->itemcget($self->{label_id},'-text'); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub set_coords{ |
119
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
120
|
0
|
|
|
|
|
|
$self->SUPER::set_coords(@_); |
121
|
0
|
|
|
|
|
|
$self->adjust_label; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
sub adjust_label{ |
125
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
my $can = $self->{canvas}; |
127
|
0
|
|
|
|
|
|
my $line = $self->{line_id}; |
128
|
0
|
|
|
|
|
|
my $label_id = $self->{label_id}; |
129
|
0
|
|
|
|
|
|
my @coords = $can->coords($line); |
130
|
0
|
|
|
|
|
|
my $d_x = $coords[2] - $coords[0]; |
131
|
0
|
|
|
|
|
|
my $d_y = $coords[3] - $coords[1]; |
132
|
0
|
|
|
|
|
|
my $center_x = ($coords[0] + $coords[2])/ 2; |
133
|
0
|
|
|
|
|
|
my $center_y = ($coords[1] + $coords[3])/ 2; |
134
|
0
|
|
0
|
|
|
|
my $term = $d_x **2 /( ($d_x **2 + $d_y**2)|| 0.0001); |
135
|
0
|
|
|
|
|
|
my $xo = sqrt(1 - $term); |
136
|
0
|
|
|
|
|
|
my $yo = sqrt($term); |
137
|
0
|
|
|
|
|
|
my $label_x ; |
138
|
|
|
|
|
|
|
my $label_y ; |
139
|
0
|
|
|
|
|
|
my $delta = 10; |
140
|
0
|
0
|
0
|
|
|
|
if ($d_x <= 0 && $d_y <= 0){ |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
|
|
0
|
0
|
|
|
|
|
141
|
0
|
|
|
|
|
|
$label_x = $center_x + $delta * $xo; |
142
|
0
|
|
|
|
|
|
$label_y = $center_y - $delta * $yo; |
143
|
|
|
|
|
|
|
#print "1\n"; |
144
|
|
|
|
|
|
|
}elsif($d_x <= 0 && $d_y >= 0){ |
145
|
0
|
|
|
|
|
|
$label_x = $center_x + $delta * $xo; |
146
|
0
|
|
|
|
|
|
$label_y = $center_y + $delta * $yo; |
147
|
|
|
|
|
|
|
#print "2\n"; |
148
|
|
|
|
|
|
|
}elsif($d_x >= 0 && $d_y >= 0){ |
149
|
0
|
|
|
|
|
|
$label_x = $center_x + $delta * $xo; |
150
|
0
|
|
|
|
|
|
$label_y = $center_y - $delta * $yo; |
151
|
|
|
|
|
|
|
#print "3\n"; |
152
|
|
|
|
|
|
|
}elsif($d_x >= 0 && $d_y <= 0){ |
153
|
0
|
|
|
|
|
|
$label_x = $center_x + $delta * $xo; |
154
|
0
|
|
|
|
|
|
$label_y = $center_y + $delta * $yo; |
155
|
|
|
|
|
|
|
#print "4\n"; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
$can->coords($label_id, |
159
|
|
|
|
|
|
|
$label_x, |
160
|
|
|
|
|
|
|
$label_y, |
161
|
|
|
|
|
|
|
); |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub canvas_items{ |
167
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
168
|
0
|
|
|
|
|
|
my @c_i = ($self->SUPER::canvas_items); |
169
|
0
|
0
|
|
|
|
|
push @c_i, $self->{label_id} if $self->{label_id}; |
170
|
0
|
|
|
|
|
|
return @c_i; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
1; |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
__END__ |