Exemplo n.º 1
0
def test_documentationtools_GraphvizGraph_copy_06():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizSubgraph())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizSubgraph())
    graph[0][-1].append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    edge = documentationtools.GraphvizEdge().attach(graph[0][1], graph[1])
    edge = documentationtools.GraphvizEdge().attach(graph[0][0],
                                                    graph[0][-1][0])
    copied = copy.copy(graph[0])
    assert str(copied) == systemtools.TestManager.clean_string(r'''
        digraph cluster_ {
            node_0;
            node_1;
            node_2;
            subgraph cluster_3 {
                node_3_0;
            }
            node_0 -> node_3_0;
        }
        ''')
    assert copied.parent is None
def test_documentationtools_GraphvizGraph_pickle_05():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizSubgraph())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizSubgraph())
    graph[0][-1].append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    documentationtools.GraphvizEdge().attach(graph[0][1], graph[1])
    documentationtools.GraphvizEdge().attach(graph[0][0], graph[0][-1][0])
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            subgraph cluster_0 {
                node_0_0;
                node_0_1;
                node_0_2;
                subgraph cluster_0_3 {
                    node_0_3_0;
                }
                node_0_0 -> node_0_3_0;
            }
            node_1;
            node_0_1 -> node_1;
        }
        ''')
    pickled = pickle.loads(pickle.dumps(graph))
    assert str(graph) == str(pickled)
def test_documentationtools_GraphvizGraph_deepcopy_05():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizSubgraph())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizSubgraph())
    graph[0][-1].append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    edge = documentationtools.GraphvizEdge().attach(graph[0][1], graph[1])
    edge = documentationtools.GraphvizEdge().attach(graph[0][0],
                                                    graph[0][-1][0])
    assert str(graph) == systemtools.TestManager.clean_string(r'''
        digraph G {
            subgraph cluster_0 {
                node_0_0;
                node_0_1;
                node_0_2;
                subgraph cluster_0_3 {
                    node_0_3_0;
                }
                node_0_0 -> node_0_3_0;
            }
            node_1;
            node_0_1 -> node_1;
        }
        ''')
    copied = copy.deepcopy(graph)
    assert str(graph) == str(copied)
def test_documentationtools_GraphvizGraph_copy_05():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizSubgraph())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizNode())
    graph[0].append(documentationtools.GraphvizSubgraph())
    graph[0][-1].append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    documentationtools.GraphvizEdge().attach(graph[0][1], graph[1])
    documentationtools.GraphvizEdge().attach(graph[0][0], graph[0][-1][0])
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            subgraph cluster_0 {
                node_0_0;
                node_0_1;
                node_0_2;
                subgraph cluster_0_3 {
                    node_0_3_0;
                }
                node_0_0 -> node_0_3_0;
            }
            node_1;
            node_0_1 -> node_1;
        }
        ''')
    copied = copy.copy(graph)
    assert str(graph) == str(copied)
Exemplo n.º 5
0
    def attach(self, other):
        r'''Attaches node to attachable Graphviz object.

        ::

            >>> my_graph = documentationtools.GraphvizGraph()
            >>> node_one = documentationtools.GraphvizNode(attributes={'label': 'One'})
            >>> node_two = documentationtools.GraphvizNode(attributes={'label': 'Two'})
            >>> my_graph.extend([node_one, node_two])
            >>> edge = node_one.attach(node_two)
            >>> graph(my_graph)  # doctest: +SKIP

        ..  doctest::

            >>> print(str(my_graph))
            digraph G {
                node_0 [label=One];
                node_1 [label=Two];
                node_0 -> node_1;
            }

        Returns GraphvizEdge.
        '''
        from abjad.tools import documentationtools
        edge = documentationtools.GraphvizEdge()
        edge.attach(self, other)
        return edge
Exemplo n.º 6
0
    def graphviz_graph(self):
        r'''The GraphvizGraph representation of payload tree.

        ::

            >>> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
            >>> tree = datastructuretools.PayloadTree(sequence)

        ::

            >>> graph = tree.graphviz_graph
            >>> topleveltools.graph(graph) # doctest: +SKIP

        Returns graphviz graph.
        '''
        from abjad.tools import documentationtools
        graph = documentationtools.GraphvizGraph(name='G')
        node_mapping = {}
        for node in self.iterate_depth_first():
            graphviz_node = documentationtools.GraphvizNode()
            if node.children:
                graphviz_node.attributes['shape'] = 'circle'
                graphviz_node.attributes['label'] = '""'
            else:
                graphviz_node.attributes['shape'] = 'box'
                graphviz_node.attributes['label'] = str(node.payload)
            graph.append(graphviz_node)
            node_mapping[node] = graphviz_node
            if node.parent is not None:
                documentationtools.GraphvizEdge()(
                    node_mapping[node.parent],
                    node_mapping[node],
                )
        return graph
Exemplo n.º 7
0
Arquivo: Meter.py Projeto: odub/abjad
 def make_offset_node(
     offset,
     leaf_one=None,
     leaf_two=None,
     is_last=False,
     ):
     if not is_last:
         offset_node = documentationtools.GraphvizNode(
             attributes={
                 'shape': 'Mrecord',
                 'style': 'filled',
                 'color': 'white',
                 'fontname': 'Arial bold',
                 'fontcolor': 'white',
                 'fillcolor': 'black',
                 },
             )
     else:
         offset_node = documentationtools.GraphvizNode(
             attributes={
                 'shape': 'Mrecord',
                 },
             )
     offset_field = documentationtools.GraphvizField(
         label=str(offset),
         )
     weight_field = documentationtools.GraphvizField(
         label='+' * offsets[offset],
         )
     group = documentationtools.GraphvizGroup()
     group.extend([offset_field, weight_field])
     offset_node.append(group)
     offset_subgraph.append(offset_node)
     leaf_one_node = node_mapping[leaf_one]
     edge = documentationtools.GraphvizEdge(
         attributes={'style': 'dotted'},
         )
     edge(leaf_one_node, offset_node)
     if leaf_two:
         leaf_two_node = node_mapping[leaf_two]
         edge = documentationtools.GraphvizEdge(
             attributes={'style': 'dotted'},
             )
         edge(leaf_two_node, offset_node)
Exemplo n.º 8
0
    def graphviz_graph(self):
        r'''The GraphvizGraph representation of the RhythmTreeContainer:

        ::

            >>> rtm = '(1 (1 (2 (1 1 1)) 2))'
            >>> tree = rhythmtreetools.RhythmTreeParser()(rtm)[0]
            >>> graph = tree.graphviz_graph
            >>> print(graph.graphviz_format)
            digraph G {
                node_0 [label=1,
                    shape=triangle];
                node_1 [label=1,
                    shape=box];
                node_2 [label=2,
                    shape=triangle];
                node_3 [label=1,
                    shape=box];
                node_4 [label=1,
                    shape=box];
                node_5 [label=1,
                    shape=box];
                node_6 [label=2,
                    shape=box];
                node_0 -> node_1;
                node_0 -> node_2;
                node_0 -> node_6;
                node_2 -> node_3;
                node_2 -> node_4;
                node_2 -> node_5;
            }

        ::

            >>> topleveltools.graph(graph) # doctest: +SKIP

        Return `GraphvizGraph` instance.
        '''

        graph = documentationtools.GraphvizGraph(name='G')
        node_mapping = {}
        for node in self.nodes:
            graphviz_node = documentationtools.GraphvizNode()
            graphviz_node.attributes['label'] = str(node.preprolated_duration)
            if isinstance(node, type(self)):
                graphviz_node.attributes['shape'] = 'triangle'
            else:
                graphviz_node.attributes['shape'] = 'box'
            graph.append(graphviz_node)
            node_mapping[node] = graphviz_node
            if node.parent is not None:
                documentationtools.GraphvizEdge()(
                    node_mapping[node.parent],
                    node_mapping[node],
                )
        return graph
Exemplo n.º 9
0
def test_documentationtools_GraphvizGraph_copy_04():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    edge = documentationtools.GraphvizEdge().attach(graph[0], graph[1])
    assert str(graph) == systemtools.TestManager.clean_string(r'''
        digraph G {
            node_0;
            node_1;
            node_0 -> node_1;
        }
        ''')
    copied = copy.copy(graph)
    assert str(graph) == str(copied)
def test_documentationtools_GraphvizGraph_pickle_04():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    documentationtools.GraphvizEdge().attach(graph[0], graph[1])
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            node_0;
            node_1;
            node_0 -> node_1;
        }
        ''')
    pickled = pickle.loads(pickle.dumps(graph))
    assert str(graph) == str(pickled)
def test_documentationtools_GraphvizGraph_deepcopy_04():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    documentationtools.GraphvizEdge().attach(graph[0], graph[1])
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            node_0;
            node_1;
            node_0 -> node_1;
        }
        ''')
    copied = copy.deepcopy(graph)
    assert str(graph) == str(copied)
def test_documentationtools_GraphvizGraph_pickle_04():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    edge = documentationtools.GraphvizEdge().attach(graph[0], graph[1])
    assert str(graph) == systemtools.TestManager.clean_string(r'''
        digraph G {
            node_0;
            node_1;
            node_0 -> node_1;
        }
        ''')
    pickled = pickle.loads(pickle.dumps(graph))
    assert str(graph) == str(pickled)
Exemplo n.º 13
0
 def _connect_nodes(synthdef, ugen_node_mapping):
     from abjad.tools import documentationtools
     from supriya.tools import synthdeftools
     for ugen in synthdef.ugens:
         tail_node = ugen_node_mapping[ugen]
         for i, input_ in enumerate(ugen.inputs):
             if not isinstance(input_, synthdeftools.OutputProxy):
                 continue
             tail_field = tail_node['inputs'][i]
             source = input_.source
             head_node = ugen_node_mapping[source]
             head_field = head_node['outputs'][input_.output_index]
             edge = documentationtools.GraphvizEdge()
             edge.attach(head_field, tail_field)
             edge.head_port_position = 'w'
             edge.tail_port_position = 'e'
             if source.calculation_rate == synthdeftools.CalculationRate.CONTROL:
                 edge.attributes['color'] = 'goldenrod'
             elif source.calculation_rate == synthdeftools.CalculationRate.AUDIO:
                 edge.attributes['color'] = 'steelblue'
             else:
                 edge.attributes['color'] = 'salmon'
Exemplo n.º 14
0
    def __graph__(self, **kwargs):
        r'''The GraphvizGraph representation of payload tree.

        ::

            >>> sequence = [[0, 1], [2, 3], [4, 5], [6, 7]]
            >>> tree = datastructuretools.PayloadTree(sequence)

        ::

            >>> tree_graph = tree.__graph__()
            >>> print(str(tree_graph))
            digraph G {
                graph [bgcolor=transparent,
                    truecolor=true];
                node_0 [label="",
                    shape=circle];
                node_1 [label="",
                    shape=circle];
                node_2 [label=0,
                    shape=box];
                node_3 [label=1,
                    shape=box];
                node_4 [label="",
                    shape=circle];
                node_5 [label=2,
                    shape=box];
                node_6 [label=3,
                    shape=box];
                node_7 [label="",
                    shape=circle];
                node_8 [label=4,
                    shape=box];
                node_9 [label=5,
                    shape=box];
                node_10 [label="",
                    shape=circle];
                node_11 [label=6,
                    shape=box];
                node_12 [label=7,
                    shape=box];
                node_0 -> node_1;
                node_0 -> node_4;
                node_0 -> node_7;
                node_0 -> node_10;
                node_1 -> node_2;
                node_1 -> node_3;
                node_4 -> node_5;
                node_4 -> node_6;
                node_7 -> node_8;
                node_7 -> node_9;
                node_10 -> node_11;
                node_10 -> node_12;
            }

        ::

            >>> graph(tree) # doctest: +SKIP

        Returns graphviz graph.
        '''
        from abjad.tools import documentationtools
        graph = documentationtools.GraphvizGraph(
            attributes={
                'bgcolor': 'transparent',
                'truecolor': True,
            },
            name='G',
        )
        node_mapping = {}
        for node in self.iterate_depth_first():
            graphviz_node = documentationtools.GraphvizNode()
            if node.children:
                graphviz_node.attributes['shape'] = 'circle'
                graphviz_node.attributes['label'] = '""'
            else:
                graphviz_node.attributes['shape'] = 'box'
                graphviz_node.attributes['label'] = str(node.payload)
            graph.append(graphviz_node)
            node_mapping[node] = graphviz_node
            if node.parent is not None:
                documentationtools.GraphvizEdge().attach(
                    node_mapping[node.parent],
                    node_mapping[node],
                )
        return graph
Exemplo n.º 15
0
    def __graph__(self, **kwargs):
        r'''Gets Graphviz format of meter.

        ..  container:: example

            **Example 1.** Graphs ``7/4``:

            ::

                >>> meter = metertools.Meter((7, 4))
                >>> meter_graph = meter.__graph__()
                >>> graph(meter_graph) # doctest: +SKIP

            ..  doctest::

                >>> print(str(meter_graph))
                digraph G {
                    graph [bgcolor=transparent,
                        fontname=Arial,
                        penwidth=2,
                        truecolor=true];
                    node [fontname=Arial,
                        fontsize=12,
                        penwidth=2];
                    edge [penwidth=2];
                    node_0 [label="7/4",
                        shape=triangle];
                    node_1 [label="3/4",
                        shape=triangle];
                    node_2 [label="1/4",
                        shape=box];
                    node_3 [label="1/4",
                        shape=box];
                    node_4 [label="1/4",
                        shape=box];
                    node_5 [label="2/4",
                        shape=triangle];
                    node_6 [label="1/4",
                        shape=box];
                    node_7 [label="1/4",
                        shape=box];
                    node_8 [label="2/4",
                        shape=triangle];
                    node_9 [label="1/4",
                        shape=box];
                    node_10 [label="1/4",
                        shape=box];
                    subgraph cluster_cluster_offsets {
                        graph [style=rounded];
                        node_11_0 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 0 | <f_0_1> +++ }",
                            shape=Mrecord,
                            style=filled];
                        node_11_1 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 1/4 | <f_0_1> + }",
                            shape=Mrecord,
                            style=filled];
                        node_11_2 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 1/2 | <f_0_1> + }",
                            shape=Mrecord,
                            style=filled];
                        node_11_3 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 3/4 | <f_0_1> ++ }",
                            shape=Mrecord,
                            style=filled];
                        node_11_4 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 1 | <f_0_1> + }",
                            shape=Mrecord,
                            style=filled];
                        node_11_5 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 5/4 | <f_0_1> ++ }",
                            shape=Mrecord,
                            style=filled];
                        node_11_6 [color=white,
                            fillcolor=black,
                            fontcolor=white,
                            fontname="Arial bold",
                            label="{ <f_0_0> 3/2 | <f_0_1> + }",
                            shape=Mrecord,
                            style=filled];
                        node_11_7 [label="{ <f_0_0> 7/4 | <f_0_1> +++ }",
                            shape=Mrecord];
                    }
                    node_0 -> node_1;
                    node_0 -> node_5;
                    node_0 -> node_8;
                    node_1 -> node_2;
                    node_1 -> node_3;
                    node_1 -> node_4;
                    node_2 -> node_11_0 [style=dotted];
                    node_2 -> node_11_1 [style=dotted];
                    node_3 -> node_11_1 [style=dotted];
                    node_3 -> node_11_2 [style=dotted];
                    node_4 -> node_11_2 [style=dotted];
                    node_4 -> node_11_3 [style=dotted];
                    node_5 -> node_6;
                    node_5 -> node_7;
                    node_6 -> node_11_3 [style=dotted];
                    node_6 -> node_11_4 [style=dotted];
                    node_7 -> node_11_4 [style=dotted];
                    node_7 -> node_11_5 [style=dotted];
                    node_8 -> node_9;
                    node_8 -> node_10;
                    node_9 -> node_11_5 [style=dotted];
                    node_9 -> node_11_6 [style=dotted];
                    node_10 -> node_11_6 [style=dotted];
                    node_10 -> node_11_7 [style=dotted];
                }

        Returns Graphviz graph.
        '''
        def make_offset_node(
            offset,
            leaf_one=None,
            leaf_two=None,
            is_last=False,
        ):
            if not is_last:
                offset_node = documentationtools.GraphvizNode(attributes={
                    'shape':
                    'Mrecord',
                    'style':
                    'filled',
                    'color':
                    'white',
                    'fontname':
                    'Arial bold',
                    'fontcolor':
                    'white',
                    'fillcolor':
                    'black',
                }, )
            else:
                offset_node = documentationtools.GraphvizNode(attributes={
                    'shape':
                    'Mrecord',
                }, )
            offset_field = documentationtools.GraphvizField(
                label=str(offset), )
            weight_field = documentationtools.GraphvizField(label='+' *
                                                            offsets[offset], )
            group = documentationtools.GraphvizGroup()
            group.extend([offset_field, weight_field])
            offset_node.append(group)
            offset_subgraph.append(offset_node)
            leaf_one_node = node_mapping[leaf_one]
            edge = documentationtools.GraphvizEdge(
                attributes={'style': 'dotted'}, )
            edge.attach(leaf_one_node, offset_node)
            if leaf_two:
                leaf_two_node = node_mapping[leaf_two]
                edge = documentationtools.GraphvizEdge(
                    attributes={'style': 'dotted'}, )
                edge.attach(leaf_two_node, offset_node)

        from abjad.tools import metertools
        offsets = metertools.MetricAccentKernel.count_offsets_in_expr(
            sequencetools.flatten_sequence(self.depthwise_offset_inventory))
        graph = documentationtools.GraphvizGraph(
            name='G',
            attributes={
                'bgcolor': 'transparent',
                'fontname': 'Arial',
                'penwidth': 2,
                'truecolor': True,
            },
            edge_attributes={
                'penwidth': 2,
            },
            node_attributes={
                'fontname': 'Arial',
                'fontsize': 12,
                'penwidth': 2,
            },
        )
        node_mapping = {}
        for node in self._root_node.nodes:
            graphviz_node = documentationtools.GraphvizNode()
            graphviz_node.attributes['label'] = str(node.preprolated_duration)
            if isinstance(node, rhythmtreetools.RhythmTreeContainer):
                graphviz_node.attributes['shape'] = 'triangle'
            else:
                graphviz_node.attributes['shape'] = 'box'
            graph.append(graphviz_node)
            node_mapping[node] = graphviz_node
            if node.parent is not None:
                documentationtools.GraphvizEdge().attach(
                    node_mapping[node.parent],
                    node_mapping[node],
                )
        leaves = self._root_node.leaves
        offset = leaves[0].start_offset
        offset_subgraph = documentationtools.GraphvizSubgraph(
            name='cluster_offsets',
            attributes={
                'style': 'rounded',
            },
        )
        graph.append(offset_subgraph)
        make_offset_node(offset, leaves[0])
        for one, two in sequencetools.iterate_sequence_nwise(leaves):
            offset = one.stop_offset
            make_offset_node(offset, one, two)
        offset = leaves[-1].stop_offset
        make_offset_node(offset, leaves[-1], is_last=True)
        return graph
Exemplo n.º 16
0
    def __graph__(self, **kwargs):
        r'''The GraphvizGraph representation of the RhythmTreeContainer:

        ::

            >>> rtm = '(1 (1 (2 (1 1 1)) 2))'
            >>> tree = rhythmtreetools.RhythmTreeParser()(rtm)[0]
            >>> graph = tree.__graph__()
            >>> print(str(graph))
            digraph G {
                graph [bgcolor=transparent,
                    truecolor=true];
                node_0 [label="1",
                    shape=triangle];
                node_1 [label="1",
                    shape=box];
                node_2 [label="2",
                    shape=triangle];
                node_3 [label="1",
                    shape=box];
                node_4 [label="1",
                    shape=box];
                node_5 [label="1",
                    shape=box];
                node_6 [label="2",
                    shape=box];
                node_0 -> node_1;
                node_0 -> node_2;
                node_0 -> node_6;
                node_2 -> node_3;
                node_2 -> node_4;
                node_2 -> node_5;
            }

        ::

            >>> topleveltools.graph(graph) # doctest: +SKIP

        Return `GraphvizGraph` instance.
        '''
        graph = documentationtools.GraphvizGraph(
            name='G',
            attributes={
                'bgcolor': 'transparent',
                'truecolor': True,
            },
        )
        node_mapping = {}
        for node in self.nodes:
            graphviz_node = documentationtools.GraphvizNode()
            graphviz_node.attributes['label'] = str(node.preprolated_duration)
            if isinstance(node, type(self)):
                graphviz_node.attributes['shape'] = 'triangle'
            else:
                graphviz_node.attributes['shape'] = 'box'
            graph.append(graphviz_node)
            node_mapping[node] = graphviz_node
            if node.parent is not None:
                documentationtools.GraphvizEdge().attach(
                    node_mapping[node.parent],
                    node_mapping[node],
                )
        return graph
Exemplo n.º 17
0
    def __graph__(self, **kwargs):
        r'''Graphviz graph of inheritance graph.
        '''
        from abjad.tools import documentationtools

        class_nodes = {}

        graph = documentationtools.GraphvizGraph(
            name='InheritanceGraph',
            attributes={
                'bgcolor': 'transparent',
                'color': 'lightslategrey',
                'fontname': 'Arial',
                'outputorder': 'edgesfirst',
                'overlap': 'prism',
                'penwidth': 2,
                #'ranksep': 0.5,
                'splines': 'spline',
                'style': ('dotted', 'rounded'),
                'truecolor': True,
            },
            edge_attributes={
                'color': 'lightsteelblue2',
                'penwidth': 2,
            },
            node_attributes={
                'colorscheme': 'pastel19',
                'fontname': 'Arial',
                'fontsize': 12,
                'penwidth': 2,
                'style': ('filled', 'rounded'),
            },
        )

        for current_class in sorted(self.parent_children_mapping,
                                    key=lambda x: (x.__module__, x.__name__)):
            pieces = self._get_class_name_pieces(current_class)

            try:
                cluster = graph[pieces[0]]
            except KeyError:
                cluster = documentationtools.GraphvizSubgraph(
                    name=pieces[0],
                    attributes={
                        'label': pieces[0],
                    },
                )
                graph.append(cluster)

            node = documentationtools.GraphvizNode(name='.'.join(pieces), )
            node.attributes['label'] = pieces[-1]

            if current_class in self.immediate_classes:
                pass
            if current_class in self.root_classes:
                pass
            if inspect.isabstract(current_class):
                node.attributes['shape'] = 'oval'
                node.attributes['style'] = 'bold'
            else:
                node.attributes['shape'] = 'box'
            if current_class in self.lineage_classes:
                node.attributes['color'] = 'black'
                node.attributes['fontcolor'] = 'white'
                node.attributes['style'] = ('filled', 'rounded')

            if self.lineage_prune_distance is None:
                cluster.append(node)
                class_nodes[current_class] = node
            elif current_class not in self.lineage_distance_mapping:
                cluster.append(node)
                class_nodes[current_class] = node
            else:
                ok_distance = self.lineage_prune_distance + 1
                distance = self.lineage_distance_mapping[current_class]
                if distance < ok_distance:
                    cluster.append(node)
                    class_nodes[current_class] = node
                elif distance == ok_distance:
                    node.attributes['shape'] = 'invis'
                    node.attributes['style'] = 'transparent'
                    node.attributes['label'] = ' '
                    cluster.append(node)
                    class_nodes[current_class] = node
                elif ok_distance < distance:
                    pass

        distances = self.lineage_distance_mapping
        for parent in sorted(self.parent_children_mapping,
                             key=lambda x: (x.__module__, x.__name__)):
            children = self.parent_children_mapping[parent]
            children = sorted(
                children,
                key=lambda x: (x.__module__, x.__name__),
            )
            for child in children:
                ok_to_join = False
                if self.lineage_prune_distance is None:
                    ok_to_join = True
                elif parent not in distances:
                    if child not in distances:
                        ok_to_join = True
                    elif child in distances and \
                        distances[child] <= ok_distance:
                        ok_to_join = True
                elif child not in distances:
                    if parent not in distances:
                        ok_to_join = True
                    elif parent in distances and \
                        distances[parent] <= ok_distance:
                        ok_to_join = True
                elif distances[child] <= ok_distance and \
                    distances[parent] <= ok_distance:
                    ok_to_join = True
                if ok_to_join:
                    parent_node = class_nodes[parent]
                    child_node = class_nodes[child]
                    documentationtools.GraphvizEdge().attach(
                        parent_node, child_node)

        for i, cluster in enumerate(
                sorted(graph.children, key=lambda x: x.name)):
            color = i % 9 + 1
            for node in cluster:
                if 'color' not in node.attributes:
                    node.attributes['color'] = color
                if self.use_groups:
                    node.attributes['group'] = i
            if not self.use_clusters:
                graph.extend(cluster[:])
                graph.remove(cluster)

        if self.root_addresses is None:
            graph.attributes['root'] = '__builtin__.object'

        return graph
Exemplo n.º 18
0
    def __graph__(self, spanner=None, **kwargs):
        r'''Graphviz graph representation of container.

        Returns Graphviz graph.
        '''
        def recurse(component, leaf_cluster):
            component_node = component._as_graphviz_node()
            node_mapping[component] = component_node
            node_order = [component_node.name]
            if isinstance(component, scoretools.Container):
                graph.append(component_node)
                this_leaf_cluster = documentationtools.GraphvizSubgraph(
                    name=component_node.name,
                    attributes={
                        'color': 'grey75',
                        'penwidth': 2,
                    },
                )
                all_are_leaves = True
                pending_node_order = []
                for child in component:
                    if not isinstance(child, scoretools.Leaf):
                        all_are_leaves = False
                    child_node, child_node_order = recurse(
                        child, this_leaf_cluster)
                    pending_node_order.extend(child_node_order)
                    edge = documentationtools.GraphvizEdge()
                    edge(component_node, child_node)
                if all_are_leaves:
                    pending_node_order.reverse()
                node_order.extend(pending_node_order)
                if len(this_leaf_cluster):
                    leaf_cluster.append(this_leaf_cluster)
            else:
                leaf_cluster.append(component_node)
            return component_node, node_order

        from abjad.tools import documentationtools
        from abjad.tools import scoretools
        node_order = []
        node_mapping = {}
        graph = documentationtools.GraphvizGraph(
            name='G',
            attributes={
                'style': 'rounded',
            },
            edge_attributes={},
            node_attributes={
                'fontname': 'Arial',
                'shape': 'none',
            },
        )
        leaf_cluster = documentationtools.GraphvizSubgraph(name='leaves')
        component_node, node_order = recurse(self, leaf_cluster)
        if len(leaf_cluster) == 1:
            graph.append(leaf_cluster[0])
        elif len(leaf_cluster):
            graph.append(leaf_cluster)
        graph._node_order = node_order

        if spanner:
            for component_one, component_two in \
                sequencetools.iterate_sequence_nwise(spanner.components):
                node_one = node_mapping[component_one]
                node_two = node_mapping[component_two]
                edge = documentationtools.GraphvizEdge(attributes={
                    'constraint': False,
                    'penwidth': 5,
                }, )
                edge(node_one, node_two)
            for component in spanner.components:
                node = node_mapping[component]
                table = node[0]
                table.attributes['border'] = 4
                table.attributes['bgcolor'] = 'grey80'
                if isinstance(component, Container):
                    for child in iterate(component).depth_first():
                        if child is component:
                            continue
                        node = node_mapping[child]
                        table = node[0]
                        table.attributes['bgcolor'] = 'grey80'

        return graph