289 }; |
289 }; |
290 |
290 |
291 var _thRedraw = _.throttle(function() { |
291 var _thRedraw = _.throttle(function() { |
292 _this.redraw(); |
292 _this.redraw(); |
293 },50); |
293 },50); |
294 |
294 |
295 this.addRepresentations("Node", this.renkan.project.get("nodes")); |
295 this.addRepresentations("Node", this.renkan.project.get("nodes")); |
296 this.addRepresentations("Edge", this.renkan.project.get("edges")); |
296 this.addRepresentations("Edge", this.renkan.project.get("edges")); |
297 this.renkan.project.on("change:title", function() { |
297 this.renkan.project.on("change:title", function() { |
298 _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
298 _this.$.find(".Rk-PadTitle").val(_renkan.project.get("title")); |
299 }); |
299 }); |
375 } |
375 } |
376 } else { |
376 } else { |
377 el.text(_title); |
377 el.text(_title); |
378 } |
378 } |
379 }); |
379 }); |
380 |
380 |
381 //register router events |
381 //register router events |
382 this.renkan.router.on("router", function(_params){ |
382 this.renkan.router.on("router", function(_params){ |
383 _this.parameters(_params); |
383 _this.setViewparameters(_params); |
384 }); |
384 }); |
385 |
385 |
386 if (_renkan.options.size_bug_fix) { |
386 if (_renkan.options.size_bug_fix) { |
387 var _delay = ( |
387 var _delay = ( |
388 typeof _renkan.options.size_bug_fix === "number" ? |
388 typeof _renkan.options.size_bug_fix === "number" ? |
685 }, |
685 }, |
686 addRepresentation: function(_type, _model) { |
686 addRepresentation: function(_type, _model) { |
687 var RendererType = requtils.getRenderer()[_type]; |
687 var RendererType = requtils.getRenderer()[_type]; |
688 var _repr = new RendererType(this, _model); |
688 var _repr = new RendererType(this, _model); |
689 this.representations.push(_repr); |
689 this.representations.push(_repr); |
690 return _repr; |
690 return _repr; |
691 }, |
691 }, |
692 addRepresentations: function(_type, _collection) { |
692 addRepresentations: function(_type, _collection) { |
693 var _this = this; |
693 var _this = this; |
694 _collection.forEach(function(_model) { |
694 _collection.forEach(function(_model) { |
695 _this.addRepresentation(_type, _model); |
695 _this.addRepresentation(_type, _model); |
1200 var projectJSONStr = JSON.stringify(projectJSON, null, 2); |
1200 var projectJSONStr = JSON.stringify(projectJSON, null, 2); |
1201 var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"}); |
1201 var blob = new Blob([projectJSONStr], {type: "application/json;charset=utf-8"}); |
1202 filesaver(blob,fileNameToSaveAs); |
1202 filesaver(blob,fileNameToSaveAs); |
1203 |
1203 |
1204 }, |
1204 }, |
1205 parameters: function(_params){ |
1205 setViewparameters: function(_params){ |
1206 this.removeRepresentationsOfType("View"); |
1206 this.removeRepresentationsOfType("View"); |
1207 if ($.isEmptyObject(_params)){ |
1207 if ($.isEmptyObject(_params)){ |
1208 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
1208 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
1209 if (!this.renkan.options.default_view){ |
1209 if (!this.renkan.options.default_view){ |
1210 this.view.autoScale(); |
1210 this.view.autoScale(); |
1230 if (this.view){ |
1230 if (this.view){ |
1231 this.view.setScale(params.zoom_level, new paper.Point(params.offset)); |
1231 this.view.setScale(params.zoom_level, new paper.Point(params.offset)); |
1232 } else{ |
1232 } else{ |
1233 this.view = this.addRepresentation("View", null); |
1233 this.view = this.addRepresentation("View", null); |
1234 this.view.params = params; |
1234 this.view.params = params; |
1235 this.view.init(); |
1235 this.view.init(); |
1236 } |
1236 } |
1237 } |
1237 } |
1238 if (!this.view){ |
1238 if (!this.view){ |
1239 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
1239 this.view = this.addRepresentation("View", this.renkan.project.get("views").at(this.validViewIndex(this.renkan.options.default_index_view))); |
1240 this.view.autoScale(); |
1240 this.view.autoScale(); |
1241 } |
1241 } |
1242 //other parameters must go after because most of them depends on a view that must be initialize before |
1242 //other parameters must go after because most of them depends on a view that must be initialize before |
1243 this.unhighlightAll(); |
1243 this.unhighlightAll(); |
1244 if (typeof _params.idNode !== 'undefined'){ |
1244 if (typeof _params.idNode !== 'undefined'){ |
1245 this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode)); |
1245 this.highlightModel(this.renkan.project.get("nodes").get(_params.idNode)); |
1246 } |
1246 } |
1247 }, |
1247 }, |
1248 validViewIndex: function(index){ |
1248 validViewIndex: function(index){ |
1249 //check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist |
1249 //check if the view index exist (negative index is from the end) and return the correct index or false if doesn't exist |
1250 var _index = parseInt(index); |
1250 var _index = parseInt(index); |
1251 var validIndex = 0; |
1251 var validIndex = 0; |
1252 if (_index < 0){ |
1252 if (_index < 0){ |
1253 validIndex = this.renkan.project.get("views").length + _index; |
1253 validIndex = this.renkan.project.get("views").length + _index; |
1254 } else { |
1254 } else { |
1255 validIndex = _index; |
1255 validIndex = _index; |
1256 } |
1256 } |
1257 if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){ |
1257 if (typeof this.renkan.project.get("views").at(_index) === 'undefined'){ |
1258 validIndex = 0; |
1258 validIndex = 0; |
1259 } |
1259 } |
1260 return validIndex; |
1260 return validIndex; |