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_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)
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)
コード例 #4
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_03():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            node_0;
            node_1;
        }
        ''')
    pickled = pickle.loads(pickle.dumps(graph))
    assert str(graph) == str(pickled)
def test_documentationtools_GraphvizGraph_deepcopy_03():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    assert str(graph) == stringtools.normalize(r'''
        digraph G {
            node_0;
            node_1;
        }
        ''')
    copied = copy.deepcopy(graph)
    assert str(graph) == str(copied)
コード例 #7
0
def test_documentationtools_GraphvizGraph_pickle_03():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    assert str(graph) == systemtools.TestManager.clean_string(r'''
        digraph G {
            node_0;
            node_1;
        }
        ''')
    pickled = pickle.loads(pickle.dumps(graph))
    assert str(graph) == str(pickled)
コード例 #8
0
def test_documentationtools_GraphvizGraph_copy_03():
    graph = documentationtools.GraphvizGraph()
    graph.append(documentationtools.GraphvizNode())
    graph.append(documentationtools.GraphvizNode())
    assert str(graph) == systemtools.TestManager.clean_string(r'''
        digraph G {
            node_0;
            node_1;
        }
        ''')
    copied = copy.copy(graph)
    assert str(graph) == str(copied)
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)
コード例 #10
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)
コード例 #11
0
ファイル: Server.py プロジェクト: kureta/supriya
    def __graph__(self):
        def recurse(graph, parent_graphviz_node, parent_server_node):
            if not isinstance(parent_server_node, servertools.Group):
                return
            for child_server_node in parent_server_node:
                if isinstance(child_server_node, servertools.Group):
                    name = 'Group {}'.format(child_server_node.node_id)
                else:
                    name = 'Synth {}'.format(child_server_node.node_id)
                child_graphviz_node = documentationtools.GraphvizNode(
                    name=name, )
                graph.append(child_graphviz_node)
                documentationtools.GraphvizEdge()(
                    parent_graphviz_node,
                    child_graphviz_node,
                )
                recurse(graph, child_graphviz_node, child_server_node)

        from abjad.tools import documentationtools
        from supriya.tools import servertools
        graph = documentationtools.GraphvizGraph(name='server', )
        root_graphviz_node = documentationtools.GraphvizNode(name='Root Node')
        graph.append(root_graphviz_node)
        recurse(graph, root_graphviz_node, self.root_node)
        return graph
コード例 #12
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
コード例 #13
0
 def _create_ugen_node_mapping(synthdef):
     from abjad.tools import documentationtools
     from supriya.tools import synthdeftools
     ugen_node_mapping = {}
     for ugen in synthdef.ugens:
         ugen_index = synthdef.ugens.index(ugen)
         node = documentationtools.GraphvizNode(
             name='ugen_{}'.format(ugen_index), )
         if ugen.calculation_rate == synthdeftools.CalculationRate.CONTROL:
             node.attributes['fillcolor'] = 'lightgoldenrod2'
         elif ugen.calculation_rate == synthdeftools.CalculationRate.AUDIO:
             node.attributes['fillcolor'] = 'lightsteelblue2'
         else:
             node.attributes['fillcolor'] = 'lightsalmon2'
         title_field = SynthDefGrapher._create_ugen_title_field(ugen)
         node.append(title_field)
         group = documentationtools.GraphvizGroup()
         input_group = SynthDefGrapher._create_ugen_input_group(
             ugen, ugen_index)
         if input_group is not None:
             group.append(input_group)
         output_group = SynthDefGrapher._create_ugen_output_group(
             synthdef, ugen, ugen_index)
         if output_group is not None:
             group.append(output_group)
         node.append(group)
         ugen_node_mapping[ugen] = node
     return ugen_node_mapping
コード例 #14
0
ファイル: Meter.py プロジェクト: 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)
コード例 #15
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
コード例 #16
0
ファイル: RhythmTreeLeaf.py プロジェクト: jdavancens/abjad
 def __graph__(self, **kwargs):
     r'''Graphviz graph of rhythm tree leaf.
     '''
     from abjad.tools import documentationtools
     graph = documentationtools.GraphvizGraph(name='G')
     node = documentationtools.GraphvizNode(
         attributes={
             'label': str(self.preprolated_duration),
             'shape': 'box'
         })
     graph.append(node)
     return graph
コード例 #17
0
ファイル: StateGrapher.py プロジェクト: lisongx/supriya
 def _create_graphviz_node(label, **kwargs):
     node = documentationtools.GraphvizNode(attributes={'margin': 0.05})
     table_attributes = {
         'border': 2,
         'cellborder': 0,
         'cellpadding': 5,
         'cellspacing': 0,
         'style': 'rounded',
     }
     table_attributes.update(**kwargs)
     table = documentationtools.GraphvizTable(attributes=table_attributes, )
     table.extend(StateGrapher._create_graphviz_table_cell(label))
     node.append(table)
     return node
コード例 #18
0
 def _as_graphviz_node(self):
     from abjad.tools import documentationtools
     score_index = self._get_parentage().score_index
     score_index = '_'.join(str(_) for _ in score_index)
     class_name = type(self).__name__
     if score_index:
         name = '{}_{}'.format(class_name, score_index)
     else:
         name = class_name
     node = documentationtools.GraphvizNode(
         name=name,
         attributes={
             'margin': 0.05,
         },
     )
     table = documentationtools.GraphvizTable(attributes={
         'border': 2,
         'cellpadding': 5,
         'style': 'rounded',
     }, )
     node.append(table)
     return node
コード例 #19
0
ファイル: InheritanceGraph.py プロジェクト: mscuthbert/abjad
    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
コード例 #20
0
ファイル: PayloadTree.py プロジェクト: mscuthbert/abjad
    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
コード例 #21
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
コード例 #22
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