How to use the transitions.extensions.diagrams.Graph function in transitions

To help you get started, we’ve selected a few transitions examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pytransitions / transitions / transitions / extensions / diagrams.py View on Github external
title = ''

        fsm_graph = pgv.AGraph(label=title, compound=True, **self.machine_attributes)
        fsm_graph.node_attr.update(self.style_attributes['node']['default'])
        fsm_graph.edge_attr.update(self.style_attributes['edge']['default'])

        # For each state, draw a circle
        self._add_nodes(self.machine.states, fsm_graph)
        self._add_edges(self.machine.events.copy(), fsm_graph)

        setattr(fsm_graph, 'style_attributes', self.style_attributes)

        return fsm_graph


class NestedGraph(Graph):

    machine_attributes = Graph.machine_attributes.copy()
    machine_attributes.update(
        {'clusterrank': 'local', 'rankdir': 'TB', 'ratio': 0.8})

    def __init__(self, *args, **kwargs):
        self.seen_nodes = []
        self.seen_transitions = []
        super(NestedGraph, self).__init__(*args, **kwargs)
        self.style_attributes['edge']['default']['minlen'] = 2

    def _add_nodes(self, states, container):
        states = [self.machine.get_state(state) for state in states] if isinstance(states, dict) else states
        for state in states:
            if state.name in self.seen_nodes:
                continue
github pytransitions / transitions / transitions / extensions / diagrams.py View on Github external
def _get_graph(self, model, title=None, force_new=False, show_roi=False):
        if title is None:
            title = self.title
        if not hasattr(model, 'graph') or force_new:
            model.graph = NestedGraph(self).get_graph(title) if isinstance(self, HierarchicalMachine) \
                else Graph(self).get_graph(title)
            self.set_node_state(model.graph, model.state, state='active')

        return model.graph if not show_roi else self._graph_roi(model)
github pytransitions / transitions / transitions / extensions / diagrams.py View on Github external
def __init__(self, *args, **kwargs):
        super(Graph, self).__init__(*args, **kwargs)
github pytransitions / transitions / transitions / extensions / diagrams.py View on Github external
fsm_graph = pgv.AGraph(label=title, compound=True, **self.machine_attributes)
        fsm_graph.node_attr.update(self.style_attributes['node']['default'])
        fsm_graph.edge_attr.update(self.style_attributes['edge']['default'])

        # For each state, draw a circle
        self._add_nodes(self.machine.states, fsm_graph)
        self._add_edges(self.machine.events.copy(), fsm_graph)

        setattr(fsm_graph, 'style_attributes', self.style_attributes)

        return fsm_graph


class NestedGraph(Graph):

    machine_attributes = Graph.machine_attributes.copy()
    machine_attributes.update(
        {'clusterrank': 'local', 'rankdir': 'TB', 'ratio': 0.8})

    def __init__(self, *args, **kwargs):
        self.seen_nodes = []
        self.seen_transitions = []
        super(NestedGraph, self).__init__(*args, **kwargs)
        self.style_attributes['edge']['default']['minlen'] = 2

    def _add_nodes(self, states, container):
        states = [self.machine.get_state(state) for state in states] if isinstance(states, dict) else states
        for state in states:
            if state.name in self.seen_nodes:
                continue
            self.seen_nodes.append(state.name)
            if len(state.children) > 0: