client/js/paper-renderer.js
changeset 117 803f14e35431
parent 116 07f9fc847d5d
child 118 c0e03c7137e3
equal deleted inserted replaced
116:07f9fc847d5d 117:803f14e35431
  1686     this.scale = _newScale;
  1686     this.scale = _newScale;
  1687     this.redraw();
  1687     this.redraw();
  1688 }
  1688 }
  1689 
  1689 
  1690 Rkns.Renderer.Scene.prototype.autoScale = function() {
  1690 Rkns.Renderer.Scene.prototype.autoScale = function() {
  1691 	console.log("Autoscale")
       
  1692     var nodes = this.renkan.project.get("nodes")
  1691     var nodes = this.renkan.project.get("nodes")
  1693     if (nodes.length > 1) {
  1692     if (nodes.length > 1) {
  1694         var _xx = nodes.map(function(_node) { return _node.get("position").x }),
  1693         var _xx = nodes.map(function(_node) { return _node.get("position").x }),
  1695             _yy = nodes.map(function(_node) { return _node.get("position").y }),
  1694             _yy = nodes.map(function(_node) { return _node.get("position").y }),
  1696             _minx = Math.min.apply(Math, _xx),
  1695             _minx = Math.min.apply(Math, _xx),
  1697             _miny = Math.min.apply(Math, _yy),
  1696             _miny = Math.min.apply(Math, _yy),
  1698             _maxx = Math.max.apply(Math, _xx),
  1697             _maxx = Math.max.apply(Math, _xx),
  1699             _maxy = Math.max.apply(Math, _yy);
  1698             _maxy = Math.max.apply(Math, _yy);
  1700         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));
  1699         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));
  1701 		console.log(_minx, _miny, _maxx, _maxy, _scale);
  1700 		this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
  1702         this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
       
  1703         this.setScale(_scale);
  1701         this.setScale(_scale);
  1704     }
  1702     }
  1705     if (nodes.length === 1) {
  1703     if (nodes.length === 1) {
  1706         this.offset = paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]));
  1704         this.offset = paper.view.center.subtract(new paper.Point([nodes.at(0).get("position").x, nodes.at(0).get("position").y]));
  1707         this.setScale(1);
  1705         this.setScale(1);