--- a/client/js/paper-renderer.js Tue Mar 26 19:22:27 2013 +0100
+++ b/client/js/paper-renderer.js Wed Mar 27 18:11:18 2013 +0100
@@ -24,6 +24,7 @@
_CLICKMODE_ENDEDGE : 3,
_IMAGE_MAX_KB : 500,
_NODE_SIZE_STEP: Math.LN2/4,
+ _AUTOSCALE_MARGIN: 50,
_MINIMAP_WIDTH: 160,
_MINIMAP_HEIGHT: 120,
_USER_PLACEHOLDER : {
@@ -1686,6 +1687,27 @@
this.redraw();
}
+Rkns.Renderer.Scene.prototype.autoScale = function() {
+ console.log("Autoscale")
+ var nodes = this.renkan.project.get("nodes")
+ if (nodes.length > 1) {
+ var _xx = nodes.map(function(_node) { return _node.get("position").x }),
+ _yy = nodes.map(function(_node) { return _node.get("position").y }),
+ _minx = Math.min.apply(Math, _xx),
+ _miny = Math.min.apply(Math, _yy),
+ _maxx = Math.max.apply(Math, _xx),
+ _maxy = Math.max.apply(Math, _yy);
+ var _scale = Math.min((paper.view.size.width - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._AUTOSCALE_MARGIN) / (_maxy - _miny));
+ console.log(_minx, _miny, _maxx, _maxy, _scale);
+ this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
+ this.setScale(_scale);
+ }
+ if (nodes.length === 1) {
+ this.offset = paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]));
+ this.setScale(1);
+ }
+}
+
Rkns.Renderer.Scene.prototype.redrawMiniframe = function() {
var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));