diff options
author | gnowgi <nagarjun@gnowledge.org> | 2012-04-02 08:45:33 -0700 |
---|---|---|
committer | gnowgi <nagarjun@gnowledge.org> | 2012-04-02 08:45:33 -0700 |
commit | ebed6bb470e946d315700311c316c03f2f4d0296 (patch) | |
tree | 2547bd24946f6b8240c341773912f6ac47063c61 | |
parent | 1c20d8b0e031ff388285e9259c8f7e98fab97831 (diff) | |
parent | 36ab2a314ed45a427383c3018a70f40e05d49849 (diff) | |
download | gnowsys-ebed6bb470e946d315700311c316c03f2f4d0296.tar.gz |
Merge pull request #10 from shefalishetty/master
JSON object modified and graphs made generic. affects data visualization.
-rw-r--r-- | gstudio/models.py | 25 | ||||
-rw-r--r-- | gstudio/templates/gstudio/skeleton.html | 84 | ||||
-rw-r--r-- | objectapp/models.py | 23 | ||||
-rw-r--r-- | objectapp/templates/objectapp/skeleton.html | 33 |
4 files changed, 113 insertions, 52 deletions
diff --git a/gstudio/models.py b/gstudio/models.py index c145ab0..3c3748d 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -680,6 +680,7 @@ class Nodetype(Node): # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} g_json = {} g_json["node_metadata"]= [] + g_json["relations"]=[] nbh = self.get_nbh @@ -699,29 +700,37 @@ class Nodetype(Node): for key in predicate_id.keys(): if nbh[key]: try: - g_json[str(key)]=[] + #g_json[str(key)]=[] + #g_json["relations"].append(key) + g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) - g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + + #g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + + g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] }) if not isinstance(nbh[key],basestring): for item in nbh[key]: - # user - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) - g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create nodes + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url()}) + + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} #this_node[str(key)]=nbh[key] key, nbh[key] #for item in value.keys(): g_json["node_metadata"].append({"_id":attr_counter,"screen_name":nbh[key]}) - g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + #g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":attr_counter }) attr_counter-=1 except: pass - # print g_json + #print g_json return json.dumps(g_json) - @property def tree_path(self): """Return nodetype's tree path, by its ancestors""" diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index cb25a87..72b0034 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -147,7 +147,7 @@ Javascript for Object type force graph --> - <script type="text/javascript" > +<script type="text/javascript" > var w = 700, h = 300, @@ -161,24 +161,50 @@ vis.append("svg:g").attr("class", "edges"); vis.append("svg:g").attr("class", "nodes"); -$(function() { - $.ajax({ - url: '/nodetypes/graphs/graph_json/{{ object.id }}', + + + +var gid={{object.id}}; +$(function fgraph(gid) { + + + $.ajax({ + url: '/gstudio/graphs/graph_json/{{object.id}}', //crossDomain: true, dataType: 'json', - success : function(json) { + success : function (json) { - //var node = NID.objects.get(slug='{{ slug }}'); + var force; // this contains all the nodes as a dict with _id as the key - var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { + var nodes_by_id = _.reduce(json.node_metadata, function(acc, n) { acc[n._id] = n; return acc; }, {}); - - var member_of = _(json.member_of).chain().map(function(e) { + + + all_edges=new Array(); + + //this contains all the links between the nodes + all_edges =_(json.relations).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" + }).value(); + + + nodes_by_id[{{object.id}}].x = w/2.0; + nodes_by_id[{{object.id}}].y = h/2.0; + + + + + /* var member_of = _(json.member_of).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; e.type = 'member_of'; @@ -245,15 +271,7 @@ $(function() { return nodes_by_id[e.from] && nodes_by_id[e.to] }).value(); - var content = _(json.content).chain().map(function(e) { - e.source = nodes_by_id[e.from]; - e.target = nodes_by_id[e.to]; - e.type = 'content'; - return e; - }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value(); - + var contains_members = _(json.contains_members).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; @@ -263,7 +281,7 @@ $(function() { return nodes_by_id[e.from] && nodes_by_id[e.to] }).value(); - + var type_of = _(json.type_of).chain().map(function(e) { e.source = nodes_by_id[e.from]; @@ -323,13 +341,13 @@ $(function() { }).filter(function(e){ return nodes_by_id[e.from] && nodes_by_id[e.to] }).value(); - + */ - nodes_by_id[{{ object.id }}].x = w/2.0; - nodes_by_id[{{ object.id }}].y = h/2.0; - - all_edges = new Array(); - all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members,content, prior_nodes, posterior_nodes); + + + //all_edges = new Array(); + + //all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of, type_of,plural,altnames,contains_members, prior_nodes, posterior_nodes); /* all_edges.concat(follows_edges); all_edges.concat(member_of_metatype); all_edges.concat(contains_members); @@ -404,13 +422,12 @@ $(function() { var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); var new_g = node.enter().append("svg:a") - .attr("class", function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + .attr("class", function(d) { if (d._id=={{ object.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; }) + .attr("xlink:href",function(d){return d.url;}) .call(force.drag); - - - + new_g.append("svg:circle") .attr("cx", function(d) { return d.x - w/2.0 + 15; }) .attr("cy", function(d) { return d.y - h/2.0 + 15; }) @@ -448,8 +465,11 @@ $(function() { }); } - + + + update(all_edges); + vis.style("opacity", 1e-6) .transition() .duration(1000) @@ -473,7 +493,9 @@ $(function() { }); -</script> +</script> + + </div> </div> <div> diff --git a/objectapp/models.py b/objectapp/models.py index 2154b46..c4a612d 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -355,9 +355,10 @@ class Gbobject(Node): def get_graph_json(self): - # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} + # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"} g_json = {} g_json["node_metadata"]= [] + g_json["relations"]=[] nbh = self.get_nbh @@ -377,26 +378,32 @@ class Gbobject(Node): for key in predicate_id.keys(): if nbh[key]: try: - g_json[str(key)]=[] + #g_json[str(key)]=[] + #g_json["relations"].append(key) g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key}) - g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + #g_json[str(key)].append({"from":self.id , "to":predicate_id[key],"value":1, "level":1 }) + g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] }) if not isinstance(nbh[key],basestring): for item in nbh[key]: - # user - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title, "title":item.title, "url":item.get_absolute_url()}) - g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + # create nodes + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url()}) + + # g_json[str(key)].append({"from":predicate_id[key] , "to":item.id ,"value":1 }) + #create links + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} #this_node[str(key)]=nbh[key] key, nbh[key] #for item in value.keys(): g_json["node_metadata"].append({"_id":attr_counter,"screen_name":nbh[key]}) - g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + #g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":attr_counter }) attr_counter-=1 except: pass - print g_json + #print g_json return json.dumps(g_json) diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index ff24c85..c6e9fd4 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -167,7 +167,7 @@ Javascript for Object type force graph $(function() { $.ajax({ - url: '/nodetypes/graphs/graph_json/{{ object.id }}', + url: '/gstudio/graphs/graph_json/{{ object.id }}', //crossDomain: true, dataType: 'json', success : function(json) { @@ -182,7 +182,22 @@ $(function() { return acc; }, {}); - var member_of = _(json.member_of).chain().map(function(e) { + + +all_edges=new Array(); + + + + all_edges =_(json.relations).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" + }).value(); + + /* var member_of = _(json.member_of).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; e.type = 'member_of'; @@ -249,6 +264,14 @@ $(function() { return nodes_by_id[e.from] && nodes_by_id[e.to] }).value(); + var authors = _(json.authors).chain().map(function(e) { + e.source = nodes_by_id[e.from]; + e.target = nodes_by_id[e.to]; + e.type = 'authors'; + return e; + }).filter(function(e){ + return nodes_by_id[e.from] && nodes_by_id[e.to] + }).value(); var type_of = _(json.type_of).chain().map(function(e) { @@ -267,7 +290,7 @@ $(function() { return e; }).filter(function(e){ return nodes_by_id[e.from] && nodes_by_id[e.to] - }).value();*/ + }).value(); contains_members = _(json.contains_members).chain().map(function(e) { e.source = nodes_by_id[e.from]; @@ -325,12 +348,12 @@ $(function() { }).filter(function(e){ return nodes_by_id[e.from] && nodes_by_id[e.to] }).value(); - + */ nodes_by_id[{{ object.id }}].x = w/2.0; nodes_by_id[{{ object.id }}].y = h/2.0; - all_edges = new Array(); + /* all_edges = new Array(); all_edges = all_edges.concat(follows_edges, member_of, contains_members, contains_subtypes, mentions_edges, right_subjecttype_of, left_subjecttype_of, subjecttype_of,type_of,plural,altnames,contains_members, prior_nodes,posterior_nodes); /* all_edges.concat(follows_edges); all_edges.concat(member_of_metatype); |