Spaces:
Runtime error
Runtime error
ugmSorcero
commited on
Commit
·
236ecdd
1
Parent(s):
8de7c36
Polishes how to draw pipelines, and adds streamlit style
Browse files- .streamlit/config.toml +6 -0
- interface/draw_pipelines.py +82 -83
.streamlit/config.toml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[theme]
|
| 2 |
+
primaryColor="#ffbf00"
|
| 3 |
+
backgroundColor="#0e1117"
|
| 4 |
+
secondaryBackgroundColor="#282929"
|
| 5 |
+
textColor = "#ffffff"
|
| 6 |
+
font="sans serif"
|
interface/draw_pipelines.py
CHANGED
|
@@ -4,14 +4,89 @@ from itertools import chain
|
|
| 4 |
import networkx as nx
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
# Start and end are lists defining start and end points
|
| 9 |
-
# Edge x and y are lists used to construct the graph
|
| 10 |
-
# arrowAngle and arrowLength define properties of the arrowhead
|
| 11 |
-
# arrowPos is None, 'middle' or 'end' based on where on the edge you want the arrow to appear
|
| 12 |
-
# arrowLength is the length of the arrowhead
|
| 13 |
-
# arrowAngle is the angle in degrees that the arrowhead makes with the edge
|
| 14 |
-
# dotSize is the plotly scatter dot size you are using (used to even out line spacing when you have a mix of edge lengths)
|
| 15 |
def addEdge(
|
| 16 |
start,
|
| 17 |
end,
|
|
@@ -148,79 +223,3 @@ def add_arrows(
|
|
| 148 |
|
| 149 |
return x_arrows, y_arrows
|
| 150 |
|
| 151 |
-
|
| 152 |
-
@st.cache(allow_output_mutation=True)
|
| 153 |
-
def get_pipeline_graph(pipeline):
|
| 154 |
-
# Controls for how the graph is drawn
|
| 155 |
-
nodeColor = "Blue"
|
| 156 |
-
nodeSize = 20
|
| 157 |
-
lineWidth = 2
|
| 158 |
-
lineColor = "#000000"
|
| 159 |
-
|
| 160 |
-
G = pipeline.graph
|
| 161 |
-
|
| 162 |
-
pos = nx.spring_layout(G)
|
| 163 |
-
|
| 164 |
-
for node in G.nodes:
|
| 165 |
-
G.nodes[node]["pos"] = list(pos[node])
|
| 166 |
-
|
| 167 |
-
# Make list of nodes for plotly
|
| 168 |
-
node_x = []
|
| 169 |
-
node_y = []
|
| 170 |
-
for node in G.nodes():
|
| 171 |
-
x, y = G.nodes[node]["pos"]
|
| 172 |
-
node_x.append(x)
|
| 173 |
-
node_y.append(y)
|
| 174 |
-
|
| 175 |
-
# Make a list of edges for plotly, including line segments that result in arrowheads
|
| 176 |
-
edge_x = []
|
| 177 |
-
edge_y = []
|
| 178 |
-
for edge in G.edges():
|
| 179 |
-
start = G.nodes[edge[0]]["pos"]
|
| 180 |
-
end = G.nodes[edge[1]]["pos"]
|
| 181 |
-
# addEdge(start, end, edge_x, edge_y, lengthFrac=1, arrowPos = None, arrowLength=0.025, arrowAngle = 30, dotSize=20)
|
| 182 |
-
edge_x, edge_y = addEdge(
|
| 183 |
-
start,
|
| 184 |
-
end,
|
| 185 |
-
edge_x,
|
| 186 |
-
edge_y,
|
| 187 |
-
lengthFrac=0.8,
|
| 188 |
-
arrowPos="end",
|
| 189 |
-
arrowLength=0.04,
|
| 190 |
-
arrowAngle=30,
|
| 191 |
-
dotSize=nodeSize,
|
| 192 |
-
)
|
| 193 |
-
|
| 194 |
-
edge_trace = go.Scatter(
|
| 195 |
-
x=edge_x,
|
| 196 |
-
y=edge_y,
|
| 197 |
-
line=dict(width=lineWidth, color=lineColor),
|
| 198 |
-
hoverinfo="none",
|
| 199 |
-
mode="lines",
|
| 200 |
-
)
|
| 201 |
-
|
| 202 |
-
node_trace = go.Scatter(
|
| 203 |
-
x=node_x,
|
| 204 |
-
y=node_y,
|
| 205 |
-
mode="markers",
|
| 206 |
-
hoverinfo="text",
|
| 207 |
-
marker=dict(showscale=False, color=nodeColor, size=nodeSize),
|
| 208 |
-
)
|
| 209 |
-
|
| 210 |
-
fig = go.Figure(
|
| 211 |
-
data=[edge_trace, node_trace],
|
| 212 |
-
layout=go.Layout(
|
| 213 |
-
showlegend=False,
|
| 214 |
-
hovermode="closest",
|
| 215 |
-
margin=dict(b=20, l=5, r=5, t=40),
|
| 216 |
-
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 217 |
-
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 218 |
-
),
|
| 219 |
-
)
|
| 220 |
-
|
| 221 |
-
# Note: if you don't use fixed ratio axes, the arrows won't be symmetrical
|
| 222 |
-
fig.update_layout(
|
| 223 |
-
yaxis=dict(scaleanchor="x", scaleratio=1), plot_bgcolor="rgb(255,255,255)"
|
| 224 |
-
)
|
| 225 |
-
|
| 226 |
-
return fig
|
|
|
|
| 4 |
import networkx as nx
|
| 5 |
import plotly.graph_objs as go
|
| 6 |
import streamlit as st
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
@st.cache(allow_output_mutation=True)
|
| 10 |
+
def get_pipeline_graph(pipeline):
|
| 11 |
+
# Controls for how the graph is drawn
|
| 12 |
+
nodeColor = "#ffbf00"
|
| 13 |
+
nodeSize = 40
|
| 14 |
+
lineWidth = 2
|
| 15 |
+
lineColor = "#ffffff"
|
| 16 |
+
|
| 17 |
+
G = pipeline.graph
|
| 18 |
+
initial_coordinate = (0, len(G.nodes))
|
| 19 |
+
fixed_pos = {node: np.array([initial_coordinate[0], initial_coordinate[1]-float(idx)]) for idx, node in enumerate(G.nodes)}
|
| 20 |
+
pos = nx.spring_layout(G, pos=fixed_pos, seed=42)
|
| 21 |
+
|
| 22 |
+
for node in G.nodes:
|
| 23 |
+
G.nodes[node]["pos"] = list(pos[node])
|
| 24 |
+
|
| 25 |
+
# Make list of nodes for plotly
|
| 26 |
+
node_x = []
|
| 27 |
+
node_y = []
|
| 28 |
+
node_name = []
|
| 29 |
+
for node in G.nodes():
|
| 30 |
+
node_name.append(G.nodes[node]['component'].name)
|
| 31 |
+
x, y = G.nodes[node]["pos"]
|
| 32 |
+
node_x.append(x)
|
| 33 |
+
node_y.append(y)
|
| 34 |
+
|
| 35 |
+
# Make a list of edges for plotly, including line segments that result in arrowheads
|
| 36 |
+
edge_x = []
|
| 37 |
+
edge_y = []
|
| 38 |
+
for edge in G.edges():
|
| 39 |
+
start = G.nodes[edge[0]]["pos"]
|
| 40 |
+
end = G.nodes[edge[1]]["pos"]
|
| 41 |
+
# addEdge(start, end, edge_x, edge_y, lengthFrac=1, arrowPos = None, arrowLength=0.025, arrowAngle = 30, dotSize=20)
|
| 42 |
+
edge_x, edge_y = addEdge(
|
| 43 |
+
start,
|
| 44 |
+
end,
|
| 45 |
+
edge_x,
|
| 46 |
+
edge_y,
|
| 47 |
+
lengthFrac=0.5,
|
| 48 |
+
arrowPos="end",
|
| 49 |
+
arrowLength=0.04,
|
| 50 |
+
arrowAngle=40,
|
| 51 |
+
dotSize=nodeSize,
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
edge_trace = go.Scatter(
|
| 55 |
+
x=edge_x,
|
| 56 |
+
y=edge_y,
|
| 57 |
+
line=dict(width=lineWidth, color=lineColor),
|
| 58 |
+
hoverinfo="none",
|
| 59 |
+
mode="lines",
|
| 60 |
+
)
|
| 61 |
+
|
| 62 |
+
node_trace = go.Scatter(
|
| 63 |
+
x=node_x,
|
| 64 |
+
y=node_y,
|
| 65 |
+
mode="markers+text",
|
| 66 |
+
textposition="middle right",
|
| 67 |
+
hoverinfo='none',
|
| 68 |
+
text=node_name,
|
| 69 |
+
marker=dict(showscale=False, color=nodeColor, size=nodeSize),
|
| 70 |
+
textfont=dict(size=18)
|
| 71 |
+
)
|
| 72 |
+
|
| 73 |
+
fig = go.Figure(
|
| 74 |
+
data=[edge_trace, node_trace],
|
| 75 |
+
layout=go.Layout(
|
| 76 |
+
showlegend=False,
|
| 77 |
+
hovermode="closest",
|
| 78 |
+
margin=dict(b=20, l=5, r=5, t=40),
|
| 79 |
+
xaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 80 |
+
yaxis=dict(showgrid=False, zeroline=False, showticklabels=False),
|
| 81 |
+
),
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
fig.update_layout(
|
| 85 |
+
yaxis=dict(scaleanchor="x", scaleratio=1), plot_bgcolor="rgb(14,17,23)"
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
return fig
|
| 89 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
def addEdge(
|
| 91 |
start,
|
| 92 |
end,
|
|
|
|
| 223 |
|
| 224 |
return x_arrows, y_arrows
|
| 225 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|