client/js/renderer/scene.js
changeset 450 88e8673aaeeb
parent 447 e246651b6626
child 451 278f8da09c04
equal deleted inserted replaced
449:aae670254c49 450:88e8673aaeeb
    23         paper.setup(this.canvas_$[0]);
    23         paper.setup(this.canvas_$[0]);
    24         this.scale = 1;
    24         this.scale = 1;
    25         this.initialScale = 1;
    25         this.initialScale = 1;
    26         this.offset = paper.view.center;
    26         this.offset = paper.view.center;
    27         this.totalScroll = 0;
    27         this.totalScroll = 0;
       
    28         this.hiddenNodes = [];
    28         this.mouse_down = false;
    29         this.mouse_down = false;
    29         this.click_target = null;
    30         this.click_target = null;
    30         this.selected_target = null;
    31         this.selected_target = null;
    31         this.edge_layer = new paper.Layer();
    32         this.edge_layer = new paper.Layer();
    32         this.node_layer = new paper.Layer();
    33         this.node_layer = new paper.Layer();
    80         _lastTapY = 0;
    81         _lastTapY = 0;
    81 
    82 
    82         this.image_cache = {};
    83         this.image_cache = {};
    83         this.icon_cache = {};
    84         this.icon_cache = {};
    84 
    85 
    85         ['edit', 'remove', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
    86         ['edit', 'remove', 'hide', 'link', 'enlarge', 'shrink', 'revert' ].forEach(function(imgname) {
    86             var img = new Image();
    87             var img = new Image();
    87             img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
    88             img.src = _renkan.options.static_url + 'img/' + imgname + '.png';
    88             _this.icon_cache[imgname] = img;
    89             _this.icon_cache[imgname] = img;
    89         });
    90         });
    90 
    91 
   236         bindClick(".Rk-ZoomOut", "zoomOut");
   237         bindClick(".Rk-ZoomOut", "zoomOut");
   237         bindClick(".Rk-ZoomIn", "zoomIn");
   238         bindClick(".Rk-ZoomIn", "zoomIn");
   238         bindClick(".Rk-ZoomFit", "autoScale");
   239         bindClick(".Rk-ZoomFit", "autoScale");
   239         this.$.find(".Rk-ZoomSave").click( function() {
   240         this.$.find(".Rk-ZoomSave").click( function() {
   240             // Save scale and offset point
   241             // Save scale and offset point
   241             _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset } );
   242             _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.hiddenNodes } );
   242         });
   243         });
   243         this.$.find(".Rk-ZoomSetSaved").click( function() {
   244         this.$.find(".Rk-ZoomSetSaved").click( function() {
   244             var view = _this.renkan.project.get("views").last();
   245             var view = _this.renkan.project.get("views").last();
   245             if(view){
   246             if(view){
   246                 _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
   247                 _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset")));
   247             }
   248                 _this.hiddenNodes = view.get("hidden_nodes");
       
   249                 _this.hideNodes();
       
   250             }
       
   251         });
       
   252         this.$.find(".Rk-ShowHiddenNodes").mouseenter( function() {
       
   253             _this.showNodes(true);
       
   254             _this.$.find(".Rk-ShowHiddenNodes").mouseleave( function() {
       
   255                 _this.hideNodes(false);
       
   256             });
       
   257         });
       
   258         this.$.find(".Rk-ShowHiddenNodes").click( function() {
       
   259             _this.showNodes(false);
       
   260             _this.$.find(".Rk-ShowHiddenNodes").off( "mouseleave" ); 
   248         });
   261         });
   249         if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
   262         if(this.renkan.project.get("views").length > 0 && this.renkan.options.save_view){
   250             this.$.find(".Rk-ZoomSetSaved").show();
   263             this.$.find(".Rk-ZoomSetSaved").show();
   251         }
   264         }
   252         this.$.find(".Rk-CurrentUser").mouseenter(
   265         this.$.find(".Rk-CurrentUser").mouseenter(
   727             return _repr;
   740             return _repr;
   728         },
   741         },
   729         addRepresentations: function(_type, _collection) {
   742         addRepresentations: function(_type, _collection) {
   730             var _this = this;
   743             var _this = this;
   731             _collection.forEach(function(_model) {
   744             _collection.forEach(function(_model) {
   732                 _this.addRepresentation(_type, _model);
   745                 //_this.addRepresentation(_type, _model);
   733             });
   746             });
   734         },
   747         },
   735         userTemplate: _.template(
   748         userTemplate: _.template(
   736                 '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>'
   749                 '<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>'
   737         ),
   750         ),
   831             _.each(this.representations, function(_repr) {
   844             _.each(this.representations, function(_repr) {
   832                 _repr.unselect();
   845                 _repr.unselect();
   833             });
   846             });
   834         },
   847         },
   835         redraw: function() {
   848         redraw: function() {
       
   849             var _this = this;
   836             if(! this.redrawActive ) {
   850             if(! this.redrawActive ) {
   837                 return;
   851                 return;
   838             }
   852             }
   839             _.each(this.representations, function(_representation) {
   853             _.each(this.representations, function(_representation) {
   840                 _representation.redraw({ dontRedrawEdges:true });
   854                 _representation.redraw({ dontRedrawEdges:true });
   848             var _tmpEdge = this.addRepresentation("TempEdge",null);
   862             var _tmpEdge = this.addRepresentation("TempEdge",null);
   849             _tmpEdge.end_pos = _point;
   863             _tmpEdge.end_pos = _point;
   850             _tmpEdge.from_representation = _from;
   864             _tmpEdge.from_representation = _from;
   851             _tmpEdge.redraw();
   865             _tmpEdge.redraw();
   852             this.click_target = _tmpEdge;
   866             this.click_target = _tmpEdge;
       
   867         },
       
   868         addHiddenNode: function(_model){
       
   869             this.hideNode(_model);
       
   870             this.hiddenNodes.push(_model.id);
       
   871         },
       
   872         hideNode: function(_model){
       
   873             var _this = this;
       
   874             if (typeof _this.getRepresentationByModel(_model) !== 'undefined'){
       
   875                 _this.getRepresentationByModel(_model).hide();
       
   876             }
       
   877         },
       
   878         hideNodes: function(){
       
   879             var _this = this;
       
   880             this.hiddenNodes.forEach(function(_id, index){
       
   881                 var node = _this.renkan.project.get("nodes").get(_id);
       
   882                 if (typeof node !== 'undefined'){
       
   883                     return _this.hideNode(_this.renkan.project.get("nodes").get(_id));
       
   884                 }else{
       
   885                     _this.hiddenNodes.splice(index, 1);
       
   886                 }
       
   887             });
       
   888             paper.view.draw();
       
   889         },
       
   890         showNodes: function(ghost){
       
   891             var _this = this;
       
   892             this.hiddenNodes.forEach(function(_id){
       
   893                 _this.getRepresentationByModel(_this.renkan.project.get("nodes").get(_id)).show(ghost);
       
   894             });
       
   895             if (!ghost){
       
   896                 this.hiddenNodes = [];
       
   897             }
       
   898             paper.view.draw();
   853         },
   899         },
   854         findTarget: function(_hitResult) {
   900         findTarget: function(_hitResult) {
   855             if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   901             if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   856                 var _newTarget = _hitResult.item.__representation;
   902                 var _newTarget = _hitResult.item.__representation;
   857                 if (this.selected_target !== _hitResult.item.__representation) {
   903                 if (this.selected_target !== _hitResult.item.__representation) {