@ISA
=
qw/Graph::Easy::Node/
;
$VERSION
=
'0.76'
;
BEGIN
{
*get_attribute
= \
&attribute
;
}
GROUP_INNER
=> 0,
GROUP_RIGHT
=> 1,
GROUP_LEFT
=> 2,
GROUP_TOP
=> 3,
GROUP_BOTTOM
=> 4,
GROUP_ALL
=> 5,
GROUP_BOTTOM_RIGHT
=> 6,
GROUP_BOTTOM_LEFT
=> 7,
GROUP_TOP_RIGHT
=> 8,
GROUP_TOP_LEFT
=> 9,
GROUP_MAX
=> 5,
};
my
$border_styles
=
{
GROUP_INNER() => [ 0, 0, 0, 0, [
'gi'
] ],
GROUP_RIGHT() => [ 0, 0, 0, 1, [
'gr'
] ],
GROUP_LEFT() => [ 0, 0, 1, 0, [
'gl'
] ],
GROUP_TOP() => [ 1, 0, 0, 0, [
'gt'
] ],
GROUP_BOTTOM() => [ 0, 1, 0, 0, [
'gb'
] ],
GROUP_ALL() => [ 0, 0, 0, 0, [
'ga'
] ],
GROUP_BOTTOM_RIGHT() => [ 0, 1, 0, 1, [
'gb'
,
'gr'
] ],
GROUP_BOTTOM_LEFT() => [ 0, 1, 1, 0, [
'gb'
,
'gl'
] ],
GROUP_TOP_RIGHT() => [ 1, 0, 0, 1, [
'gt'
,
'gr'
] ],
GROUP_TOP_LEFT() => [ 1, 0, 1, 0, [
'gt'
,
'gl'
] ],
};
my
$border_name
= [
'top'
,
'bottom'
,
'left'
,
'right'
];
sub
_css
{
my
(
$c
,
$id
,
$group
,
$border
) =
@_
;
my
$css
=
''
;
for
my
$type
(0 .. 5)
{
my
$b
=
$border_styles
->{
$type
};
next
if
$border
eq
'none'
;
my
$cl
=
'.'
.
$b
->[4]->[0];
$css
.=
"table.graph$id $cl {"
;
if
(
$type
== GROUP_INNER)
{
$css
.=
" border: none;"
;
}
elsif
(
$type
== GROUP_ALL)
{
$css
.=
" border-style: $border;"
;
}
else
{
for
(
my
$i
= 0;
$i
< 4;
$i
++)
{
$css
.=
' border-'
.
$border_name
->[
$i
] .
"-style: $border;"
if
$b
->[
$i
];
}
}
$css
.=
"}\n"
;
}
$css
;
}
sub
_init
{
my
(
$self
,
$args
) =
@_
;
$self
->{class} =
'group'
;
$self
->{cell_class} =
' gi'
;
$self
->{name} =
''
;
$self
->{
'x'
} = 0;
$self
->{
'y'
} = 0;
foreach
my
$k
(
sort
keys
%$args
)
{
$self
->{
$k
} =
$args
->{
$k
};
}
if
(
defined
$self
->{group})
{
$self
->{group}->_add_cell (
$self
);
$self
->{class} =
$self
->{group}->{class};
$self
->{class} =
'group'
unless
defined
$self
->{class};
}
$self
;
}
sub
_set_type
{
my
(
$self
,
$cells
) =
@_
;
my
@coord
= (
[ 0, -1,
' gt'
],
[ +1, 0,
' gr'
],
[ 0, +1,
' gb'
],
[ -1, 0,
' gl'
],
);
my
(
$sx
,
$sy
) = (
$self
->{x},
$self
->{y});
my
$class
=
''
;
my
$gr
=
$self
->{group};
foreach
my
$co
(
@coord
)
{
my
(
$x
,
$y
,
$c
) =
@$co
;
$x
+=
$sx
;
$y
+=
$sy
;
my
$cell
=
$cells
->{
"$x,$y"
};
my
$go
= 0;
$go
=
$cell
->group()
if
UNIVERSAL::can(
$cell
,
'group'
);
$class
.=
$c
unless
defined
$go
&&
$gr
==
$go
;
}
$class
=
' ga'
if
$class
eq
' gt gr gb gl'
;
$self
->{cell_class} =
$class
;
$self
;
}
sub
_set_label
{
my
$self
=
shift
;
$self
->{has_label} = 1;
$self
->{name} =
$self
->{group}->label();
}
sub
shape
{
'rect'
;
}
sub
attribute
{
my
(
$self
,
$name
) =
@_
;
my
$group
=
$self
->{group};
return
$group
->{att}->{
$name
}
if
exists
$group
->{att}->{
$name
};
$group
->{cache} = {}
unless
exists
$group
->{cache};
$group
->{cache}->{att} = {}
unless
exists
$group
->{cache}->{att};
my
$cache
=
$group
->{cache}->{att};
return
$cache
->{
$name
}
if
exists
$cache
->{
$name
};
$cache
->{
$name
} =
$group
->attribute(
$name
);
}
sub
as_ascii
{
my
(
$self
,
$x
,
$y
) =
@_
;
my
$fb
=
$self
->_framebuffer(
$self
->{w},
$self
->{h});
my
$border_style
=
$self
->attribute(
'borderstyle'
);
my
$EM
= 14;
my
$border_width
= Graph::Easy::_border_width_in_pixels(
$self
,
$EM
);
$border_style
=
'bold'
if
$border_width
> 2;
$border_style
=
'broad'
if
$border_width
>
$EM
* 0.2 &&
$border_width
<
$EM
* 0.75;
$border_style
=
'wide'
if
$border_width
>=
$EM
* 0.75;
if
(
$border_style
ne
'none'
)
{
my
$c
=
$self
->{cell_class};
my
$b_top
=
$border_style
;
my
$b_left
=
$border_style
;
my
$b_right
=
$border_style
;
my
$b_bottom
=
$border_style
;
if
(
$c
!~
'ga'
)
{
$b_top
=
'none'
unless
$c
=~ /gt/;
$b_left
=
'none'
unless
$c
=~ /gl/;
$b_right
=
'none'
unless
$c
=~ /gr/;
$b_bottom
=
'none'
unless
$c
=~ /gb/;
}
$self
->_draw_border(
$fb
,
$b_right
,
$b_bottom
,
$b_left
,
$b_top
,
$x
,
$y
);
}
if
(
$self
->{has_label})
{
my
$align
=
$self
->attribute(
'align'
);
my
$ys
= 0.5;
$ys
= 0
if
$border_style
eq
'none'
;
my
$h
=
$self
->{h} - 1;
$h
++
if
$border_style
eq
'none'
;
$self
->_printfb_aligned (
$fb
, 0,
$ys
,
$self
->{w},
$h
,
$self
->_aligned_label(
$align
),
'middle'
);
}
join
(
"\n"
,
@$fb
);
}
sub
class
{
my
$self
=
shift
;
$self
->{class} .
$self
->{cell_class};
}
sub
_correct_size
{
my
(
$self
,
$format
) =
@_
;
if
(!
defined
$self
->{w})
{
my
$border
=
$self
->attribute(
'borderstyle'
);
$self
->{w} = 0;
$self
->{h} = 0;
$self
->{h} = 1
if
$self
->{has_label};
if
(
$border
ne
'none'
)
{
if
(
$self
->{has_label} || (
$self
->{cell_class} =~ /g[rltb] /))
{
$self
->{w} = 2;
$self
->{h} = 2;
}
elsif
(
$self
->{cell_class} =~ /^ g[rl]\z/)
{
$self
->{w} = 2;
}
elsif
(
$self
->{cell_class} =~ /^ g[bt]\z/)
{
$self
->{h} = 2;
}
}
}
if
(
$self
->{has_label})
{
my
(
$w
,
$h
) =
$self
->dimensions();
$self
->{h} +=
$h
;
$self
->{w} +=
$w
;
}
}
1;