changeset 17:09c0a9ceb778

more pimping of commentaries_authors.
author casties
date Wed, 07 Oct 2015 15:41:00 +0200
parents ad3eefa2cb80
children c5fffe4338a1
files ismi-python-neo4jrestclient/ismi-vis.py ismi-python-neo4jrestclient/static/commentaries_authors2.html
diffstat 2 files changed, 32 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/ismi-python-neo4jrestclient/ismi-vis.py	Tue Oct 06 19:26:46 2015 +0200
+++ b/ismi-python-neo4jrestclient/ismi-vis.py	Wed Oct 07 15:41:00 2015 +0200
@@ -151,17 +151,21 @@
     except KeyError:
         return []
     else:
-        query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON) "
-                 "WHERE p.ismi_id = {id} "
-                 "RETURN t,p")
+        query = ("MATCH (t:TEXT)-[:was_created_by]->(p:PERSON {ismi_id: {id}})"
+                 " RETURN t,p,exists((t)-[:is_commentary_on]->()),exists(()-[:is_commentary_on]->(t))")
         results = gdb.query(
             query,
-            returns=(Node,Node),
+            returns=(Node,Node,bool,bool),
             params={"id": int(q)}
         )
         # {"name": "(?i).*" + q + ".*"}
         print("search for %s returned %s results"%(repr(q),len(results)))
-        return Response(dumps([{"text": text.properties, "author": author.properties} for [text,author] in results]),
+        data = [{"text": t.properties, 
+                 "author": a.properties, 
+                 "is_commentary": is_com, 
+                 "has_commentaries": has_com} 
+                for [t,a,is_com,has_com] in results]
+        return Response(dumps(data),
                         mimetype="application/json")
 
 
--- a/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Tue Oct 06 19:26:46 2015 +0200
+++ b/ismi-python-neo4jrestclient/static/commentaries_authors2.html	Wed Oct 07 15:41:00 2015 +0200
@@ -16,7 +16,7 @@
                             <div class="form-group">
                                 <input type="text" value="7437" placeholder="Search for person-id" class="form-control" name="search">
                             </div>
-                            <button class="btn btn-default" type="submit">Search</button>
+                            <button class="btn btn-default" type="submit">Search for author id</button>
                         </form>
                     </li>
                 </ul>
@@ -38,7 +38,7 @@
 <div class="row">
     <div class="col-md-5">
         <div class="panel panel-default">
-            <div class="panel-heading">Search Results</div>
+            <div class="panel-heading">Texts by this author</div>
             <table id="results" class="table table-striped table-hover">
                 <thead>
                 <tr>
@@ -55,7 +55,7 @@
     </div>
     <div class="col-md-7">
         <div class="panel panel-default">
-            <div class="panel-heading" id="title">Details</div>
+            <div class="panel-heading" id="title">Text details</div>
             <div class="row">
                 <!-- <div class="col-sm-4 col-md-4">
                     <img src="" class="well" id="poster"/>
@@ -76,8 +76,11 @@
     </div>
 </div>
 <div class="col-lg-12">
-<div id="graph" class="panel panel-default">
-</div>
+    <div class="panel panel-default">
+        <div class="panel-heading">Graph of commentaries</div>
+        <div id="graph">
+        </div>
+    </div>
 </div>
 
 <style type="text/css">
@@ -86,6 +89,7 @@
     .node.TEXT.marked { stroke: red; }
     .node.TEXT.selected { fill: red; }
     .link { stroke: #999; stroke-opacity: .6; stroke-width: 1px; }
+    tr.marked {border: 2px solid red;}
 </style>
 
 <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js"></script>
@@ -98,7 +102,7 @@
             $.get(backendApiPrefix+"/textandcommentaries/" + encodeURIComponent(text_id),
                     function (data) {
                         if (!data) return;
-                        $("#title").text(data.title);
+                        $("#title").text("Title: "+data.title);
                         var $list = $("#info").empty();
                         $list.append($("<li> author: " + data.author + "</li>"));
                         for (var key in data.attrs) {
@@ -137,8 +141,12 @@
                         data.forEach(function (row) {
                             var text = row.text;
                             var author = row.author;
-                            $("<tr><td>" + author.label + "</td><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
+                            var comm = row.is_commentary || row.has_commentaries;
+                            var $row = $("<tr><td>" + author.label + "</td><td>" + text.label + "</td><td>" + text.full_title + "</td><td class='text_id'>" + text.ismi_id + "</td></tr>").appendTo(t)
                                     .click(function() { showText($(this).find("td.text_id").text());});
+                            if (comm) {
+                                $row.addClass("marked");
+                            }
                             // set mark
                             $("#graph .ismi-"+text.ismi_id).each(function(){this.classList.add("marked")});
                         });
@@ -153,13 +161,15 @@
 </script>
 
 <script type="text/javascript">
-    var width = 1800, height = 1800;
+    var width = 1400, height = 1400;
 
     var force = d3.layout.force()
-            .charge(-200).linkDistance(30).size([width, height]);
+            .charge(-100) // -200
+            .linkDistance(15) // 30
+            .size([width, height]);
 
     var svg = d3.select("#graph").append("svg")
-            .attr("width", "1800px").attr("height", "1800px")
+            .attr("width", "1400px").attr("height", "1400px")
             .attr("pointer-events", "all");
 
     d3.json(backendApiPrefix+"/graph?limit=1000", function(error, graph) {
@@ -175,13 +185,13 @@
                 .data(graph.nodes).enter()
                 .append("circle")
                 .attr("class", function (d) { return "node "+d.label+" ismi-"+d.ismi_id})
-                .attr("r", 10)
+                .attr("r", 8) // 10
                 .call(force.drag);
 
         // html title attribute
         node.append("title")
                 .text(function (d) { return d.title; })
-
+                
         // force feed algo ticks
         force.on("tick", function() {
             link.attr("x1", function(d) { return d.source.x; })
@@ -193,6 +203,7 @@
                     .attr("cy", function(d) { return d.y; });
         });
     });
+
 </script>
 </body>
 </html>