client/js/paper-renderer.js
changeset 116 07f9fc847d5d
parent 114 110f99eb417e
child 117 803f14e35431
equal deleted inserted replaced
115:e905eb562074 116:07f9fc847d5d
    22     _CLICKMODE_ADDNODE : 1,
    22     _CLICKMODE_ADDNODE : 1,
    23     _CLICKMODE_STARTEDGE : 2,
    23     _CLICKMODE_STARTEDGE : 2,
    24     _CLICKMODE_ENDEDGE : 3,
    24     _CLICKMODE_ENDEDGE : 3,
    25     _IMAGE_MAX_KB : 500,
    25     _IMAGE_MAX_KB : 500,
    26     _NODE_SIZE_STEP: Math.LN2/4,
    26     _NODE_SIZE_STEP: Math.LN2/4,
       
    27     _AUTOSCALE_MARGIN: 50,
    27     _MINIMAP_WIDTH: 160,
    28     _MINIMAP_WIDTH: 160,
    28     _MINIMAP_HEIGHT: 120,
    29     _MINIMAP_HEIGHT: 120,
    29     _USER_PLACEHOLDER : {
    30     _USER_PLACEHOLDER : {
    30         color: "#000000",
    31         color: "#000000",
    31         title: "(unknown user)",
    32         title: "(unknown user)",
  1684 Rkns.Renderer.Scene.prototype.setScale = function(_newScale) {
  1685 Rkns.Renderer.Scene.prototype.setScale = function(_newScale) {
  1685     this.scale = _newScale;
  1686     this.scale = _newScale;
  1686     this.redraw();
  1687     this.redraw();
  1687 }
  1688 }
  1688 
  1689 
       
  1690 Rkns.Renderer.Scene.prototype.autoScale = function() {
       
  1691 	console.log("Autoscale")
       
  1692     var nodes = this.renkan.project.get("nodes")
       
  1693     if (nodes.length > 1) {
       
  1694         var _xx = nodes.map(function(_node) { return _node.get("position").x }),
       
  1695             _yy = nodes.map(function(_node) { return _node.get("position").y }),
       
  1696             _minx = Math.min.apply(Math, _xx),
       
  1697             _miny = Math.min.apply(Math, _yy),
       
  1698             _maxx = Math.max.apply(Math, _xx),
       
  1699             _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));
       
  1701 		console.log(_minx, _miny, _maxx, _maxy, _scale);
       
  1702         this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale));
       
  1703         this.setScale(_scale);
       
  1704     }
       
  1705     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]));
       
  1707         this.setScale(1);
       
  1708     }
       
  1709 }
       
  1710 
  1689 Rkns.Renderer.Scene.prototype.redrawMiniframe = function() {
  1711 Rkns.Renderer.Scene.prototype.redrawMiniframe = function() {
  1690 	var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
  1712 	var topleft = this.toMinimapCoords(this.toModelCoords(new paper.Point([0,0]))),
  1691 		bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
  1713 		bottomright = this.toMinimapCoords(this.toModelCoords(paper.view.bounds.bottomRight));
  1692 	this.minimap.miniframe.fitBounds(topleft, bottomright);
  1714 	this.minimap.miniframe.fitBounds(topleft, bottomright);
  1693 }
  1715 }