Fix for edges with missing nodes
authorveltr
Fri, 29 Mar 2013 12:03:58 +0100
changeset 118 c0e03c7137e3
parent 117 803f14e35431
child 119 0f7d2275a88f
Fix for edges with missing nodes
client/js/paper-renderer.js
client/render-test.html
--- a/client/js/paper-renderer.js	Thu Mar 28 18:44:12 2013 +0100
+++ b/client/js/paper-renderer.js	Fri Mar 29 12:03:58 2013 +0100
@@ -222,6 +222,8 @@
     Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
 }
 
+Rkns.Renderer._BaseRepresentation.prototype.redraw = function() {}
+
 Rkns.Renderer._BaseRepresentation.prototype.moveTo = function() {}
 
 Rkns.Renderer._BaseRepresentation.prototype.show = function() {}
@@ -275,7 +277,7 @@
     this.renderer.minimap.node_group.addChild(this.minimap_circle);
 }
 
-Rkns.Renderer.Node.prototype.redraw = function() {
+Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) {
     var _model_coords = new paper.Point(this.model.get("position")),
     	_baseRadius = Rkns.Renderer._NODE_SIZE_BASE * Math.exp((this.model.get("size") || 0) * Rkns.Renderer._NODE_SIZE_STEP);
     if (!this.is_dragging || !this.paper_coords) {
@@ -358,13 +360,16 @@
     	miniradius = this.renderer.minimap.scale * _baseRadius,
     	minisize = new paper.Size([miniradius, miniradius]);
     this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2));
-        
-    Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){
-        var repr = this.renderer.getRepresentationByModel(edge);
-    	if(repr != null && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") {
-    		repr.redraw();
-    	}
-    }, this);
+    
+    if (!_dontRedrawEdges) {
+    	Rkns._.each(this.project.get("edges").filter(function (ed) { return ((ed.to === this.model) || (ed.from === this.model));}), function(edge, index, list){
+	        var repr = this.renderer.getRepresentationByModel(edge);
+	    	if(repr != null && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") {
+	    		repr.redraw();
+	    	}
+	    }, this);
+    }
+
 }
 
 Rkns.Renderer.Node.prototype.paperShift = function(_delta) {
@@ -511,6 +516,9 @@
 Rkns.Renderer.Edge.prototype.redraw = function() {
     this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from"));
     this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to"));
+    if (!this.from_representation || !this.to_representation) {
+    	return;
+    }
     var _p0a = this.from_representation.paper_coords,
         _p1a = this.to_representation.paper_coords,
         _v = _p1a.subtract(_p0a),
@@ -1817,7 +1825,7 @@
 
 Rkns.Renderer.Scene.prototype.redraw = function() {
     Rkns._(this.representations).each(function(_representation) {
-        _representation.redraw();
+    	_representation.redraw(true);
     });
     this.redrawMiniframe();
     paper.view.draw();
--- a/client/render-test.html	Thu Mar 28 18:44:12 2013 +0100
+++ b/client/render-test.html	Fri Mar 29 12:03:58 2013 +0100
@@ -26,7 +26,6 @@
             var _renkan;
             $(function() {
                 _renkan = new Rkns.Renkan({
-                    url: "data/simple-persist.php",
                     bins: [
                     	{
                             title: "Projet Lignes de Temps",