client/js/paper-renderer.js
changeset 153 7fcb35795ff4
parent 152 5306bf5284c2
child 154 0f87088e03bc
equal deleted inserted replaced
152:5306bf5284c2 153:7fcb35795ff4
    72         _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
    72         _path.fillColor = new paper.GradientColor(new paper.Gradient([_options.tooltip_top_color, _options.tooltip_bottom_color]), [0,_top], [0, _bottom]);
    73         _selector.css({
    73         _selector.css({
    74             left: (_options.tooltip_padding + Math.min(_left, _right)),
    74             left: (_options.tooltip_padding + Math.min(_left, _right)),
    75             top: (_options.tooltip_padding + _top)
    75             top: (_options.tooltip_padding + _top)
    76         });
    76         });
       
    77         return _path;
    77     },
    78     },
    78     sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) {
    79     sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) {
    79         var _options = _repr.renderer.renkan.options,
    80         var _options = _repr.renderer.renkan.options,
    80         	_startRads = _startAngle * Math.PI / 180,
    81         	_startRads = _startAngle * Math.PI / 180,
    81             _endRads = _endAngle * Math.PI / 180,
    82             _endRads = _endAngle * Math.PI / 180,
   302     this.title.paragraphStyle.justification = 'center';
   303     this.title.paragraphStyle.justification = 'center';
   303     
   304     
   304     if (this.renderer.minimap) {
   305     if (this.renderer.minimap) {
   305 	    this.renderer.minimap.node_layer.activate();
   306 	    this.renderer.minimap.node_layer.activate();
   306 	    this.minimap_circle = new paper.Path.Circle([0, 0], 1);
   307 	    this.minimap_circle = new paper.Path.Circle([0, 0], 1);
       
   308 	    this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
   307 	    this.renderer.minimap.node_group.addChild(this.minimap_circle);
   309 	    this.renderer.minimap.node_group.addChild(this.minimap_circle);
   308     }
   310     }
   309 }
   311 }
   310 
   312 
   311 Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) {
   313 Rkns.Renderer.Node.prototype.redraw = function(_dontRedrawEdges) {
   560     
   562     
   561     if (this.renderer.minimap) {
   563     if (this.renderer.minimap) {
   562     	this.renderer.minimap.edge_layer.activate();
   564     	this.renderer.minimap.edge_layer.activate();
   563 	    this.minimap_line = new paper.Path();
   565 	    this.minimap_line = new paper.Path();
   564 	    this.minimap_line.add([0,0],[0,0]);
   566 	    this.minimap_line.add([0,0],[0,0]);
       
   567 	    this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation;
   565 	    this.minimap_line.strokeWidth = 1;
   568 	    this.minimap_line.strokeWidth = 1;
   566     }
   569     }
   567 }
   570 }
   568 
   571 
   569 Rkns.Renderer.Edge.prototype.redraw = function() {
   572 Rkns.Renderer.Edge.prototype.redraw = function() {
   653 Rkns.Renderer.Edge.prototype.mouseup = function(_event) {
   656 Rkns.Renderer.Edge.prototype.mouseup = function(_event) {
   654     if (!this.renkan.read_only) {
   657     if (!this.renkan.read_only) {
   655         if (this.renderer.is_dragging) {
   658         if (this.renderer.is_dragging) {
   656             this.from_representation.saveCoords();
   659             this.from_representation.saveCoords();
   657             this.to_representation.saveCoords();
   660             this.to_representation.saveCoords();
       
   661             this.from_representation.is_dragging = false;
       
   662             this.to_representation.is_dragging = false;
   658         } else {
   663         } else {
   659             this.openEditor();
   664             this.openEditor();
   660         }
   665         }
   661     }
   666     }
   662     this.renderer.click_target = null;
   667     this.renderer.click_target = null;
   820 Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
   825 Rkns.Renderer.NodeEditor.prototype.readOnlyTemplate = Rkns._.template(
   821     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-node.color%>;"></span>'
   826     '<h2><span class="Rk-CloseX">&times;</span><span class="Rk-UserColor" style="background:<%-node.color%>;"></span>'
   822     + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
   827     + '<span class="Rk-Display-Title"><% if (node.uri) { %><a href="<%-node.uri%>" target="_blank"><% } %><%-node.title%><% if (node.uri) { %></a><% } %></span></h2>'
   823     + '<% if (node.uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
   828     + '<% if (node.uri) { %><p class="Rk-Display-URI"><a href="<%-node.uri%>" target="_blank"><%-node.short_uri%></a></p><% } %>'
   824     + '<p><%-node.description%></p>'
   829     + '<p><%-node.description%></p>'
       
   830     + '<% if (node.image) { %><img class="Rk-Display-ImgPreview" src="<%-node.image%>" /><% } %>'
   825     + '<% if (node.has_creator) { %><p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %></p><% } %>'
   831     + '<% if (node.has_creator) { %><p><span class="Rk-Editor-Label"><%-translate("Created by:")%></span><span class="Rk-UserColor" style="background:<%-node.created_by_color%>;"></span><%- Rkns.Renderer.Utils.shortenText(node.created_by_title, 25) %></p><% } %>'
   826 );
   832 );
   827 
   833 
   828 Rkns.Renderer.NodeEditor.prototype.draw = function() {
   834 Rkns.Renderer.NodeEditor.prototype.draw = function() {
   829     var _model = this.source_representation.model,
   835     var _model = this.source_representation.model,
  1174     this.imageFile = 'img/remove.png';
  1180     this.imageFile = 'img/remove.png';
  1175     this.text = "Remove";
  1181     this.text = "Remove";
  1176 }
  1182 }
  1177 
  1183 
  1178 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() {
  1184 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() {
       
  1185     this.renderer.click_target = null;
       
  1186     this.renderer.is_dragging = false;
  1179     this.renderer.removeRepresentationsOfType("editor");
  1187     this.renderer.removeRepresentationsOfType("editor");
  1180     if (this.renderer.isEditable() && confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
  1188     if (this.renderer.isEditable() && confirm(this.renkan.translate('Do you really wish to remove node ') + '"' + this.source_representation.model.get("title") + '"?')) {
  1181         this.project.removeNode(this.source_representation.model);
  1189         this.project.removeNode(this.source_representation.model);
  1182     }
  1190     }
  1183 }
  1191 }
  1295     this.notif_$ = this.$.find(".Rk-Notifications");
  1303     this.notif_$ = this.$.find(".Rk-Notifications");
  1296     paper.setup(this.canvas_$[0]);
  1304     paper.setup(this.canvas_$[0]);
  1297     this.scale = 1;
  1305     this.scale = 1;
  1298     this.offset = paper.view.center;
  1306     this.offset = paper.view.center;
  1299     this.totalScroll = 0;
  1307     this.totalScroll = 0;
       
  1308     this.mouse_down = false;
  1300     this.click_target = null;
  1309     this.click_target = null;
  1301     this.selected_target = null;
  1310     this.selected_target = null;
  1302     this.edge_layer = new paper.Layer();
  1311     this.edge_layer = new paper.Layer();
  1303     this.node_layer = new paper.Layer();
  1312     this.node_layer = new paper.Layer();
  1304     this.buttons_layer = new paper.Layer();
  1313     this.buttons_layer = new paper.Layer();
  1338     	paper.view.draw();
  1347     	paper.view.draw();
  1339     }).throttle(100);
  1348     }).throttle(100);
  1340     
  1349     
  1341     this.bundles = [];
  1350     this.bundles = [];
  1342     this.click_mode = false;
  1351     this.click_mode = false;
  1343     var _tool = new paper.Tool(),
  1352     
  1344         _this = this,
  1353     var _this = this,
  1345         _allowScroll = true;
  1354         _allowScroll = true;
  1346     
  1355     
  1347     _tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE;
  1356     this.canvas_$.on({
  1348     _tool.onMouseMove = function(_event) {
  1357     	mousedown: function(_event) {
       
  1358     		_this.onMouseDown(_event);
       
  1359     	},
       
  1360     	mousemove: function(_event) {
  1349         _this.onMouseMove(_event);
  1361         _this.onMouseMove(_event);
  1350     }
  1362 	    },
  1351     _tool.onMouseDown = function(_event) {
  1363 	    mouseup: function(_event) {
  1352         _this.onMouseDown(_event);
  1364 	        _this.onMouseUp(_event);
  1353     }
  1365 	    },
  1354     _tool.onMouseDrag = function(_event) {
  1366 	    mousewheel: function(_event, _delta) {
  1355         _this.onMouseDrag(_event);
  1367 	        if (_allowScroll) {
  1356     }
  1368 	        	_this.onScroll(_event, _delta);
  1357     this.canvas_$.mouseup(function(_event) {
  1369 	        }
  1358         _this.onMouseUp(_event);
  1370 	    },
  1359     });
  1371 	    dblclick: function(_event) {
  1360     this.canvas_$.mousewheel(function(_event, _delta) {
  1372 	        _this.onDoubleClick(_event);
  1361         if (_allowScroll) {
  1373 	    },
  1362         	_this.onScroll(_event, _delta);
  1374 	    mouseleave: function(_event) {
  1363         }
  1375 	        _this.onMouseUp(_event);
  1364     });
  1376 	        _this.click_target = null;
  1365     this.canvas_$.dblclick(function(_event) {
  1377 	        _this.is_dragging = false;
  1366         _this.onDoubleClick(_event);
  1378 	    },
  1367     });
  1379 	    dragover: function(_event) {
  1368     this.canvas_$.on("dragover", function(_event) {
  1380 	    	_event.preventDefault();
  1369     	_event.preventDefault();
  1381 	    },
  1370     });
  1382 	    dragenter: function(_event) {
  1371     this.canvas_$.on("dragenter", function(_event) {
  1383 	    	_allowScroll = false;
  1372     	_allowScroll = false;
  1384 	    	_event.preventDefault();
  1373     	_event.preventDefault();
  1385 	    },
  1374     });
  1386 	    dragleave: function(_event) {
  1375     this.canvas_$.on("dragleave", function(_event) {
  1387 	    	_allowScroll = true;
  1376     	_allowScroll = true;
  1388 	    	_event.preventDefault();
  1377     	_event.preventDefault();
  1389 	    },
  1378     });
  1390     drop: function(_event) {
  1379     this.canvas_$.on("drop", function(_event) {
       
  1380     	_event.preventDefault();
  1391     	_event.preventDefault();
  1381     	_allowScroll = true;
  1392     	_allowScroll = true;
  1382     	if (!_this.isEditable()) {
  1393     	if (!_this.isEditable()) {
  1383     		return;
  1394     		return;
  1384     	}
  1395     	}
  1509                 }
  1520                 }
  1510             };
  1521             };
  1511         	var _node = _this.renkan.project.addNode(_data);
  1522         	var _node = _this.renkan.project.addNode(_data);
  1512             _this.getRepresentationByModel(_node).openEditor();
  1523             _this.getRepresentationByModel(_node).openEditor();
  1513     	}
  1524     	}
  1514     })
  1525     }
       
  1526     });
  1515     this.editor_$.find(".Rk-ZoomOut").click(function() {
  1527     this.editor_$.find(".Rk-ZoomOut").click(function() {
  1516     	var _newScale = _this.scale * Math.SQRT1_2,
  1528     	var _newScale = _this.scale * Math.SQRT1_2,
  1517     		_offset = new paper.Point([
  1529     		_offset = new paper.Point([
  1518 	            _this.canvas_$.width(),
  1530 	            _this.canvas_$.width(),
  1519 	            _this.canvas_$.height()
  1531 	            _this.canvas_$.height()
  1911 	this.offset = this.offset.add(_delta);
  1923 	this.offset = this.offset.add(_delta);
  1912     this.redraw();
  1924     this.redraw();
  1913 }
  1925 }
  1914 
  1926 
  1915 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) {
  1927 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) {
  1916     var _hitResult = paper.project.hitTest(_event.point);
  1928     var _off = this.canvas_$.offset(),
       
  1929     	_point = new paper.Point([
       
  1930             _event.pageX - _off.left,
       
  1931             _event.pageY - _off.top
       
  1932         ]);
       
  1933 	var _delta = _point.subtract(this.last_point);
       
  1934 	this.last_point = _point;
       
  1935     if (!this.is_dragging && this.mouse_down && _delta.length > Rkns.Renderer._MIN_DRAG_DISTANCE) {
       
  1936     	this.is_dragging = true;
       
  1937     }
       
  1938     var _hitResult = paper.project.hitTest(_point);
  1917     if (this.is_dragging) {
  1939     if (this.is_dragging) {
  1918         if (this.click_target && typeof this.click_target.paperShift === "function") {
  1940         if (this.click_target && typeof this.click_target.paperShift === "function") {
  1919             this.click_target.paperShift(_event.delta);
  1941             this.click_target.paperShift(_delta);
  1920         } else {
  1942         } else {
  1921             this.paperShift(_event.delta);
  1943             this.paperShift(_delta);
  1922         }
  1944         }
  1923     } else {
  1945     } else {
  1924         this.findTarget(_hitResult);
  1946         this.findTarget(_hitResult);
  1925     }
  1947     }
       
  1948     paper.view.draw();
  1926 }
  1949 }
  1927 
  1950 
  1928 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
  1951 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
       
  1952     var _off = this.canvas_$.offset(),
       
  1953     	_point = new paper.Point([
       
  1954             _event.pageX - _off.left,
       
  1955             _event.pageY - _off.top
       
  1956         ]);
       
  1957     this.last_point = _point;
       
  1958     this.mouse_down = true;
  1929     if (!this.click_target || this.click_target.type !== "Temp-edge") {
  1959     if (!this.click_target || this.click_target.type !== "Temp-edge") {
  1930         this.removeRepresentationsOfType("editor");
  1960         this.removeRepresentationsOfType("editor");
  1931         this.is_dragging = false;
  1961         this.is_dragging = false;
  1932         var _hitResult = paper.project.hitTest(_event.point);
  1962         var _hitResult = paper.project.hitTest(_point);
  1933         if (this.isEditable() && _hitResult && typeof _hitResult.item.__representation !== "undefined") {
  1963         if (this.isEditable() && _hitResult && typeof _hitResult.item.__representation !== "undefined") {
  1934             this.click_target = _hitResult.item.__representation;
  1964             this.click_target = _hitResult.item.__representation;
  1935             if (this.click_target.type === "Node-link-button") {
  1965             if (this.click_target.type === "Node-link-button") {
  1936                 this.removeRepresentationsOfType("editor");
  1966                 this.removeRepresentationsOfType("editor");
  1937                 this.addTempEdge(this.click_target.source_representation, _event.point);
  1967                 this.addTempEdge(this.click_target.source_representation, _point);
  1938             }
  1968             }
  1939         } else {
  1969         } else {
  1940             this.click_target = null;
  1970             this.click_target = null;
  1941             if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) {
  1971             if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) {
  1942                 var _coords = this.toModelCoords(_event.point),
  1972                 var _coords = this.toModelCoords(_point),
  1943                     _data = {
  1973                     _data = {
  1944                         id: Rkns.Utils.getUID('node'),
  1974                         id: Rkns.Utils.getUID('node'),
  1945                         created_by: this.renkan.current_user,
  1975                         created_by: this.renkan.current_user,
  1946                         position: {
  1976                         position: {
  1947                             x: _coords.x,
  1977                             x: _coords.x,
  1954         }
  1984         }
  1955     }
  1985     }
  1956     if (this.click_mode) {
  1986     if (this.click_mode) {
  1957         if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
  1987         if (this.isEditable() && this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") {
  1958             this.removeRepresentationsOfType("editor");
  1988             this.removeRepresentationsOfType("editor");
  1959             this.addTempEdge(this.click_target, _event.point);
  1989             this.addTempEdge(this.click_target, _point);
  1960             this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE;
  1990             this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE;
  1961             this.notif_$.fadeOut(function() {
  1991             this.notif_$.fadeOut(function() {
  1962                 Rkns.$(this).html(_renkan.translate("Click on a second node to complete the edge")).fadeIn();
  1992                 Rkns.$(this).html(_renkan.translate("Click on a second node to complete the edge")).fadeIn();
  1963             });
  1993             });
  1964         } else {
  1994         } else {
  1966             this.click_mode = false;
  1996             this.click_mode = false;
  1967         }
  1997         }
  1968     }
  1998     }
  1969 }
  1999 }
  1970 
  2000 
  1971 Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) {
       
  1972     this.is_dragging = true;
       
  1973     this.onMouseMove(_event);
       
  1974 }
       
  1975 
       
  1976 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
  2001 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
       
  2002 	this.mouse_down = false;
  1977     if (this.click_target) {
  2003     if (this.click_target) {
  1978         var _off = this.canvas_$.offset();
  2004         var _off = this.canvas_$.offset();
  1979         this.click_target.mouseup(
  2005         this.click_target.mouseup(
  1980             {
  2006             {
  1981                 point: new paper.Point([
  2007                 point: new paper.Point([