Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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)
def __init__(self, *args, **kwargs):
super(Graph, self).__init__(*args, **kwargs)
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: