Bug#737781: [PATCH 3/3] Provide a "graphviz" attribute for setting other attributes.

Ian Jackson ijackson at chiark.greenend.org.uk
Fri Feb 7 18:00:01 UTC 2014


Signed-off-by: Ian Jackson <ijackson at chiark.greenend.org.uk>
---
 lib/Graph/Writer/GraphViz.pm |   30 ++++++++++++++++++++++++++++--
 1 file changed, 28 insertions(+), 2 deletions(-)

diff --git a/lib/Graph/Writer/GraphViz.pm b/lib/Graph/Writer/GraphViz.pm
index 163f0c0..2767c21 100644
--- a/lib/Graph/Writer/GraphViz.pm
+++ b/lib/Graph/Writer/GraphViz.pm
@@ -71,6 +71,14 @@ sub graph2graphviz {
     return $r;
 }
 
+sub _strip_undefs ($) {
+    my ($param) = @_;
+    foreach my $key (keys %$param) {
+	next if defined $param->{$key};
+	delete $param->{$key};
+    }
+}
+
 sub add_edges {
     my ($self,$r,$g) = @_;
     my @e = $g->edges;
@@ -87,6 +95,10 @@ sub add_edges {
                 $param{$attr} = $w;
             }
         }
+	if($g->has_edge_attribute($a,$b,'graphviz')) {
+	    %param = (%param, %{ $g->get_edge_attribute($a,$b,'graphviz') });
+	    _strip_undefs(\%param);
+	}
 	$r->add_edge($a,$b,%param);
     }
 }
@@ -102,6 +114,10 @@ sub add_nodes {
                 $param{$attr} = $w;
             }
         }
+	if($g->has_vertex_attribute($_,'graphviz')) {
+	    %param = (%param, %{ $g->get_vertex_attribute($_,'graphviz') });
+	    _strip_undefs(\%param);
+	}
 	$r->add_node($_,%param) ;
     }
     return $r;
@@ -157,9 +173,19 @@ system, like, 'gif' if you have 'as_gif', 'text' if you can do
 
 =head1 VERTEX AND EDGE ATTRIBUTES
 
+If a Graph edge or vertex has an attribute named C<graphviz>, it
+should be a hashref whose names are Graphviz attribute names, and
+whose values are the values to be used.
+
 Certain Graph vertex and edge attributes are automatically transferred
-to GraphViz.  For vertices these are: style shape label color
-fillcolor rank cluster; for edges these are: style label color.
+to GraphViz, without them being included in the C<graphviz> attribute.
+For vertices these are: style shape label color fillcolor rank
+cluster; for edges these are: style label color.  Values in the
+C<graphviz> attribute override ones straight out of the vertex or edge
+attribute namespace.
+
+Entries in the C<graphviz> vertex attribute with the value undef
+suppress those graphiviz attributes.
 
 =head1 SEE ALSO
 
-- 
1.7.10.4



More information about the pkg-perl-maintainers mailing list