{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Most examples work across multiple plotting backends, this example is also available for:\n",
    "\n",
    "* [Matplotlib Directed Airline Routes](../matplotlib/directed_airline_routes.ipynb)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import networkx as nx\n",
    "import holoviews as hv\n",
    "from holoviews import opts\n",
    "\n",
    "from holoviews.element.graphs import layout_nodes\n",
    "from bokeh.sampledata.airport_routes import routes, airports\n",
    "\n",
    "hv.extension('bokeh')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Declare data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Create dataset indexed by AirportID and with additional value dimension\n",
    "airports = hv.Dataset(airports, ['AirportID'], ['Name', 'IATA', 'City'])\n",
    "\n",
    "label = 'Alaska Airline Routes'\n",
    "\n",
    "# Select just Alaska Airline routes\n",
    "as_graph = hv.Graph((routes[routes.Airline=='AS'], airports), ['SourceID', \"DestinationID\"], 'Airline', label=label)\n",
    "\n",
    "as_graph = layout_nodes(as_graph, layout=nx.layout.fruchterman_reingold_layout)\n",
    "labels = hv.Labels(as_graph.nodes, ['x', 'y'], ['IATA', 'City'], label=label)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "(as_graph * labels).opts(\n",
    "    opts.Graph(directed=True, node_size=8, bgcolor='gray', xaxis=None, yaxis=None,\n",
    "               edge_line_color='white', edge_line_width=1, width=800, height=800, arrowhead_length=0.01,\n",
    "               node_fill_color='white', node_nonselection_fill_color='black'),\n",
    "    opts.Labels(xoffset=-0.04, yoffset=0.03, text_font_size='10pt'))"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python",
   "pygments_lexer": "ipython3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
