27 this.edge_layer = new paper.Layer(); |
27 this.edge_layer = new paper.Layer(); |
28 this.node_layer = new paper.Layer(); |
28 this.node_layer = new paper.Layer(); |
29 this.buttons_layer = new paper.Layer(); |
29 this.buttons_layer = new paper.Layer(); |
30 this.delete_list = []; |
30 this.delete_list = []; |
31 this.redrawActive = true; |
31 this.redrawActive = true; |
|
32 |
|
33 var currentWidth = this.canvas_$.width(); |
|
34 var currentHeight = this.canvas_$.height(); |
32 |
35 |
33 if (_renkan.options.show_minimap) { |
36 if (_renkan.options.show_minimap) { |
34 this.minimap = { |
37 this.minimap = { |
35 background_layer: new paper.Layer(), |
38 background_layer: new paper.Layer(), |
36 edge_layer: new paper.Layer(), |
39 edge_layer: new paper.Layer(), |
274 $(this).find(".Rk-TopBar-Tooltip").hide(); |
277 $(this).find(".Rk-TopBar-Tooltip").hide(); |
275 }); |
278 }); |
276 bindClick(".Rk-Fold-Bins", "foldBins"); |
279 bindClick(".Rk-Fold-Bins", "foldBins"); |
277 |
280 |
278 paper.view.onResize = function(_event) { |
281 paper.view.onResize = function(_event) { |
279 // Because of paper bug which does not calculate the good height (and width a fortiori) |
282 var _ratio, |
280 // We have to update manually the canvas's height |
283 newWidth= _this.canvas_$.parent().width(), |
|
284 newHeight = _this.canvas_$.parent().height(); |
|
285 |
281 paper.view._viewSize.height = _event.size.height = _this.canvas_$.parent().height(); |
286 paper.view._viewSize.height = _event.size.height = _this.canvas_$.parent().height(); |
282 |
287 |
283 if (_this.minimap) { |
288 if (_this.minimap) { |
284 _this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size); |
289 _this.minimap.topleft = paper.view.bounds.bottomRight.subtract(_this.minimap.size); |
285 _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4])); |
290 _this.minimap.rectangle.fitBounds(_this.minimap.topleft.subtract([2,2]), _this.minimap.size.add([4,4])); |
286 _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size); |
291 _this.minimap.cliprectangle.fitBounds(_this.minimap.topleft, _this.minimap.size); |
287 } |
292 } |
288 _this.redraw(); |
293 |
|
294 if (newHeight < newWidth) { |
|
295 _ratio = (newHeight/currentHeight); |
|
296 } else { |
|
297 _ratio = (newWidth/currentWidth); |
|
298 } |
|
299 |
|
300 _this.resizeZoom((newWidth/currentWidth), (newHeight/currentHeight), _ratio); |
|
301 |
|
302 currentWidth = newWidth; |
|
303 currentHeight = newHeight; |
|
304 |
|
305 _this.redraw(); |
|
306 |
289 }; |
307 }; |
290 |
308 |
291 var _thRedraw = _.throttle(function() { |
309 var _thRedraw = _.throttle(function() { |
292 _this.redraw(); |
310 _this.redraw(); |
293 },50); |
311 },50); |
1171 if (typeof document[_cancelMethods[i]] === "function") { |
1189 if (typeof document[_cancelMethods[i]] === "function") { |
1172 document[_cancelMethods[i]](); |
1190 document[_cancelMethods[i]](); |
1173 break; |
1191 break; |
1174 } |
1192 } |
1175 } |
1193 } |
|
1194 var widthAft = this.$.width(); |
|
1195 var heightAft = this.$.height(); |
|
1196 |
|
1197 if (this.renkan.options.show_top_bar) { |
|
1198 heightAft -= this.$.find(".Rk-TopBar").height(); |
|
1199 } |
|
1200 if (this.renkan.options.show_bins && (this.renkan.$.find(".Rk-Bins").position().left > 0)) { |
|
1201 widthAft -= this.renkan.$.find(".Rk-Bins").width(); |
|
1202 } |
|
1203 |
|
1204 this.canvas_$.attr({ |
|
1205 width: widthAft, |
|
1206 height: heightAft |
|
1207 }); |
|
1208 |
|
1209 paper.view.viewSize = new paper.Size([this.canvas_$.width(), this.canvas_$.height()]); |
|
1210 |
1176 } else { |
1211 } else { |
1177 for (i = 0; i < _requestMethods.length; i++) { |
1212 for (i = 0; i < _requestMethods.length; i++) { |
1178 if (typeof _el[_requestMethods[i]] === "function") { |
1213 if (typeof _el[_requestMethods[i]] === "function") { |
1179 _el[_requestMethods[i]](); |
1214 _el[_requestMethods[i]](); |
1180 break; |
1215 break; |
1194 var _newScale = this.scale * Math.SQRT2, |
1229 var _newScale = this.scale * Math.SQRT2, |
1195 _offset = new paper.Point([ |
1230 _offset = new paper.Point([ |
1196 this.canvas_$.width(), |
1231 this.canvas_$.width(), |
1197 this.canvas_$.height() |
1232 this.canvas_$.height() |
1198 ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
1233 ]).multiply( 0.5 * ( 1 - Math.SQRT2 ) ).add(this.offset.multiply( Math.SQRT2 )); |
|
1234 this.setScale( _newScale, _offset ); |
|
1235 }, |
|
1236 resizeZoom: function(_scaleWidth, _scaleHeight, _ratio) { |
|
1237 var _newScale = this.scale * _ratio, |
|
1238 _offset = new paper.Point([ |
|
1239 (this.offset.x * _scaleWidth), |
|
1240 (this.offset.y * _scaleHeight) |
|
1241 ]); |
1199 this.setScale( _newScale, _offset ); |
1242 this.setScale( _newScale, _offset ); |
1200 }, |
1243 }, |
1201 addNodeBtn: function() { |
1244 addNodeBtn: function() { |
1202 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1245 if (this.click_mode === Utils._CLICKMODE_ADDNODE) { |
1203 this.click_mode = false; |
1246 this.click_mode = false; |
1257 |
1300 |
1258 }, |
1301 }, |
1259 foldBins: function() { |
1302 foldBins: function() { |
1260 var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
1303 var foldBinsButton = this.$.find(".Rk-Fold-Bins"), |
1261 bins = this.renkan.$.find(".Rk-Bins"); |
1304 bins = this.renkan.$.find(".Rk-Bins"); |
1262 var _this = this; |
1305 var _this = this, |
|
1306 sizeBef = _this.$.width(), |
|
1307 sizeAft; |
1263 if (bins.position().left < 0) { |
1308 if (bins.position().left < 0) { |
1264 bins.animate({left: 0},250); |
1309 bins.animate({left: 0},250); |
1265 this.$.animate({left: 300},250,function() { |
1310 this.$.animate({left: 300},250,function() { |
1266 var w = _this.$.width(); |
1311 var w = _this.$.width(); |
1267 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1312 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1268 }); |
1313 }); |
|
1314 if ((sizeBef - bins.width()) < bins.width()){ |
|
1315 sizeAft = sizeBef; |
|
1316 } else { |
|
1317 sizeAft = sizeBef - bins.width(); |
|
1318 } |
1269 foldBinsButton.html("«"); |
1319 foldBinsButton.html("«"); |
1270 } else { |
1320 } else { |
1271 bins.animate({left: -300},250); |
1321 bins.animate({left: -300},250); |
1272 this.$.animate({left: 0},250,function() { |
1322 this.$.animate({left: 0},250,function() { |
1273 var w = _this.$.width(); |
1323 var w = _this.$.width(); |
1274 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1324 paper.view.viewSize = new paper.Size([w, _this.canvas_$.height()]); |
1275 }); |
1325 }); |
|
1326 sizeAft = sizeBef+300; |
1276 foldBinsButton.html("»"); |
1327 foldBinsButton.html("»"); |
1277 } |
1328 } |
|
1329 _this.resizeZoom(1, 1, (sizeAft/sizeBef)); |
1278 }, |
1330 }, |
1279 save: function() { }, |
1331 save: function() { }, |
1280 open: function() { } |
1332 open: function() { } |
1281 }); |
1333 }); |
1282 |
1334 |