Skip to content

Commit

Permalink
adding mobile patent suits example
Browse files Browse the repository at this point in the history
  • Loading branch information
ssunkara1 committed Jul 12, 2017
1 parent af06244 commit ebf0e2c
Showing 1 changed file with 124 additions and 0 deletions.
124 changes: 124 additions & 0 deletions 6 - Mobile Patent Suits.ipynb
@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"from itertools import chain\n",
"\n",
"from bqplot import OrdinalColorScale, Figure, Graph\n",
"from ipywidgets import Layout"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"# mobile patent suits - http://bl.ocks.org/mbostock/1153292\n",
"suits = [\n",
" {'source': 'Microsoft', 'target': 'Amazon', 'type': 'licensing'},\n",
" {'source': 'Microsoft', 'target': 'HTC', 'type': 'licensing'},\n",
" {'source': 'Samsung', 'target': 'Apple', 'type': 'suit'},\n",
" {'source': 'Motorola', 'target': 'Apple', 'type': 'suit'},\n",
" {'source': 'Nokia', 'target': 'Apple', 'type': 'resolved'},\n",
" {'source': 'HTC', 'target': 'Apple', 'type': 'suit'},\n",
" {'source': 'Kodak', 'target': 'Apple', 'type': 'suit'},\n",
" {'source': 'Microsoft', 'target': 'Barnes & Noble', 'type': 'suit'},\n",
" {'source': 'Microsoft', 'target': 'Foxconn', 'type': 'suit'},\n",
" {'source': 'Oracle', 'target': 'Google', 'type': 'suit'},\n",
" {'source': 'Apple', 'target': 'HTC', 'type': 'suit'},\n",
" {'source': 'Microsoft', 'target': 'Inventec', 'type': 'suit'},\n",
" {'source': 'Samsung', 'target': 'Kodak', 'type': 'resolved'},\n",
" {'source': 'LG', 'target': 'Kodak', 'type': 'resolved'},\n",
" {'source': 'RIM', 'target': 'Kodak', 'type': 'suit'},\n",
" {'source': 'Sony', 'target': 'LG', 'type': 'suit'},\n",
" {'source': 'Kodak', 'target': 'LG', 'type': 'resolved'},\n",
" {'source': 'Apple', 'target': 'Nokia', 'type': 'resolved'},\n",
" {'source': 'Qualcomm', 'target': 'Nokia', 'type': 'resolved'},\n",
" {'source': 'Apple', 'target': 'Motorola', 'type': 'suit'},\n",
" {'source': 'Microsoft', 'target': 'Motorola', 'type': 'suit'},\n",
" {'source': 'Motorola', 'target': 'Microsoft', 'type': 'suit'},\n",
" {'source': 'Huawei', 'target': 'ZTE', 'type': 'suit'},\n",
" {'source': 'Ericsson', 'target': 'ZTE', 'type': 'suit'},\n",
" {'source': 'Kodak', 'target': 'Samsung', 'type': 'resolved'},\n",
" {'source': 'Apple', 'target': 'Samsung', 'type': 'suit'},\n",
" {'source': 'Kodak', 'target': 'RIM', 'type': 'suit'},\n",
" {'source': 'Nokia', 'target': 'Qualcomm', 'type': 'suit'},\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false,
"deletable": true,
"editable": true
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "85c4a75d06c44bbfade097a0786e0a35"
}
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"# transform data into nodes and links\n",
"nodes = list(set(chain(*((suit['source'], suit['target']) for suit in suits))))\n",
"\n",
"# set custom node attrs\n",
"node_data = [{'label': node, 'shape_attrs': {'r': 6}, 'label_display': 'outside'} for node in nodes]\n",
"# for links, source and target should be indices into the nodes list\n",
"nodes_index_map = {node: i for i, node in enumerate(nodes)}\n",
"link_data = [{'source': nodes_index_map[s['source']], \n",
" 'target': nodes_index_map[s['target']], \n",
" 'value': s['type']} for s in suits]\n",
"\n",
"# encode suit type with link color\n",
"link_color_scale = OrdinalColorScale(domain=['licensing', 'suit', 'resolved'], \n",
" colors=['limegreen', 'dodgerblue', 'orangered'])\n",
"graph = Graph(node_data=node_data, link_data=link_data, link_type='arc', \n",
" scales={'link_color': link_color_scale}, colors=['gray'], \n",
" directed=True, link_distance=100, charge=-600)\n",
"Figure(marks=[graph], layout=Layout(height='900px', width='1000px'), title='Mobile Patent Suits')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit ebf0e2c

Please sign in to comment.