client/js/paper-renderer.js
changeset 156 83d7a10e1ad7
parent 155 7d5f722d76b2
child 157 cdfc0b1547f3
equal deleted inserted replaced
155:7d5f722d76b2 156:83d7a10e1ad7
   279 	    this.h_ratio = 1;
   279 	    this.h_ratio = 1;
   280     } else {
   280     } else {
   281     	this.circle.opacity = .01;
   281     	this.circle.opacity = .01;
   282     	this.h_ratio = 0;
   282     	this.h_ratio = 0;
   283     }
   283     }
   284     this.title = new paper.PointText([0,0]);
   284     this.title = Rkns.$('<div class="Rk-Label">').appendTo(this.renderer.labels_$);
   285     this.title.characterStyle = {
       
   286         font: this.options.node_label_font,
       
   287         fontSize: this.options.node_label_font_size,
       
   288         fillColor: this.options.node_label_color
       
   289     };
       
   290     if (this.options.editor_mode) {
   285     if (this.options.editor_mode) {
   291     	this.buttons = [
   286     	this.buttons = [
   292     		new Rkns.Renderer.NodeEditButton(this.renderer, null),
   287     		new Rkns.Renderer.NodeEditButton(this.renderer, null),
   293     		new Rkns.Renderer.NodeRemoveButton(this.renderer, null),
   288     		new Rkns.Renderer.NodeRemoveButton(this.renderer, null),
   294     		new Rkns.Renderer.NodeLinkButton(this.renderer, null),
   289     		new Rkns.Renderer.NodeLinkButton(this.renderer, null),
   300     	}
   295     	}
   301     } else {
   296     } else {
   302     	this.buttons = [];
   297     	this.buttons = [];
   303     }
   298     }
   304     this.last_circle_radius = 1;
   299     this.last_circle_radius = 1;
   305     this.title.paragraphStyle.justification = 'center';
   300 //    this.title.paragraphStyle.justification = 'center';
   306     
   301     
   307     if (this.renderer.minimap) {
   302     if (this.renderer.minimap) {
   308 	    this.renderer.minimap.node_layer.activate();
   303 	    this.renderer.minimap.node_layer.activate();
   309 	    this.minimap_circle = new paper.Path.Circle([0, 0], 1);
   304 	    this.minimap_circle = new paper.Path.Circle([0, 0], 1);
   310 	    this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
   305 	    this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation;
   337         }
   332         }
   338     }
   333     }
   339     this.last_circle_radius = this.circle_radius;
   334     this.last_circle_radius = this.circle_radius;
   340     
   335     
   341     var _text = this.model.get("title") || this.renkan.translate("(untitled)");
   336     var _text = this.model.get("title") || this.renkan.translate("(untitled)");
   342     this.title.content = Rkns.Renderer.Utils.shortenText(_text, this.options.node_label_max_length);
   337 	_text = Rkns.Renderer.Utils.shortenText(_text, this.options.node_label_max_length);
   343 
   338 	this.title.text(_text);
   344     this.title.position = this.paper_coords.add([
   339 	this.title.css({
   345     	0,
   340 		left: this.paper_coords.x,
   346     	this.circle_radius * this.h_ratio + this.options.node_label_font_size + this.options.node_label_distance
   341 		top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance
   347 	]);
   342 	})
   348     var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
   343     var _color = this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
   349     this.circle.strokeColor = _color;
   344     this.circle.strokeColor = _color;
   350     var _pc = this.paper_coords;
   345     var _pc = this.paper_coords;
   351 	this.buttons.forEach(function(b) {
   346 	this.buttons.forEach(function(b) {
   352 		b.moveTo(_pc);
   347 		b.moveTo(_pc);
   562     	[ 0, 0 ],
   557     	[ 0, 0 ],
   563     	[ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
   558     	[ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ],
   564     	[ 0, this.options.edge_arrow_width ]
   559     	[ 0, this.options.edge_arrow_width ]
   565 	);
   560 	);
   566     this.arrow.__representation = this;
   561     this.arrow.__representation = this;
   567     this.text = new paper.PointText();
   562     this.text = Rkns.$('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$);
   568     this.text.characterStyle = {
       
   569         font: this.options.edge_label_font,
       
   570         fontSize: this.options.edge_label_font_size,
       
   571         fillColor: this.options.edge_label_color
       
   572     };
       
   573     this.text.paragraphStyle.justification = 'center';
       
   574     this.text_angle = 0;
       
   575     this.arrow_angle = 0;
   563     this.arrow_angle = 0;
   576     if (this.options.editor_mode) {
   564     if (this.options.editor_mode) {
   577         this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null);
   565         this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null);
   578         this.edit_button.source_representation = this;
   566         this.edit_button.source_representation = this;
   579         this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null);
   567         this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null);
   626     }
   614     }
   627     if (_a < -90) {
   615     if (_a < -90) {
   628         _a += 180;
   616         _a += 180;
   629         _textdelta = _textdelta.multiply(-1);
   617         _textdelta = _textdelta.multiply(-1);
   630     }
   618     }
   631     this.text.rotate(_a - this.text_angle);
       
   632     var _text = this.model.get("title");
   619     var _text = this.model.get("title");
   633     this.text.content = Rkns.Renderer.Utils.shortenText(_text, this.options.edge_label_max_length);
   620 	_text = Rkns.Renderer.Utils.shortenText(_text, this.options.node_label_max_length);
   634     this.text.position = this.paper_coords.add(_textdelta);
   621     this.text.text(_text);
       
   622     var _textpos = this.paper_coords.add(_textdelta);
       
   623     this.text.css({
       
   624     	left: _textpos.x,
       
   625     	top: _textpos.y,
       
   626     	transform: "rotate(" + _a + "deg)",
       
   627     	"-moz-transform": "rotate(" + _a + "deg)",
       
   628     	"-webkit-transform": "rotate(" + _a + "deg)"
       
   629     });
   635     this.text_angle = _a;
   630     this.text_angle = _a;
   636     if (this.options.editor_mode) {
   631     if (this.options.editor_mode) {
   637 	    this.edit_button.moveTo(this.paper_coords);
   632 	    this.edit_button.moveTo(this.paper_coords);
   638 	    this.remove_button.moveTo(this.paper_coords);
   633 	    this.remove_button.moveTo(this.paper_coords);
   639     }
   634     }
  1210 Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
  1205 Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
  1211 
  1206 
  1212 Rkns.Renderer.NodeRemoveButton.prototype._init = function() {
  1207 Rkns.Renderer.NodeRemoveButton.prototype._init = function() {
  1213     this.type = "Node-remove-button";
  1208     this.type = "Node-remove-button";
  1214     this.lastSectorInner = 0;
  1209     this.lastSectorInner = 0;
  1215     this.startAngle = 90;
  1210     this.startAngle = 0;
  1216     this.endAngle = 180;
  1211     this.endAngle = 90;
  1217     this.imageFile = 'img/remove.png';
  1212     this.imageFile = 'img/remove.png';
  1218     this.text = "Remove";
  1213     this.text = "Remove";
  1219 }
  1214 }
  1220 
  1215 
  1221 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() {
  1216 Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() {
  1232 Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
  1227 Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._NodeButton);
  1233 
  1228 
  1234 Rkns.Renderer.NodeLinkButton.prototype._init = function() {
  1229 Rkns.Renderer.NodeLinkButton.prototype._init = function() {
  1235     this.type = "Node-link-button";
  1230     this.type = "Node-link-button";
  1236     this.lastSectorInner = 0;
  1231     this.lastSectorInner = 0;
  1237     this.startAngle = 0;
  1232     this.startAngle = 90;
  1238     this.endAngle = 90;
  1233     this.endAngle = 180;
  1239     this.imageFile = 'img/link.png';
  1234     this.imageFile = 'img/link.png';
  1240     this.text = "Link to another node";
  1235     this.text = "Link to another node";
  1241 }
  1236 }
  1242 
  1237 
  1243 Rkns.Renderer.NodeLinkButton.prototype.mousedown = function(_event, _isTouch) {
  1238 Rkns.Renderer.NodeLinkButton.prototype.mousedown = function(_event, _isTouch) {
  1349     this.$ = Rkns.$(".Rk-Render");
  1344     this.$ = Rkns.$(".Rk-Render");
  1350     this.representations = [];
  1345     this.representations = [];
  1351     this.$.html(this.template(_renkan));
  1346     this.$.html(this.template(_renkan));
  1352     this.onStatusChange();
  1347     this.onStatusChange();
  1353     this.canvas_$ = this.$.find(".Rk-Canvas");
  1348     this.canvas_$ = this.$.find(".Rk-Canvas");
       
  1349     this.labels_$ = this.$.find(".Rk-Labels");
  1354     this.editor_$ = this.$.find(".Rk-Editor");
  1350     this.editor_$ = this.$.find(".Rk-Editor");
  1355     this.notif_$ = this.$.find(".Rk-Notifications");
  1351     this.notif_$ = this.$.find(".Rk-Notifications");
  1356     paper.setup(this.canvas_$[0]);
  1352     paper.setup(this.canvas_$[0]);
  1357     this.scale = 1;
  1353     this.scale = 1;
  1358     this.offset = paper.view.center;
  1354     this.offset = paper.view.center;
  1407         _originalScale,
  1403         _originalScale,
  1408         _zooming = false;
  1404         _zooming = false;
  1409     
  1405     
  1410     this.canvas_$.on({
  1406     this.canvas_$.on({
  1411     	mousedown: function(_event) {
  1407     	mousedown: function(_event) {
       
  1408     		_event.preventDefault();
  1412     		_this.onMouseDown(_event, false);
  1409     		_this.onMouseDown(_event, false);
  1413     	},
  1410     	},
  1414     	mousemove: function(_event) {
  1411     	mousemove: function(_event) {
       
  1412     		_event.preventDefault();
  1415         	_this.onMouseMove(_event, false);
  1413         	_this.onMouseMove(_event, false);
  1416 	    },
  1414 	    },
  1417 	    mouseup: function(_event) {
  1415 	    mouseup: function(_event) {
       
  1416     		_event.preventDefault();
  1418 	        _this.onMouseUp(_event, false);
  1417 	        _this.onMouseUp(_event, false);
  1419 	    },
  1418 	    },
  1420 	    mousewheel: function(_event, _delta) {
  1419 	    mousewheel: function(_event, _delta) {
       
  1420     		_event.preventDefault();
  1421 	        if (_allowScroll) {
  1421 	        if (_allowScroll) {
  1422 	        	_this.onScroll(_event, _delta);
  1422 	        	_this.onScroll(_event, _delta);
  1423 	        }
  1423 	        }
  1424 	    },
  1424 	    },
  1425 	    touchstart: function(_event) {
  1425 	    touchstart: function(_event) {
  1452 	    touchend: function(_event) {
  1452 	    touchend: function(_event) {
  1453 	    	_event.preventDefault();
  1453 	    	_event.preventDefault();
  1454 	    	_this.onMouseUp(_event.originalEvent.changedTouches[0], true);
  1454 	    	_this.onMouseUp(_event.originalEvent.changedTouches[0], true);
  1455 	    },
  1455 	    },
  1456 	    dblclick: function(_event) {
  1456 	    dblclick: function(_event) {
       
  1457     		_event.preventDefault();
  1457 	        _this.onDoubleClick(_event);
  1458 	        _this.onDoubleClick(_event);
  1458 	    },
  1459 	    },
  1459 	    mouseleave: function(_event) {
  1460 	    mouseleave: function(_event) {
       
  1461     		_event.preventDefault();
  1460 	        _this.onMouseUp(_event, false);
  1462 	        _this.onMouseUp(_event, false);
  1461 	        _this.click_target = null;
  1463 	        _this.click_target = null;
  1462 	        _this.is_dragging = false;
  1464 	        _this.is_dragging = false;
  1463 	    },
  1465 	    },
  1464 	    dragover: function(_event) {
  1466 	    dragover: function(_event) {
  1465 	    	_event.preventDefault();
  1467 	    	_event.preventDefault();
  1466 	    },
  1468 	    },
  1467 	    dragenter: function(_event) {
  1469 	    dragenter: function(_event) {
       
  1470 	    	_event.preventDefault();
  1468 	    	_allowScroll = false;
  1471 	    	_allowScroll = false;
  1469 	    	_event.preventDefault();
       
  1470 	    },
  1472 	    },
  1471 	    dragleave: function(_event) {
  1473 	    dragleave: function(_event) {
       
  1474 	    	_event.preventDefault();
  1472 	    	_allowScroll = true;
  1475 	    	_allowScroll = true;
  1473 	    	_event.preventDefault();
       
  1474 	    },
  1476 	    },
  1475 	    drop: function(_event) {
  1477 	    drop: function(_event) {
  1476 	    	_event.preventDefault();
  1478 	    	_event.preventDefault();
  1477 	    	_allowScroll = true;
  1479 	    	_allowScroll = true;
  1478 	    	var res = {};
  1480 	    	var res = {};
  1700     + '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div>'
  1702     + '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-Save-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"> </div></div></div>'
  1701     + '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">'
  1703     + '<div class="Rk-TopBar-Separator"></div><a class="Rk-TopBar-Button Rk-Bookmarklet-Button" href="#"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents">'
  1702     + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a>'
  1704     + '<%-translate("Renkan \'Drag-to-Add\' bookmarklet")%></div></div></a>'
  1703     + '<div class="Rk-TopBar-Separator"></div>'
  1705     + '<div class="Rk-TopBar-Separator"></div>'
  1704     + '<% } %></div><% } %>'
  1706     + '<% } %></div><% } %>'
  1705     + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>"><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
  1707     + '<div class="Rk-Editing-Space<% if (!options.show_top_bar) { %> Rk-Editing-Space-Full<% } %>">'
       
  1708     + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
  1706     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1709     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1707     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1710     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1708     + '</div></div>'
  1711     + '</div></div>'
  1709 );
  1712 );
  1710 
  1713