18 this.bundle = this.renderer.addToBundles(this); |
18 this.bundle = this.renderer.addToBundles(this); |
19 this.line = new paper.Path(); |
19 this.line = new paper.Path(); |
20 this.line.add([0,0],[0,0],[0,0]); |
20 this.line.add([0,0],[0,0],[0,0]); |
21 this.line.__representation = this; |
21 this.line.__representation = this; |
22 this.line.strokeWidth = this.options.edge_stroke_width; |
22 this.line.strokeWidth = this.options.edge_stroke_width; |
|
23 this.arrow_scale = 1; |
23 this.arrow = new paper.Path(); |
24 this.arrow = new paper.Path(); |
24 this.arrow.add( |
25 this.arrow.add( |
25 [ 0, 0 ], |
26 [ 0, 0 ], |
26 [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ], |
27 [ this.options.edge_arrow_length, this.options.edge_arrow_width / 2 ], |
27 [ 0, this.options.edge_arrow_width ] |
28 [ 0, this.options.edge_arrow_width ] |
28 ); |
29 ); |
|
30 this.arrow.pivot = new paper.Point([ this.options.edge_arrow_length / 2, this.options.edge_arrow_width / 2 ]); |
29 this.arrow.__representation = this; |
31 this.arrow.__representation = this; |
30 this.text = $('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$); |
32 this.text = $('<div class="Rk-Label Rk-Edge-Label">').appendTo(this.renderer.labels_$); |
31 this.arrow_angle = 0; |
33 this.arrow_angle = 0; |
32 if (this.options.editor_mode) { |
34 if (this.options.editor_mode) { |
33 var Renderer = requtils.getRenderer(); |
35 var Renderer = requtils.getRenderer(); |
53 this.minimap_line.add([0,0],[0,0]); |
55 this.minimap_line.add([0,0],[0,0]); |
54 this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation; |
56 this.minimap_line.__representation = this.renderer.minimap.miniframe.__representation; |
55 this.minimap_line.strokeWidth = 1; |
57 this.minimap_line.strokeWidth = 1; |
56 } |
58 } |
57 }, |
59 }, |
|
60 _getStrokeWidth: function() { |
|
61 var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1; |
|
62 return this.options.edge_stroke_width + (thickness-1) * (this.options.edge_stroke_max_width - this.options.edge_stroke_width) / (this.options.edge_stroke_witdh_scale-1); |
|
63 }, |
|
64 _getSelectedStrokeWidth: function() { |
|
65 var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1; |
|
66 return this.options.selected_edge_stroke_width + (thickness-1) * (this.options.selected_edge_stroke_max_width - this.options.selected_edge_stroke_width) / (this.options.edge_stroke_witdh_scale-1); |
|
67 }, |
|
68 _getArrowScale: function() { |
|
69 var thickness = (this.model.has('style') && this.model.get('style').thickness) || 1; |
|
70 return 1 + (thickness-1) * ((this.options.edge_arrow_max_width / this.options.edge_arrow_width) - 1) / (this.options.edge_stroke_witdh_scale-1); |
|
71 }, |
58 redraw: function() { |
72 redraw: function() { |
59 var from = this.model.get("from"), |
73 var from = this.model.get("from"), |
60 to = this.model.get("to"); |
74 to = this.model.get("to"); |
61 if (!from || !to) { |
75 if (!from || !to) { |
62 return; |
76 return; |
64 this.from_representation = this.renderer.getRepresentationByModel(from); |
78 this.from_representation = this.renderer.getRepresentationByModel(from); |
65 this.to_representation = this.renderer.getRepresentationByModel(to); |
79 this.to_representation = this.renderer.getRepresentationByModel(to); |
66 if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined") { |
80 if (typeof this.from_representation === "undefined" || typeof this.to_representation === "undefined") { |
67 return; |
81 return; |
68 } |
82 } |
69 var _p0a = this.from_representation.paper_coords, |
83 var _strokeWidth = this._getStrokeWidth(), |
|
84 _arrow_scale = this._getArrowScale(), |
|
85 _p0a = this.from_representation.paper_coords, |
70 _p1a = this.to_representation.paper_coords, |
86 _p1a = this.to_representation.paper_coords, |
71 _v = _p1a.subtract(_p0a), |
87 _v = _p1a.subtract(_p0a), |
72 _r = _v.length, |
88 _r = _v.length, |
73 _u = _v.divide(_r), |
89 _u = _v.divide(_r), |
74 _ortho = new paper.Point([- _u.y, _u.x]), |
90 _ortho = new paper.Point([- _u.y, _u.x]), |
75 _group_pos = this.bundle.getPosition(this), |
91 _group_pos = this.bundle.getPosition(this), |
76 _delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ), |
92 _delta = _ortho.multiply( this.options.edge_gap_in_bundles * _group_pos ), |
77 _p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
93 _p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
78 _p1b = _p1a.add(_delta), /* to differentiate bundled links */ |
94 _p1b = _p1a.add(_delta), /* to differentiate bundled links */ |
79 _a = _v.angle, |
95 _a = _v.angle, |
80 _textdelta = _ortho.multiply(this.options.edge_label_distance), |
96 _textdelta = _ortho.multiply(this.options.edge_label_distance + 0.5 * _arrow_scale * this.options.edge_arrow_width), |
81 _handle = _v.divide(3), |
97 _handle = _v.divide(3), |
82 _color = (this.model.has("style") && this.model.get("style").color) || (this.model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"), |
98 _color = (this.model.has("style") && this.model.get("style").color) || (this.model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"), |
83 _dash = (this.model.has("style") && this.model.get("style").dash) ? this.options.default_dash_array : null, |
99 _dash = (this.model.has("style") && this.model.get("style").dash) ? this.options.default_dash_array : null, |
84 opacity = 1; |
100 opacity = 1; |
85 |
101 |
90 opacity = 1; |
106 opacity = 1; |
91 this.line.dashArray = null; |
107 this.line.dashArray = null; |
92 } |
108 } |
93 |
109 |
94 var old_act_btn = this.active_buttons; |
110 var old_act_btn = this.active_buttons; |
|
111 |
|
112 var array_opacity = |
|
113 (this.model.has("style") && this.model.get("style").arrow) || !this.model.has("style") || (typeof this.model.get("style").arrow === 'undefined') ? opacity : 0; |
95 |
114 |
96 this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons; |
115 this.active_buttons = this.model.get("delete_scheduled") ? this.pending_delete_buttons : this.normal_buttons; |
97 |
116 |
98 if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) { |
117 if (this.selected && this.renderer.isEditable() && old_act_btn !== this.active_buttons) { |
99 old_act_btn.forEach(function(b) { |
118 old_act_btn.forEach(function(b) { |
105 } |
124 } |
106 |
125 |
107 |
126 |
108 |
127 |
109 this.paper_coords = _p0b.add(_p1b).divide(2); |
128 this.paper_coords = _p0b.add(_p1b).divide(2); |
|
129 this.line.strokeWidth = _strokeWidth; |
110 this.line.strokeColor = _color; |
130 this.line.strokeColor = _color; |
111 this.line.dashArray = _dash; |
131 this.line.dashArray = _dash; |
112 this.line.opacity = opacity; |
132 this.line.opacity = opacity; |
113 this.line.segments[0].point = _p0a; |
133 this.line.segments[0].point = _p0a; |
114 this.line.segments[1].point = this.paper_coords; |
134 this.line.segments[1].point = this.paper_coords; |
115 this.line.segments[1].handleIn = _handle.multiply(-1); |
135 this.line.segments[1].handleIn = _handle.multiply(-1); |
116 this.line.segments[1].handleOut = _handle; |
136 this.line.segments[1].handleOut = _handle; |
117 this.line.segments[2].point = _p1a; |
137 this.line.segments[2].point = _p1a; |
118 this.arrow.rotate(_a - this.arrow_angle); |
138 this.arrow.scale(_arrow_scale / this.arrow_scale); |
|
139 this.arrow_scale = _arrow_scale; |
119 this.arrow.fillColor = _color; |
140 this.arrow.fillColor = _color; |
120 this.arrow.opacity = opacity; |
141 this.arrow.opacity = array_opacity; |
|
142 this.arrow.rotate(_a - this.arrow_angle, this.arrow.bounds.center); |
121 this.arrow.position = this.paper_coords; |
143 this.arrow.position = this.paper_coords; |
|
144 |
122 this.arrow_angle = _a; |
145 this.arrow_angle = _a; |
123 if (_a > 90) { |
146 if (_a > 90) { |
124 _a -= 180; |
147 _a -= 180; |
125 _textdelta = _textdelta.multiply(-1); |
148 _textdelta = _textdelta.multiply(-1); |
126 } |
149 } |
178 if (this.options.editor_mode) { |
201 if (this.options.editor_mode) { |
179 this.all_buttons.forEach(function(b) { |
202 this.all_buttons.forEach(function(b) { |
180 b.hide(); |
203 b.hide(); |
181 }); |
204 }); |
182 } |
205 } |
183 this.line.strokeWidth = this.options.edge_stroke_width; |
206 this.line.strokeWidth = this._getStrokeWidth(); |
184 this._super("unselect"); |
207 this._super("unselect"); |
185 } |
208 } |
186 }, |
209 }, |
187 mousedown: function(_event, _isTouch) { |
210 mousedown: function(_event, _isTouch) { |
188 if (_isTouch) { |
211 if (_isTouch) { |