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.mouse_down = false; |
25 this.mouse_down = false; |
29 this.click_target = null; |
26 this.click_target = null; |
30 this.selected_target = null; |
27 this.selected_target = null; |
31 this.edge_layer = new paper.Layer(); |
28 this.edge_layer = new paper.Layer(); |
125 _this.onDoubleClick(_touches); |
122 _this.onDoubleClick(_touches); |
126 } else { |
123 } else { |
127 _lastTap = new Date(); |
124 _lastTap = new Date(); |
128 _lastTapX = _touches.pageX; |
125 _lastTapX = _touches.pageX; |
129 _lastTapY = _touches.pageY; |
126 _lastTapY = _touches.pageY; |
130 _originalScale = _this.scale; |
127 _originalScale = _this.view.scale; |
131 _zooming = false; |
128 _zooming = false; |
132 _this.onMouseDown(_touches, true); |
129 _this.onMouseDown(_touches, true); |
133 } |
130 } |
134 }, |
131 }, |
135 touchmove: function(_event) { |
132 touchmove: function(_event) { |
146 } |
143 } |
147 if (_event.originalEvent.scale === "undefined") { |
144 if (_event.originalEvent.scale === "undefined") { |
148 return; |
145 return; |
149 } |
146 } |
150 var _newScale = _event.originalEvent.scale * _originalScale, |
147 var _newScale = _event.originalEvent.scale * _originalScale, |
151 _scaleRatio = _newScale / _this.scale, |
148 _scaleRatio = _newScale / _this.view.scale, |
152 _newOffset = new paper.Point([ |
149 _newOffset = new paper.Point([ |
153 _this.canvas_$.width(), |
150 _this.canvas_$.width(), |
154 _this.canvas_$.height() |
151 _this.canvas_$.height() |
155 ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.offset.multiply( _scaleRatio )); |
152 ]).multiply( 0.5 * ( 1 - _scaleRatio ) ).add(_this.view.offset.multiply( _scaleRatio )); |
156 _this.setScale(_newScale, _newOffset); |
153 _this.view.setScale(_newScale, _newOffset); |
157 } |
154 } |
158 }, |
155 }, |
159 touchend: function(_event) { |
156 touchend: function(_event) { |
160 _event.preventDefault(); |
157 _event.preventDefault(); |
161 _this.onMouseUp(_event.originalEvent.changedTouches[0], true); |
158 _this.onMouseUp(_event.originalEvent.changedTouches[0], true); |
231 _this[fname](evt); |
228 _this[fname](evt); |
232 return false; |
229 return false; |
233 }); |
230 }); |
234 }; |
231 }; |
235 |
232 |
236 bindClick(".Rk-ZoomOut", "zoomOut"); |
|
237 bindClick(".Rk-ZoomIn", "zoomIn"); |
|
238 bindClick(".Rk-ZoomFit", "autoScale"); |
|
239 this.$.find(".Rk-ZoomSave").click( function() { |
|
240 // Save scale and offset point |
|
241 _this.renkan.project.addView( { zoom_level:_this.scale, offset:_this.offset, hidden_nodes: _this.view.hiddenNodes } ); |
|
242 }); |
|
243 this.$.find(".Rk-ZoomSetSaved").click( function() { |
|
244 var view = _this.renkan.project.get("views").last(); |
|
245 if(view){ |
|
246 _this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); |
|
247 } |
|
248 }); |
|
249 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){ |
250 this.$.find(".Rk-ZoomSetSaved").show(); |
234 this.$.find(".Rk-ZoomSetSaved").show(); |
251 } |
235 } |
252 this.$.find(".Rk-CurrentUser").mouseenter( |
236 this.$.find(".Rk-CurrentUser").mouseenter( |
253 function() { _this.$.find(".Rk-UserList").slideDown(); } |
237 function() { _this.$.find(".Rk-UserList").slideDown(); } |
351 var timer = setTimeout(function(){ |
335 var timer = setTimeout(function(){ |
352 _this.$.find(".loader").hide(250); |
336 _this.$.find(".loader").hide(250); |
353 }, 3000); |
337 }, 3000); |
354 } |
338 } |
355 else{ |
339 else{ |
|
340 _this.view = _this.addRepresentation("View", _this.renkan.project.get("views").last()); |
356 Backbone.history.start(); |
341 Backbone.history.start(); |
|
342 _thRedraw(); |
357 } |
343 } |
358 }); |
344 }); |
359 |
345 |
360 this.renkan.project.on("add:users remove:users", _thRedrawUsers); |
346 this.renkan.project.on("add:users remove:users", _thRedrawUsers); |
361 |
347 |
378 _this.addRepresentation("Edge", _edge); |
364 _this.addRepresentation("Edge", _edge); |
379 if (!_this.renkan.project.get("loadingStatus")){ |
365 if (!_this.renkan.project.get("loadingStatus")){ |
380 _thRedraw(); |
366 _thRedraw(); |
381 } |
367 } |
382 }); |
368 }); |
383 this.renkan.project.on("add:views", function(_view) { |
369 // this.renkan.project.on("add:views", function(_view) { |
384 if (!_this.view){ |
370 // if (!_this.view){ |
385 _this.view = _this.addRepresentation("View", _view); |
371 // _this.view = _this.addRepresentation("View", _view); |
386 } |
372 // } |
387 if (!_this.renkan.project.get("loadingStatus")){ |
373 // if (!_this.renkan.project.get("loadingStatus")){ |
388 _thRedraw(); |
374 // _thRedraw(); |
389 } |
375 // } |
390 }); |
376 // }); |
391 this.renkan.project.on("change:title", function(_model, _title) { |
377 this.renkan.project.on("change:title", function(_model, _title) { |
392 var el = _this.$.find(".Rk-PadTitle"); |
378 var el = _this.$.find(".Rk-PadTitle"); |
393 if (el.is("input")) { |
379 if (el.is("input")) { |
394 if (el.val() !== _title) { |
380 if (el.val() !== _title) { |
395 el.val(_title); |
381 el.val(_title); |
508 |
494 |
509 }; |
495 }; |
510 |
496 |
511 _(Scene.prototype).extend({ |
497 _(Scene.prototype).extend({ |
512 fixSize: function() { |
498 fixSize: function() { |
513 if( this.renkan.options.default_view && this.renkan.project.get("views").length > 0) { |
499 if( this.renkan.options.default_view && this.view) { |
514 var view = this.renkan.project.get("views").last(); |
500 this.view.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); |
515 this.setScale(view.get("zoom_level"), new paper.Point(view.get("offset"))); |
|
516 } |
501 } |
517 else{ |
502 else{ |
518 this.autoScale(); |
503 this.view.autoScale(); |
519 } |
504 } |
520 }, |
505 }, |
521 drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) { |
506 drawSector: function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgname, _caption) { |
522 var _options = this.renkan.options, |
507 var _options = this.renkan.options, |
523 _startRads = _startAngle * Math.PI / 180, |
508 _startRads = _startAngle * Math.PI / 180, |
664 tip.text(this.renkan.translate("Auto-save enabled")); |
649 tip.text(this.renkan.translate("Auto-save enabled")); |
665 } |
650 } |
666 } |
651 } |
667 this.redrawUsers(); |
652 this.redrawUsers(); |
668 }, |
653 }, |
669 setScale: function(_newScale, _offset) { |
|
670 if ((_newScale/this.initialScale) > Utils._MIN_SCALE && (_newScale/this.initialScale) < Utils._MAX_SCALE) { |
|
671 this.scale = _newScale; |
|
672 if (_offset) { |
|
673 this.offset = _offset; |
|
674 } |
|
675 this.redraw(); |
|
676 } |
|
677 }, |
|
678 autoScale: function(force_view) { |
|
679 var nodes = this.renkan.project.get("nodes"); |
|
680 if (nodes.length > 1) { |
|
681 var _xx = nodes.map(function(_node) { return _node.get("position").x; }), |
|
682 _yy = nodes.map(function(_node) { return _node.get("position").y; }), |
|
683 _minx = Math.min.apply(Math, _xx), |
|
684 _miny = Math.min.apply(Math, _yy), |
|
685 _maxx = Math.max.apply(Math, _xx), |
|
686 _maxy = Math.max.apply(Math, _yy); |
|
687 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)); |
|
688 this.initialScale = _scale; |
|
689 // Override calculated scale if asked |
|
690 if((typeof force_view !== "undefined") && parseFloat(force_view.zoom_level)>0 && parseFloat(force_view.offset.x)>0 && parseFloat(force_view.offset.y)>0){ |
|
691 this.setScale(parseFloat(force_view.zoom_level), new paper.Point(parseFloat(force_view.offset.x), parseFloat(force_view.offset.y))); |
|
692 } |
|
693 else{ |
|
694 this.setScale(_scale, paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale))); |
|
695 } |
|
696 } |
|
697 if (nodes.length === 1) { |
|
698 this.setScale(1, paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]))); |
|
699 } |
|
700 }, |
|
701 redrawMiniframe: function() { |
654 redrawMiniframe: function() { |
702 var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
655 var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))), |
703 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
656 bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight)); |
704 this.minimap.miniframe.fitBounds(topleft, bottomright); |
657 this.minimap.miniframe.fitBounds(topleft, bottomright); |
705 }, |
658 }, |
711 _minx = Math.min.apply(Math, _xx), |
664 _minx = Math.min.apply(Math, _xx), |
712 _miny = Math.min.apply(Math, _yy), |
665 _miny = Math.min.apply(Math, _yy), |
713 _maxx = Math.max.apply(Math, _xx), |
666 _maxx = Math.max.apply(Math, _xx), |
714 _maxy = Math.max.apply(Math, _yy); |
667 _maxy = Math.max.apply(Math, _yy); |
715 var _scale = Math.min( |
668 var _scale = Math.min( |
716 this.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
669 this.view.scale * 0.8 * this.renkan.options.minimap_width / paper.view.bounds.width, |
717 this.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
670 this.view.scale * 0.8 * this.renkan.options.minimap_height / paper.view.bounds.height, |
718 ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
671 ( this.renkan.options.minimap_width - 2 * this.renkan.options.minimap_padding ) / (_maxx - _minx), |
719 ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
672 ( this.renkan.options.minimap_height - 2 * this.renkan.options.minimap_padding ) / (_maxy - _miny) |
720 ); |
673 ); |
721 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
674 this.minimap.offset = this.minimap.size.divide(2).subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
722 this.minimap.scale = _scale; |
675 this.minimap.scale = _scale; |
726 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)); |
679 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)); |
727 } |
680 } |
728 this.redraw(); |
681 this.redraw(); |
729 }, |
682 }, |
730 toPaperCoords: function(_point) { |
683 toPaperCoords: function(_point) { |
731 return _point.multiply(this.scale).add(this.offset); |
684 return _point.multiply(this.view.scale).add(this.view.offset); |
732 }, |
685 }, |
733 toMinimapCoords: function(_point) { |
686 toMinimapCoords: function(_point) { |
734 return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
687 return _point.multiply(this.minimap.scale).add(this.minimap.offset).add(this.minimap.topleft); |
735 }, |
688 }, |
736 toModelCoords: function(_point) { |
689 toModelCoords: function(_point) { |
737 return _point.subtract(this.offset).divide(this.scale); |
690 return _point.subtract(this.view.offset).divide(this.view.scale); |
738 }, |
691 }, |
739 addRepresentation: function(_type, _model) { |
692 addRepresentation: function(_type, _model) { |
740 var RendererType = requtils.getRenderer()[_type]; |
693 var RendererType = requtils.getRenderer()[_type]; |
741 var _repr = new RendererType(this, _model); |
694 var _repr = new RendererType(this, _model); |
742 this.representations.push(_repr); |
695 this.representations.push(_repr); |
854 return; |
807 return; |
855 } |
808 } |
856 _.each(this.representations, function(_representation) { |
809 _.each(this.representations, function(_representation) { |
857 _representation.redraw({ dontRedrawEdges:true }); |
810 _representation.redraw({ dontRedrawEdges:true }); |
858 }); |
811 }); |
859 if (this.minimap) { |
812 if (this.minimap && typeof this.view !== 'undefined') { |
860 this.redrawMiniframe(); |
813 this.redrawMiniframe(); |
861 } |
814 } |
862 paper.view.draw(); |
815 paper.view.draw(); |
863 }, |
816 }, |
864 addTempEdge: function(_from, _point) { |
817 addTempEdge: function(_from, _point) { |
884 } |
837 } |
885 this.selected_target = null; |
838 this.selected_target = null; |
886 } |
839 } |
887 }, |
840 }, |
888 paperShift: function(_delta) { |
841 paperShift: function(_delta) { |
889 this.offset = this.offset.add(_delta); |
842 this.view.offset = this.view.offset.add(_delta); |
890 this.redraw(); |
843 this.redraw(); |
891 }, |
844 }, |
892 onMouseMove: function(_event) { |
845 onMouseMove: function(_event) { |
893 var _off = this.canvas_$.offset(), |
846 var _off = this.canvas_$.offset(), |
894 _point = new paper.Point([ |
847 _point = new paper.Point([ |
986 if (Math.abs(this.totalScroll) >= 1) { |
939 if (Math.abs(this.totalScroll) >= 1) { |
987 var _off = this.canvas_$.offset(), |
940 var _off = this.canvas_$.offset(), |
988 _delta = new paper.Point([ |
941 _delta = new paper.Point([ |
989 _event.pageX - _off.left, |
942 _event.pageX - _off.left, |
990 _event.pageY - _off.top |
943 _event.pageY - _off.top |
991 ]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
944 ]).subtract(this.view.offset).multiply( Math.SQRT2 - 1 ); |
992 if (this.totalScroll > 0) { |
945 if (this.totalScroll > 0) { |
993 this.setScale( this.scale * Math.SQRT2, this.offset.subtract(_delta) ); |
946 this.view.setScale( this.view.scale * Math.SQRT2, this.view.offset.subtract(_delta) ); |
994 } else { |
947 } else { |
995 this.setScale( this.scale * Math.SQRT1_2, this.offset.add(_delta.divide(Math.SQRT2))); |
948 this.view.setScale( this.view.scale * Math.SQRT1_2, this.view.offset.add(_delta.divide(Math.SQRT2))); |
996 } |
949 } |
997 this.totalScroll = 0; |
950 this.totalScroll = 0; |
998 } |
951 } |
999 }, |
952 }, |
1000 onDoubleClick: function(_event) { |
953 onDoubleClick: function(_event) { |
1190 } |
1143 } |
1191 } |
1144 } |
1192 this.redraw(); |
1145 this.redraw(); |
1193 } |
1146 } |
1194 }, |
1147 }, |
1195 zoomOut: function() { |
|
1196 var _newScale = this.scale * Math.SQRT1_2, |
|
1197 _offset = new paper.Point([ |
|
1198 this.canvas_$.width(), |
|
1199 this.canvas_$.height() |
|
1200 ]).multiply( 0.5 * ( 1 - Math.SQRT1_2 ) ).add(this.offset.multiply( Math.SQRT1_2 )); |
|
1201 this.setScale( _newScale, _offset ); |
|
1202 }, |
|
1203 zoomIn: function() { |
|
1204 var _newScale = this.scale * Math.SQRT2, |
|
1205 _offset = new paper.Point([ |
|
1206 this.canvas_$.width(), |
|
1207 this.canvas_$.height() |
|
1208 ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
|
1209 this.setScale( _newScale, _offset ); |
|
1210 }, |
|
1211 resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) { |
|
1212 var _newScale = this.scale * _ratio, |
|
1213 _offset = new paper.Point([ |
|
1214 (this.offset.x * _scaleWidth), |
|
1215 (this.offset.y * _scaleHeight) |
|
1216 ]); |
|
1217 this.setScale( _newScale, _offset ); |
|
1218 }, |
|
1219 addNodeBtn: function() { |
1148 addNodeBtn: function() { |
1220 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1149 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1221 this.click_mode = false; |
1150 this.click_mode = false; |
1222 this.notif_$.hide(); |
1151 this.notif_$.hide(); |
1223 } else { |
1152 } else { |
1313 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1242 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1314 }); |
1243 }); |
1315 sizeAft = sizeBef+300; |
1244 sizeAft = sizeBef+300; |
1316 foldBinsButton.html("»"); |
1245 foldBinsButton.html("»"); |
1317 } |
1246 } |
1318 _this.resizeZoom(1, 1, (sizeAft/sizeBef)); |
1247 _this.view.resizeZoom(1, 1, (sizeAft/sizeBef)); |
1319 }, |
1248 }, |
1320 save: function() { }, |
1249 save: function() { }, |
1321 open: function() { } |
1250 open: function() { } |
1322 }).value(); |
1251 }).value(); |
1323 |
1252 |