Skip to content

Commit c573bd7

Browse files
committed
Optimize Jupyter artifact dependency visualization
1 parent dcada13 commit c573bd7

File tree

1 file changed

+53
-28
lines changed

1 file changed

+53
-28
lines changed

jupyter/ArtifactDependencies.ipynb

Lines changed: 53 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
"source": [
88
"## Artifact Dependencies\n",
99
"\n",
10+
"This report includes graph visualization(s) using JavaScript and might not be exportable to some document formats.\n",
11+
"\n",
1012
"### References\n",
1113
"\n",
1214
"- [neovis.js (GitHub)](https://github.com/neo4j-contrib/neovis.js)\n",
1315
"- [vis-network (GitHub)](https://github.com/visjs/vis-network)\n",
1416
"- [vis network documentation](https://visjs.github.io/vis-network/docs/network)\n",
15-
"- [Neo4j Graph Algorithms Jupyter Notebooks (GitHub)](https://github.com/neo4j-graph-analytics/graph-algorithms-notebooks)\n"
17+
"- [Neo4j Graph Algorithms Jupyter Notebooks (GitHub)](https://github.com/neo4j-graph-analytics/graph-algorithms-notebooks)\n",
18+
"- [Neo4j Graph Data Science Topological Sort](https://neo4j.com/docs/graph-data-science/current/algorithms/alpha/topological-sort)\n"
1619
]
1720
},
1821
{
@@ -72,34 +75,41 @@
7275
"metadata": {},
7376
"outputs": [],
7477
"source": [
75-
"def visualization_configuration():\n",
78+
"def visualization_configuration(node_distance: int = 150):\n",
7679
" return {\n",
7780
" \"visConfig\": {\n",
7881
" \"nodes\": {\n",
7982
" \"shape\": \"hexagon\",\n",
8083
" \"font\": {\n",
81-
" \"strokeWidth\": 30,\n",
82-
" \"strokeColor\": \"#F0F0FF\"\n",
84+
" \"strokeWidth\": 4,\n",
85+
" \"strokeColor\": \"#D0D0FF\",\n",
86+
" \"size\": 32\n",
8387
" },\n",
84-
" \"size\": 50,\n",
85-
" \"borderWidth\": 2\n",
88+
" \"size\": 60,\n",
89+
" \"borderWidth\": 2,\n",
90+
" \"widthConstraint\": {\n",
91+
" \"maximum\": 120\n",
92+
" }\n",
8693
" },\n",
8794
" \"edges\": {\n",
8895
" \"arrows\": {\n",
89-
" \"to\": { \"enabled\": True }\n",
96+
" \"to\": { \n",
97+
" \"enabled\": True,\n",
98+
" \"scaleFactor\": 0.5\n",
99+
" }\n",
90100
" },\n",
91101
" \"scaling\": {\n",
92-
" \"max\": 15\n",
102+
" \"max\": 8\n",
93103
" }\n",
94104
" },\n",
95105
" \"physics\": {\n",
96106
" \"hierarchicalRepulsion\": {\n",
97-
" \"nodeDistance\": 300, # 100\n",
98-
" \"centralGravity\": 0.5, # 0.2\n",
99-
" \"springLength\": 180, # 200\n",
100-
" \"springConstant\": 0.06, # 0.05\n",
107+
" \"nodeDistance\": node_distance, # 120\n",
108+
" \"centralGravity\": 0.2, # 0.0\n",
109+
" \"springLength\": 100, # 100\n",
110+
" \"springConstant\": 0.02, # 0.01\n",
101111
" \"damping\": 0.09, # 0.09\n",
102-
" \"avoidOverlap\": 0.1 # 0\n",
112+
" \"avoidOverlap\": 0.9 # 0\n",
103113
" },\n",
104114
" \"solver\": \"hierarchicalRepulsion\" # barnesHut\n",
105115
" },\n",
@@ -120,9 +130,9 @@
120130
"metadata": {},
121131
"outputs": [],
122132
"source": [
123-
"def graph_query_configuration():\n",
133+
"def graph_query_configuration(query: str):\n",
124134
" return {\n",
125-
" \"initialCypher\": \"MATCH (s:Artifact)-[r:DEPENDS_ON]->(d:Artifact) RETURN s,r,d\",\n",
135+
" \"initialCypher\": query,\n",
126136
" \"labels\": {\n",
127137
" \"Artifact\": {\n",
128138
" \"label\": \"fileName\"\n",
@@ -137,33 +147,48 @@
137147
" }"
138148
]
139149
},
150+
{
151+
"cell_type": "markdown",
152+
"id": "3328314d",
153+
"metadata": {},
154+
"source": [
155+
"## Hierarchical Artifact Dependencies\n",
156+
"\n",
157+
"The following hierarchical graph shows artifact dependencies with the most used basis/shared artifact at the bottom and the artifact the builds upon the other dependencies on top. The visualization is limited to the first 60 nodes and their direct dependency ordered by the dependency layer (\"maxDistanceFromSource\") descending. \n",
158+
"\n",
159+
"For the whole list of topologically sorted artifacts including the hierarchical layer go to the report `TopologicalSortedArtifacts.csv`. This is also known as the \"build order\"."
160+
]
161+
},
140162
{
141163
"cell_type": "code",
142164
"execution_count": null,
143165
"id": "48cd3f44",
144166
"metadata": {},
145167
"outputs": [],
146168
"source": [
169+
"query = \"\"\"\n",
170+
" MATCH (artifact:Artifact:Archive)-[dependency:DEPENDS_ON]->(dependent:Artifact:Archive)\n",
171+
" WHERE artifact.maxDistanceFromSource IS NOT NULL\n",
172+
" AND dependent.maxDistanceFromSource > artifact.maxDistanceFromSource\n",
173+
"RETURN artifact, dependency, dependent\n",
174+
" ORDER BY artifact.maxDistanceFromSource DESC\n",
175+
" ,artifact.maxDistanceFromSource ASC\n",
176+
" ,artifact.topologicalSortIndex ASC\n",
177+
" ,dependent.topologicalSortIndex ASC\n",
178+
"LIMIT 60 \n",
179+
"\"\"\"\n",
180+
"\n",
147181
"htmlElement = {\"containerId\": \"graph-visualization\"}\n",
148182
"serverConfiguration = neo4j_server_configuration(uri=neo4jUri, user=neo4jUser,password=neo4jPassword)\n",
149183
"\n",
150184
"# Assemble the neovis.js configuration by joining the different parts of it\n",
151-
"graphVisualizationConfiguration = {**htmlElement, **visualization_configuration(), **serverConfiguration, **graph_query_configuration()}\n",
185+
"graphVisualizationConfiguration = {**htmlElement, **visualization_configuration(), **serverConfiguration, **graph_query_configuration(query)}\n",
186+
"#graphVisualizationConfiguration = {**htmlElement, **visualization_configuration(node_distance=220), **serverConfiguration, **graph_query_configuration(query)}\n",
152187
"\n",
153188
"# Create a javascript variable containing the whole configuration in JSON format\n",
154189
"Javascript(\"\"\"window.graphVisualizationConfiguration={};\"\"\".format(json.dumps(graphVisualizationConfiguration)))"
155190
]
156191
},
157-
{
158-
"cell_type": "markdown",
159-
"id": "3328314d",
160-
"metadata": {},
161-
"source": [
162-
"## Hierarchical Artifact Dependencies\n",
163-
"\n",
164-
"The following hierarchical graph shows artifact dependencies with the most used basis/shared artifact at the bottom and the artifact the builds upon all other dependencies on top. "
165-
]
166-
},
167192
{
168193
"cell_type": "code",
169194
"execution_count": null,
@@ -176,8 +201,8 @@
176201
"%%html\n",
177202
"<style type=\"text/css\">\n",
178203
" #graph-visualization {\n",
179-
" width: 650px;\n",
180-
" height: 850px;\n",
204+
" width: 660px;\n",
205+
" height: 660px;\n",
181206
" border: 1px solid lightgray;\n",
182207
" }\n",
183208
"</style>\n",

0 commit comments

Comments
 (0)