1# Annotation: Deeply nested records using nested array-refs.
2
3use strict;
4use warnings;
5use File::Spec;
6use GraphViz2;
7
8my $id    = '3';
9my $graph = GraphViz2->new(
10	global => {directed => 1, combine_node_and_port => 0, record_shape => 'record'},
11	graph  => {
12          label => "Record demo $id - Deeply nested records " .
13            "using nested array-refs"
14        },
15);
16
17$graph->add_node(name => 'Alphabet', label => [
18  { port => 'port_a', text => 'a:port_a' },
19  [
20    { port => 'port_b', text => 'b:port_b' },
21    'c',
22    [
23      { port => 'port_d', text => 'd:port_d' },
24      'e',
25      'f',
26      [
27        'g',
28        { port => 'port_h', text => 'h:port_h' },
29        'i',
30        'j',
31        [
32          'k',
33          'l',
34          'm',
35          { port => 'port_n', text => 'n:port_n' },
36          'o',
37          'p',
38        ],
39        'q',
40        'r',
41        { port => 'port_s', text => 's:port_s' },
42        't',
43      ],
44      'u',
45      'v',
46      { port => 'port_w', text => 'w:port_w' },
47    ],
48    'x',
49    { port => 'port_y', text => 'y:port_y' },
50  ],
51  'z',
52]);
53
54$graph -> add_edge(
55  from => 'Alphabet', tailport => 'port_a', to => 'Alphabet', headport => 'port_n', color => 'maroon',
56);
57$graph -> add_edge(
58  from => 'Alphabet', tailport => 'port_b', to => 'Alphabet', headport => 'port_s', color => 'blue',
59);
60$graph -> add_edge(
61  from => 'Alphabet', tailport => 'port_d', to => 'Alphabet', headport => 'port_w', color => 'red',
62);
63$graph -> add_edge(
64  from => 'Alphabet', tailport => 'port_y', to => 'Alphabet', headport => 'port_h', color => 'green',
65);
66
67if (@ARGV) {
68  my($format)      = shift || 'svg';
69  my($output_file) = shift || File::Spec -> catfile('html', "record.$id.$format");
70  $graph -> run(format => $format, output_file => $output_file);
71} else {
72  # run as a test
73  require Test::More;
74  require Test::Snapshot;
75  Test::Snapshot::is_deeply_snapshot($graph->dot_input, 'dot file');
76  Test::More::done_testing();
77}
78