diff options
author | Neha shah <shan.akshata@gmail.com> | 2012-05-09 14:37:37 +0530 |
---|---|---|
committer | Neha shah <shan.akshata@gmail.com> | 2012-05-09 14:37:37 +0530 |
commit | 0c6fa488209e61220b2ebea4580e2caf97b30d6c (patch) | |
tree | 9c237f1a0111a51ca3832efe73f60c7cda5a561d | |
parent | 0643630713261d8939ff64a312ae1ba494c01db7 (diff) | |
parent | 6b77378be56f722d36459056b7d3083d1a422448 (diff) | |
download | gnowsys-0c6fa488209e61220b2ebea4580e2caf97b30d6c.tar.gz |
Merge remote branch 'gn/master'
-rw-r--r-- | demo/grappelli/templates/admin/change_form.html | 1 | ||||
-rw-r--r-- | gstudio/admin/attribute.py | 1 | ||||
-rw-r--r-- | gstudio/models.py | 32 | ||||
-rw-r--r-- | gstudio/static/gstudio/css/screen.css | 6 | ||||
-rw-r--r-- | gstudio/templates/gstudio/skeleton.html | 60 | ||||
-rw-r--r-- | gstudio/urls/ajaxurls.py | 2 | ||||
-rw-r--r-- | gstudio/views/ajaxviews.py | 15 | ||||
-rw-r--r-- | objectapp/models.py | 24 | ||||
-rw-r--r-- | objectapp/static/objectapp/css/screen.css | 6 | ||||
-rw-r--r-- | objectapp/templates/objectapp/skeleton.html | 33 |
10 files changed, 123 insertions, 57 deletions
diff --git a/demo/grappelli/templates/admin/change_form.html b/demo/grappelli/templates/admin/change_form.html index c5a2654..7228290 100644 --- a/demo/grappelli/templates/admin/change_form.html +++ b/demo/grappelli/templates/admin/change_form.html @@ -17,6 +17,7 @@ <script src="{% admin_media_prefix %}js/grappelli/jquery.grp_inline.js" type="text/javascript"></script> {% if change %} <script type="text/javascript" src="{{STATIC_URL}}gstudio/js/URI.js"></script> + <script type="text/javascript" charset="utf-8"> (function($){ $(document).ready(function() { diff --git a/gstudio/admin/attribute.py b/gstudio/admin/attribute.py index b66f66e..31266c4 100644 --- a/gstudio/admin/attribute.py +++ b/gstudio/admin/attribute.py @@ -14,6 +14,7 @@ class AttributeAdmin(reversion.VersionAdmin): ) + class Media: js = ("gstudio/js/gstudio.js",) diff --git a/gstudio/models.py b/gstudio/models.py index 65262cc..0b6886d 100644 --- a/gstudio/models.py +++ b/gstudio/models.py @@ -729,7 +729,7 @@ class Nodetype(Node): predicate_id = {} for key in nbh.keys(): - val = str(counter)+"a" + val = str(counter) + "a" predicate_id[key] = val counter = counter + 1 #print predicate_id @@ -750,14 +750,30 @@ class Nodetype(Node): #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]: - #create nodes - g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false"}) - - # 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 }) + if 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(),"expanded":"false"}) + + # 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: + + if item.left_subject.id==self.id: + item1=item.right_subject + elif item.right_subject.id==self.id: + item1=item.left_subject + + g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"expanded":"false"}) + + # 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":item1.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} @@ -765,7 +781,7 @@ class Nodetype(Node): #for item in value.keys(): g_json["node_metadata"].append({"_id":(str(attr_counter)+"a"),"screen_name":nbh[key]}) #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":(str(attr_counter)+"a") }) + g_json["relations"].append({"from":predicate_id[key] ,"type":str(key) ,"value":1,"to":(str(attr_counter)+"a")}) attr_counter-=1 except: diff --git a/gstudio/static/gstudio/css/screen.css b/gstudio/static/gstudio/css/screen.css index f786de6..a5e3ba3 100644 --- a/gstudio/static/gstudio/css/screen.css +++ b/gstudio/static/gstudio/css/screen.css @@ -475,9 +475,9 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss { - margin-left: 224px; - margin-right: 150px; - margin-top: 1px; + margin-left: 180px; + margin-right: 200px; + margin-top: -150px; position: absolute; width: 300px; height: 900px diff --git a/gstudio/templates/gstudio/skeleton.html b/gstudio/templates/gstudio/skeleton.html index 1e790ff..c5a15c3 100644 --- a/gstudio/templates/gstudio/skeleton.html +++ b/gstudio/templates/gstudio/skeleton.html @@ -10,7 +10,7 @@ } .nodetext { #pointer-events: none; - font: 10px Serif; + font: 12px Serif; font-style:italic; } .mainnode{ @@ -192,10 +192,10 @@ function init(a,b) all_edges =_(b).chain().map(function(e) { e.source = nodes_by_id[e.from]; e.target = nodes_by_id[e.to]; - + //`e.type = nodes_by_id[e.type] return e; }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" }).value(); @@ -253,7 +253,7 @@ var a = 25 * s; .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(75) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) @@ -279,6 +279,9 @@ var a = 25 * s; force.links(edges); force.start(); + + + link = d3.select("#chart g.edges").selectAll("line.link") .data(edges, function(e){return e.from + "-" + e.to + "-" + e.type}); @@ -301,13 +304,13 @@ var a = 25 * s; }) .attr("text", function(d) { return d.type; - }) + }); + + + - .append("a") - .text(function(d) { return d.type; }); - var node = d3.select("#chart g.nodes").selectAll("g.node").data(nodes); @@ -316,30 +319,40 @@ var a = 25 * s; var new_g = node.enter().append("svg:a") - .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("xlink:href",function(d){return d.url;}) + .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"; }) + .call(force.drag); - +$(window).bind('keydown',function(event){ + if(17==event.keyCode){ new_g.on("click",function(d){ - if(d._id>0) + if(d._id>0 && d.expanded=="false") { d3.select("#amazingViz").remove(); d.expanded="true"; $.getJSON('/nodetypes/graphs/graph_json/' + d._id , function (json2) { new_metadata=json2.node_metadata; - new_relations=json2.relations; + new_relations=json2.relations; metadata=_.union(new_metadata,metadata); relations=_.union(new_relations,relations); init(metadata,relations); load(d._id) }) - } - }); + + }); + +} +}); + + + + new_g.on("click", function(d) { + + new_g.attr("xlink:href",function(d){return d.url;}); + }); /*new_g.append("svg:ellipse") @@ -356,8 +369,9 @@ var a = 25 * s; var 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("dy", 20) - .attr("dx", 25) + .attr("y", 20) + .attr("x", 25) + .attr("dy", ".35em") .attr("text-anchor","middle") // .attr("style",function text(d) { if ((d._id)>0) return "font-size:9.00pt;fill:blue;" ; else return "font-size:9.00pt;fill:black;"}) @@ -370,9 +384,10 @@ var a = 25 * s; new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect") - .attr("x",bbox.x-5) + .attr("x",bbox.x-22 + ) .attr("y", bbox.y) - .attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length + bbox.width)}) + .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") @@ -388,9 +403,9 @@ var a = 25 * s; .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 + 45)}) + .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)}) .attr("ry",13) - .style("fill-opacity", ".5") + .style("fill-opacity", ".2") .style("stroke", "#666") .style("stroke-width", "1.5px") .style("fill", function color(d) {var e=(d._id).charAt(0); if (d.expanded=="true") return "red"; else return "none"}); @@ -398,6 +413,7 @@ var a = 25 * s; + node.exit().remove(); diff --git a/gstudio/urls/ajaxurls.py b/gstudio/urls/ajaxurls.py index 778b0de..facc603 100644 --- a/gstudio/urls/ajaxurls.py +++ b/gstudio/urls/ajaxurls.py @@ -20,7 +20,7 @@ from django.conf.urls.defaults import url from django.conf.urls.defaults import patterns urlpatterns = patterns('gstudio.views.ajaxviews', - url(r'^$', 'AjaxAttribute',name='ajax_views'), + url(r'^ajaxattribute/$', 'AjaxAttribute',name='ajax_views'), url(r'^relation/add/ajaxleft/$', 'AjaxRelationleft',name='ajax_relnleft_views'), url(r'^relation/add/ajaxright/$', 'AjaxRelationright',name='ajax_relnright_views'), url(r'^relation/ajaxleft/$', 'AjaxRelationleft',name='ajax_relnleft_views'), diff --git a/gstudio/views/ajaxviews.py b/gstudio/views/ajaxviews.py index 3991a89..23c06e5 100644 --- a/gstudio/views/ajaxviews.py +++ b/gstudio/views/ajaxviews.py @@ -27,10 +27,19 @@ def AjaxAttribute(request): subjecttype = attr.subjecttype returndict = {} - for each in Objecttype.objects.all(): - if attr.subjecttype.id == each.id: - for member in each.get_members: + for ots in Objecttype.objects.all(): + if attr.subjecttype.id ==ots.id: + for member in ots.get_members: returndict[member.id] = member.title + childrenots = ots.get_children() + + if childrenots: + for eachchild in childrenots: + returndict[eachchild.id] = eachchild.title + membs=eachchild.ref.get_members + for each in membs: + returndict[each.id] = each.title + jsonobject = json.dumps(returndict) return HttpResponse(jsonobject, "application/json") diff --git a/objectapp/models.py b/objectapp/models.py index a27832a..97501c8 100644 --- a/objectapp/models.py +++ b/objectapp/models.py @@ -391,13 +391,27 @@ class Gbobject(Node): 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 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(),"expanded":"false"}) - # 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 }) - + g_json["node_metadata"].append({"_id":str(item.id),"screen_name":item.title,"title":self.title, "url":item.get_absolute_url(),"expanded":"false"}) + + # 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: + + if item.left_subject.id==self.id: + item1=item.right_subject + elif item.right_subject.id==self.id: + item1=item.left_subject + + g_json["node_metadata"].append({"_id":str(item1.id),"screen_name":item1.title,"title":self.title, "url":item1.get_absolute_url(),"expanded":"false"}) + + # 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":item1.id }) else: #value={nbh["plural"]:"a4",nbh["altnames"]:"a5"} #this_node[str(key)]=nbh[key] key, nbh[key] diff --git a/objectapp/static/objectapp/css/screen.css b/objectapp/static/objectapp/css/screen.css index c69ca99..fd913f7 100644 --- a/objectapp/static/objectapp/css/screen.css +++ b/objectapp/static/objectapp/css/screen.css @@ -479,9 +479,9 @@ a:hover { text-decoration: underline; } font-weight: bold; } #graphcss{ - margin-left: 230px; - margin-right: 150px; - margin-top: 1px; + margin-left: 180px; + margin-right: 200px; + margin-top: -150px; position: absolute; width: 300px; height: 900px diff --git a/objectapp/templates/objectapp/skeleton.html b/objectapp/templates/objectapp/skeleton.html index 34bc9b5..f3325b8 100644 --- a/objectapp/templates/objectapp/skeleton.html +++ b/objectapp/templates/objectapp/skeleton.html @@ -11,7 +11,7 @@ } .nodetext { #pointer-events: none; - font: 10px Serif; + font: 12px Serif; font-style:italic; } .mainnode{ @@ -24,7 +24,7 @@ } .relnode { - font: 10px sans-serif; + font: 12px sans-serif; font-weight:bold; fill:#000; } @@ -206,7 +206,7 @@ function init(a,b) return e; }).filter(function(e){ - return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" + return nodes_by_id[e.from] && nodes_by_id[e.to]&& e.type!="title" && e.type!="content" }).value(); @@ -264,7 +264,7 @@ var a = 800 * s; .charge(-5000) .friction(0.7) .gravity(0.7) - .linkDistance(75) + .linkDistance(50) .nodes([]) .links([]) .size([w, h]) @@ -327,16 +327,17 @@ var a = 800 * s; var new_g = node.enter().append("svg:a") - .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("xlink:href",function(d){return d.url;}) + .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"; }) + .call(force.drag); +$(window).bind('keydown',function(event){ + if(17==event.keyCode){ new_g.on("click",function(d){ - if(d._id>0) + if(d._id>0 && d.expanded=="false") { d3.select("#amazingViz").remove(); d.expanded="true"; @@ -351,6 +352,13 @@ var a = 800 * s; } }); +} +}); + + new_g.on("click", function(d) { + + new_g.attr("xlink:href",function(d){return d.url;}); + }); /*new_g.append("svg:ellipse") @@ -381,15 +389,16 @@ var a = 800 * s; new_g.filter(function(d) { return (d._id).charAt(0)=="-"; }).append("svg:rect") - .attr("x",bbox.x-5) + .attr("x",bbox.x-22) .attr("y", bbox.y) - .attr("width", function(d) {var ttx=d.screen_name ; return (ttx.length + bbox.width)}) + .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" ); + @@ -399,9 +408,9 @@ var a = 800 * s; .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 + 45)}) + .attr("rx",function(d) {var ttx=d.screen_name ; return (ttx.length + 40)}) .attr("ry",13) - .style("fill-opacity", ".5") + .style("fill-opacity", ".2") .style("stroke", "#666") .style("stroke-width", "1.5px") .style("fill", function color(d) {var e=(d._id).charAt(0); if (d.expanded=="true") return "red"; else return "none"}); |