| 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<Tk::GraphItems::LabeledConnector> supports the following additional methods: | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | =over 4 | ||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||
| 40 | =item B<new(> 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<label(> [$labeltext] 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 | 2 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | our $VERSION = '0.12'; | |||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 85 | 2 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | require Tk::GraphItems::Connector; | |||||||||||||||||||||||||||||||||||||||
| 87 | 2 | our @ISA = ('Tk::GraphItems::Connector'); | |||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | sub initialize{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
initialize: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 91 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $labeltext = delete ($args{label}) || ''; | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
delete $args{'label'} || ''
MC/DC0%0/1
delete $args{'label'} || ''
delete $args{'label'}
Truth table0%0/2
A
A= delete $args{'label'}
| |||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | my $can = $args{source}->get_canvas; | |||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | eval{$self->{label_id} = $can->createText(10,10, | |||||||||||||||||||||||||||||||||||||||
| 97 | -text => $labeltext, | ||||||||||||||||||||||||||||||||||||||||
| 98 | -anchor => 'w')}; | ||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub label{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
label: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $can = $self->get_canvas; | |||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub set_coords{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_coords: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 120 | 0 | $self->SUPER::set_coords(@_); | |||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->adjust_label; | |||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | sub adjust_label{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
adjust_label: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 125 | 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 | ▶ | my $term = $d_x **2 /( ($d_x **2 + $d_y**2)|| 0.0001); | ||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$d_x ** 2 + $d_y ** 2 || 0.0001
MC/DC0%0/1
$d_x ** 2 + $d_y ** 2 || 0.0001
$d_x ** 2 + $d_y ** 2
Truth table0%0/2
A
A= $d_x ** 2 + $d_y ** 2
| |||||||||||||||||||||||||||||||||||||||||
| 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 | ▶ | if ($d_x <= 0 && $d_y <= 0){ | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
$d_x <= 0 and $d_y <= 0
MC/DC0%0/2
$d_x <= 0 and $d_y <= 0
$d_x <= 0
$d_y <= 0
Truth table0%0/3
A and B
A= $d_x <= 0B= $d_y <= 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){ | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$d_x <= 0 and $d_y >= 0
MC/DC0%0/2
$d_x <= 0 and $d_y >= 0
$d_x <= 0
$d_y >= 0
Truth table0%0/3
A and B
A= $d_x <= 0B= $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){ | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$d_x >= 0 and $d_y >= 0
MC/DC0%0/2
$d_x >= 0 and $d_y >= 0
$d_x >= 0
$d_y >= 0
Truth table0%0/3
A and B
A= $d_x >= 0B= $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){ | |||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$d_x >= 0 and $d_y <= 0
MC/DC0%0/2
$d_x >= 0 and $d_y <= 0
$d_x >= 0
$d_y <= 0
Truth table0%0/3
A and B
A= $d_x >= 0B= $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 | 0 | ▶ | sub canvas_items{ | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
canvas_items: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my @c_i = ($self->SUPER::canvas_items); | |||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | push @c_i, $self->{label_id} if $self->{label_id}; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return @c_i; | |||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||
| 178 | __END__ | ||||||||||||||||||||||||||||||||||||||||