summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gstudio/models.py64
-rw-r--r--gstudio/templates/gstudio/display.html330
-rw-r--r--gstudio/templates/gstudio/skeleton.html9
-rw-r--r--gstudio/urls/graphs.py3
-rw-r--r--gstudio/views/graphs.py12
-rw-r--r--objectapp/models.py150
-rw-r--r--objectapp/templates/objectapp/display.html312
-rw-r--r--objectapp/templates/objectapp/skeleton.html7
8 files changed, 379 insertions, 508 deletions
diff --git a/gstudio/models.py b/gstudio/models.py
index b1de4f50..694c49f4 100644
--- a/gstudio/models.py
+++ b/gstudio/models.py
@@ -1007,7 +1007,7 @@ class Nodetype(Node):
g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] })
- if not isinstance(nbh[key],basestring):
+ if not isinstance(nbh[key],basestring) and len(nbh[key])<=2:
for item in nbh[key]:
if item.reftype=="Relationtype":
@@ -1027,9 +1027,13 @@ class Nodetype(Node):
else:
-
- g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]})
- g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")})
+ if not isinstance(nbh[key],basestring):
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":str(len(nbh[key]))})
+ #g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")})
+ else:
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]})
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")})
+
attr_counter-=1
except:
@@ -1040,7 +1044,14 @@ class Nodetype(Node):
return json.dumps(g_json)
-
+ def get_label(self,key):
+ nbh=self.get_nbh
+ list_of_nodes=[]
+ for item in nbh[key]:
+ node=NID.objects.get(id=item.id)
+ node=node.ref
+ list_of_nodes.append(node)
+ return list_of_nodes
@property
def get_possible_attributes(self):
@@ -1616,10 +1627,11 @@ class Objecttype(Nodetype):
nbh['member_of_metatypes']=member_of_dict
nbh['count_member_of_metatypes'] = len(nbh['member_of_metatypes'])
typeof={}
- parent=self.parent_id
- if parent:
- obj=NID.objects.get(id=parent)
- typeof[parent] = obj.ref.get_absolute_url()
+ parentid=self.parent_id
+ if parentid:
+ parent=Nodetype.objects.get(id=parentid)
+ if parent:
+ typeof[parent] = parent.get_absolute_url()
nbh['type_of']=typeof
nbh['count_type_of'] = len(nbh['type_of'])
#get all subtypes
@@ -1727,37 +1739,38 @@ class Objecttype(Nodetype):
ver_dict=ast.literal_eval(ver_dict['nbhood'])
g_json = {}
g_json["node_metadata"]= []
+ g_json["relations"]=[]
predicate_id = {}
- counter = 1
+ counter=1
+ attr_counter=-1
for key in ver_dict.keys():
val = "a" + str(counter)
predicate_id[key] = val
counter = counter + 1
#print predicate_id
- attr_counter = -1
+
+ this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"refType":self.reftype}
+ g_json["node_metadata"].append(this_node)
- this_node = {"_id":str(self.id),"title":ver_dict['title'],"screen_name":ver_dict['title'], "url":self.get_absolute_url()}
- g_json["node_metadata"].append(this_node)
for key in predicate_id.keys():
- if ver_dict[key]:
- try:
- g_json[str(key)]=[]
+ if (ver_dict[key] and (ver_dict[key])!=0 and not(isinstance(ver_dict[key],int ) )
+) :
+ try:
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["relations"].append({"from":self.id , "to":predicate_id[key],"value":1, "type":str(key) })
if not isinstance(ver_dict[key],basestring):
for item in ver_dict[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 })
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"aa"),"screen_name":item })
+ #create links
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":(str(attr_counter)+"aa") })
+ attr_counter-=1
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":ver_dict[key]})
- g_json[str(key)].append({"from":predicate_id[key] , "to":attr_counter ,"value":1, "level":2 })
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":ver_dict[key]})
+ g_json["relations"].append({"from":predicate_id[key] , "to":(str(attr_counter)+"a") ,"value":1, "type":str(key) })
attr_counter-=1
except:
@@ -2227,7 +2240,8 @@ class Relation(Edge):
right_subject_scope = models.CharField(max_length=50, verbose_name='object scope or qualification', null=True, blank=True)
right_subject = models.ForeignKey(NID, related_name="right_subject_of", verbose_name='object name')
- def ApplicableNodeTypes_filter(self,choice):
+ def ApplicableNodeType
+s_filter(self,choice):
nodeslist = []
diff --git a/gstudio/templates/gstudio/display.html b/gstudio/templates/gstudio/display.html
index 751c8de3..90b5b271 100644
--- a/gstudio/templates/gstudio/display.html
+++ b/gstudio/templates/gstudio/display.html
@@ -153,206 +153,61 @@
Javascript for Object type force graph
-->
<script type="text/javascript" >
+function init(a,b)
+{
- var w = 700,
- h = 300,
- fill = d3.scale.category20();
-
- var vis = d3.select("#chart")
- .append("svg:svg")
- .attr("width", w)
- .attr("height", h);
-
- vis.append("svg:g").attr("class", "edges");
- vis.append("svg:g").attr("class", "nodes");
-
-$(function() {
- $.ajax({
- url: '/nodetypes/graphs/version_graph_json/{{ ssid }}',
- //crossDomain: true,
- dataType: '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) {
- acc[n._id] = n;
+
+ nodes_by_id = _.reduce(a, function(acc, n) {
+ acc[n._id] = n;
return acc;
}, {});
- 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';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var contains_subtypes = _(json.contains_subtypes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'contains_subtypes';
- 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];
- e.type = 'contains_members';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var left_subjecttype_of = _(json.left_subjecttype_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'left_subjecttype_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var subjecttype_of = _(json.subjecttype_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'subjecttype_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
- var plural = _(json.plural).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'plural';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var altnames = _(json.altnames).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'altnames';
- return e;
- }).filter(function(e){
- 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];
- e.type = 'contains_members';
- 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) {
+ all_edges=new Array();
+ //this contains all the links between the nodes
+ all_edges =_(b).chain().map(function(e) {
e.source = nodes_by_id[e.from];
e.target = nodes_by_id[e.to];
- e.type = 'type_of';
+ //`e.type = nodes_by_id[e.type]
return e;
}).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var right_subjecttype_of = _(json.right_subjecttype_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'right_subjecttype_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var follows_edges = _(json.is_followed_by).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'follows_edges';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
-
- var prior_nodes = _(json.prior_nodes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'prior_node';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+ return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" && e.type!="authors"
+ }).value();
+
+$(function fgraph() {
- var posterior_nodes = _(json.posterior_nodes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'posterior_node';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+$.getJSON('/nodetypes/graphs/version_graph_json/{{ ssid }}', function (json1) {
+ metadata=json1.node_metadata;
+ relations=json1.relations;
+
+ init(metadata,relations);
+ load({{ssid}}) });
- var mentions_edges = _(json.is_mentioned_by).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'mentions_edges';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
+
+function load(key)
+{
+ var w = 700,
+ h = 500,
+ fill = d3.scale.category20();
+
+ var vis = d3.select("#chart")
+ .append("svg:svg")
+ .attr("width", w)
+ .attr("height", h);
+ vis.append("svg:g").attr("class", "edges");
+ vis.append("svg:g").attr("class", "nodes");
+
- nodes_by_id[{{ nt.id }}].x = w/2.0;
- nodes_by_id[{{ nt.id }}].y = h/2.0;
+
+ nodes_by_id[{{nt.id}}].x = w/2.0;
+ nodes_by_id[{{nt.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.concat(follows_edges);
- all_edges.concat(member_of_metatype);
- all_edges.concat(contains_members);
- all_edges.concat(contains_subtypes);
- all_edges.concat(mentions_edges);
-
-
- document.getElementById('debugbox1').value= follows_edges; //member_of_metatype
- document.getElementById('debugbox2').value= mentions_edges;
- //document.getElementById('debugbox2').value= member_of_metatype;
- document.getElementById('debugbox3').value= all_edges;
- */
- var force = d3.layout.force()
- .linkStrength(0.5)
- .charge(-2000)
+ var force = d3.layout.force()
+ .linkStrength(0.3)
+ .charge(-5000)
.friction(0.7)
.gravity(0.7)
- .linkDistance(13)
+ .linkDistance(10)
.nodes([])
.links([])
.size([w, h])
@@ -378,9 +233,10 @@ $(function() {
force.links(edges);
force.start();
- link = d3.select("#chart g.edges").selectAll("line.link")
+ link = d3.select("#chart g.edges").selectAll("line.link").select(this.arrowhead)
.data(edges, function(e){return e.from + "-" + e.to + "-" + e.type});
+
link.enter().append("svg:line")
.attr("class", "link")
.style("stroke-width", 2 /* function(d) {
@@ -401,43 +257,80 @@ $(function() {
.attr("text", function(d) {
return d.type;
})
+ .attr("marker-end", "url(#arrowhead)");
- .append("a")
- .text(function(d) { return d.type; });
+
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=={{ nt.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; })
- .attr("r", function(d) { if (d._id=={{ nt.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 })
- .style("fill", function color(d) { if (d._id=={{ nt.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"});
+
-
- new_g.append("svg:text")
- .attr("class",function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; })
- .attr("dy", 20)
- .attr("dx", 25)
- .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"})
+var new_g = node.enter().append("svg:a")
+ .attr("class", function(d) { var e=(d._id).charAt(0); if (d._id=={{nt.id}}) return "mainnode"; else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode" ; else return "node"; })
+
+ .call(force.drag);
-// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"})
+ new_g.append("svg:marker")
+ .attr("id", "arrowhead")
+ .attr("viewBox","0 0 10 10")
+ .attr("refX","20")
+ .attr("refY","5")
+ .attr("markerUnits","strokeWidth")
+ .attr("markerWidth","9")
+ .attr("markerHeight","5")
+ .attr("orient","auto")
+ .append("svg:path")
+ .attr("d","M 0 0 L 10 5 L 0 10 z")
+ .attr("fill", "#6D6666");
+
+
+
+ text1 = new_g.append("svg:text")
+ .attr("class",function(d) {var e=(d._id).charAt(0); if (d._id=={{nt.id}}) return "mainnode";else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode"; else return "node"; })
+ .attr("y", 20)
+ .attr("x", 25)
+ .attr("dy", ".35em")
+ .attr("text-anchor","middle")
+
.text(function(d) {
return d.screen_name;
});
- node.exit().remove();
+ bbox = text1.node().getBBox();
+ console.log(bbox);
+
-
+ new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect")
+ .attr("x",bbox.x-22)
+ .attr("y", bbox.y)
+ .attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length+bbox.width+40)})
+ .attr("height", bbox.height)
+ .call(force.drag)
+ .style("fill-opacity", ".1")
+ .style("stroke", "#000")
+ .style("stroke-width","1px" );
+
+new_g.filter(function(d) { return (d._id)>0;}).append("svg:ellipse")
+ .attr("cx", bbox.x+25)
+ .attr("cy", bbox.y+13)
+ .call(force.drag)
+ .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)})
+ .attr("ry",13)
+ .style("fill-opacity", ".2")
+ .style("stroke", "#666")
+ .style("stroke-width", "1.5px")
+ .style("fill", function(d) {if (d.refType=="Objecttype") return "blue"; else if(d.refType=="Gbobject") return "red"; else return "none"});
+
+
+
+
+
+ node.exit().remove();
+
+
+
force.on("tick", function() {
@@ -460,21 +353,10 @@ $(function() {
.duration(1000)
.style("opacity", 1);
- /* $('input#follows').change(function(){
- update(all_edges);
- });
- */
+
- /* $('input#mentions').change(function(){
- update(all_edges);
- }); */
- }
- });
-
-// $("#relation_type").buttonset();
-
-// $('input#mentions').change(function(){console.log(this)});
-// $('input#follows').change(function(){console.log(this)});
+
+ }
});
diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html
index 6bb3d46a..c99bab9e 100644
--- a/gstudio/templates/gstudio/skeleton.html
+++ b/gstudio/templates/gstudio/skeleton.html
@@ -502,7 +502,7 @@ $(window).bind('keydown',function(event) {
- var text1 = new_g.append("svg:text")
+ text1 = new_g.append("svg:text")
.attr("class",function(d) {var e=(d._id).charAt(0); if (d._id==key) return "mainnode";else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode"; else return "node"; })
.attr("y", 20)
.attr("x", 25)
@@ -514,12 +514,11 @@ $(window).bind('keydown',function(event) {
return d.screen_name;
});
- var bbox = text1.node().getBBox();
-
+ bbox = text1.node().getBBox();
+ console.log(bbox);
new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect")
- .attr("x",bbox.x-22
- )
+ .attr("x",bbox.x-22)
.attr("y", bbox.y)
.attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length+bbox.width+40)})
.attr("height", bbox.height)
diff --git a/gstudio/urls/graphs.py b/gstudio/urls/graphs.py
index 4aa8c4b5..2f8d6f23 100644
--- a/gstudio/urls/graphs.py
+++ b/gstudio/urls/graphs.py
@@ -28,5 +28,6 @@ urlpatterns = patterns(
'gstudio.views.graphs',
url(r'^graph_json/(?P<node_id>\d+)$','graph_json', name='graph_json_d3'),
url(r'^version_graph_json/(?P<ssid>\d+)$','version_graph_json', name='version_graph_d3'),
- url(r'^graph/(?P<node_id>\d+)$','force_graph', name='force_graph_d3'),
+ url(r'^graph/(?P<node_id>\d+)$','force_graph', name='force_graph_d3'),
+ url(r'^graph_label/(?P<node_id>\d+)/(?P<key>[-\w]+)/$','graph_label', name='graph_label'),
)
diff --git a/gstudio/views/graphs.py b/gstudio/views/graphs.py
index ff2fa401..e1ca63b1 100644
--- a/gstudio/views/graphs.py
+++ b/gstudio/views/graphs.py
@@ -97,7 +97,19 @@ def graph_json(request, node_id):
return HttpResponse(node.get_graph_json(), "application/json")
+def graph_label(request, node_id,key):
+
+
+ try:
+ node = NID.objects.get(id=node_id)
+ node = node.ref
+ except:
+
+ return HttpResponse("node not found", "text/html")
+ lis=node.get_label(key)
+ return render_to_response('gstudio/label_list.html',{'lis': lis })
+
def force_graph(request, node_id):
diff --git a/objectapp/models.py b/objectapp/models.py
index 86da47ff..6849cfa7 100644
--- a/objectapp/models.py
+++ b/objectapp/models.py
@@ -97,6 +97,7 @@ from gstudio.models import Relation
from gstudio.models import Node
from gstudio.models import Edge
from gstudio.models import Author
+from gstudio.models import NID
import ast
from objectapp.settings import UPLOAD_TO
from objectapp.settings import MARKUP_LANGUAGE
@@ -475,53 +476,120 @@ class Gbobject(Node):
for key in predicate_id.keys():
if nbh[key]:
- try:
+ try:
- g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
-
- 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]:
- if isinstance(item,unicode):
- g_json["node_metadata"].append({"_id":(str(attr_counter)+"b"),"screen_name":str(item)})
- g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"b") })
- attr_counter-=1
-
- elif item.reftype!="Relation":
- # 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["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id })
-
-
-
- else:
-
- if item.left_subject.id==self.id:
- item1=item.right_subject
- flag=1
-
- elif item.right_subject.id==self.id:
- item1=item.left_subject
- flag=0
-
-
- g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"refType":item.reftype,"inverse":item.relationtype.inverse,"flag":flag})
-
-
- g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item1.id })
- else:
-
- g_json["node_metadata"].append({"_id":(str(attr_counter)+"b"),"screen_name":nbh[key]})
+ g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
+
+ g_json["relations"].append({"from":self.id ,"type":str(key),"value":1,"to":predicate_id[key] })
+
+ if not isinstance(nbh[key],basestring) and len(nbh[key])<=2:
+ for item in nbh[key]:
+ if isinstance(item,unicode):
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"b"),"screen_name":str(item)})
g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"b") })
attr_counter-=1
-
- except EOFError:
- print "Oops! That was no valid number. Try again..."
+
+ elif item.reftype!="Relation":
+ # create nodes
+ g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"refType":item.reftype})
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item.id })
+
+ else:
+
+ if item.left_subject.id==self.id:
+ item1=item.right_subject
+ flag=1
+
+ elif item.right_subject.id==self.id:
+ item1=item.left_subject
+ flag=0
+
+ g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"refType":item.reftype,"inverse":item.relationtype.inverse,"flag":flag})
+
+
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":item1.id })
+ else:
+ if not isinstance(nbh[key],basestring):
+ g_json["node_metadata"].append({"_id":(str(attr_counter))+"a","screen_name":str(len(nbh[key]))+" nodes...","title":str(key),"url":"/nodetypes/graphs/graph_label/"+str(self.id)+"/"+str(key)})
+ #g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter))})
+ else:
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]})
+
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")})
+
+ attr_counter-=1
+
+ except:
+ pass
#print g_json
return json.dumps(g_json)
+ def get_label(self,key):
+ nbh=self.get_nbh
+ list_of_nodes=[]
+ for item in nbh[key]:
+ node = NID.objects.get(id=item.id)
+ node = node.ref
+ list_of_nodes.append(node)
+ return list_of_nodes
+
+
+
+ def get_Version_graph_json(self,ssid):
+
+
+ # # predicate_id={"plural":"a1","altnames":"a2","contains_members":"a3","contains_subtypes":"a4","prior_nodes":"a5", "posterior_nodes":"a6"}
+ # slist=self.get_ssid
+ ver_dict=self.version_info(ssid)
+ ver_dict1=self.version_info(ssid)
+ #ver_dict=str(ver['nbhood'])
+ ver_dict=ast.literal_eval(ver_dict['nbhood'])
+ g_json = {}
+ g_json["node_metadata"]= []
+ g_json["relations"]=[]
+ predicate_id = {}
+ counter=1
+ attr_counter=-1
+ for key in ver_dict.keys():
+ val = "a" + str(counter)
+ predicate_id[key] = val
+ counter = counter + 1
+ #print predicate_id
+
+
+
+ this_node = {"_id":str(self.id),"title":self.title,"screen_name":self.title, "url":self.get_absolute_url(),"refType":self.reftype}
+ g_json["node_metadata"].append(this_node)
+
+
+ for key in predicate_id.keys():
+ if (ver_dict[key] and (ver_dict[key])!=0 and not(isinstance(ver_dict[key],int ) )) :
+ try:
+
+ g_json["node_metadata"].append({"_id":str(predicate_id[key]),"screen_name":key})
+ g_json["relations"].append({"from":self.id , "to":predicate_id[key],"value":1, "type":str(key) })
+
+ if not isinstance(ver_dict[key],basestring):
+ for item in ver_dict[key]:
+ # user
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"aa"),"screen_name":item })
+ #create links
+ g_json["relations"].append({"from":predicate_id[key] ,"type":str(key), "value":1,"to":(str(attr_counter)+"aa") })
+ attr_counter-=1
+ else:
+
+ g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":ver_dict[key]})
+ g_json["relations"].append({"from":predicate_id[key] , "to":(str(attr_counter)+"a") ,"value":1, "type":str(key) })
+ attr_counter-=1
+
+
+ except:
+ pass
+# print g_json
+
+
+
+ return json.dumps(g_json)
@property
def get_rendered_relations(self):
diff --git a/objectapp/templates/objectapp/display.html b/objectapp/templates/objectapp/display.html
index 7c920678..ca8b7aa0 100644
--- a/objectapp/templates/objectapp/display.html
+++ b/objectapp/templates/objectapp/display.html
@@ -154,205 +154,73 @@
-->
<script type="text/javascript" >
- var w = 700,
- h = 300,
- fill = d3.scale.category20();
-
- var vis = d3.select("#chart")
- .append("svg:svg")
- .attr("width", w)
- .attr("height", h);
+function init(a,b)
+{
- vis.append("svg:g").attr("class", "edges");
- vis.append("svg:g").attr("class", "nodes");
-
-$(function() {
- $.ajax({
- url: '/nodetypes/graphs/version_graph_json/{{ ssid }}',
- //crossDomain: true,
- dataType: '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
+
+ nodes_by_id = _.reduce(a, 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) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'member_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var contains_subtypes = _(json.contains_subtypes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'contains_subtypes';
- 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];
- e.type = 'contains_members';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var left_subjecttype_of = _(json.left_subjecttype_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'left_subjecttype_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+
+ all_edges=new Array();
- var subjecttype_of = _(json.subjecttype_of).chain().map(function(e) {
+ //this contains all the links between the nodes
+ all_edges =_(b).chain().map(function(e) {
e.source = nodes_by_id[e.from];
e.target = nodes_by_id[e.to];
- e.type = 'subjecttype_of';
+
return e;
}).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
+ return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" && e.type!="authors"
}).value();
- var plural = _(json.plural).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'plural';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+$(function fgraph() {
- var altnames = _(json.altnames).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'altnames';
- return e;
- }).filter(function(e){
- 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];
- e.type = 'contains_members';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+$.getJSON('/nodetypes/graphs/version_graph_json/{{ ssid }}', function (json1) {
+ metadata=json1.node_metadata;
+ relations=json1.relations;
+
+ init(metadata,relations);
+ load({{ssid}}) });
+function load(key)
+{
+ var w = 700,
+ h = 500,
+ fill = d3.scale.category20();
+
+ var vis = d3.select("#chart")
+ .append("svg:svg")
+ .attr("width", w)
+ .attr("height", h);
- var type_of = _(json.type_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'type_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var right_subjecttype_of = _(json.right_subjecttype_of).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'right_subjecttype_of';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
- var follows_edges = _(json.is_followed_by).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'follows_edges';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
+
+ vis.append("svg:g").attr("class", "edges");
+ vis.append("svg:g").attr("class", "nodes");
+
- var prior_nodes = _(json.prior_nodes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'prior_node';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
- var posterior_nodes = _(json.posterior_nodes).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'posterior_node';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- var mentions_edges = _(json.is_mentioned_by).chain().map(function(e) {
- e.source = nodes_by_id[e.from];
- e.target = nodes_by_id[e.to];
- e.type = 'mentions_edges';
- return e;
- }).filter(function(e){
- return nodes_by_id[e.from] && nodes_by_id[e.to]
- }).value();
-
-
- nodes_by_id[{{ nt.id }}].x = w/2.0;
- nodes_by_id[{{ nt.id }}].y = h/2.0;
+
+ nodes_by_id[{{nt.id}}].x = w/2.0;
+ nodes_by_id[{{nt.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.concat(follows_edges);
- all_edges.concat(member_of_metatype);
- all_edges.concat(contains_members);
- all_edges.concat(contains_subtypes);
- all_edges.concat(mentions_edges);
-
-
- document.getElementById('debugbox1').value= follows_edges; //member_of_metatype
- document.getElementById('debugbox2').value= mentions_edges;
- //document.getElementById('debugbox2').value= member_of_metatype;
- document.getElementById('debugbox3').value= all_edges;
- */
+
+
+
var force = d3.layout.force()
- .linkStrength(0.5)
- .charge(-2000)
+ .linkStrength(0.3)
+ .charge(-5000)
.friction(0.7)
.gravity(0.7)
- .linkDistance(13)
+ .linkDistance(10)
.nodes([])
.links([])
.size([w, h])
@@ -377,14 +245,14 @@ $(function() {
force.nodes(nodes);
force.links(edges);
force.start();
-
- link = d3.select("#chart g.edges").selectAll("line.link")
+ link = d3.select("#chart g.edges").selectAll("line.link").select(this.arrowhead)
.data(edges, function(e){return e.from + "-" + e.to + "-" + e.type});
link.enter().append("svg:line")
.attr("class", "link")
.style("stroke-width", 2 /* function(d) {
- return Math.sqrt(d.value);
+
+ return Math.sqrt(d.value);
} */ )
.attr("x1", function(d) {
return d.source.x;
@@ -402,40 +270,77 @@ $(function() {
return d.type;
})
- .append("a")
- .text(function(d) { return d.type; });
-
+ .attr("marker-end", "url(#arrowhead)");
+
+
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=={{ nt.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;})
+ .attr("class", function(d) { var e=(d._id).charAt(0); if (d._id=={{nt.id}}) return "mainnode"; else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode" ; else return "node"; })
+
.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; })
- .attr("r", function(d) { if (d._id=={{ nt.id }}) return 8; else if (isNaN(d._id) || (d._id)<0) return 1; else return 7 })
- .style("fill", function color(d) { if (d._id=={{ nt.id }}) return "red"; else if (isNaN(d._id) || (d._id)<0) return "white" ; else return "green"});
+ new_g.append("svg:marker")
+ .attr("id", "arrowhead")
+ .attr("viewBox","0 0 10 10")
+ .attr("refX","20")
+ .attr("refY","5")
+ .attr("markerUnits","strokeWidth")
+ .attr("markerWidth","9")
+ .attr("markerHeight","5")
+ .attr("orient","auto")
+ .append("svg:path")
+ .attr("d","M 0 0 L 10 5 L 0 10 z")
+ .attr("fill", "#6D6666");
- new_g.append("svg:text")
- .attr("class",function(d) { if (d._id=={{ nt.id }}) return "mainnode"; else if (isNaN(d._id)) return "relnode"; else if ((d._id)<0) return "nodetext"; else return "node"; })
- .attr("dy", 20)
- .attr("dx", 25)
- .attr("text-anchor",function text(d) { if (isNaN(d._id) || (d._id)<0) return "middle" ; else return "left"})
-
-// .attr("style",function text(d) { if (isNaN(d._id)) return "font-size:9.00pt;fill:#333;" ; else return "font-size:9.00pt;fill:black;"})
+ text1 = new_g.append("svg:text")
+ .attr("class",function(d) {var e=(d._id).charAt(0); if (d._id=={{nt.id}}) return "mainnode";else if (e=="-") return "nodetext"; else if (isNaN(d._id)) return "relnode"; else return "node"; })
+ .attr("y", 20)
+ .attr("x", 25)
+ .attr("dy", ".35em")
+ .attr("text-anchor","middle")
.text(function(d) {
return d.screen_name;
});
- node.exit().remove();
+ new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect")
+ .attr("x",bbox.x-22)
+ .attr("y", bbox.y)
+ .attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length+bbox.width+40)})
+ .attr("height", bbox.height)
+ .call(force.drag)
+ .style("fill-opacity", ".1")
+ .style("stroke", "#000")
+ .style("stroke-width","1px" );
+
+
+
+
+
+
+ new_g.filter(function(d) { return (d._id)>0;}).append("svg:ellipse")
+ .attr("cx", bbox.x+25)
+ .attr("cy", bbox.y+13)
+ .call(force.drag)
+ .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)})
+ .attr("ry",13)
+ .style("fill-opacity", ".2")
+ .style("stroke", "#666")
+ .style("stroke-width", "1.5px")
+ .style("fill", function(d) {if (d.refType=="Objecttype") return "blue"; else if(d.refType=="Gbobject") return "red"; else return "none"});
+
+
+
+
+
+ node.exit().remove();
@@ -459,23 +364,12 @@ $(function() {
.transition()
.duration(1000)
.style("opacity", 1);
-
- /* $('input#follows').change(function(){
- update(all_edges);
- });
- */
+}
+});
+
- /* $('input#mentions').change(function(){
- update(all_edges);
- }); */
- }
- });
-
-// $("#relation_type").buttonset();
-
-// $('input#mentions').change(function(){console.log(this)});
-// $('input#follows').change(function(){console.log(this)});
-});
+
+
</script>
diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html
index 72432f15..193808cc 100644
--- a/objectapp/templates/objectapp/skeleton.html
+++ b/objectapp/templates/objectapp/skeleton.html
@@ -560,12 +560,13 @@ $(window).bind('keydown',function(event) {
.attr("cx", bbox.x+25)
.attr("cy", bbox.y+13)
.call(force.drag)
- .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 55)})
- .attr("ry",14)
+ .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)})
+ .attr("ry",13)
+
.style("fill-opacity", ".2")
.style("stroke", "#666")
.style("stroke-width", "1.5px")
- .style("fill", function color(d) {if (d.expanded=="true" && d.refType=="Objecttype") return "blue"; else if(d.expanded=="true" && d.refType=="Gbobject") return "red"; else return "none"});
+ .style("fill", function(d) {if ((d.expanded=="true" && d.refType=="Gbobject") ||(d._id=={{object.id}}) ) return "red"; else if(d.expanded=="true" && d.refType=="Objecttype") return "blue"; else return "none"})