Created
March 27, 2018 11:47
-
-
Save mapio/b59df475e624b9ab116c762123578afd to your computer and use it in GitHub Desktop.
VivaGraphJS in Jupyter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"hideCode": false, | |
"hidePrompt": false, | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"application/javascript": [ | |
"\n", | |
"require.config({\n", | |
" paths: { 'viva': 'https://cdnjs.cloudflare.com/ajax/libs/vivagraphjs/0.10.1/vivagraph' }\n", | |
"});\n", | |
"\n", | |
"require(['viva'], function(Viva) {\n", | |
" \n", | |
"var outelem = element[0];\n", | |
"outelem.style.width = '640px';\n", | |
"outelem.style.height = '480px';\n", | |
" \n", | |
"var graphGenerator = Viva.Graph.generator();\n", | |
" \n", | |
"var graph = graphGenerator.grid(10, 100);\n", | |
" \n", | |
"var layout = Viva.Graph.Layout.forceDirected(graph, {\n", | |
" springLength : 30,\n", | |
" springCoeff : 0.0008,\n", | |
" dragCoeff : 0.01,\n", | |
" gravity : -1.2,\n", | |
" theta : 1\n", | |
"});\n", | |
"\n", | |
"var graphics = Viva.Graph.View.webglGraphics();\n", | |
"\n", | |
"var renderer = Viva.Graph.View.renderer(graph, {\n", | |
" layout: layout,\n", | |
" graphics: graphics,\n", | |
" renderLinks: true,\n", | |
" prerender: true,\n", | |
" container: outelem\n", | |
"});\n", | |
"\n", | |
"renderer.run();\n", | |
"\n", | |
"});" | |
], | |
"text/plain": [ | |
"<IPython.core.display.Javascript object>" | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
} | |
], | |
"source": [ | |
"%%javascript\n", | |
"\n", | |
"require.config({\n", | |
" paths: { 'viva': 'https://cdnjs.cloudflare.com/ajax/libs/vivagraphjs/0.10.1/vivagraph' }\n", | |
"});\n", | |
"\n", | |
"require(['viva'], function(Viva) {\n", | |
" \n", | |
"var outelem = element[0];\n", | |
"outelem.style.width = '640px';\n", | |
"outelem.style.height = '480px';\n", | |
" \n", | |
"var graphGenerator = Viva.Graph.generator();\n", | |
" \n", | |
"var graph = graphGenerator.grid(10, 100);\n", | |
" \n", | |
"var layout = Viva.Graph.Layout.forceDirected(graph, {\n", | |
" springLength : 30,\n", | |
" springCoeff : 0.0008,\n", | |
" dragCoeff : 0.01,\n", | |
" gravity : -1.2,\n", | |
" theta : 1\n", | |
"});\n", | |
"\n", | |
"var graphics = Viva.Graph.View.webglGraphics();\n", | |
"\n", | |
"var renderer = Viva.Graph.View.renderer(graph, {\n", | |
" layout: layout,\n", | |
" graphics: graphics,\n", | |
" renderLinks: true,\n", | |
" prerender: true,\n", | |
" container: outelem\n", | |
"});\n", | |
"\n", | |
"renderer.run();\n", | |
"\n", | |
"});" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"hideCode": false, | |
"hidePrompt": false | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"hide_code_all_hidden": false, | |
"kernelspec": { | |
"display_name": "Python 3", | |
"language": "python", | |
"name": "python3" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython3", | |
"version": "3.6.4" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment