From 5b471951b6e269cc29f3b23148944ba3bc1c9e6c Mon Sep 17 00:00:00 2001 From: franck cuny Date: Sat, 21 May 2011 16:33:56 +0200 Subject: udpate roles for viz Signed-off-by: franck cuny --- lib/Graph/GEXF/Role/Viz/Color.pm | 20 +++++++++++++++++--- lib/Graph/GEXF/Role/Viz/Shape.pm | 11 ++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/lib/Graph/GEXF/Role/Viz/Color.pm b/lib/Graph/GEXF/Role/Viz/Color.pm index 166186f..e168ad1 100644 --- a/lib/Graph/GEXF/Role/Viz/Color.pm +++ b/lib/Graph/GEXF/Role/Viz/Color.pm @@ -3,14 +3,28 @@ package Graph::GEXF::Role::Viz::Color; use Moose::Role; use Moose::Util::TypeConstraints; -subtype RGBColor => as 'Int' => where { $_ >= 0 && $_ <= 255 }; +subtype RGBColor => as 'Num' => where { $_ >= 0 && $_ <= 255 }; +subtype Alpha => as 'Num' => where { $_ > 0 and $_ <= 1 }; + +my $_has_colors = 0; has [qw/r g b/] => ( - is => 'rw', - isa => 'RGBColor', + is => 'rw', + isa => 'RGBColor', + default => 0, + trigger => sub {$_has_colors++}, +); + +has a => ( + is => 'rw', + isa => 'Alpha', + default => 1, ); +sub has_colors { $_has_colors } + no Moose::Util::TypeConstraints; no Moose::Role; + 1; diff --git a/lib/Graph/GEXF/Role/Viz/Shape.pm b/lib/Graph/GEXF/Role/Viz/Shape.pm index f522786..f8e57de 100644 --- a/lib/Graph/GEXF/Role/Viz/Shape.pm +++ b/lib/Graph/GEXF/Role/Viz/Shape.pm @@ -14,7 +14,16 @@ parameter for => ( role { my $p = shift; - my $type = lcfirst( $p->for ) . 'Shape'; + my ( $type, $default ); + + $type = lcfirst( $p->for ) . 'Shape'; + + if ( $p->for eq 'node' ) { + $default = 'disc'; + } + else { + $default = 'solid'; + } has shape => ( is => 'rw', -- cgit 1.4.1