450 Rkns.Renderer.Edge.prototype._init = function() { |
450 Rkns.Renderer.Edge.prototype._init = function() { |
451 this.renderer.edge_layer.activate(); |
451 this.renderer.edge_layer.activate(); |
452 this.type = "Edge"; |
452 this.type = "Edge"; |
453 this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
453 this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
454 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
454 this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
455 this.bundle = this.renderer.addToBundles(this); |
455 this.line = new paper.Path(); |
456 this.line = new paper.Path(); |
456 this.line.add([0,0],[0,0]); |
457 this.line.add([0,0],[0,0],[0,0]); |
457 this.line.__representation = this; |
458 this.line.__representation = this; |
458 this.arrow = new paper.Path(); |
459 this.arrow = new paper.Path(); |
459 this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
460 this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
460 this.arrow.__representation = this; |
461 this.arrow.__representation = this; |
461 this.text = new paper.PointText(); |
462 this.text = new paper.PointText(); |
468 this.text_angle = 0; |
469 this.text_angle = 0; |
469 this.arrow_angle = 0; |
470 this.arrow_angle = 0; |
470 } |
471 } |
471 |
472 |
472 Rkns.Renderer.Edge.prototype.redraw = function() { |
473 Rkns.Renderer.Edge.prototype.redraw = function() { |
473 var _p0o = this.from_representation.paper_coords, |
474 var _p0a = this.from_representation.paper_coords, |
474 _p1o = this.to_representation.paper_coords, |
475 _p1a = this.to_representation.paper_coords, |
475 _v = _p1o.subtract(_p0o), |
476 _v = _p1a.subtract(_p0a), |
476 _r = _v.length, |
477 _r = _v.length, |
477 _u = _v.divide(_r), |
478 _u = _v.divide(_r), |
478 _delta = new paper.Point([- _u.y, _u.x]).multiply( 4 ), |
479 _group_pos = this.bundle.getPosition(this), |
479 _p0 = _p0o.add(_delta), /* Adding a 4 px difference */ |
480 _delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
480 _p1 = _p1o.add(_delta), /* to differentiate inbound and outbound links */ |
481 _p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
482 _p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
481 _a = _v.angle, |
483 _a = _v.angle, |
|
484 _handle = _v.divide(3), |
482 _color = this.model.get("created_by").get("color"); |
485 _color = this.model.get("created_by").get("color"); |
483 this.paper_coords = _p0.add(_p1).divide(2); |
486 this.paper_coords = _p0b.add(_p1b).divide(2); |
484 this.line.strokeColor = _color; |
487 this.line.strokeColor = _color; |
485 this.line.segments[0].point = _p0; |
488 this.line.segments[0].point = _p0a; |
486 this.line.segments[1].point = _p1; |
489 this.line.segments[1].point = this.paper_coords; |
|
490 this.line.segments[1].handleIn = _handle.multiply(-1); |
|
491 this.line.segments[1].handleOut = _handle; |
|
492 this.line.segments[2].point = _p1a; |
487 this.arrow.rotate(_a - this.arrow_angle); |
493 this.arrow.rotate(_a - this.arrow_angle); |
488 this.arrow.fillColor = _color; |
494 this.arrow.fillColor = _color; |
489 this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
495 this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
490 this.arrow_angle = _a; |
496 this.arrow_angle = _a; |
491 if (_a > 90) { |
497 if (_a > 90) { |
662 this.click_target = null; |
672 this.click_target = null; |
663 this.selected_target = null; |
673 this.selected_target = null; |
664 this.edge_layer = new paper.Layer(); |
674 this.edge_layer = new paper.Layer(); |
665 this.node_layer = new paper.Layer(); |
675 this.node_layer = new paper.Layer(); |
666 this.overlay_layer = new paper.Layer(); |
676 this.overlay_layer = new paper.Layer(); |
|
677 this.bundles = []; |
667 var _tool = new paper.Tool(), |
678 var _tool = new paper.Tool(), |
668 _this = this; |
679 _this = this; |
669 _tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
680 _tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
670 _tool.onMouseMove = function(_event) { |
681 _tool.onMouseMove = function(_event) { |
671 _this.onMouseMove(_event); |
682 _this.onMouseMove(_event); |
725 Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
736 Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
726 '<canvas class="Rk-Canvas" width="<%=width%>" height="<%=height%>"></canvas><div class="Rk-Editor">' |
737 '<canvas class="Rk-Canvas" width="<%=width%>" height="<%=height%>"></canvas><div class="Rk-Editor">' |
727 + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
738 + '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
728 + '</div>' |
739 + '</div>' |
729 ); |
740 ); |
|
741 |
|
742 Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
|
743 var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
744 return ( |
|
745 ( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
746 || ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
747 ); |
|
748 }); |
|
749 if (typeof _bundle !== "undefined") { |
|
750 _bundle.edges.push(_edgeRepr) |
|
751 } else { |
|
752 _bundle = { |
|
753 from: _edgeRepr.from_representation, |
|
754 to: _edgeRepr.to_representation, |
|
755 edges: [ _edgeRepr ], |
|
756 getPosition: function(_er) { |
|
757 var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
758 return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
759 } |
|
760 } |
|
761 this.bundles.push(_bundle); |
|
762 } |
|
763 return _bundle; |
|
764 } |
730 |
765 |
731 Rkns.Renderer.Scene.prototype.autoScale = function() { |
766 Rkns.Renderer.Scene.prototype.autoScale = function() { |
732 if (this.renkan.project.get("nodes").length) { |
767 if (this.renkan.project.get("nodes").length) { |
733 var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }), |
768 var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }), |
734 _yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }), |
769 _yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }), |