Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update wardley.py #7

Merged
merged 1 commit into from
May 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion ipywardley/wardley.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(self, owm):
self.title = None
self.nodes = {}
self.edges = []
self.bluelines = []
self.evolutions = {}
self.annotations = []
self.annotation = {}
Expand Down Expand Up @@ -64,6 +65,14 @@ def __init__(self, owm):
elif "->" in cl:
n_from, n_to = cl.split('->')
self.edges.append([n_from.strip(), n_to.strip()])
elif "+<>" in cl:
edge_parts = cl.split('+<>')
if len(edge_parts) != 2:
self.warnings.append(f"Unexpected format for blueline definition: {cl}. Skipping this edge.")
continue
n_from, n_to = edge_parts
self.bluelines.append([n_from.strip(), n_to.strip()])
continue
elif cl.startswith('evolve '):
match = self._evolve_regex.search(cl)
if match != None:
Expand Down Expand Up @@ -208,7 +217,22 @@ def generate_wardley_plot(self, ax, wm):
lc = LineCollection(l, color=matplotlib.rcParams['axes.edgecolor'], lw=1)
#lc = LineCollection(l, color="k", lw=1, linestyle=['-'])
ax.add_collection(lc)


# Plot bluelines :
b = []
for blueline in wm.bluelines:
if blueline[0] in wm.nodes and blueline[1] in wm.nodes:
n_from = wm.nodes[blueline[0]]
n_to = wm.nodes[blueline[1]]
b.append([ (n_from['mat'],n_from['vis']), (n_to['mat'],n_to['vis']) ])
else:
for n in blueline:
if n not in wm.nodes:
show_warning("Could not find a component called '%s'!" % n)
if len(b) > 0:
lc = LineCollection(b, color='blue', lw=2)
ax.add_collection(lc)

# Add the nodes:
for node_title in wm.nodes:
n = wm.nodes[node_title]
Expand Down