|
27 | 27 | "source": [ |
28 | 28 | "import os\n", |
29 | 29 | "from neo4j import GraphDatabase\n", |
30 | | - "from IPython.core.display import Javascript\n", |
| 30 | + "from IPython.core.display import Javascript, HTML\n", |
31 | 31 | "import json" |
32 | 32 | ] |
33 | 33 | }, |
|
80 | 80 | " \"visConfig\": {\n", |
81 | 81 | " \"nodes\": {\n", |
82 | 82 | " \"shape\": \"hexagon\",\n", |
| 83 | + " \"shadow\": False,\n", |
83 | 84 | " \"font\": {\n", |
84 | 85 | " \"strokeWidth\": 4,\n", |
85 | | - " \"strokeColor\": \"#D0D0FF\",\n", |
86 | | - " \"size\": 32\n", |
| 86 | + " \"strokeColor\": \"#F2F2FF\",\n", |
| 87 | + " \"size\": 12\n", |
87 | 88 | " },\n", |
88 | | - " \"size\": 40,\n", |
| 89 | + " \"size\": 22,\n", |
89 | 90 | " \"borderWidth\": 2,\n", |
90 | 91 | " \"widthConstraint\": {\n", |
91 | | - " \"maximum\": 120\n", |
| 92 | + " \"maximum\": 60\n", |
92 | 93 | " }\n", |
93 | 94 | " },\n", |
94 | 95 | " \"edges\": {\n", |
|
99 | 100 | " }\n", |
100 | 101 | " },\n", |
101 | 102 | " \"scaling\": {\n", |
102 | | - " \"max\": 8\n", |
| 103 | + " \"max\": 6\n", |
103 | 104 | " }\n", |
104 | 105 | " },\n", |
105 | 106 | " \"physics\": {\n", |
|
126 | 127 | { |
127 | 128 | "cell_type": "code", |
128 | 129 | "execution_count": null, |
129 | | - "id": "b446809d", |
| 130 | + "id": "5f15d92e", |
130 | 131 | "metadata": {}, |
131 | 132 | "outputs": [], |
132 | 133 | "source": [ |
133 | | - "# Initialize global Javascript array that contains all visualization configurations\n", |
134 | | - "Javascript(\"\"\"window.graphVisualizationConfiguration=[];\"\"\")" |
| 134 | + "cssTemplate = \"\"\"\n", |
| 135 | + ".graph-visualization {\n", |
| 136 | + " width: 660px;\n", |
| 137 | + " height: 660px;\n", |
| 138 | + " border: 1px solid lightgray;\n", |
| 139 | + "}\n", |
| 140 | + "div.vis-tooltip {\n", |
| 141 | + " font-size: 6px;\n", |
| 142 | + "}\n", |
| 143 | + "\"\"\"\n", |
| 144 | + "\n", |
| 145 | + "# Use JavaScript library neovis.js to render the graph into the HTML above\n", |
| 146 | + "javascriptTemplate = \"\"\"\n", |
| 147 | + "function draw(NeoVis) {\n", |
| 148 | + " configuration.labels[NeoVis.NEOVIS_DEFAULT_CONFIG] = {\n", |
| 149 | + " [NeoVis.NEOVIS_ADVANCED_CONFIG]: {\n", |
| 150 | + " function: {\n", |
| 151 | + " title: NeoVis.objectToTitleHtml // Show all node properties in the tooltip\n", |
| 152 | + " }\n", |
| 153 | + " }\n", |
| 154 | + " }\n", |
| 155 | + " configuration.relationships[NeoVis.NEOVIS_DEFAULT_CONFIG] = {\n", |
| 156 | + " [NeoVis.NEOVIS_ADVANCED_CONFIG]: {\n", |
| 157 | + " function: {\n", |
| 158 | + " title: NeoVis.objectToTitleHtml // Show all relationship properties in the tooltip\n", |
| 159 | + " }\n", |
| 160 | + " }\n", |
| 161 | + " }\n", |
| 162 | + " configuration.labels.Artifact = {\n", |
| 163 | + " [NeoVis.NEOVIS_ADVANCED_CONFIG]: {\n", |
| 164 | + " function: {\n", |
| 165 | + " // Use \"fileName\" as label. Remove leading slash, trailing \".jar\" and version number.\n", |
| 166 | + " // TODO Enrich the Graph so that there is a distinct property for the \"cleaned up\" artifact name\n", |
| 167 | + " label: (node) => node.properties.fileName.replace('/', '').replace('.jar', '').replace(/-[\\d\\\\.]+/, '')\n", |
| 168 | + " }\n", |
| 169 | + " }\n", |
| 170 | + " }\n", |
| 171 | + " console.debug(configuration)\n", |
| 172 | + " const neoViz = new NeoVis.default(configuration);\n", |
| 173 | + " neoViz.render();\n", |
| 174 | + "}\n", |
| 175 | + "\n", |
| 176 | + "// Use JavaScript library neovis.js to render the graph into the HTML above\n", |
| 177 | + "requirejs(['https://unpkg.com/[email protected]'], function(NeoVis){ \n", |
| 178 | + " draw(NeoVis);\n", |
| 179 | + "}, function (err) {\n", |
| 180 | + " throw new Error(\"Failed to load NeoVis:\" + err);\n", |
| 181 | + "});\n", |
| 182 | + "\"\"\"\n", |
| 183 | + "\n", |
| 184 | + "htmlTemplate=\"\"\"\n", |
| 185 | + "<!DOCTYPE html>\n", |
| 186 | + "<html>\n", |
| 187 | + "<head>\n", |
| 188 | + " <title>Jupyter Notebook embedded neovis.js visualization</title>\n", |
| 189 | + " <style type=\"text/css\">{css}</style>\n", |
| 190 | + "</head>\n", |
| 191 | + "<body>\n", |
| 192 | + " <div id=\"{containerId}\" class=\"graph-visualization\"></div>\n", |
| 193 | + " <script type=\"text/javascript\" defer>\n", |
| 194 | + " {script}\n", |
| 195 | + " </script>\n", |
| 196 | + "</body>\n", |
| 197 | + "</html>\n", |
| 198 | + "\"\"\"" |
135 | 199 | ] |
136 | 200 | }, |
137 | 201 | { |
|
175 | 239 | " ,dependent.topologicalSortIndex ASC\n", |
176 | 240 | " LIMIT 20 \n", |
177 | 241 | " \"\"\"\n", |
| 242 | + " \n", |
178 | 243 | " return {\n", |
179 | 244 | " \"initialCypher\": query,\n", |
180 | 245 | " \"labels\": {\n", |
|
204 | 269 | "# Assemble the neovis.js configuration by joining the different parts of it\n", |
205 | 270 | "graphVisualizationConfiguration = {**htmlElement, **visualization_configuration(), **serverConfiguration, **java_artifact_query_configuration()}\n", |
206 | 271 | "\n", |
207 | | - "# Add the configuration in JSON format to a (global) Javascript array\n", |
208 | | - "# print(json.dumps(graphVisualizationConfiguration, indent=3)) # Prints the assembled configuration for debugging\n", |
209 | | - "Javascript(\"\"\"window.graphVisualizationConfiguration.push({});\"\"\".format(json.dumps(graphVisualizationConfiguration)))" |
210 | | - ] |
211 | | - }, |
212 | | - { |
213 | | - "cell_type": "code", |
214 | | - "execution_count": null, |
215 | | - "id": "55aa9696", |
216 | | - "metadata": { |
217 | | - "scrolled": true |
218 | | - }, |
219 | | - "outputs": [], |
220 | | - "source": [ |
221 | | - "%%html\n", |
222 | | - "<style type=\"text/css\">\n", |
223 | | - " .graph-visualization {\n", |
224 | | - " width: 660px;\n", |
225 | | - " height: 660px;\n", |
226 | | - " border: 1px solid lightgray;\n", |
227 | | - " }\n", |
228 | | - "</style>\n", |
229 | | - "<div id=\"graph-visualization-java-artifacts\" class=\"graph-visualization\"></div>" |
| 272 | + "# Assemble the HTML by including CSS and Javascript\n", |
| 273 | + "jsonConfiguration = json.dumps(graphVisualizationConfiguration)\n", |
| 274 | + "javascriptContent=\"configuration=\" + jsonConfiguration +\"; \" + javascriptTemplate\n", |
| 275 | + "htmlContent = htmlTemplate.format(script=javascriptContent, css=cssTemplate, containerId=htmlElement[\"containerId\"])\n", |
| 276 | + "\n", |
| 277 | + "# Display the HTML\n", |
| 278 | + "display(HTML(htmlContent))" |
230 | 279 | ] |
231 | 280 | }, |
232 | 281 | { |
|
242 | 291 | { |
243 | 292 | "cell_type": "code", |
244 | 293 | "execution_count": null, |
245 | | - "id": "8455926e", |
| 294 | + "id": "5c344092", |
246 | 295 | "metadata": {}, |
247 | 296 | "outputs": [], |
248 | 297 | "source": [ |
|
264 | 313 | " \"label\": \"name\"\n", |
265 | 314 | " },\n", |
266 | 315 | " \"labels\": {\n", |
267 | | - " \"Module\": {\n", |
| 316 | + " \"File\": {\n", |
268 | 317 | " \"label\": \"name\"\n", |
269 | 318 | " }\n", |
270 | 319 | " },\n", |
|
280 | 329 | { |
281 | 330 | "cell_type": "code", |
282 | 331 | "execution_count": null, |
283 | | - "id": "0f705d6a", |
| 332 | + "id": "dcc6fe3d", |
284 | 333 | "metadata": {}, |
285 | 334 | "outputs": [], |
286 | 335 | "source": [ |
|
290 | 339 | "# Assemble the neovis.js configuration by joining the different parts of it\n", |
291 | 340 | "graphVisualizationConfiguration = {**htmlElement, **visualization_configuration(), **serverConfiguration, **typescript_module_query_configuration()}\n", |
292 | 341 | "\n", |
293 | | - "# Add the configuration in JSON format to a (global) Javascript array\n", |
294 | | - "# print(json.dumps(graphVisualizationConfiguration, indent=3)) # Prints the assembled configuration for debugging\n", |
295 | | - "Javascript(\"\"\"window.graphVisualizationConfiguration.push({});\"\"\".format(json.dumps(graphVisualizationConfiguration)))" |
296 | | - ] |
297 | | - }, |
298 | | - { |
299 | | - "cell_type": "code", |
300 | | - "execution_count": null, |
301 | | - "id": "16c95d81", |
302 | | - "metadata": {}, |
303 | | - "outputs": [], |
304 | | - "source": [ |
305 | | - "%%html\n", |
306 | | - "<style type=\"text/css\">\n", |
307 | | - " .graph-visualization {\n", |
308 | | - " width: 660px;\n", |
309 | | - " height: 660px;\n", |
310 | | - " border: 1px solid lightgray;\n", |
311 | | - " }\n", |
312 | | - "</style>\n", |
313 | | - "<div id=\"graph-visualization-typescript-modules\" class=\"graph-visualization\"></div>" |
314 | | - ] |
315 | | - }, |
316 | | - { |
317 | | - "cell_type": "markdown", |
318 | | - "id": "39a03a60", |
319 | | - "metadata": {}, |
320 | | - "source": [ |
321 | | - "## Visualization using neovis.js\n", |
322 | | - "\n", |
323 | | - "Use the JavaScript library [neovis.js](https://github.com/neo4j-contrib/neovis.js) to render the graph into the HTML above with the following javascript block." |
324 | | - ] |
325 | | - }, |
326 | | - { |
327 | | - "cell_type": "code", |
328 | | - "execution_count": null, |
329 | | - "id": "55a96744", |
330 | | - "metadata": {}, |
331 | | - "outputs": [], |
332 | | - "source": [ |
333 | | - "%%javascript\n", |
| 342 | + "# Assemble the HTML by including CSS and Javascript\n", |
| 343 | + "jsonConfiguration = json.dumps(graphVisualizationConfiguration)\n", |
| 344 | + "javascriptContent=\"configuration=\" + jsonConfiguration +\"; \" + javascriptTemplate\n", |
| 345 | + "htmlContent = htmlTemplate.format(script=javascriptContent, css=cssTemplate, containerId=htmlElement[\"containerId\"])\n", |
334 | 346 | "\n", |
335 | | - "// Use JavaScript library neovis.js to render the graph into the HTML above\n", |
336 | | - "requirejs(['https://unpkg.com/[email protected]'], function(NeoVis){ \n", |
337 | | - " window.graphVisualizationConfiguration.forEach((configuration) => {\n", |
338 | | - " configuration.labels.Artifact = {\n", |
339 | | - " [NeoVis.NEOVIS_ADVANCED_CONFIG]: {\n", |
340 | | - " function: {\n", |
341 | | - " // Print all properties for the title (when nodes are clicked)\n", |
342 | | - " title: NeoVis.objectToTitleHtml,\n", |
343 | | - " // Use \"fileName\" as label. Remove leading slash, trailing \".jar\" and version number.\n", |
344 | | - " label: (node) => node.properties.fileName.replace('/', '').replace('.jar', '').replace(/-[\\d\\\\.]+/, '')\n", |
345 | | - " },\n", |
346 | | - " }\n", |
347 | | - " }\n", |
348 | | - " \n", |
349 | | - " const viz = new NeoVis.default(configuration);\n", |
350 | | - " viz.render();\n", |
351 | | - " });\n", |
352 | | - " }, function (err) {\n", |
353 | | - " throw new Error(\"Failed to load NeoVis:\" + err);\n", |
354 | | - " }\n", |
355 | | - ");" |
| 347 | + "# Display the HTML\n", |
| 348 | + "display(HTML(htmlContent))" |
356 | 349 | ] |
357 | 350 | }, |
358 | 351 | { |
|
0 commit comments