client/js/paper-renderer.js
changeset 163 fca0475da9a7
parent 161 c7a503c80ef4
child 169 a60a450b8f3b
equal deleted inserted replaced
162:1b7289414d3c 163:fca0475da9a7
    39         var _height = _selector.outerHeight() + 2* _options.tooltip_padding,
    39         var _height = _selector.outerHeight() + 2* _options.tooltip_padding,
    40             _isLeft = (_coords.x < paper.view.center.x ? 1 : -1),
    40             _isLeft = (_coords.x < paper.view.center.x ? 1 : -1),
    41             _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ),
    41             _left = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length ),
    42             _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ),
    42             _right = _coords.x + _isLeft * ( _xmargin + _options.tooltip_arrow_length + _options.tooltip_width ),
    43             _top = _coords.y - _height / 2;
    43             _top = _coords.y - _height / 2;
       
    44         if (_top + _height > (paper.view.size.height - _options.tooltip_margin)) {
       
    45             _top = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 ) - _height;
       
    46         }
    44         if (_top < _options.tooltip_margin) {
    47         if (_top < _options.tooltip_margin) {
    45             _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
    48             _top = Math.min( _options.tooltip_margin, _coords.y - _options.tooltip_arrow_width / 2 );
    46         }
    49         }
    47         var _bottom = _top + _height;
    50         var _bottom = _top + _height;
    48         if (_bottom > (paper.view.size.height - _options.tooltip_margin)) {
       
    49             _bottom = Math.max( paper.view.size.height - _options.tooltip_margin, _coords.y + _options.tooltip_arrow_width / 2 );
       
    50             _top = _bottom - _height;
       
    51         }
       
    52         _path.segments[0].point
    51         _path.segments[0].point
    53             = _path.segments[7].point
    52             = _path.segments[7].point
    54             = _coords.add([_isLeft * _xmargin, 0]);
    53             = _coords.add([_isLeft * _xmargin, 0]);
    55         _path.segments[1].point.x
    54         _path.segments[1].point.x
    56             = _path.segments[2].point.x
    55             = _path.segments[2].point.x
    94                 _renderer.removeRepresentation(_this);
    93                 _renderer.removeRepresentation(_this);
    95                 _(function() {
    94                 _(function() {
    96                     _renderer.redraw()
    95                     _renderer.redraw()
    97                 }).defer();
    96                 }).defer();
    98             }
    97             }
       
    98             this._selectBinding = function() {
       
    99                 _this.select();
       
   100             }
       
   101             this._unselectBinding = function() {
       
   102                 _this.unselect();
       
   103             }
    99             this.model.on("change", this._changeBinding );
   104             this.model.on("change", this._changeBinding );
   100             this.model.on("remove", this._removeBinding );
   105             this.model.on("remove", this._removeBinding );
       
   106             this.model.on("select", this._selectBinding );
       
   107             this.model.on("unselect", this._unselectBinding );
   101         }
   108         }
   102     }
   109     }
   103 }
   110 }
   104 
   111 
   105 Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) {
   112 Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) {
   112 
   119 
   113 Rkns.Renderer._BaseRepresentation.prototype.show = function() {}
   120 Rkns.Renderer._BaseRepresentation.prototype.show = function() {}
   114 
   121 
   115 Rkns.Renderer._BaseRepresentation.prototype.hide = function() {}
   122 Rkns.Renderer._BaseRepresentation.prototype.hide = function() {}
   116 
   123 
   117 Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
   124 Rkns.Renderer._BaseRepresentation.prototype.select = function() {
   118 
   125     if (this.model) {
   119 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
   126         this.model.trigger("selected");
       
   127     }
       
   128 }
       
   129 
       
   130 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {
       
   131     if (this.model) {
       
   132         this.model.trigger("unselected");
       
   133     }
       
   134 }
   120 
   135 
   121 Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {}
   136 Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {}
   122 
   137 
   123 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
   138 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
   124 
   139 
   125 Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {}
   140 Rkns.Renderer._BaseRepresentation.prototype.mousedown = function() {}
   126 
   141 
   127 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
   142 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {
       
   143     if (this.model) {
       
   144         this.model.trigger("clicked");
       
   145     }
       
   146 }
   128 
   147 
   129 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
   148 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
   130     if (this.model) {
   149     if (this.model) {
   131         this.model.off("change", this._changeBinding );
   150         this.model.off("change", this._changeBinding );
   132         this.model.off("remove", this._removeBinding );
   151         this.model.off("remove", this._removeBinding );
       
   152         this.model.off("select", this._selectBinding );
       
   153         this.model.off("unselect", this._unselectBinding );
   133     }
   154     }
   134 }
   155 }
   135 
   156 
   136 /* */
   157 /* */
   137 
   158 
   236     this.last_circle_radius = this.circle_radius;
   257     this.last_circle_radius = this.circle_radius;
   237     
   258     
   238     var old_act_btn = this.active_buttons;
   259     var old_act_btn = this.active_buttons;
   239     
   260     
   240     if (this.model.get("delete_scheduled")) {
   261     if (this.model.get("delete_scheduled")) {
   241         var opacity = .33;
   262         var opacity = .5;
   242         this.active_buttons = this.pending_delete_buttons;
   263         this.active_buttons = this.pending_delete_buttons;
       
   264         this.circle.dashArray = [2,2];
   243     } else {
   265     } else {
   244         var opacity = 1;
   266         var opacity = 1;
   245         this.active_buttons = this.normal_buttons;
   267         this.active_buttons = this.normal_buttons;
   246     }
   268         this.circle.dashArray = null;
   247     
   269     }
   248     if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) {
   270     
   249         old_act_btn.forEach(function(b) {
   271     if (this.selected && this.renderer.isEditable()) {
   250             b.hide();
   272         if (old_act_btn !== this.active_buttons) {
   251         });
   273             old_act_btn.forEach(function(b) {
       
   274                 b.hide();
       
   275             });
       
   276         }
   252         this.active_buttons.forEach(function(b) {
   277         this.active_buttons.forEach(function(b) {
   253             b.show();
   278             b.show();
   254         });
   279         });
   255     }
   280     }
   256     
   281     
   380     
   405     
   381     if (this.renderer.minimap) {
   406     if (this.renderer.minimap) {
   382         this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight;
   407         this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight;
   383         this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
   408         this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
   384     }
   409     }
       
   410     this.super("select");
   385 }
   411 }
   386 
   412 
   387 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
   413 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
   388     if (!_newTarget || _newTarget.source_representation !== this) {
   414     if (!_newTarget || _newTarget.source_representation !== this) {
   389         this.selected = false;
   415         this.selected = false;
   393         this.circle.strokeWidth = this.options.node_stroke_width;
   419         this.circle.strokeWidth = this.options.node_stroke_width;
   394         Rkns.$('.Rk-Bin-Item').removeClass("selected");
   420         Rkns.$('.Rk-Bin-Item').removeClass("selected");
   395         if (this.renderer.minimap) {
   421         if (this.renderer.minimap) {
   396             this.minimap_circle.strokeColor = undefined;
   422             this.minimap_circle.strokeColor = undefined;
   397         }
   423         }
       
   424         this.super("unselect");
   398     }
   425     }
   399 }
   426 }
   400     
   427     
   401 Rkns.Renderer.Node.prototype.highlight = function() {
   428 Rkns.Renderer.Node.prototype.highlight = function() {
   402     if (this.highlighted) {
   429     if (this.highlighted) {
   441         this.saveCoords();
   468         this.saveCoords();
   442     } else {
   469     } else {
   443         if (!_isTouch && !this.model.get("delete_scheduled")) {
   470         if (!_isTouch && !this.model.get("delete_scheduled")) {
   444             this.openEditor();
   471             this.openEditor();
   445         }
   472         }
       
   473         this.model.trigger("clicked");
   446     }
   474     }
   447     this.renderer.click_target = null;
   475     this.renderer.click_target = null;
   448     this.renderer.is_dragging = false;
   476     this.renderer.is_dragging = false;
   449     this.is_dragging = false;
   477     this.is_dragging = false;
   450 }
   478 }
   532         _a = _v.angle,
   560         _a = _v.angle,
   533         _textdelta = _ortho.multiply(this.options.edge_label_distance),
   561         _textdelta = _ortho.multiply(this.options.edge_label_distance),
   534         _handle = _v.divide(3),
   562         _handle = _v.divide(3),
   535         _color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
   563         _color = this.model.get("color") || this.model.get("color") || (this.model.get("created_by") || Rkns.Renderer._USER_PLACEHOLDER(this.renkan)).get("color");
   536     
   564     
   537     var opacity = (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) ? .33 : 1;
   565     if (this.model.get("delete_scheduled") || this.from_representation.model.get("delete_scheduled") || this.to_representation.model.get("delete_scheduled")) {
       
   566         var opacity = .5;
       
   567         this.line.dashArray = [2, 2];
       
   568     } else {
       
   569         var opacity = 1;
       
   570         this.line.dashArray = null;
       
   571     }
   538     
   572     
   539     var old_act_btn = this.active_buttons;
   573     var old_act_btn = this.active_buttons;
   540     
   574     
   541     this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
   575     this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons;
   542     
   576     
   612         });
   646         });
   613     }
   647     }
   614     if (!this.options.editor_mode) {
   648     if (!this.options.editor_mode) {
   615         this.openEditor();
   649         this.openEditor();
   616     }
   650     }
       
   651     this.super("select");
   617 }
   652 }
   618 
   653 
   619 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
   654 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
   620     if (!_newTarget || _newTarget.source_representation !== this) {
   655     if (!_newTarget || _newTarget.source_representation !== this) {
   621         this.selected = false;
   656         this.selected = false;
   623             this.all_buttons.forEach(function(b) {
   658             this.all_buttons.forEach(function(b) {
   624                 b.hide();
   659                 b.hide();
   625             });
   660             });
   626         }
   661         }
   627         this.line.strokeWidth = this.options.edge_stroke_width;
   662         this.line.strokeWidth = this.options.edge_stroke_width;
       
   663         this.super("unselect");
   628     }
   664     }
   629 }
   665 }
   630 
   666 
   631 Rkns.Renderer.Edge.prototype.mousedown = function(_event, _isTouch) {
   667 Rkns.Renderer.Edge.prototype.mousedown = function(_event, _isTouch) {
   632     if (_isTouch) {
   668     if (_isTouch) {
   643         this.to_representation.is_dragging = false;
   679         this.to_representation.is_dragging = false;
   644     } else {
   680     } else {
   645         if (!_isTouch) {
   681         if (!_isTouch) {
   646             this.openEditor();
   682             this.openEditor();
   647         }
   683         }
       
   684         this.model.trigger("clicked");
   648     }
   685     }
   649     this.renderer.click_target = null;
   686     this.renderer.click_target = null;
   650     this.renderer.is_dragging = false;
   687     this.renderer.is_dragging = false;
   651 }
   688 }
   652 
   689 
   769 
   806 
   770 /* */
   807 /* */
   771 
   808 
   772 Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   809 Rkns.Renderer._BaseEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   773 
   810 
       
   811 Rkns.Renderer._BaseEditor.prototype._init = function() {
       
   812     this.renderer.buttons_layer.activate();
       
   813     this.type = "editor";
       
   814     this.editor_block = new paper.Path();
       
   815     var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]});
       
   816     this.editor_block.add.apply(this.editor_block, _pts);
       
   817     this.editor_block.strokeWidth = this.options.tooltip_border_width;
       
   818     this.editor_block.strokeColor = this.options.tooltip_border_color;
       
   819     this.editor_block.opacity = .8;
       
   820     this.editor_$ = Rkns.$('<div>')
       
   821         .appendTo(this.renderer.editor_$)
       
   822         .css({
       
   823             position: "absolute",
       
   824             opacity: .8
       
   825         })
       
   826         .hide();
       
   827 }
       
   828 
   774 Rkns.Renderer._BaseEditor.prototype.destroy = function() {
   829 Rkns.Renderer._BaseEditor.prototype.destroy = function() {
   775     this.editor_block.remove();
   830     this.editor_block.remove();
   776     this.editor_$.detach();
   831     this.editor_$.remove();
   777 }
   832 }
   778 
   833 
   779 /* */
   834 /* */
   780 
   835 
   781 Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
   836 Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
   954 }
  1009 }
   955 
  1010 
   956 /* */
  1011 /* */
   957 
  1012 
   958 Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
  1013 Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseEditor);
   959 
       
   960 Rkns.Renderer.EdgeEditor.prototype._init = function() {
       
   961     this.renderer.buttons_layer.activate();
       
   962     this.type = "editor";
       
   963     this.editor_block = new paper.Path();
       
   964     var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]});
       
   965     this.editor_block.add.apply(this.editor_block, _pts);
       
   966     this.editor_block.strokeWidth = this.options.tooltip_border_width;
       
   967     this.editor_block.strokeColor = this.options.tooltip_border_color;
       
   968     this.editor_block.opacity = .8;
       
   969     this.editor_$ = Rkns.$('<div>')
       
   970         .appendTo(this.renderer.editor_$)
       
   971         .css({
       
   972             position: "absolute",
       
   973             opacity: .8
       
   974         })
       
   975         .hide();
       
   976 }
       
   977 
  1014 
   978 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
  1015 Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template(
   979     '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Edge")%></span></h2>'
  1016     '<h2><span class="Rk-CloseX">&times;</span><%-renkan.translate("Edit Edge")%></span></h2>'
   980     + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>'
  1017     + '<p><label><%-renkan.translate("Title:")%></label><input class="Rk-Edit-Title" type="text" value="<%-edge.title%>"/></p>'
   981     + '<p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>'
  1018     + '<p><label><%-renkan.translate("URI:")%></label><input class="Rk-Edit-URI" type="text" value="<%-edge.uri%>"/><a class="Rk-Edit-Goto" href="<%-edge.uri%>" target="_blank"></a></p>'
  1120 Rkns.Renderer.EdgeEditor.prototype.redraw = function() {
  1157 Rkns.Renderer.EdgeEditor.prototype.redraw = function() {
  1121     var _coords = this.source_representation.paper_coords;
  1158     var _coords = this.source_representation.paper_coords;
  1122     Rkns.Renderer.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
  1159     Rkns.Renderer.drawEditBox(this.options, _coords, this.editor_block, 5, this.editor_$);
  1123     this.editor_$.show();
  1160     this.editor_$.show();
  1124     paper.view.draw();
  1161     paper.view.draw();
  1125 }
       
  1126 
       
  1127 /* */
       
  1128 
       
  1129 Rkns.Renderer._BaseEditor.prototype._init = function() {
       
  1130     this.renderer.buttons_layer.activate();
       
  1131     this.type = "editor";
       
  1132     this.editor_block = new paper.Path();
       
  1133     var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]});
       
  1134     this.editor_block.add.apply(this.editor_block, _pts);
       
  1135     this.editor_block.strokeWidth = this.options.tooltip_border_width;
       
  1136     this.editor_block.strokeColor = this.options.tooltip_border_color;
       
  1137     this.editor_block.opacity = .8;
       
  1138     this.editor_$ = Rkns.$('<div>')
       
  1139         .appendTo(this.renderer.editor_$)
       
  1140         .css({
       
  1141             position: "absolute",
       
  1142             opacity: .8
       
  1143         })
       
  1144         .hide();
       
  1145 }
  1162 }
  1146 
  1163 
  1147 /* */
  1164 /* */
  1148 
  1165 
  1149 Rkns.Renderer._NodeButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
  1166 Rkns.Renderer._NodeButton = Rkns.Utils.inherit(Rkns.Renderer._BaseButton);
  1728             el.text(_title);
  1745             el.text(_title);
  1729         }
  1746         }
  1730     });
  1747     });
  1731     
  1748     
  1732     if (_renkan.options.size_bug_fix) {
  1749     if (_renkan.options.size_bug_fix) {
       
  1750         var _delay = (
       
  1751             typeof _renkan.options.size_bug_fix === "number"
       
  1752             ? _renkan.options.size_bug_fix
       
  1753             : 500
       
  1754         );
  1733         window.setTimeout(
  1755         window.setTimeout(
  1734             function() {
  1756             function() {
  1735                 var w = _this.$.width(),
  1757                 _this.fixSize(true);
  1736                     h = _this.$.height();
       
  1737                 if (_renkan.options.show_top_bar) {
       
  1738                     h -= _this.$.find(".Rk-TopBar").height();
       
  1739                 }
       
  1740                 _this.canvas_$.attr({
       
  1741                     width: w,
       
  1742                     height: h
       
  1743                 });
       
  1744                 
       
  1745                 paper.view.viewSize = new paper.Size([w, h]);
       
  1746                 _this.autoScale();
       
  1747             },
  1758             },
  1748             500
  1759             _delay
  1749         );
  1760         );
       
  1761     }
       
  1762     
       
  1763     if (_renkan.options.force_resize) {
       
  1764         $(window).resize(function() {
       
  1765             _this.fixSize(false);
       
  1766         });
  1750     }
  1767     }
  1751     
  1768     
  1752     this.redraw();
  1769     this.redraw();
  1753     
  1770     
  1754     window.setInterval(function() {
  1771     window.setInterval(function() {
  1795     + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
  1812     + '<div class="Rk-Labels"></div><canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>'
  1796     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1813     + '<% if (options.show_bins) { %><div class="Rk-Fold-Bins">&laquo;</div><% } %>'
  1797     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1814     + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%-translate("Zoom In")%>"></div><div class="Rk-ZoomOut" title="<%-translate("Zoom Out")%>"></div></div>'
  1798     + '</div></div>'
  1815     + '</div></div>'
  1799 );
  1816 );
       
  1817 
       
  1818 Rkns.Renderer.Scene.prototype.fixSize = function(_autoscale) {
       
  1819     var w = this.$.width(),
       
  1820         h = this.$.height();
       
  1821     if (this.renkan.options.show_top_bar) {
       
  1822         h -= this.$.find(".Rk-TopBar").height();
       
  1823     }
       
  1824     this.canvas_$.attr({
       
  1825         width: w,
       
  1826         height: h
       
  1827     });
       
  1828     
       
  1829     paper.view.viewSize = new paper.Size([w, h]);
       
  1830     
       
  1831     if (_autoscale) {
       
  1832         this.autoScale();
       
  1833     }
       
  1834 }
  1800 
  1835 
  1801 Rkns.Renderer.Scene.prototype.drawSector = function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
  1836 Rkns.Renderer.Scene.prototype.drawSector = function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
  1802     var _options = this.renkan.options,
  1837     var _options = this.renkan.options,
  1803         _startRads = _startAngle * Math.PI / 180,
  1838         _startRads = _startAngle * Math.PI / 180,
  1804         _endRads = _endAngle * Math.PI / 180,
  1839         _endRads = _endAngle * Math.PI / 180,