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