{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Try local javascript\n", "\n", "Use javascript in a notebook with local scripts."]}, {"cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [{"data": {"text/html": ["
run previous cell, wait for 2 seconds
\n", ""], "text/plain": [""]}, "execution_count": 2, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import add_notebook_menu\n", "add_notebook_menu()"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## JSJSON"]}, {"cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", "\n"], "text/plain": [""]}, "execution_count": 3, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import JSONJS\n", "JSONJS(dict(name=\"xavier\", city=\"Paris\"), only_html=True, show_to_level=3, local=True)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["The function copies the javascript code in the current folder."]}, {"cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [{"data": {"text/plain": ["['custom_demo.js', 'renderjson.js', 'vis.min.js', 'viz-lite.js', 'viz.js']"]}, "execution_count": 4, "metadata": {}, "output_type": "execute_result"}], "source": ["import os\n", "[_ for _ in os.listdir(os.getcwd()) if '.js' in _]"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## RenderJsDot"]}, {"cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", ""], "text/plain": [""]}, "execution_count": 5, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import RenderJsDot\n", "\n", "dot = \"\"\"\n", "digraph {\n", " d[label=\"longer label\"];\n", " a -> b -> c;\n", " b -> d;\n", "}\n", "\"\"\"\n", "\n", "RenderJsDot(dot, local=True)"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## RenderJsVis"]}, {"cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [], "source": ["script = \"\"\"\n", " var nodes = new vis.DataSet([\n", " {id: 1, label: 'Node 1'},\n", " {id: 2, label: 'Node 2'},\n", " {id: 3, label: 'Node 3'},\n", " {id: 4, label: 'Node 4'},\n", " {id: 5, label: 'Node 5'}\n", " ]);\n", "\n", " // create an array with edges\n", " var edges = new vis.DataSet([\n", " {from: 1, to: 3},\n", " {from: 1, to: 2},\n", " {from: 2, to: 4},\n", " {from: 2, to: 5},\n", " {from: 3, to: 3}\n", " ]);\n", "\n", " // create a network\n", " var data = {\n", " nodes: nodes,\n", " edges: edges\n", " };\n", " var options = {};\n", "\"\"\""]}, {"cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", ""], "text/plain": [""]}, "execution_count": 7, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import RenderJsVis\n", "RenderJsVis(script, local=False, width=\"400px\", height=\"300px\")"]}, {"cell_type": "markdown", "metadata": {}, "source": ["## RenderJsVis with DOT\n", "\n", "[DOT](https://en.wikipedia.org/wiki/DOT_(graph_description_language) is quite popular to desccribe graph."]}, {"cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", ""], "text/plain": [""]}, "execution_count": 8, "metadata": {}, "output_type": "execute_result"}], "source": ["from jyquickhelper import RenderJsVis\n", "\n", "dot = \"\"\"\n", "digraph {\n", " d[label=\"longer label\"];\n", " a -> b -> c;\n", " b -> d;\n", "}\n", "\"\"\"\n", "\n", "RenderJsVis(dot=dot, local=True)"]}, {"cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [{"data": {"text/html": ["
\n", ""], "text/plain": [""]}, "execution_count": 9, "metadata": {}, "output_type": "execute_result"}], "source": ["RenderJsVis(dot=dot, local=True, layout=\"hierarchical\", height=\"200px\")"]}, {"cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": []}], "metadata": {"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.7.2"}}, "nbformat": 4, "nbformat_minor": 2}