Skip to content

Commit e8fbea5

Browse files
author
Mark Needham
committed
tidy up
1 parent b4d20da commit e8fbea5

File tree

3 files changed

+42
-23
lines changed

3 files changed

+42
-23
lines changed

generate_notebook.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,12 @@ def find_tag(file, tag):
142142
from IPython.core.display import display, HTML, Javascript
143143
from string import Template
144144
import json
145+
from scripts.algo import viz_config, render_image
145146
146-
query = "MATCH (p1:Page)-[r:LINKS]->(p2:Page) RETURN *"
147-
labels_json = {'Page': {'caption': 'name', 'size': 'pagerank'}}
148-
relationships_json = {'LINKS': {'thickness': 'weight', 'caption': False}}
147+
config = viz_config("%s")
148+
query = config["query"]
149+
labels_json = config["labels_json"]
150+
relationships_json = config["relationships_json"]
149151
150152
json_graph = {
151153
"query": query,
@@ -156,7 +158,7 @@ def find_tag(file, tag):
156158
"password": password
157159
}
158160
159-
Javascript("""window.jsonGraph={};""".format(json.dumps(json_graph)))'''
161+
Javascript("""window.jsonGraph={};""".format(json.dumps(json_graph)))''' % algorithm_name
160162

161163
neo_vis_div_cell = '''\
162164
%%html
@@ -204,7 +206,7 @@ def find_tag(file, tag):
204206
var cell_element = output_area.element.parents('.cell');
205207
var cell_idx = Jupyter.notebook.get_cell_elements().index(cell_element);
206208
var cell = Jupyter.notebook.get_cell(cell_idx+1);
207-
cell.set_text("HTML('<img id=\\"viz-image\\" width=\\"300px\\" src=\\"%s\\" />' % image_src)")
209+
cell.set_text("render_image(image_src)")
208210
cell.execute();
209211
});
210212
});'''

notebooks/PageRank.ipynb

Lines changed: 20 additions & 18 deletions
Large diffs are not rendered by default.

notebooks/scripts/algo.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from IPython.core.display import HTML
2+
3+
4+
def viz_config(algorithm_name):
5+
return {
6+
"Page Rank": {
7+
"query": "MATCH (p1:Page)-[r:LINKS]->(p2:Page) RETURN *",
8+
"labels_json": {'Page': {'caption': 'name', 'size': 'pagerank'}},
9+
"relationships_json": {'LINKS': {'thickness': 'weight', 'caption': False}}
10+
}
11+
}[algorithm_name]
12+
13+
14+
def render_image(image_src):
15+
return HTML('<img id="viz-image" width="300px" src="%s" />' % image_src)

0 commit comments

Comments
 (0)