client/js/renderer/scene.js
changeset 512 480c1d2d6915
parent 490 8b05c7322e93
parent 511 4a48a1a9fd1e
child 519 b94a34c139c1
equal deleted inserted replaced
497:3ba7920facf4 512:480c1d2d6915
    19         }else{
    19         }else{
    20             this.editor_$ = this.$.find(".Rk-Editor");
    20             this.editor_$ = this.$.find(".Rk-Editor");
    21         }
    21         }
    22         this.notif_$ = this.$.find(".Rk-Notifications");
    22         this.notif_$ = this.$.find(".Rk-Notifications");
    23         paper.setup(this.canvas_$[0]);
    23         paper.setup(this.canvas_$[0]);
    24         this.scale = 1;
       
    25         this.initialScale = 1;
       
    26         this.offset = paper.view.center;
       
    27         this.totalScroll = 0;
    24         this.totalScroll = 0;
    28         this.hiddenNodes = [];
       
    29         this.mouse_down = false;
    25         this.mouse_down = false;
    30         this.click_target = null;
    26         this.click_target = null;
    31         this.selected_target = null;
    27         this.selected_target = null;
    32         this.edge_layer = new paper.Layer();
    28         this.edge_layer = new paper.Layer();
    33         this.node_layer = new paper.Layer();
    29         this.node_layer = new paper.Layer();
   126                     _this.onDoubleClick(_touches);
   122                     _this.onDoubleClick(_touches);
   127                 } else {
   123                 } else {
   128                     _lastTap = new Date();
   124                     _lastTap = new Date();
   129                     _lastTapX = _touches.pageX;
   125                     _lastTapX = _touches.pageX;
   130                     _lastTapY = _touches.pageY;
   126                     _lastTapY = _touches.pageY;
   131                     _originalScale = _this.scale;
   127                     _originalScale = _this.view.scale;
   132                     _zooming = false;
   128                     _zooming = false;
   133                     _this.onMouseDown(_touches, true);
   129                     _this.onMouseDown(_touches, true);
   134                 }
   130                 }
   135             },
   131             },
   136             touchmove: function(_event) {
   132             touchmove: function(_event) {
   147                     }
   143                     }
   148                     if (_event.originalEvent.scale === "undefined") {
   144                     if (_event.originalEvent.scale === "undefined") {
   149                         return;
   145                         return;
   150                     }
   146                     }
   151                     var _newScale = _event.originalEvent.scale * _originalScale,
   147                     var _newScale = _event.originalEvent.scale * _originalScale,
   152                     _scaleRatio = _newScale / _this.scale,
   148                     _scaleRatio = _newScale / _this.view.scale,
   153                     _newOffset = new paper.Point([
   149                     _newOffset = new paper.Point([
   154                                                   _this.canvas_$.width(),
   150                                                   _this.canvas_$.width(),
   155                                                   _this.canvas_$.height()
   151                                                   _this.canvas_$.height()
   156                                                   ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio ));
   152                                                   ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.view.offset.multiply( _scaleRatio ));
   157                     _this.setScale(_newScale, _newOffset);
   153                     _this.view.setScale(_newScale, _newOffset);
   158                 }
   154                 }
   159             },
   155             },
   160             touchend: function(_event) {
   156             touchend: function(_event) {
   161                 _event.preventDefault();
   157                 _event.preventDefault();
   162                 _this.onMouseUp(_event.originalEvent.changedTouches[0], true);
   158                 _this.onMouseUp(_event.originalEvent.changedTouches[0], true);
   232                 _this[fname](evt);
   228                 _this[fname](evt);
   233                 return false;
   229                 return false;
   234             });
   230             });
   235         };
   231         };
   236 
   232 
   237         bindClick(".Rk-ZoomOut", "zoomOut");
       
   238         bindClick(".Rk-ZoomIn", "zoomIn");
       
   239         bindClick(".Rk-ZoomFit", "autoScale");
       
   240         this.$.find(".Rk-ZoomSave").click( function() {
       
   241             // Save scale and offset point
       
   242             _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.hiddenNodes } );
       
   243         });
       
   244         this.$.find(".Rk-ZoomSetSaved").click( function() {
       
   245             var view = _this.renkan.project.get("views").last();
       
   246             if(view){
       
   247                 _this.showNodes(false);
       
   248                 _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
       
   249                 if (_this.renkan.options.hide_nodes){
       
   250                     _this.hiddenNodes = (view.get("hidden_nodes") || []).concat();
       
   251                     _this.hideNodes();                    
       
   252                 }
       
   253             }
       
   254         });
       
   255         this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
       
   256             _this.showNodes(true);
       
   257             _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
       
   258                 _this.hideNodes();
       
   259             });
       
   260         });
       
   261         this.$.find(".Rk-ShowHiddenNodes").click( function() {
       
   262             _this.showNodes(false);
       
   263             _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" );
       
   264         });
       
   265         if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
   233         if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
   266             this.$.find(".Rk-ZoomSetSaved").show();
   234             this.$.find(".Rk-ZoomSetSaved").show();
   267         }
   235         }
   268         this.$.find(".Rk-CurrentUser").mouseenter(
   236         this.$.find(".Rk-CurrentUser").mouseenter(
   269                 function() { _this.$.find(".Rk-UserList").slideDown(); }
   237                 function() { _this.$.find(".Rk-UserList").slideDown(); }
   312                     _ratio = ratioH;
   280                     _ratio = ratioH;
   313             } else {
   281             } else {
   314                 _ratio = ratioW;
   282                 _ratio = ratioW;
   315             }
   283             }
   316 
   284 
   317             _this.resizeZoom(ratioW, ratioH, _ratio);
   285             _this.view.resizeZoom(ratioW, ratioH, _ratio);
   318 
   286 
   319             _this.redraw();
   287             _this.redraw();
   320 
   288 
   321         };
   289         };
   322 
   290 
   323         var _thRedraw = _.throttle(function() {
   291         var _thRedraw = _.throttle(function() {
   324             _this.redraw();
   292             _this.redraw();
   325         },50);
   293         },50);
   326 
   294            
   327         this.addRepresentations("Node", this.renkan.project.get("nodes"));
   295         this.addRepresentations("Node", this.renkan.project.get("nodes"));
   328         this.addRepresentations("Edge", this.renkan.project.get("edges"));
   296         this.addRepresentations("Edge", this.renkan.project.get("edges"));
   329         this.renkan.project.on("change:title", function() {
   297         this.renkan.project.on("change:title", function() {
   330             _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
   298             _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title"));
   331         });
   299         });
   368                     _this.$.find(".loader").hide(250);
   336                     _this.$.find(".loader").hide(250);
   369                 }, 3000);
   337                 }, 3000);
   370             }
   338             }
   371             else{
   339             else{
   372                 Backbone.history.start();
   340                 Backbone.history.start();
       
   341                 _thRedraw();
   373             }
   342             }
   374         });
   343         });
   375 
   344 
   376         this.renkan.project.on("add:users remove:users", _thRedrawUsers);
   345         this.renkan.project.on("add:users remove:users", _thRedrawUsers);
   377 
   346 
   516 
   485 
   517     };
   486     };
   518 
   487 
   519     _(Scene.prototype).extend({
   488     _(Scene.prototype).extend({
   520         fixSize: function() {
   489         fixSize: function() {
   521             if( this.renkan.options.default_view && this.renkan.project.get("views").length > 0) {
   490 //            if(typeothis.view) {
   522                 var view = this.renkan.project.get("views").last();
   491 //                this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
   523                 this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
   492 //            }
   524             }
   493 //            else{
   525             else{
   494 //                this.view.autoScale();
   526                 this.autoScale();
   495 //            }
   527             }
       
   528         },
   496         },
   529         drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
   497         drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) {
   530             var _options = this.renkan.options,
   498             var _options = this.renkan.options,
   531                 _startRads = _startAngle * Math.PI / 180,
   499                 _startRads = _startAngle * Math.PI / 180,
   532                 _endRads = _endAngle * Math.PI / 180,
   500                 _endRads = _endAngle * Math.PI / 180,
   672                     tip.text(this.renkan.translate("Auto-save enabled"));
   640                     tip.text(this.renkan.translate("Auto-save enabled"));
   673                 }
   641                 }
   674             }
   642             }
   675             this.redrawUsers();
   643             this.redrawUsers();
   676         },
   644         },
   677         setScale: function(_newScale, _offset) {
       
   678             if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) {
       
   679                 this.scale = _newScale;
       
   680                 if (_offset) {
       
   681                     this.offset = _offset;
       
   682                 }
       
   683                 this.redraw();
       
   684             }
       
   685         },
       
   686         autoScale: function(force_view) {
       
   687             var nodes = this.renkan.project.get("nodes");
       
   688             if (nodes.length > 1) {
       
   689                 var _xx = nodes.map(function(_node) { return _node.get("position").x; }),
       
   690                 _yy = nodes.map(function(_node) { return _node.get("position").y; }),
       
   691                 _minx = Math.min.apply(Math, _xx),
       
   692                 _miny = Math.min.apply(Math, _yy),
       
   693                 _maxx = Math.max.apply(Math, _xx),
       
   694                 _maxy = Math.max.apply(Math, _yy);
       
   695                 var _scale = Math.min( (paper.view.size.width - 2 * this.renkan.options.autoscale_padding) / (_maxx - _minx), (paper.view.size.height - 2 * this.renkan.options.autoscale_padding) / (_maxy - _miny));
       
   696                 this.initialScale = _scale;
       
   697                 // Override calculated scale if asked
       
   698                 if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset.x)>0 && parseFloat(force_view.offset.y)>0){
       
   699                     this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset.x), parseFloat(force_view.offset.y)));
       
   700                 }
       
   701                 else{
       
   702                     this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)));
       
   703                 }
       
   704             }
       
   705             if (nodes.length === 1) {
       
   706                 this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y])));
       
   707             }
       
   708         },
       
   709         redrawMiniframe: function() {
   645         redrawMiniframe: function() {
   710             var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
   646             var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
   711                 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
   647                 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
   712             this.minimap.miniframe.fitBounds(topleft, bottomright);
   648             this.minimap.miniframe.fitBounds(topleft, bottomright);
   713         },
   649         },
   719                     _minx = Math.min.apply(Math, _xx),
   655                     _minx = Math.min.apply(Math, _xx),
   720                     _miny = Math.min.apply(Math, _yy),
   656                     _miny = Math.min.apply(Math, _yy),
   721                     _maxx = Math.max.apply(Math, _xx),
   657                     _maxx = Math.max.apply(Math, _xx),
   722                     _maxy = Math.max.apply(Math, _yy);
   658                     _maxy = Math.max.apply(Math, _yy);
   723                 var _scale = Math.min(
   659                 var _scale = Math.min(
   724                         this.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width,
   660                         this.view.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width,
   725                         this.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height,
   661                         this.view.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height,
   726                         ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
   662                         ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx),
   727                         ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
   663                         ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny)
   728                 );
   664                 );
   729                 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
   665                 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
   730                 this.minimap.scale = _scale;
   666                 this.minimap.scale = _scale;
   734                 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale));
   670                 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]).multiply(this.minimap.scale));
   735             }
   671             }
   736             this.redraw();
   672             this.redraw();
   737         },
   673         },
   738         toPaperCoords: function(_point) {
   674         toPaperCoords: function(_point) {
   739             return _point.multiply(this.scale).add(this.offset);
   675             return _point.multiply(this.view.scale).add(this.view.offset);
   740         },
   676         },
   741         toMinimapCoords: function(_point) {
   677         toMinimapCoords: function(_point) {
   742             return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
   678             return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft);
   743         },
   679         },
   744         toModelCoords: function(_point) {
   680         toModelCoords: function(_point) {
   745             return _point.subtract(this.offset).divide(this.scale);
   681             return _point.subtract(this.view.offset).divide(this.view.scale);
   746         },
   682         },
   747         addRepresentation: function(_type, _model) {
   683         addRepresentation: function(_type, _model) {
   748             var RendererType = requtils.getRenderer()[_type];
   684             var RendererType = requtils.getRenderer()[_type];
   749             var _repr = new RendererType(this, _model);
   685             var _repr = new RendererType(this, _model);
   750             this.representations.push(_repr);
   686             this.representations.push(_repr);
   751             return _repr;
   687             return _repr;                
   752         },
   688         },
   753         addRepresentations: function(_type, _collection) {
   689         addRepresentations: function(_type, _collection) {
   754             var _this = this;
   690             var _this = this;
   755             _collection.forEach(function(_model) {
   691             _collection.forEach(function(_model) {
   756                 _this.addRepresentation(_type, _model);
   692                 _this.addRepresentation(_type, _model);
   862                 return;
   798                 return;
   863             }
   799             }
   864             _.each(this.representations, function(_representation) {
   800             _.each(this.representations, function(_representation) {
   865                 _representation.redraw({ dontRedrawEdges:true });
   801                 _representation.redraw({ dontRedrawEdges:true });
   866             });
   802             });
   867             if (this.minimap) {
   803             if (this.minimap && typeof this.view !== 'undefined') {
   868                 this.redrawMiniframe();
   804                 this.redrawMiniframe();
   869             }
   805             }
   870             paper.view.draw();
   806             paper.view.draw();
   871         },
   807         },
   872         addTempEdge: function(_from, _point) {
   808         addTempEdge: function(_from, _point) {
   874             _tmpEdge.end_pos = _point;
   810             _tmpEdge.end_pos = _point;
   875             _tmpEdge.from_representation = _from;
   811             _tmpEdge.from_representation = _from;
   876             _tmpEdge.redraw();
   812             _tmpEdge.redraw();
   877             this.click_target = _tmpEdge;
   813             this.click_target = _tmpEdge;
   878         },
   814         },
   879         addHiddenNode: function(_model){
       
   880             this.hideNode(_model);
       
   881             this.hiddenNodes.push(_model.id);
       
   882         },
       
   883         hideNode: function(_model){
       
   884             var _this = this;
       
   885             if (typeof _this.getRepresentationByModel(_model) !== 'undefined'){
       
   886                 _this.getRepresentationByModel(_model).hide();
       
   887             }
       
   888         },
       
   889         hideNodes: function(){
       
   890             var _this = this;
       
   891             this.hiddenNodes.forEach(function(_id, index){
       
   892                 var node = _this.renkan.project.get("nodes").get(_id);
       
   893                 if (typeof node !== 'undefined'){
       
   894                     return _this.hideNode(_this.renkan.project.get("nodes").get(_id));
       
   895                 }else{
       
   896                     _this.hiddenNodes.splice(index, 1);
       
   897                 }
       
   898             });
       
   899             paper.view.draw();
       
   900         },
       
   901         showNodes: function(ghost){
       
   902             var _this = this;
       
   903             var i = 0;
       
   904             this.hiddenNodes.forEach(function(_id){
       
   905                 i++;
       
   906                 _this.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost);
       
   907             });
       
   908             if (!ghost){
       
   909                 this.hiddenNodes = [];
       
   910             }
       
   911             paper.view.draw();
       
   912         },
       
   913         findTarget: function(_hitResult) {
   815         findTarget: function(_hitResult) {
   914             if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   816             if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   915                 var _newTarget = _hitResult.item.__representation;
   817                 var _newTarget = _hitResult.item.__representation;
   916                 if (this.selected_target !== _hitResult.item.__representation) {
   818                 if (this.selected_target !== _hitResult.item.__representation) {
   917                     if (this.selected_target) {
   819                     if (this.selected_target) {
   924                 if (this.selected_target) {
   826                 if (this.selected_target) {
   925                     this.selected_target.unselect();
   827                     this.selected_target.unselect();
   926                 }
   828                 }
   927                 this.selected_target = null;
   829                 this.selected_target = null;
   928             }
   830             }
   929         },
       
   930         paperShift: function(_delta) {
       
   931             this.offset = this.offset.add(_delta);
       
   932             this.redraw();
       
   933         },
   831         },
   934         onMouseMove: function(_event) {
   832         onMouseMove: function(_event) {
   935             var _off = this.canvas_$.offset(),
   833             var _off = this.canvas_$.offset(),
   936             _point = new paper.Point([
   834             _point = new paper.Point([
   937                                       _event.pageX - _off.left,
   835                                       _event.pageX - _off.left,
   945             var _hitResult = paper.project.hitTest(_point);
   843             var _hitResult = paper.project.hitTest(_point);
   946             if (this.is_dragging) {
   844             if (this.is_dragging) {
   947                 if (this.click_target && typeof this.click_target.paperShift === "function") {
   845                 if (this.click_target && typeof this.click_target.paperShift === "function") {
   948                     this.click_target.paperShift(_delta);
   846                     this.click_target.paperShift(_delta);
   949                 } else {
   847                 } else {
   950                     this.paperShift(_delta);
   848                     this.view.paperShift(_delta);
   951                 }
   849                 }
   952             } else {
   850             } else {
   953                 this.findTarget(_hitResult);
   851                 this.findTarget(_hitResult);
   954             }
   852             }
   955             paper.view.draw();
   853             paper.view.draw();
  1018                 this.click_target = null;
   916                 this.click_target = null;
  1019                 this.is_dragging = false;
   917                 this.is_dragging = false;
  1020                 if (_isTouch) {
   918                 if (_isTouch) {
  1021                     this.unselectAll();
   919                     this.unselectAll();
  1022                 }
   920                 }
       
   921                 this.view.updateUrl();
  1023             }
   922             }
  1024             paper.view.draw();
   923             paper.view.draw();
  1025         },
   924         },
  1026         onScroll: function(_event, _scrolldelta) {
   925         onScroll: function(_event, _scrolldelta) {
  1027             this.totalScroll += _scrolldelta;
   926             this.totalScroll += _scrolldelta;
  1028             if (Math.abs(this.totalScroll) >= 1) {
   927             if (Math.abs(this.totalScroll) >= 1) {
  1029                 var _off = this.canvas_$.offset(),
   928                 var _off = this.canvas_$.offset(),
  1030                 _delta = new paper.Point([
   929                 _delta = new paper.Point([
  1031                                           _event.pageX - _off.left,
   930                                           _event.pageX - _off.left,
  1032                                           _event.pageY - _off.top
   931                                           _event.pageY - _off.top
  1033                                           ]).subtract(this.offset).multiply( Math.SQRT2 - 1 );
   932                                           ]).subtract(this.view.offset).multiply( Math.SQRT2 - 1 );
  1034                 if (this.totalScroll > 0) {
   933                 if (this.totalScroll > 0) {
  1035                     this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) );
   934                     this.view.setScale( this.view.scale * Math.SQRT2, this.view.offset.subtract(_delta) );
  1036                 } else {
   935                 } else {
  1037                     this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2)));
   936                     this.view.setScale( this.view.scale * Math.SQRT1_2, this.view.offset.add(_delta.divide(Math.SQRT2)));
  1038                 }
   937                 }
  1039                 this.totalScroll = 0;
   938                 this.totalScroll = 0;
  1040             }
   939             }
  1041         },
   940         },
  1042         onDoubleClick: function(_event) {
   941         onDoubleClick: function(_event) {
  1232                     }
  1131                     }
  1233                 }
  1132                 }
  1234                 this.redraw();
  1133                 this.redraw();
  1235             }
  1134             }
  1236         },
  1135         },
  1237         zoomOut: function() {
       
  1238             var _newScale = this.scale * Math.SQRT1_2,
       
  1239             _offset = new paper.Point([
       
  1240                                        this.canvas_$.width(),
       
  1241                                        this.canvas_$.height()
       
  1242                                        ]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 ));
       
  1243             this.setScale( _newScale, _offset );
       
  1244         },
       
  1245         zoomIn: function() {
       
  1246             var _newScale = this.scale * Math.SQRT2,
       
  1247             _offset = new paper.Point([
       
  1248                                        this.canvas_$.width(),
       
  1249                                        this.canvas_$.height()
       
  1250                                        ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 ));
       
  1251             this.setScale( _newScale, _offset );
       
  1252         },
       
  1253         resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) {
       
  1254             var _newScale = this.scale * _ratio,
       
  1255                 _offset = new paper.Point([
       
  1256                                        (this.offset.x * _scaleWidth),
       
  1257                                        (this.offset.y * _scaleHeight)
       
  1258                                        ]);
       
  1259             this.setScale( _newScale, _offset );
       
  1260         },
       
  1261         addNodeBtn: function() {
  1136         addNodeBtn: function() {
  1262             if (this.click_mode === Utils._CLICKMODE_ADDNODE) {
  1137             if (this.click_mode === Utils._CLICKMODE_ADDNODE) {
  1263                 this.click_mode = false;
  1138                 this.click_mode = false;
  1264                 this.notif_$.hide();
  1139                 this.notif_$.hide();
  1265             } else {
  1140             } else {
  1323           var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"});
  1198           var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"});
  1324           filesaver(blob,fileNameToSaveAs);
  1199           filesaver(blob,fileNameToSaveAs);
  1325 
  1200 
  1326         },
  1201         },
  1327         parameters: function(_params){
  1202         parameters: function(_params){
  1328             if (typeof _params.idnode !== 'undefined'){
  1203             if ($.isEmptyObject(_params)){
       
  1204                 this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
       
  1205                 return;
       
  1206             }
       
  1207             if (typeof _params.view !== 'undefined'){
       
  1208                 var viewParams = _params.view.split(",");
       
  1209                 if (viewParams.length >= 3){
       
  1210                     var params = {
       
  1211                             "project": this.renkan.project,
       
  1212                             "offset": {
       
  1213                                 "x": parseFloat(viewParams[0]),
       
  1214                                 "y": parseFloat(viewParams[1])
       
  1215                             },
       
  1216                             "zoom_level": parseFloat(viewParams[2])
       
  1217                     };
       
  1218                     for (var i = 3; i < viewParams.length; i++){
       
  1219                         params.hidden_nodes.push(viewParams[i]);
       
  1220                     }
       
  1221                     //var view = new Rkns.Models.View(params);
       
  1222                     
       
  1223                     if (this.view){
       
  1224                         this.view.showNodes(false);
       
  1225                         this.removeRepresentation(this.view);
       
  1226                     }
       
  1227                     
       
  1228                     this.view = this.addRepresentation("View", null);
       
  1229                     this.view.params = params;
       
  1230                     this.view.init();
       
  1231                 } else {
       
  1232                     this.view = this.addRepresentation("View", this.renkan.project.get("views").last());
       
  1233                 }
       
  1234             }
       
  1235             //other parameters must go after because most of them depends on a view that must be initialize before
       
  1236             if (typeof _params.idNode !== 'undefined'){
  1329                 this.unhighlightAll();
  1237                 this.unhighlightAll();
  1330                 this.highlightModel(this.renkan.project.get("nodes").get(_params.idnode));                 
  1238                 this.highlightModel(this.renkan.project.get("nodes").get(_params.iNnode));                 
  1331             }
  1239             }
  1332         },
  1240         },
  1333         foldBins: function() {
  1241         foldBins: function() {
  1334             var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
  1242             var foldBinsButton = this.$.find(".Rk-Fold-Bins"),
  1335                 bins = this.renkan.$.find(".Rk-Bins");
  1243                 bins = this.renkan.$.find(".Rk-Bins");
  1355                     paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
  1263                     paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]);
  1356                 });
  1264                 });
  1357                 sizeAft = sizeBef+300;
  1265                 sizeAft = sizeBef+300;
  1358                 foldBinsButton.html("&raquo;");
  1266                 foldBinsButton.html("&raquo;");
  1359             }
  1267             }
  1360             _this.resizeZoom(1, 1, (sizeAft/sizeBef));
  1268             _this.view.resizeZoom(1, 1, (sizeAft/sizeBef));
  1361         },
  1269         },
  1362         save: function() { },
  1270         save: function() { },
  1363         open: function() { }
  1271         open: function() { }
  1364     }).value();
  1272     }).value();
  1365 
  1273