Mercurial > hg > NetworkVis
comparison ismi-python-neo4jrestclient/static/commentaries.html @ 23:80010fb9dbce
make new commentaries visualisation the default.
author | casties |
---|---|
date | Fri, 30 Oct 2015 15:37:43 +0100 |
parents | ismi-python-neo4jrestclient/static/commentaries_authors3.html@b709419d4235 |
children | eb0be386736f |
comparison
equal
deleted
inserted
replaced
22:b709419d4235 | 23:80010fb9dbce |
---|---|
1 <html> | 1 <html> |
2 <head> | 2 <head> |
3 <meta name="viewport" content="width=device-width, initial-scale=1.0"> | 3 <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
4 <link rel="stylesheet" href="//neo4j-contrib.github.io/developer-resources/language-guides/assets/css/main.css"> | 4 <link rel="stylesheet" href="static/main.css"> |
5 <title>ISMI commentary relations</title> | 5 <title>ISMI commentary relations</title> |
6 </head> | 6 </head> |
7 | 7 |
8 <body style="background:none;"> | 8 <body style="background:none;"> |
9 <div id="graph"> | |
10 </div> | |
11 <div role="navigation" class="navbar navbar-default navbar-static-top"> | 9 <div role="navigation" class="navbar navbar-default navbar-static-top"> |
12 <div class="container"> | 10 <div class="container"> |
13 <div class="row"> | 11 <div class="row"> |
14 <div class="col-sm-6 col-md-6"> | 12 <div class="col-sm-6 col-md-6"> |
15 <ul class="nav navbar-nav"> | 13 <ul class="nav navbar-nav"> |
16 <li> | 14 <li> |
17 <form role="search" class="navbar-form" id="search"> | 15 <form role="search" class="navbar-form" id="search"> |
18 <div class="form-group"> | 16 <div class="form-group"> |
19 <input type="text" value="Qushji" placeholder="Search for Title" class="form-control" name="search"> | 17 <input type="text" value="7437" placeholder="Search for person-id" class="form-control" name="search"> |
20 </div> | 18 </div> |
21 <button class="btn btn-default" type="submit">Search</button> | 19 <button class="btn btn-default" type="submit">Search for author id</button> |
22 </form> | 20 </form> |
23 </li> | 21 </li> |
24 </ul> | 22 </ul> |
25 </div> | 23 </div> |
26 <div class="navbar-header col-sm-6 col-md-6"> | 24 <div class="navbar-header col-sm-6 col-md-6"> |
38 </div> | 36 </div> |
39 | 37 |
40 <div class="row"> | 38 <div class="row"> |
41 <div class="col-md-5"> | 39 <div class="col-md-5"> |
42 <div class="panel panel-default"> | 40 <div class="panel panel-default"> |
43 <div class="panel-heading">Search Results</div> | 41 <div class="panel-heading"> |
42 <span id="author">Titles by this author</span> | |
43 <span class="clickhide">(click to hide)</span> | |
44 <span class="clickhide" style="display:none;">(click to show)</span> | |
45 </div> | |
44 <table id="results" class="table table-striped table-hover"> | 46 <table id="results" class="table table-striped table-hover"> |
45 <thead> | 47 <thead> |
46 <tr> | 48 <tr> |
47 <th>Title (translit)</th> | 49 <th>Title (translit)</th> |
48 <th>Title (arabic)</th> | 50 <th>Title (arabic)</th> |
54 </table> | 56 </table> |
55 </div> | 57 </div> |
56 </div> | 58 </div> |
57 <div class="col-md-7"> | 59 <div class="col-md-7"> |
58 <div class="panel panel-default"> | 60 <div class="panel panel-default"> |
59 <div class="panel-heading" id="title">Details</div> | 61 <div class="panel-heading"> |
62 <span id="title">Text details</span> | |
63 <span class="clickhide">(click to hide)</span> | |
64 <span class="clickhide" style="display:none;">(click to show)</span> | |
65 </div> | |
60 <div class="row"> | 66 <div class="row"> |
61 <!-- <div class="col-sm-4 col-md-4"> | 67 <!-- <div class="col-sm-4 col-md-4"> |
62 <img src="" class="well" id="poster"/> | 68 <img src="" class="well" id="poster"/> |
63 </div> --> | 69 </div> --> |
64 <div class="col-md-8 col-sm-8"> | 70 <div class="col-md-8 col-sm-8"> |
65 <h4>Details</h4> | 71 <h4>Details</h4> |
66 <ul id="info"> | 72 <ul id="info"> |
67 </ul> | 73 </ul> |
74 <h4>Commenting on</h4> | |
75 <ul id="commenting"> | |
76 </ul> | |
77 <h4>Commentaries</h4> | |
78 <ul id="commentaries"> | |
79 </ul> | |
68 </div> | 80 </div> |
69 </div> | 81 </div> |
70 </div> | 82 </div> |
71 </div> | 83 </div> |
72 </div> | 84 </div> |
85 <div class="col-lg-12"> | |
86 <div class="panel panel-default"> | |
87 <div class="panel-heading"> | |
88 <span>Graph of commentaries</span> | |
89 <span class="clickhide">(click to hide)</span> | |
90 <span class="clickhide" style="display:none;">(click to show)</span> | |
91 </div> | |
92 <div id="graph"> | |
93 </div> | |
94 </div> | |
95 </div> | |
96 | |
73 <style type="text/css"> | 97 <style type="text/css"> |
74 .node { stroke: #222; stroke-width: 1.5px; } | 98 .node { stroke: #222; stroke-width: 1.5px; } |
75 .node.TEXT { fill: #888; } | 99 .node.TEXT { fill: #888; } |
76 .node.movie { fill: #BBB; } | 100 .node.TEXT.marked { stroke: red; } |
77 .link { stroke: #999; stroke-opacity: .6; stroke-width: 1px; } | 101 .node.TEXT.selected { fill: red; } |
102 .link { stroke: #999; stroke-opacity: .6; stroke-width: 2px; } | |
103 .arrowHead { fill: #999 } | |
104 tr.marked {border: 2px solid red;} | |
78 </style> | 105 </style> |
79 | 106 |
80 <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script> | 107 <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script> |
81 <!-- <script src="https://d3js.org/d3.v3.min.js" type="text/javascript"></script> --> | 108 <!-- <script src="https://d3js.org/d3.v3.min.js" type="text/javascript"></script> --> |
82 <script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" type="text/javascript"></script> | 109 <script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js" type="text/javascript"></script> |
83 <script type="text/javascript"> | 110 <script type="text/javascript"> |
84 backendApiPrefix = ""; | 111 // make panels roll-up |
112 $(".panel-heading").on("click", function() { | |
113 $(this).find(".clickhide").toggle(); | |
114 $(this).next().slideToggle(); | |
115 }); | |
116 // provide search and graph | |
117 backendApiPrefix = "/netvis-ismi"; | |
118 searchApi = {}; | |
85 $(function () { | 119 $(function () { |
86 function showMovie(text_id) { | 120 function showText(text_id) { |
87 $.get(backendApiPrefix+"/text/" + encodeURIComponent(text_id), | 121 $.get(backendApiPrefix+"/textandcommentaries/" + encodeURIComponent(text_id), |
88 function (data) { | 122 function (data) { |
89 if (!data) return; | 123 if (!data) return; |
90 $("#title").text(data.title); | 124 $("#title").text("Title: "+data.title); |
91 // $("#poster").attr("src","//neo4j-contrib.github.io/developer-resources/language-guides/assets/posters/"+encodeURIComponent(data.title)+".jpg"); | |
92 var $list = $("#info").empty(); | 125 var $list = $("#info").empty(); |
93 for (key in data.attrs) { | 126 $list.append($("<li>Author: " + data.author.label + " [" + data.author.ismi_id + "]</li>") |
94 val = data.attrs[key]; | 127 .click(function() { |
128 search(data.author.ismi_id, true); | |
129 })); | |
130 for (var key in data.attrs) { | |
131 var val = data.attrs[key]; | |
95 if (key === "link") { | 132 if (key === "link") { |
96 val = "<a href=\"" + val + "\" target=\"_blank\">" + val + "</a>"; | 133 val = "<a href=\"" + val + "\" target=\"_blank\">" + val + "</a>"; |
97 } | 134 } |
98 $list.append($("<li>" + key + ": " + val + "</li>")); | 135 $list.append($("<li>" + key + ": " + val + "</li>")); |
99 }; | 136 }; |
137 // re-set selected | |
138 $("#graph .selected").each(function(){this.classList.remove("selected")}); | |
139 $("#graph .ismi-"+data.attrs.ismi_id).each(function(){this.classList.add("selected")}); | |
140 // add commentaries | |
141 var $commentaries = $("#commentaries").empty(); | |
142 for (var key in data.commentaries) { | |
143 var val = data.commentaries[key]; | |
144 $commentaries.append($("<li>" + val.title + " [<span class=\"text_id\">" + key + "</span>] by " + val.author + "</li>") | |
145 .click(function() { showText($(this).find("span.text_id").text());})); | |
146 } | |
147 var $commenting = $("#commenting").empty(); | |
148 for (var key in data.commenting) { | |
149 var val = data.commenting[key]; | |
150 $commenting.append($("<li>" + val.title + " [<span class=\"text_id\">" + key + "</span>] by " + val.author + "</li>") | |
151 .click(function() { showText($(this).find("span.text_id").text());})); | |
152 } | |
100 }, "json"); | 153 }, "json"); |
101 return false; | 154 return false; |
102 } | 155 } |
103 function search() { | 156 function search(query, keep_detail_view) { |
104 var query=$("#search").find("input[name=search]").val(); | 157 if (query == null) { |
158 query=$("#search").find("input[name=search]").val(); | |
159 } | |
105 $.get(backendApiPrefix+"/search?q=" + encodeURIComponent(query), | 160 $.get(backendApiPrefix+"/search?q=" + encodeURIComponent(query), |
106 function (data) { | 161 function (data) { |
107 var t = $("table#results tbody").empty(); | 162 var t = $("table#results tbody").empty(); |
108 if (!data || data.length == 0) return; | 163 if (!data || data.length == 0) return; |
164 // clear all marks | |
165 $("#graph .marked").each(function(){this.classList.remove("marked")}); | |
166 // fill table of titles | |
109 data.forEach(function (row) { | 167 data.forEach(function (row) { |
110 var text = row.text; | 168 var text = row.text; |
111 $("<tr><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t) | 169 var author = row.author; |
112 .click(function() { showMovie($(this).find("td.text_id").text());}) | 170 $("#author").text("Titles by Author: "+author.label+" ["+author.ismi_id+"]"); |
171 var comm = row.is_commentary || row.has_commentaries; | |
172 var $row = $("<tr><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t) | |
173 .click(function() { showText($(this).find("td.text_id").text());}); | |
174 if (comm) { | |
175 $row.addClass("marked"); | |
176 } | |
177 // set mark | |
178 $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")}); | |
113 }); | 179 }); |
114 showMovie(data[0].text.ismi_id); | 180 if (!keep_detail_view) { |
181 // show first title | |
182 showText(data[0].text.ismi_id); | |
183 } | |
115 }, "json"); | 184 }, "json"); |
116 return false; | 185 return false; |
117 } | 186 } |
118 | 187 // export API |
188 searchApi.showText = showText; | |
189 searchApi.search = search; | |
190 // start search | |
119 $("#search").submit(search); | 191 $("#search").submit(search); |
120 search(); | 192 search(); |
121 }) | 193 }); |
122 </script> | 194 </script> |
123 | 195 |
124 <script type="text/javascript"> | 196 <script type="text/javascript"> |
125 var width = 800, height = 800; | 197 var width = 1400, height = 1400; |
126 | 198 |
127 var force = d3.layout.force() | 199 var force = d3.layout.force() |
128 .charge(-200).linkDistance(30).size([width, height]); | 200 .charge(-100) // -200 |
201 .linkDistance(30) // 30 | |
202 .size([width, height]); | |
129 | 203 |
130 var svg = d3.select("#graph").append("svg") | 204 var svg = d3.select("#graph").append("svg") |
131 .attr("width", "100%").attr("height", "100%") | 205 .attr("width", "1400px").attr("height", "1400px") |
132 .attr("pointer-events", "all"); | 206 .attr("pointer-events", "all"); |
133 | 207 |
134 d3.json(backendApiPrefix+"/graph", function(error, graph) { | 208 // arrow head marker |
209 var defs = svg.append("defs").append("marker") | |
210 .attr({ | |
211 "id":"arrow", | |
212 "markerUnits": "strokeWidth", | |
213 "viewBox":"0 -5 10 10", | |
214 "refX": 20, // 5 | |
215 "refY":0, | |
216 "markerWidth":4, | |
217 "markerHeight":4, | |
218 "orient":"auto" | |
219 }) | |
220 .append("path") | |
221 .attr("d", "M0,-5 L10,0 L0,5") | |
222 .attr("class","arrowHead"); | |
223 | |
224 // load graph | |
225 d3.json(backendApiPrefix+"/graph?limit=1000", function(error, graph) { | |
135 if (error) return; | 226 if (error) return; |
136 | 227 |
137 force.nodes(graph.nodes).links(graph.links).start(); | 228 force.nodes(graph.nodes).links(graph.links).start(); |
138 | 229 |
139 var link = svg.selectAll(".link") | 230 var link = svg.selectAll(".link") |
140 .data(graph.links).enter() | 231 .data(graph.links).enter() |
141 .append("line").attr("class", "link"); | 232 .append("line").attr({ |
233 "class": "link", | |
234 "marker-end": "url(#arrow)" | |
235 }); | |
142 | 236 |
143 var node = svg.selectAll(".node") | 237 var node = svg.selectAll(".node") |
144 .data(graph.nodes).enter() | 238 .data(graph.nodes).enter() |
145 .append("circle") | 239 .append("circle") |
146 .attr("class", function (d) { return "node "+d.label }) | 240 .attr("class", function (d) { return "node "+d.label+" ismi-"+d.ismi_id}) |
147 .attr("r", 10) | 241 .attr("r", 8) // 10 |
242 .attr("data-ismi_id", function(d) {return d.ismi_id}) | |
243 .on("click", function() { | |
244 var id = this.getAttribute("data-ismi_id"); | |
245 searchApi.showText(id); | |
246 }) | |
148 .call(force.drag); | 247 .call(force.drag); |
149 | 248 |
249 console.log("searchApi:", searchApi); | |
150 // html title attribute | 250 // html title attribute |
151 node.append("title") | 251 node.append("title") |
152 .text(function (d) { return d.title; }) | 252 .text(function (d) { return d.title; }) |
153 | 253 |
154 // force feed algo ticks | 254 // force feed algo ticks |
155 force.on("tick", function() { | 255 force.on("tick", function() { |
156 link.attr("x1", function(d) { return d.source.x; }) | 256 link.attr("x1", function(d) { return d.source.x; }) |
157 .attr("y1", function(d) { return d.source.y; }) | 257 .attr("y1", function(d) { return d.source.y; }) |
158 .attr("x2", function(d) { return d.target.x; }) | 258 .attr("x2", function(d) { return d.target.x; }) |
160 | 260 |
161 node.attr("cx", function(d) { return d.x; }) | 261 node.attr("cx", function(d) { return d.x; }) |
162 .attr("cy", function(d) { return d.y; }); | 262 .attr("cy", function(d) { return d.y; }); |
163 }); | 263 }); |
164 }); | 264 }); |
265 | |
165 </script> | 266 </script> |
166 </body> | 267 </body> |
167 </html> | 268 </html> |