Skip to content
Snippets Groups Projects
Commit 0b8da540 authored by Brandon Rodriguez's avatar Brandon Rodriguez
Browse files

Create visual display of node initial states

For state machines
parent fccedd01
No related merge requests found
......@@ -10,6 +10,7 @@ Parent structure containing various Nodes and Edges.
"""
# System Imports.
import math
# User Class Imports.
import resources.directed_graph.graph as directed_graph
......@@ -32,10 +33,33 @@ class Graph(directed_graph.Graph):
self._graph_type = Graph
self._node_type = sm_node.Node
def _create_node_hover_text(self):
"""
Hook for child classes to edit node hover text, if needed.
:return: List of hover text values for nodes.
"""
node_hover_text = []
# Loop through all nodes and create hover text.
for node in self.get_all_nodes().values():
hover_text = 'Node: {0}<br>Connection Count: {1}'.format(node.get_name(), node.get_edge_count())
# Check if node is initial state.
if node.is_initial:
hover_text += '<br>Initial State'
# Check if node is final state.
if node.is_final:
hover_text += '<br>Final State'
node_hover_text.append(hover_text)
return node_hover_text
def _create_additional_node_mappings(self):
"""
Creates additional visual node mappings for all "final state" nodes.
Only applicable to directed graphs.
Only applicable to state machine graphs.
:return: List of additional "final state" node mappings.
"""
# System Import for graphing.
......@@ -47,6 +71,7 @@ class Graph(directed_graph.Graph):
# Loop through all nodes.
for node in self.get_all_nodes().values():
# Only do anything if node is set to be a final state.
if node.is_final:
node_x.append(node.x_coord)
node_y.append(node.y_coord)
......@@ -74,6 +99,52 @@ class Graph(directed_graph.Graph):
# Return node mapping objects.
return node_mapping
def _create_additional_edge_mappings(self):
"""
Creates additional visual edge mappings for all "initial state" nodes.
Only applicable to state machine graphs.
:return: List of additional mappings.
"""
# System Import for graphing.
# Not imported at top of file so that the rest of the program can run without required imports.
from plotly import graph_objects
# First get parent pointers, because we still want all parent functionality.
edge_mappings = super()._create_additional_edge_mappings()
# Loop through all nodes.
for node in self.get_all_nodes().values():
# Only do anything if node is set to be a final state.
if node.is_initial:
# Get associated coordinates.
node_x = node.x_coord
node_y = node.y_coord
# Calculate point to left.
mid_x = node_x - 0.5
mid_y = node_y
# Create arrow tip coords based on this left-ward point.
mid_left_x = mid_x - 0.5
mid_right_x = mid_left_x
mid_left_y = mid_y + 0.5
mid_right_y = mid_y - 0.5
# Create edge mapping scatter object for node state.
edge_mappings.append(graph_objects.Scatter(
x=[mid_left_x, mid_x, mid_right_x],
y=[mid_left_y, mid_y, mid_right_y],
mode='lines',
hoverinfo='skip',
line={
'width': 2,
'color': 'black'
},
))
return edge_mappings
def _create_edge_pointer_text(self, edge):
"""
Creates text display for given edge pointer.
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment