{
  "nbformat_minor": 0, 
  "nbformat": 4, 
  "cells": [
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "%matplotlib inline"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }, 
    {
      "source": [
        "\n# Javascript\n\n\nExample of writing JSON format graph data and using the D3 Javascript library to produce an HTML/Javascript drawing.\n\n"
      ], 
      "cell_type": "markdown", 
      "metadata": {}
    }, 
    {
      "execution_count": null, 
      "cell_type": "code", 
      "source": [
        "# Author: Aric Hagberg <aric.hagberg@gmail.com>\n\n#    Copyright (C) 2011-2017 by\n#    Aric Hagberg <hagberg@lanl.gov>\n#    Dan Schult <dschult@colgate.edu>\n#    Pieter Swart <swart@lanl.gov>\n#    All rights reserved.\n#    BSD license.\nimport json\n\nimport flask\nimport networkx as nx\nfrom networkx.readwrite import json_graph\n\nG = nx.barbell_graph(6, 3)\n# this d3 example uses the name attribute for the mouse-hover value,\n# so add a name to each node\nfor n in G:\n    G.nodes[n]['name'] = n\n# write json formatted data\nd = json_graph.node_link_data(G)  # node-link format to serialize\n# write json\njson.dump(d, open('force/force.json', 'w'))\nprint('Wrote node-link JSON data to force/force.json')\n\n# Serve the file over http to allow for cross origin requests\napp = flask.Flask(__name__, static_folder=\"force\")\n\n@app.route('/<path:path>')\ndef static_proxy(path):\n    return app.send_static_file(path)\n\nprint('\\nGo to http://localhost:8000/force.html to see the example\\n')\napp.run(port=8000)"
      ], 
      "outputs": [], 
      "metadata": {
        "collapsed": false
      }
    }
  ], 
  "metadata": {
    "kernelspec": {
      "display_name": "Python 2", 
      "name": "python2", 
      "language": "python"
    }, 
    "language_info": {
      "mimetype": "text/x-python", 
      "nbconvert_exporter": "python", 
      "name": "python", 
      "file_extension": ".py", 
      "version": "2.7.12", 
      "pygments_lexer": "ipython2", 
      "codemirror_mode": {
        "version": 2, 
        "name": "ipython"
      }
    }
  }
}