From a4c04c63dfef4705d7e02e257b5628c3a7f4fcfb Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 6 Feb 2006 22:40:07 +0000 Subject: [PATCH] Add support for edge styles, and use it for edge weight --- NEWS | 4 ++++ graph-includes | 5 ++++- lib/DEPS/Style/Edge/WeightLabel.pm | 41 ++++++++++++++++++++++++++++++++++++++ lib/graphincludes/renderer/dot.pm | 31 ++++++++++++++++++---------- 4 files changed, 70 insertions(+), 11 deletions(-) create mode 100644 lib/DEPS/Style/Edge/WeightLabel.pm diff --git a/NEWS b/NEWS index edf57c1..197d999 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,10 @@ Version 0.13 - UNRELEASED * New node style attributes "label" and "extralabel" for the dot renderer. + * Added support for edge styling, and support for "label" attribute + in the dot renderer. New WeightLabel edge styler to replace old + ad-hoc code. + * Class moves and renames: transforms, styles. ================================================== diff --git a/graph-includes b/graph-includes index a3a050d..9cc8ccf 100644 --- a/graph-includes +++ b/graph-includes @@ -210,9 +210,12 @@ foreach my $colspec (@colspecs) { } } -# number of ingredients in nodes +# number of ingredients and intra edges in nodes use DEPS::Style::Node::GroupStats; push @nodestylers, new DEPS::Style::Node::GroupStats(); +# number of ingredients in edges +use DEPS::Style::Edge::WeightLabel; +push @edgestylers, new DEPS::Style::Edge::WeightLabel(); our $stat_nfiles = scalar $project->{ROOTGRAPH}->get_nodes; # NOTE: $stat_nedges below is a cut'n'paste of $stat_ndeps diff --git a/lib/DEPS/Style/Edge/WeightLabel.pm b/lib/DEPS/Style/Edge/WeightLabel.pm new file mode 100644 index 0000000..1c35e05 --- /dev/null +++ b/lib/DEPS/Style/Edge/WeightLabel.pm @@ -0,0 +1,41 @@ +# This file is part of the DEPS/graph-includes package +# +# (c) 2006 Yann Dirson +# Distributed under version 2 of the GNU GPL. + +package DEPS::Style::Edge::WeightLabel; + +use warnings; +use strict; + +use base qw(DEPS::Style); +use Hash::Util qw(lock_keys unlock_keys); +use Carp qw(croak); + +sub new { + my $class = shift; + my $self = $class->SUPER::new([], [], + @_); + + unlock_keys (%$self); + bless ($self, $class); + lock_keys (%$self); + return $self; +} + +# FIXME: should be able to specify the level relative to which counting is done + +sub apply { + my $self = shift; + my ($edge, $graphnode, $style) = @_; + + my $nedges = $edge->weight; + # FIXME: be more friendly + print STDERR "Warning; overriding label from DEPS::Style::Edge::WeightLabel" + if defined $style->{label}; + $style->{label} = "[$nedges]"; + + return $style; +} + +1; diff --git a/lib/graphincludes/renderer/dot.pm b/lib/graphincludes/renderer/dot.pm index 7fd81c7..45cc79f 100644 --- a/lib/graphincludes/renderer/dot.pm +++ b/lib/graphincludes/renderer/dot.pm @@ -75,7 +75,7 @@ sub _node_stylestring { } elsif ($key eq 'bordercolor') { push @attrs, 'color='.$style->{$key}; } else { - print STDERR "Warning: graphincludes::renderer::dot does not support attribute '$key'\n"; + print STDERR "Warning: graphincludes::renderer::dot does not support attribute '$key' for nodes\n"; } } unshift @attrs, "label=\"$label\""; @@ -83,6 +83,20 @@ sub _node_stylestring { join ',', @attrs; } +sub _edge_stylestring { + my ($node, $style) = @_; + my @attrs; + foreach my $key (keys %$style) { + if ($key eq 'label') { + push @attrs, "label=\".$style->{$key}\""; + } else { + print STDERR "Warning: graphincludes::renderer::dot does not support style attribute '$key' for edges\n"; + } + } + + join ',', @attrs; +} + sub printgraph { my $self = shift; my ($graphnode, $nodestylers, $edgestylers) = @_; @@ -109,15 +123,12 @@ sub printgraph { } foreach my $file ($graph->get_edge_origins) { - foreach my $dest ($graph->get_dep_names_from($file)) { - print "\"$file\" -> \"$dest\""; - my $special = { label => [] }; # $project->special_edge($file, $dest); - # special handling for label, as array - push @{$special->{label}}, '[' . $graph->get_edge_weight($file, $dest) . ']'; - $special->{label} = join '\n', @{$special->{label}}; - # - print " [", join (',', map {$_ . '="' . $special->{$_} . '"'} keys %$special), "]" if defined $special; - print ";\n"; + foreach my $edge ($graph->get_edges_from($file)) { + my $style = {}; + foreach my $styler (@$edgestylers) { + $styler->apply($edge, $graphnode, $style); + } + print "\"$file\" -> \"$edge->{DST}{LABEL}\" [", _edge_stylestring($edge, $style), "]\n"; } } -- 2.11.4.GIT