| author | veltr |
| Tue, 13 Nov 2012 11:46:27 +0100 | |
| changeset 42 | 48d825187d67 |
| parent 39 | 84eea249ce7e |
| child 43 | 90f6937c417e |
| permissions | -rw-r--r-- |
| 28 | 1 |
Rkns.Renderer = { |
2 |
_MARGIN_X: 80, |
|
3 |
_MARGIN_Y: 50, |
|
4 |
_MIN_DRAG_DISTANCE: 2, |
|
| 37 | 5 |
_NODE_RADIUS: 25, |
6 |
_NODE_BUTTON_INNER: 26, |
|
7 |
_NODE_BUTTON_OUTER: 60, |
|
| 35 | 8 |
_EDGE_BUTTON_INNER: 1, |
| 31 | 9 |
_EDGE_BUTTON_OUTER: 40, |
| 28 | 10 |
_NODE_FONT_SIZE: 10, |
11 |
_EDGE_FONT_SIZE: 9, |
|
12 |
_NODE_MAX_CHAR: 50, |
|
13 |
_EDGE_MAX_CHAR: 40, |
|
14 |
_ARROW_LENGTH: 16, |
|
15 |
_ARROW_WIDTH: 8, |
|
| 5 | 16 |
_EDITOR_ARROW_LENGTH : 20, |
17 |
_EDITOR_ARROW_WIDTH : 40, |
|
18 |
_EDITOR_MARGIN : 15, |
|
19 |
_EDITOR_PADDING : 10, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
20 |
_EDITOR_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
21 |
_CLICKMODE_ADDNODE : 1, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
22 |
_CLICKMODE_STARTEDGE : 2, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
23 |
_CLICKMODE_ENDEDGE : 3 |
| 28 | 24 |
} |
25 |
||
26 |
Rkns.Renderer.Utils = { |
|
27 |
drawEditBox : function(_coords, _path, _width, _xmargin, _selector) { |
|
28 |
_selector.css({ |
|
29 |
width: (_width - 2* Rkns.Renderer._EDITOR_PADDING), |
|
30 |
}) |
|
31 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._EDITOR_PADDING, |
|
32 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
33 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH ), |
|
34 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._EDITOR_ARROW_LENGTH + _width ), |
|
| 5 | 35 |
_top = _coords.y - _height / 2; |
| 28 | 36 |
if (_top < Rkns.Renderer._EDITOR_MARGIN) { |
37 |
_top = Math.min( Rkns.Renderer._EDITOR_MARGIN, _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 38 |
} |
39 |
var _bottom = _top + _height; |
|
| 28 | 40 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN)) { |
41 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._EDITOR_MARGIN, _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2 ); |
|
| 5 | 42 |
_top = _bottom - _height; |
43 |
} |
|
44 |
_path.segments[0].point |
|
45 |
= _path.segments[7].point |
|
| 28 | 46 |
= _coords.add([_isLeft * _xmargin, 0]); |
| 5 | 47 |
_path.segments[1].point.x |
48 |
= _path.segments[2].point.x |
|
49 |
= _path.segments[5].point.x |
|
50 |
= _path.segments[6].point.x |
|
51 |
= _left; |
|
52 |
_path.segments[3].point.x |
|
53 |
= _path.segments[4].point.x |
|
54 |
= _right; |
|
55 |
_path.segments[2].point.y |
|
56 |
= _path.segments[3].point.y |
|
57 |
= _top; |
|
58 |
_path.segments[4].point.y |
|
59 |
= _path.segments[5].point.y |
|
60 |
= _bottom; |
|
| 28 | 61 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
62 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._EDITOR_ARROW_WIDTH / 2; |
|
63 |
_path.closed = true; |
|
64 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._EDITOR_GRADIENT, [0,_top], [0, _bottom]); |
|
65 |
_selector.css({ |
|
66 |
left: (Rkns.Renderer._EDITOR_PADDING + Math.min(_left, _right)), |
|
67 |
top: (Rkns.Renderer._EDITOR_PADDING + _top) |
|
68 |
}); |
|
| 7 | 69 |
}, |
| 38 | 70 |
sector : function(_repr, _inR, _outR, _startAngle, _endAngle, _padding, _imgsrc, _caption) { |
| 7 | 71 |
var _startRads = _startAngle * Math.PI / 180, |
72 |
_endRads = _endAngle * Math.PI / 180, |
|
73 |
_img = new Image(), |
|
74 |
_span = _endRads - _startRads, |
|
75 |
_k = .0879 * _span, |
|
76 |
_kin = _k * _inR, |
|
77 |
_kout = _k * _outR, |
|
78 |
_startdx = - Math.sin(_startRads), |
|
79 |
_startdy = Math.cos(_startRads), |
|
80 |
_startXIn = Math.cos(_startRads) * _inR + _padding * _startdx, |
|
81 |
_startYIn = Math.sin(_startRads) * _inR + _padding * _startdy, |
|
82 |
_startXOut = Math.cos(_startRads) * _outR + _padding * _startdx, |
|
83 |
_startYOut = Math.sin(_startRads) * _outR + _padding * _startdy, |
|
84 |
_enddx = - Math.sin(_endRads), |
|
85 |
_enddy = Math.cos(_endRads), |
|
86 |
_endXIn = Math.cos(_endRads) * _inR - _padding * _enddx, |
|
87 |
_endYIn = Math.sin(_endRads) * _inR - _padding * _enddy, |
|
88 |
_endXOut = Math.cos(_endRads) * _outR - _padding * _enddx, |
|
89 |
_endYOut = Math.sin(_endRads) * _outR - _padding * _enddy, |
|
90 |
_centerR = (_inR + _outR)/2, |
|
91 |
_centerRads = (_startRads + _endRads) / 2, |
|
92 |
_centerX = Math.cos(_centerRads) * _centerR, |
|
93 |
_centerY = Math.sin(_centerRads) * _centerR, |
|
| 38 | 94 |
_textX = Math.cos(_centerRads) * (_outR + 3), |
95 |
_textY = Math.sin(_centerRads) * (_outR + 3), |
|
| 7 | 96 |
_segments = []; |
97 |
_segments.push([[_startXIn, _startYIn], [0, 0], [ _kin * _startdx, _kin * _startdy ]]); |
|
98 |
for (var i = 1; i < 4; i++) { |
|
99 |
var _rads = i * _span / 4 + _startRads, |
|
100 |
_dx = - Math.sin(_rads), |
|
101 |
_dy = Math.cos(_rads), |
|
102 |
_x = Math.cos(_rads) * _inR, |
|
103 |
_y = Math.sin(_rads) * _inR; |
|
104 |
_segments.push([[_x, _y], [ - _kin * _dx, - _kin * _dy], [ _kin * _dx, _kin * _dy ]]); |
|
105 |
} |
|
106 |
_segments.push([[_endXIn, _endYIn], [ - _kin * _enddx, - _kin * _enddy ], [0,0]]); |
|
107 |
_segments.push([[_endXOut, _endYOut], [ 0,0 ], [ - _kout * _enddx, - _kout * _enddy ]]); |
|
108 |
for (var i = 3; i > 0; i--) { |
|
109 |
var _rads = i * _span / 4 + _startRads, |
|
110 |
_dx = - Math.sin(_rads), |
|
111 |
_dy = Math.cos(_rads), |
|
112 |
_x = Math.cos(_rads) * _outR, |
|
113 |
_y = Math.sin(_rads) * _outR; |
|
114 |
_segments.push([[_x, _y], [ _kout * _dx, _kout * _dy], [ - _kout * _dx, - _kout * _dy ]]); |
|
115 |
} |
|
116 |
_segments.push([[_startXOut, _startYOut], [ _kout * _startdx, _kout * _startdy ], [0, 0]]); |
|
| 18 | 117 |
var _path = new paper.Path(); |
| 7 | 118 |
_path.add.apply(_path, _segments); |
119 |
_path.fillColor = "#333333"; |
|
| 15 | 120 |
_path.opacity = .5; |
| 7 | 121 |
_path.closed = true; |
| 23 | 122 |
_path.__representation = _repr; |
| 38 | 123 |
if (_textX >= -2 && _textX <= 2) { |
124 |
if (_textY > 0) { |
|
125 |
_textY += 6; |
|
126 |
} |
|
127 |
} |
|
128 |
var _text = new paper.PointText(_textX,_textY); |
|
129 |
_text.characterStyle = { |
|
130 |
fontSize: 9, |
|
131 |
fillColor: '#c000c0' |
|
132 |
}; |
|
133 |
if (_textX > 2) { |
|
134 |
_text.paragraphStyle.justification = 'left'; |
|
135 |
} else if (_textX < -2) { |
|
136 |
_text.paragraphStyle.justification = 'right'; |
|
137 |
} else { |
|
138 |
_text.paragraphStyle.justification = 'center'; |
|
139 |
} |
|
140 |
_text.visible = false; |
|
| 18 | 141 |
var _visible = false, |
142 |
_restPos = new paper.Point(-200, -200), |
|
| 38 | 143 |
_grp = new paper.Group([_path, _text]), |
| 18 | 144 |
_delta = _grp.position, |
145 |
_imgdelta = new paper.Point([_centerX, _centerY]), |
|
146 |
_currentPos = new paper.Point(0,0); |
|
| 38 | 147 |
_text.content = _caption; |
| 18 | 148 |
_grp.visible = false; |
149 |
_grp.position = _restPos; |
|
150 |
var _res = { |
|
151 |
show: function() { |
|
152 |
_visible = true; |
|
153 |
_grp.position = _currentPos.add(_delta); |
|
154 |
_grp.visible = true; |
|
155 |
}, |
|
156 |
moveTo: function(_point) { |
|
157 |
_currentPos = _point; |
|
158 |
if (_visible) { |
|
159 |
_grp.position = _point.add(_delta); |
|
160 |
} |
|
161 |
}, |
|
162 |
hide: function() { |
|
163 |
_visible = false; |
|
164 |
_grp.visible = false; |
|
165 |
_grp.position = _restPos; |
|
166 |
}, |
|
167 |
select: function() { |
|
168 |
_path.opacity = .8; |
|
| 38 | 169 |
_text.visible = true; |
| 18 | 170 |
}, |
171 |
unselect: function() { |
|
172 |
_path.opacity = .5; |
|
| 38 | 173 |
_text.visible = false; |
| 18 | 174 |
}, |
175 |
destroy: function() { |
|
176 |
_grp.remove(); |
|
| 7 | 177 |
} |
| 18 | 178 |
} |
| 7 | 179 |
_img.onload = function() { |
| 38 | 180 |
var _h = _img.height; |
| 7 | 181 |
var _raster = new paper.Raster(_img); |
| 18 | 182 |
_raster.position = _imgdelta.add(_grp.position).subtract(_delta); |
| 7 | 183 |
_grp.addChild(_raster); |
184 |
} |
|
185 |
_img.src = _imgsrc; |
|
186 |
return _res |
|
| 5 | 187 |
} |
188 |
} |
|
189 |
||
| 23 | 190 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
| 1 | 191 |
if (typeof _renderer !== "undefined") { |
| 23 | 192 |
this.renderer = _renderer; |
193 |
this.project = _renderer.renkan.project; |
|
194 |
this.model = _model; |
|
| 39 | 195 |
if (this.model) { |
196 |
var _this = this; |
|
197 |
this._changeBinding = function() { |
|
198 |
_this.redraw(); |
|
199 |
} |
|
200 |
this._removeBinding = function() { |
|
201 |
_renderer.removeRepresentation(_this); |
|
202 |
_renderer.redraw(); |
|
203 |
} |
|
204 |
this.model.on("change", this._changeBinding ); |
|
205 |
this.model.on("remove", this._removeBinding ); |
|
206 |
} |
|
| 1 | 207 |
} |
208 |
} |
|
209 |
||
| 39 | 210 |
Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) { |
211 |
Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1)); |
|
212 |
} |
|
213 |
||
| 23 | 214 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
| 4 | 215 |
|
| 23 | 216 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
| 7 | 217 |
|
| 26 | 218 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
219 |
||
220 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
221 |
||
| 23 | 222 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
| 4 | 223 |
|
| 39 | 224 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() { |
225 |
if (this.model) { |
|
226 |
this.model.off("change", this._changeBinding ); |
|
227 |
this.model.off("remove", this._removeBinding ); |
|
228 |
} |
|
229 |
} |
|
| 5 | 230 |
|
| 23 | 231 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 1 | 232 |
|
| 7 | 233 |
Rkns.Renderer.Node.prototype._init = function() { |
| 23 | 234 |
this.renderer.node_layer.activate(); |
| 20 | 235 |
this.type = "Node"; |
| 28 | 236 |
this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
| 7 | 237 |
this.circle.fillColor = '#ffffff'; |
| 23 | 238 |
this.circle.__representation = this; |
| 7 | 239 |
this.title = new paper.PointText([0,0]); |
240 |
this.title.characterStyle = { |
|
| 28 | 241 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
| 2 | 242 |
fillColor: 'black' |
243 |
}; |
|
| 39 | 244 |
this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null); |
| 23 | 245 |
this.edit_button.node_representation = this; |
| 39 | 246 |
this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null); |
| 23 | 247 |
this.remove_button.node_representation = this; |
| 39 | 248 |
this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null); |
| 23 | 249 |
this.link_button.node_representation = this; |
| 7 | 250 |
this.title.paragraphStyle.justification = 'center'; |
| 1 | 251 |
} |
252 |
||
| 7 | 253 |
Rkns.Renderer.Node.prototype.redraw = function() { |
| 23 | 254 |
var _model_coords = new paper.Point(this.model.get("position")); |
255 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
|
| 7 | 256 |
this.circle.position = this.paper_coords; |
| 23 | 257 |
this.title.content = this.model.get("title"); |
| 37 | 258 |
this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); |
| 23 | 259 |
this.circle.strokeColor = this.model.get("created_by").get("color"); |
| 7 | 260 |
this.edit_button.moveTo(this.paper_coords); |
261 |
this.remove_button.moveTo(this.paper_coords); |
|
| 11 | 262 |
this.link_button.moveTo(this.paper_coords); |
| 37 | 263 |
var _img = this.model.get("image"); |
264 |
if (_img && _img !== this.img) { |
|
265 |
var _image = new Image(), |
|
266 |
_this = this; |
|
267 |
_image.onload = function() { |
|
268 |
if (_this.node_image) { |
|
269 |
_this.node_image.remove(); |
|
270 |
} |
|
271 |
_this.renderer.node_layer.activate(); |
|
272 |
var _ratio = Math.min(1, 2 * Rkns.Renderer._NODE_RADIUS / _image.width, 2 * Rkns.Renderer._NODE_RADIUS / _image.height ); |
|
273 |
var _raster = new paper.Raster(_image); |
|
274 |
var _clip = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
|
275 |
_raster.scale(_ratio); |
|
276 |
_this.node_image = new paper.Group(_clip, _raster); |
|
277 |
_this.node_image.opacity = .9; |
|
| 38 | 278 |
/* This is a workaround to allow clipping at group level |
279 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
|
280 |
*/ |
|
| 37 | 281 |
_this.node_image.clipped = true; |
282 |
_this.node_image.position = _this.paper_coords; |
|
283 |
_this.node_image.__representation = _this; |
|
| 38 | 284 |
_clip.__representation = _this; |
| 37 | 285 |
paper.view.draw(); |
286 |
} |
|
287 |
_image.src = _img; |
|
288 |
} |
|
289 |
this.img = _img; |
|
290 |
if (this.node_image) { |
|
291 |
if (!this.img) { |
|
292 |
this.node_image.remove(); |
|
293 |
delete this.node_image; |
|
294 |
} else { |
|
295 |
this.node_image.position = this.paper_coords; |
|
296 |
} |
|
297 |
} |
|
| 1 | 298 |
} |
299 |
||
| 7 | 300 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
| 23 | 301 |
var _coords = this.renderer.toModelCoords(this.paper_coords.add(_delta)), |
| 5 | 302 |
_data = { |
303 |
position: { |
|
304 |
x: _coords.x, |
|
305 |
y: _coords.y |
|
306 |
} |
|
307 |
}; |
|
| 23 | 308 |
this.model.set(_data); |
309 |
this.renderer.redraw(); |
|
| 2 | 310 |
} |
311 |
||
| 8 | 312 |
Rkns.Renderer.Node.prototype.openEditor = function() { |
| 23 | 313 |
this.renderer.removeRepresentationsOfType("editor"); |
314 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
315 |
_editor.node_representation = this; |
|
| 37 | 316 |
_editor.draw(); |
| 8 | 317 |
} |
318 |
||
| 7 | 319 |
Rkns.Renderer.Node.prototype.select = function() { |
320 |
this.circle.strokeWidth = 3; |
|
321 |
this.edit_button.show(); |
|
322 |
this.remove_button.show(); |
|
| 11 | 323 |
this.link_button.show(); |
| 26 | 324 |
var _uri = this.model.get("uri"); |
325 |
Rkns.$('.Rk-Bin-Item').each(function() { |
|
326 |
var _el = Rkns.$(this); |
|
327 |
if (_el.attr("data-uri") == _uri) { |
|
328 |
_el.addClass("selected"); |
|
329 |
} |
|
330 |
}); |
|
| 7 | 331 |
} |
332 |
||
333 |
Rkns.Renderer.Node.prototype.unselect = function(_newTarget) { |
|
| 35 | 334 |
if (!_newTarget || _newTarget.node_representation !== this) { |
| 7 | 335 |
this.edit_button.hide(); |
336 |
this.remove_button.hide(); |
|
| 11 | 337 |
this.link_button.hide(); |
| 35 | 338 |
this.circle.strokeWidth = 1; |
339 |
Rkns.$('.Rk-Bin-Item').removeClass("selected"); |
|
| 7 | 340 |
} |
| 26 | 341 |
} |
342 |
||
343 |
Rkns.Renderer.Node.prototype.highlight = function() { |
|
| 37 | 344 |
this.circle.fillColor = "#ffff80"; |
345 |
if (this.node_image) { |
|
346 |
this.node_image.opacity = .5; |
|
347 |
} |
|
| 26 | 348 |
} |
349 |
||
350 |
Rkns.Renderer.Node.prototype.unhighlight = function(_newTarget) { |
|
351 |
this.circle.fillColor = "#ffffff"; |
|
| 37 | 352 |
if (this.node_image) { |
353 |
this.node_image.opacity = .9; |
|
354 |
} |
|
| 4 | 355 |
} |
356 |
||
| 7 | 357 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
| 23 | 358 |
if (!this.renderer.is_dragging) { |
| 8 | 359 |
this.openEditor(); |
| 7 | 360 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
361 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
362 |
this.renderer.is_dragging = false; |
| 7 | 363 |
} |
364 |
||
365 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
| 39 | 366 |
this.super("destroy"); |
| 7 | 367 |
this.edit_button.destroy(); |
368 |
this.remove_button.destroy(); |
|
| 26 | 369 |
this.link_button.destroy(); |
| 7 | 370 |
this.circle.remove(); |
371 |
this.title.remove(); |
|
| 37 | 372 |
if (this.node_image) { |
373 |
this.node_image.remove(); |
|
374 |
} |
|
| 4 | 375 |
} |
376 |
||
| 2 | 377 |
/* */ |
378 |
||
| 23 | 379 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 2 | 380 |
|
| 7 | 381 |
Rkns.Renderer.Edge.prototype._init = function() { |
| 23 | 382 |
this.renderer.edge_layer.activate(); |
| 20 | 383 |
this.type = "Edge"; |
| 23 | 384 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
385 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
| 31 | 386 |
this.bundle = this.renderer.addToBundles(this); |
| 7 | 387 |
this.line = new paper.Path(); |
| 31 | 388 |
this.line.add([0,0],[0,0],[0,0]); |
| 23 | 389 |
this.line.__representation = this; |
| 7 | 390 |
this.arrow = new paper.Path(); |
| 28 | 391 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 392 |
this.arrow.__representation = this; |
| 7 | 393 |
this.text = new paper.PointText(); |
394 |
this.text.characterStyle = { |
|
| 28 | 395 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
| 2 | 396 |
fillColor: 'black' |
397 |
}; |
|
| 7 | 398 |
this.text.paragraphStyle.justification = 'center'; |
399 |
this.text_angle = 0; |
|
400 |
this.arrow_angle = 0; |
|
| 39 | 401 |
this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null); |
| 23 | 402 |
this.edit_button.edge_representation = this; |
| 39 | 403 |
this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null); |
| 23 | 404 |
this.remove_button.edge_representation = this; |
| 2 | 405 |
} |
406 |
||
| 7 | 407 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
| 31 | 408 |
var _p0a = this.from_representation.paper_coords, |
409 |
_p1a = this.to_representation.paper_coords, |
|
410 |
_v = _p1a.subtract(_p0a), |
|
| 15 | 411 |
_r = _v.length, |
| 18 | 412 |
_u = _v.divide(_r), |
| 31 | 413 |
_group_pos = this.bundle.getPosition(this), |
414 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
|
415 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
416 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
| 15 | 417 |
_a = _v.angle, |
| 31 | 418 |
_handle = _v.divide(3), |
| 23 | 419 |
_color = this.model.get("created_by").get("color"); |
| 31 | 420 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
| 7 | 421 |
this.line.strokeColor = _color; |
| 31 | 422 |
this.line.segments[0].point = _p0a; |
423 |
this.line.segments[1].point = this.paper_coords; |
|
424 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
425 |
this.line.segments[1].handleOut = _handle; |
|
426 |
this.line.segments[2].point = _p1a; |
|
| 7 | 427 |
this.arrow.rotate(_a - this.arrow_angle); |
428 |
this.arrow.fillColor = _color; |
|
| 18 | 429 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
| 7 | 430 |
this.arrow_angle = _a; |
| 2 | 431 |
if (_a > 90) { |
432 |
_a -= 180; |
|
433 |
} |
|
434 |
if (_a < -90) { |
|
435 |
_a += 180; |
|
436 |
} |
|
| 7 | 437 |
this.text.rotate(_a - this.text_angle); |
| 23 | 438 |
this.text.content = this.model.get("title"); |
| 15 | 439 |
this.text.position = this.paper_coords; |
| 7 | 440 |
this.text_angle = _a; |
| 15 | 441 |
this.edit_button.moveTo(this.paper_coords); |
442 |
this.remove_button.moveTo(this.paper_coords); |
|
| 7 | 443 |
} |
444 |
||
| 18 | 445 |
Rkns.Renderer.Edge.prototype.openEditor = function() { |
| 23 | 446 |
this.renderer.removeRepresentationsOfType("editor"); |
447 |
var _editor = this.renderer.addRepresentation("EdgeEditor",null); |
|
448 |
_editor.edge_representation = this; |
|
| 37 | 449 |
_editor.draw(); |
| 18 | 450 |
} |
451 |
||
| 7 | 452 |
Rkns.Renderer.Edge.prototype.select = function() { |
453 |
this.line.strokeWidth = 3; |
|
| 15 | 454 |
this.edit_button.show(); |
455 |
this.remove_button.show(); |
|
| 7 | 456 |
} |
457 |
||
458 |
Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) { |
|
| 35 | 459 |
if (!_newTarget || _newTarget.edge_representation !== this) { |
| 15 | 460 |
this.edit_button.hide(); |
461 |
this.remove_button.hide(); |
|
| 35 | 462 |
this.line.strokeWidth = 1; |
| 15 | 463 |
} |
| 4 | 464 |
} |
465 |
||
| 7 | 466 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
| 23 | 467 |
if (!this.renderer.is_dragging) { |
| 18 | 468 |
this.openEditor(); |
| 7 | 469 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
470 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
471 |
this.renderer.is_dragging = false; |
| 4 | 472 |
} |
473 |
||
| 7 | 474 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
| 23 | 475 |
this.from_representation.paperShift(_delta); |
476 |
this.to_representation.paperShift(_delta); |
|
477 |
this.renderer.redraw(); |
|
| 2 | 478 |
} |
479 |
||
| 7 | 480 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
| 39 | 481 |
this.super("destroy"); |
| 7 | 482 |
this.line.remove(); |
483 |
this.arrow.remove(); |
|
484 |
this.text.remove(); |
|
| 15 | 485 |
this.edit_button.destroy(); |
486 |
this.remove_button.destroy(); |
|
| 31 | 487 |
var _this = this; |
488 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
489 |
return _edge === _this; |
|
490 |
}); |
|
| 2 | 491 |
} |
| 5 | 492 |
|
| 4 | 493 |
/* */ |
494 |
||
| 23 | 495 |
Rkns.Renderer.TempEdge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 4 | 496 |
|
| 7 | 497 |
Rkns.Renderer.TempEdge.prototype._init = function() { |
| 23 | 498 |
this.renderer.edge_layer.activate(); |
| 4 | 499 |
this.type = "temp-edge"; |
| 23 | 500 |
|
501 |
var _color = this.project.get("users").get(this.renderer.renkan.current_user).get("color"); |
|
| 7 | 502 |
this.line = new paper.Path(); |
503 |
this.line.strokeColor = _color; |
|
504 |
this.line.add([0,0],[0,0]); |
|
| 23 | 505 |
this.line.__representation = this; |
| 7 | 506 |
this.arrow = new paper.Path(); |
507 |
this.arrow.fillColor = _color; |
|
| 28 | 508 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
| 23 | 509 |
this.arrow.__representation = this; |
| 7 | 510 |
this.arrow_angle = 0; |
| 4 | 511 |
} |
512 |
||
| 7 | 513 |
Rkns.Renderer.TempEdge.prototype.redraw = function() { |
| 23 | 514 |
var _p0 = this.from_representation.paper_coords, |
| 4 | 515 |
_p1 = this.end_pos, |
516 |
_a = _p1.subtract(_p0).angle, |
|
517 |
_c = _p0.add(_p1).divide(2); |
|
| 7 | 518 |
this.line.segments[0].point = _p0; |
519 |
this.line.segments[1].point = _p1; |
|
520 |
this.arrow.rotate(_a - this.arrow_angle); |
|
521 |
this.arrow.position = _c; |
|
522 |
this.arrow_angle = _a; |
|
| 4 | 523 |
} |
524 |
||
| 7 | 525 |
Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) { |
| 4 | 526 |
this.end_pos = this.end_pos.add(_delta); |
| 21 | 527 |
var _hitResult = paper.project.hitTest(this.end_pos); |
| 23 | 528 |
this.renderer.findTarget(_hitResult); |
| 4 | 529 |
this.redraw(); |
530 |
} |
|
531 |
||
| 7 | 532 |
Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
533 |
var _hitResult = paper.project.hitTest(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
534 |
_model = this.from_representation.model, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
535 |
_endDrag = true; |
| 23 | 536 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
537 |
var _target = _hitResult.item.__representation; |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
538 |
if (_target.type === "Node" && _model !== _target.model) { |
| 23 | 539 |
var _data = { |
540 |
id: Rkns.Utils.getUID('edge'), |
|
541 |
created_by: this.renderer.renkan.current_user, |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
542 |
from: _model.get("_id"), |
| 30 | 543 |
to: _target.model.get("_id") |
| 23 | 544 |
}; |
545 |
this.project.addEdge(_data); |
|
| 4 | 546 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
547 |
if (_model === _target.model || (_target.node_representation && _target.node_representation.model === _model)) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
548 |
_endDrag = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
549 |
this.renderer.is_dragging = true; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
550 |
} |
| 4 | 551 |
} |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
552 |
if (_endDrag) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
553 |
this.renderer.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
554 |
this.renderer.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
555 |
this.renderer.removeRepresentation(this); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
556 |
paper.view.draw(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
557 |
} |
| 5 | 558 |
} |
559 |
||
| 7 | 560 |
Rkns.Renderer.TempEdge.prototype.destroy = function() { |
561 |
this.arrow.remove(); |
|
562 |
this.line.remove(); |
|
| 5 | 563 |
} |
564 |
||
565 |
/* */ |
|
566 |
||
| 23 | 567 |
Rkns.Renderer.NodeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 568 |
|
| 7 | 569 |
Rkns.Renderer.NodeEditor.prototype._init = function() { |
| 23 | 570 |
this.renderer.overlay_layer.activate(); |
| 5 | 571 |
this.type = "editor"; |
572 |
this.editor_block = new paper.Path(); |
|
573 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
574 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
575 |
this.editor_block.strokeWidth = 2; |
|
576 |
this.editor_block.strokeColor = "#999999"; |
|
577 |
this.editor_block.fillColor = "#e0e0e0"; |
|
578 |
this.editor_block.opacity = .8; |
|
579 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 580 |
.appendTo(this.renderer.editor_$) |
| 5 | 581 |
.css({ |
582 |
position: "absolute", |
|
583 |
opacity: .8 |
|
584 |
}) |
|
585 |
.hide(); |
|
586 |
} |
|
587 |
||
| 7 | 588 |
Rkns.Renderer.NodeEditor.prototype.template = Rkns._.template( |
| 5 | 589 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_node%></span></h2>' |
590 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=node.title%>"/></p>' |
|
| 26 | 591 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=node.uri%>"/><a class="Rk-Edit-Goto" href="<%=node.uri%>" target="_blank"></a></p>' |
| 5 | 592 |
+ '<p><label><%=l10n.edit_description%></label><textarea class="Rk-Edit-Description"><%=node.description%></textarea></p>' |
| 37 | 593 |
+ '<p><label><%=l10n.edit_image%></label><input class="Rk-Edit-Image" type="text" value="<%=node.image%>"/><img class="Rk-Edit-ImgPreview" src="<%=node.image%>" /></p>' |
| 25 | 594 |
+ '<p><label><%=l10n.created_by%></label> <span class="Rk-UserColor" style="background:<%=node.created_by_color%>;"></span><%=node.created_by_title%></p>' |
| 5 | 595 |
); |
596 |
||
| 37 | 597 |
Rkns.Renderer.NodeEditor.prototype.draw = function() { |
598 |
var _model = this.node_representation.model; |
|
| 5 | 599 |
this.editor_$ |
600 |
.html(this.template({ |
|
| 23 | 601 |
node: { |
602 |
title: _model.get("title"), |
|
603 |
uri: _model.get("uri"), |
|
604 |
description: _model.get("description"), |
|
| 37 | 605 |
image: _model.get("image") || "", |
| 25 | 606 |
created_by_color: _model.get("created_by").get("color"), |
607 |
created_by_title: _model.get("created_by").get("title") |
|
| 23 | 608 |
}, |
609 |
l10n: this.renderer.renkan.l10n |
|
| 37 | 610 |
})); |
611 |
this.redraw(); |
|
| 5 | 612 |
var _this = this; |
613 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 614 |
_this.renderer.removeRepresentation(_this); |
| 5 | 615 |
paper.view.draw(); |
616 |
}); |
|
617 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 37 | 618 |
var _uri = _this.editor_$.find(".Rk-Edit-URI").val(), |
619 |
_image = _this.editor_$.find(".Rk-Edit-Image").val(); |
|
620 |
_this.editor_$.find(".Rk-Edit-ImgPreview").attr("src", _image); |
|
621 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_uri); |
|
| 5 | 622 |
var _data = { |
623 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
624 |
description: _this.editor_$.find(".Rk-Edit-Description").val(), |
|
| 37 | 625 |
uri: _uri, |
626 |
image: _image |
|
| 5 | 627 |
} |
| 23 | 628 |
_model.set(_data); |
| 37 | 629 |
_this.redraw(); |
| 5 | 630 |
}); |
| 38 | 631 |
this.editor_$.find("img").load(function() { |
632 |
_this.redraw(); |
|
633 |
}) |
|
| 8 | 634 |
this.editor_$.find(".Rk-Edit-Title")[0].focus(); |
| 37 | 635 |
} |
636 |
||
637 |
Rkns.Renderer.NodeEditor.prototype.redraw = function() { |
|
638 |
var _coords = this.node_representation.paper_coords; |
|
639 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 20, this.editor_$); |
|
640 |
this.editor_$.show(); |
|
| 23 | 641 |
paper.view.draw(); |
| 5 | 642 |
} |
643 |
||
| 7 | 644 |
Rkns.Renderer.NodeEditor.prototype.destroy = function() { |
| 5 | 645 |
this.editor_block.remove(); |
646 |
this.editor_$.detach(); |
|
647 |
} |
|
648 |
||
649 |
/* */ |
|
650 |
||
| 23 | 651 |
Rkns.Renderer.EdgeEditor = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 5 | 652 |
|
| 7 | 653 |
Rkns.Renderer.EdgeEditor.prototype._init = function() { |
| 23 | 654 |
this.renderer.overlay_layer.activate(); |
| 5 | 655 |
this.type = "editor"; |
656 |
this.editor_block = new paper.Path(); |
|
657 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
658 |
this.editor_block.add.apply(this.editor_block, _pts); |
|
659 |
this.editor_block.strokeWidth = 2; |
|
660 |
this.editor_block.strokeColor = "#999999"; |
|
661 |
this.editor_block.fillColor = "#e0e0e0"; |
|
662 |
this.editor_block.opacity = .8; |
|
663 |
this.editor_$ = Rkns.$('<div>') |
|
| 23 | 664 |
.appendTo(this.renderer.editor_$) |
| 5 | 665 |
.css({ |
666 |
position: "absolute", |
|
667 |
opacity: .8 |
|
668 |
}) |
|
669 |
.hide(); |
|
670 |
} |
|
671 |
||
| 7 | 672 |
Rkns.Renderer.EdgeEditor.prototype.template = Rkns._.template( |
| 5 | 673 |
'<h2><span class="Rk-CloseX">×</span><%=l10n.edit_edge%></span></h2>' |
674 |
+ '<p><label><%=l10n.edit_title%></label><input class="Rk-Edit-Title" type="text" value="<%=edge.title%>"/></p>' |
|
| 26 | 675 |
+ '<p><label><%=l10n.edit_uri%></label><input class="Rk-Edit-URI" type="text" value="<%=edge.uri%>"/><a class="Rk-Edit-Goto" href="<%=edge.uri%>" target="_blank"></a></p>' |
| 25 | 676 |
+ '<p><label><%=l10n.edit_from%></label><span class="Rk-UserColor" style="background:<%=edge.from_created_by_color%>;"></span><%=edge.from_title%></p>' |
677 |
+ '<p><label><%=l10n.edit_to%></label><span class="Rk-UserColor" style="background:<%=edge.to_created_by_color%>;"></span><%=edge.to_title%></p>' |
|
678 |
+ '<p><label><%=l10n.created_by%> </label><span class="Rk-UserColor" style="background:<%=edge.created_by_color%>;"></span><%=edge.created_by_title%></p>' |
|
| 5 | 679 |
); |
680 |
||
| 37 | 681 |
Rkns.Renderer.EdgeEditor.prototype.draw = function() { |
682 |
var _model = this.edge_representation.model; |
|
| 5 | 683 |
this.editor_$ |
684 |
.html(this.template({ |
|
| 25 | 685 |
edge: { |
686 |
title: _model.get("title"), |
|
687 |
uri: _model.get("uri"), |
|
688 |
description: _model.get("description"), |
|
689 |
from_title: _model.get("from").get("title"), |
|
690 |
to_title: _model.get("to").get("title"), |
|
691 |
from_created_by_color: _model.get("from").get("created_by").get("color"), |
|
692 |
to_created_by_color: _model.get("to").get("created_by").get("color"), |
|
693 |
created_by_color: _model.get("created_by").get("color"), |
|
694 |
created_by_title: _model.get("created_by").get("title") |
|
695 |
}, |
|
| 23 | 696 |
l10n: this.renderer.renkan.l10n |
| 37 | 697 |
})); |
698 |
this.redraw(); |
|
| 5 | 699 |
var _this = this; |
700 |
this.editor_$.find(".Rk-CloseX").click(function() { |
|
| 23 | 701 |
_this.renderer.removeRepresentation(_this); |
| 5 | 702 |
paper.view.draw(); |
703 |
}); |
|
704 |
this.editor_$.find("input, textarea").bind("keyup change", function() { |
|
| 28 | 705 |
_this.editor_$.find(".Rk-Edit-Goto").attr("href",_this.editor_$.find(".Rk-Edit-URI").val()); |
| 5 | 706 |
var _data = { |
707 |
title: _this.editor_$.find(".Rk-Edit-Title").val(), |
|
708 |
uri: _this.editor_$.find(".Rk-Edit-URI").val() |
|
709 |
} |
|
| 23 | 710 |
_model.set(_data); |
| 37 | 711 |
_this.redraw(); |
| 5 | 712 |
}); |
| 37 | 713 |
} |
714 |
Rkns.Renderer.EdgeEditor.prototype.redraw = function() { |
|
715 |
var _coords = this.edge_representation.paper_coords; |
|
716 |
Rkns.Renderer.Utils.drawEditBox(_coords, this.editor_block, 250, 5, this.editor_$); |
|
717 |
this.editor_$.show(); |
|
| 23 | 718 |
paper.view.draw(); |
| 5 | 719 |
} |
720 |
||
| 7 | 721 |
Rkns.Renderer.EdgeEditor.prototype.destroy = function() { |
| 5 | 722 |
this.editor_block.remove(); |
723 |
this.editor_$.detach(); |
|
| 4 | 724 |
} |
| 2 | 725 |
|
726 |
/* */ |
|
| 1 | 727 |
|
| 23 | 728 |
Rkns.Renderer.NodeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 729 |
|
730 |
Rkns.Renderer.NodeEditButton.prototype._init = function() { |
|
| 35 | 731 |
this.renderer.overlay_layer.activate(); |
| 20 | 732 |
this.type = "Node-edit-button"; |
| 38 | 733 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, - 90, 30, 1, 'img/edit.png', this.renderer.renkan.l10n.caption_edit); |
| 7 | 734 |
} |
735 |
||
736 |
Rkns.Renderer.NodeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 737 |
this.sector.moveTo(_pos); |
| 7 | 738 |
} |
739 |
||
740 |
Rkns.Renderer.NodeEditButton.prototype.show = function() { |
|
| 18 | 741 |
this.sector.show(); |
| 7 | 742 |
} |
743 |
||
744 |
Rkns.Renderer.NodeEditButton.prototype.hide = function() { |
|
| 18 | 745 |
this.sector.hide(); |
| 7 | 746 |
} |
747 |
||
748 |
Rkns.Renderer.NodeEditButton.prototype.select = function() { |
|
| 18 | 749 |
this.sector.select(); |
| 7 | 750 |
} |
751 |
||
| 35 | 752 |
Rkns.Renderer.NodeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 753 |
this.sector.unselect(); |
| 35 | 754 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
755 |
this.node_representation.unselect(); |
|
756 |
} |
|
| 7 | 757 |
} |
758 |
||
759 |
Rkns.Renderer.NodeEditButton.prototype.mouseup = function() { |
|
| 23 | 760 |
if (!this.renderer.is_dragging) { |
761 |
this.node_representation.openEditor(); |
|
| 7 | 762 |
} |
763 |
} |
|
764 |
||
765 |
Rkns.Renderer.NodeEditButton.prototype.destroy = function() { |
|
| 18 | 766 |
this.sector.destroy(); |
| 7 | 767 |
} |
768 |
||
769 |
/* */ |
|
770 |
||
| 23 | 771 |
Rkns.Renderer.NodeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 7 | 772 |
|
773 |
Rkns.Renderer.NodeRemoveButton.prototype._init = function() { |
|
| 35 | 774 |
this.renderer.overlay_layer.activate(); |
| 20 | 775 |
this.type = "Node-remove-button"; |
| 38 | 776 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, -210, -90, 1, 'img/remove.png', this.renderer.renkan.l10n.caption_remove); |
| 7 | 777 |
} |
778 |
||
779 |
Rkns.Renderer.NodeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 780 |
this.sector.moveTo(_pos); |
| 7 | 781 |
} |
782 |
||
783 |
Rkns.Renderer.NodeRemoveButton.prototype.show = function() { |
|
| 18 | 784 |
this.sector.show(); |
| 7 | 785 |
} |
786 |
||
787 |
Rkns.Renderer.NodeRemoveButton.prototype.hide = function() { |
|
| 18 | 788 |
this.sector.hide(); |
| 7 | 789 |
} |
790 |
||
791 |
Rkns.Renderer.NodeRemoveButton.prototype.select = function() { |
|
| 18 | 792 |
this.sector.select(); |
| 7 | 793 |
} |
794 |
||
| 35 | 795 |
Rkns.Renderer.NodeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 796 |
this.sector.unselect(); |
| 35 | 797 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
798 |
this.node_representation.unselect(); |
|
799 |
} |
|
| 7 | 800 |
} |
801 |
||
802 |
Rkns.Renderer.NodeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
803 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 804 |
if (confirm('Do you really wish to remove node "' + this.node_representation.model.get("title") + '"?')) { |
805 |
this.project.removeNode(this.node_representation.model); |
|
| 10 | 806 |
} |
| 7 | 807 |
} |
808 |
||
809 |
Rkns.Renderer.NodeRemoveButton.prototype.destroy = function() { |
|
| 18 | 810 |
this.sector.destroy(); |
| 7 | 811 |
} |
812 |
||
813 |
/* */ |
|
814 |
||
| 23 | 815 |
Rkns.Renderer.NodeLinkButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 11 | 816 |
|
817 |
Rkns.Renderer.NodeLinkButton.prototype._init = function() { |
|
| 35 | 818 |
this.renderer.overlay_layer.activate(); |
| 20 | 819 |
this.type = "Node-link-button"; |
| 38 | 820 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._NODE_BUTTON_INNER, Rkns.Renderer._NODE_BUTTON_OUTER, 30, 150, 1, 'img/link.png', this.renderer.renkan.l10n.caption_link); |
| 11 | 821 |
} |
822 |
||
823 |
Rkns.Renderer.NodeLinkButton.prototype.moveTo = function(_pos) { |
|
| 18 | 824 |
this.sector.moveTo(_pos); |
| 11 | 825 |
} |
826 |
||
827 |
Rkns.Renderer.NodeLinkButton.prototype.show = function() { |
|
| 18 | 828 |
this.sector.show(); |
| 11 | 829 |
} |
830 |
||
831 |
Rkns.Renderer.NodeLinkButton.prototype.hide = function() { |
|
| 18 | 832 |
this.sector.hide(); |
| 11 | 833 |
} |
834 |
||
835 |
Rkns.Renderer.NodeLinkButton.prototype.select = function() { |
|
| 18 | 836 |
this.sector.select(); |
| 11 | 837 |
} |
838 |
||
| 35 | 839 |
Rkns.Renderer.NodeLinkButton.prototype.unselect = function(_newTarget) { |
| 18 | 840 |
this.sector.unselect(); |
| 35 | 841 |
if (!_newTarget || (_newTarget !== this.node_representation && _newTarget.node_representation !== this.node_representation)) { |
842 |
this.node_representation.unselect(); |
|
843 |
} |
|
| 11 | 844 |
} |
845 |
||
846 |
Rkns.Renderer.NodeLinkButton.prototype.destroy = function() { |
|
| 18 | 847 |
this.sector.destroy(); |
| 11 | 848 |
} |
849 |
||
850 |
/* */ |
|
851 |
||
| 23 | 852 |
Rkns.Renderer.EdgeEditButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 853 |
|
854 |
Rkns.Renderer.EdgeEditButton.prototype._init = function() { |
|
| 35 | 855 |
this.renderer.overlay_layer.activate(); |
| 20 | 856 |
this.type = "Edge-edit-button"; |
| 38 | 857 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 90, 90, 1, 'img/edit.png', this.renderer.renkan.l10n.caption_edit); |
| 15 | 858 |
} |
859 |
||
860 |
Rkns.Renderer.EdgeEditButton.prototype.moveTo = function(_pos) { |
|
| 18 | 861 |
this.sector.moveTo(_pos); |
| 15 | 862 |
} |
863 |
||
864 |
Rkns.Renderer.EdgeEditButton.prototype.show = function() { |
|
| 18 | 865 |
this.sector.show(); |
| 15 | 866 |
} |
867 |
||
868 |
Rkns.Renderer.EdgeEditButton.prototype.hide = function() { |
|
| 18 | 869 |
this.sector.hide(); |
| 15 | 870 |
} |
871 |
||
872 |
Rkns.Renderer.EdgeEditButton.prototype.select = function() { |
|
| 18 | 873 |
this.sector.select(); |
| 15 | 874 |
} |
875 |
||
| 35 | 876 |
Rkns.Renderer.EdgeEditButton.prototype.unselect = function(_newTarget) { |
| 18 | 877 |
this.sector.unselect(); |
| 35 | 878 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
879 |
this.edge_representation.unselect(); |
|
880 |
} |
|
| 15 | 881 |
} |
882 |
||
883 |
Rkns.Renderer.EdgeEditButton.prototype.mouseup = function() { |
|
| 23 | 884 |
if (!this.renderer.is_dragging) { |
885 |
this.edge_representation.openEditor(); |
|
| 15 | 886 |
} |
887 |
} |
|
888 |
||
889 |
Rkns.Renderer.EdgeEditButton.prototype.destroy = function() { |
|
| 18 | 890 |
this.sector.destroy(); |
| 15 | 891 |
} |
892 |
||
893 |
/* */ |
|
894 |
||
| 23 | 895 |
Rkns.Renderer.EdgeRemoveButton = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
| 15 | 896 |
|
897 |
Rkns.Renderer.EdgeRemoveButton.prototype._init = function() { |
|
| 35 | 898 |
this.renderer.overlay_layer.activate(); |
| 20 | 899 |
this.type = "Edge-remove-button"; |
| 38 | 900 |
this.sector = Rkns.Renderer.Utils.sector(this, Rkns.Renderer._EDGE_BUTTON_INNER, Rkns.Renderer._EDGE_BUTTON_OUTER, - 270, -90, 1, 'img/remove.png', this.renderer.renkan.l10n.caption_remove); |
| 15 | 901 |
} |
902 |
Rkns.Renderer.EdgeRemoveButton.prototype.moveTo = function(_pos) { |
|
| 18 | 903 |
this.sector.moveTo(_pos); |
| 15 | 904 |
} |
905 |
||
906 |
Rkns.Renderer.EdgeRemoveButton.prototype.show = function() { |
|
| 18 | 907 |
this.sector.show(); |
| 15 | 908 |
} |
909 |
||
910 |
Rkns.Renderer.EdgeRemoveButton.prototype.hide = function() { |
|
| 18 | 911 |
this.sector.hide(); |
| 15 | 912 |
} |
913 |
||
914 |
Rkns.Renderer.EdgeRemoveButton.prototype.select = function() { |
|
| 18 | 915 |
this.sector.select(); |
| 15 | 916 |
} |
917 |
||
| 35 | 918 |
Rkns.Renderer.EdgeRemoveButton.prototype.unselect = function(_newTarget) { |
| 18 | 919 |
this.sector.unselect(); |
| 35 | 920 |
if (!_newTarget || (_newTarget !== this.edge_representation && _newTarget.edge_representation !== this.edge_representation)) { |
921 |
this.edge_representation.unselect(); |
|
922 |
} |
|
| 15 | 923 |
} |
924 |
||
925 |
Rkns.Renderer.EdgeRemoveButton.prototype.mouseup = function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
926 |
this.renderer.removeRepresentationsOfType("editor"); |
| 23 | 927 |
if (confirm('Do you really wish to remove edge "' + this.edge_representation.model.get("title") + '"?')) { |
928 |
this.project.removeEdge(this.edge_representation.model); |
|
| 15 | 929 |
} |
930 |
} |
|
931 |
||
932 |
Rkns.Renderer.EdgeRemoveButton.prototype.destroy = function() { |
|
| 18 | 933 |
this.sector.destroy(); |
| 15 | 934 |
} |
935 |
||
936 |
/* */ |
|
937 |
||
| 23 | 938 |
Rkns.Renderer.Scene = function(_renkan) { |
939 |
this.renkan = _renkan; |
|
| 20 | 940 |
this.$ = Rkns.$(".Rk-Render"); |
| 23 | 941 |
this.representations = []; |
| 20 | 942 |
this.$.html(this.template({ |
| 23 | 943 |
l10n: _renkan.l10n |
| 20 | 944 |
})) |
945 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
946 |
this.editor_$ = this.$.find(".Rk-Editor"); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
947 |
this.notif_$ = this.$.find(".Rk-Notifications"); |
| 20 | 948 |
paper.setup(this.canvas_$[0]); |
| 2 | 949 |
this.scale = 1; |
950 |
this.offset = paper.view.center; |
|
951 |
this.totalScroll = 0; |
|
| 5 | 952 |
this.click_target = null; |
| 4 | 953 |
this.selected_target = null; |
| 2 | 954 |
this.edge_layer = new paper.Layer(); |
955 |
this.node_layer = new paper.Layer(); |
|
| 5 | 956 |
this.overlay_layer = new paper.Layer(); |
| 31 | 957 |
this.bundles = []; |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
958 |
this.click_mode = false; |
| 2 | 959 |
var _tool = new paper.Tool(), |
960 |
_this = this; |
|
| 28 | 961 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
| 4 | 962 |
_tool.onMouseMove = function(_event) { |
963 |
_this.onMouseMove(_event); |
|
964 |
} |
|
| 2 | 965 |
_tool.onMouseDown = function(_event) { |
966 |
_this.onMouseDown(_event); |
|
967 |
} |
|
968 |
_tool.onMouseDrag = function(_event) { |
|
969 |
_this.onMouseDrag(_event); |
|
970 |
} |
|
| 21 | 971 |
this.canvas_$.mouseup(function(_event) { |
| 4 | 972 |
_this.onMouseUp(_event); |
| 21 | 973 |
}); |
| 20 | 974 |
this.canvas_$.mousewheel(function(_event, _delta) { |
| 2 | 975 |
_this.onScroll(_event, _delta); |
| 21 | 976 |
}); |
| 20 | 977 |
this.canvas_$.dblclick(function(_event) { |
| 4 | 978 |
_this.onDoubleClick(_event); |
| 11 | 979 |
}); |
| 21 | 980 |
this.canvas_$.mouseenter(function(_event) { |
981 |
_this.onMouseEnter(_event); |
|
982 |
}); |
|
| 11 | 983 |
this.editor_$.find(".Rk-ZoomOut").click(function() { |
984 |
_this.offset = new paper.Point([ |
|
| 20 | 985 |
_this.canvas_$.width(), |
986 |
_this.canvas_$.height() |
|
| 11 | 987 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
| 28 | 988 |
_this.setScale( _this.scale * Math.SQRT1_2 ); |
| 11 | 989 |
_this.redraw(); |
990 |
}); |
|
991 |
this.editor_$.find(".Rk-ZoomIn").click(function() { |
|
992 |
_this.offset = new paper.Point([ |
|
| 20 | 993 |
_this.canvas_$.width(), |
994 |
_this.canvas_$.height() |
|
| 11 | 995 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
| 28 | 996 |
_this.setScale( _this.scale * Math.SQRT2 ); |
| 11 | 997 |
_this.redraw(); |
998 |
}); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
999 |
this.$.find(".Rk-CurrentUser").mouseenter( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1000 |
function() { _this.$.find(".Rk-UserList").slideDown() } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1001 |
); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1002 |
this.$.find(".Rk-Users").mouseleave( |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1003 |
function() { _this.$.find(".Rk-UserList").slideUp(); } |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1004 |
); |
| 34 | 1005 |
this.$.find(".Rk-FullScreen-Button").click(function() { |
1006 |
var _isFull = document.fullScreen || document.mozFullScreen || document.webkitIsFullScreen, |
|
1007 |
_el = _this.renkan.$[0], |
|
1008 |
_requestMethods = ["requestFullScreen","mozRequestFullScreen","webkitRequestFullScreen"], |
|
1009 |
_cancelMethods = ["cancelFullScreen","mozCancelFullScreen","webkitCancelFullScreen"]; |
|
1010 |
if (_isFull) { |
|
1011 |
for (var i = 0; i < _cancelMethods.length; i++) { |
|
1012 |
if (typeof document[_cancelMethods[i]] === "function") { |
|
1013 |
document[_cancelMethods[i]](); |
|
1014 |
break; |
|
1015 |
} |
|
1016 |
} |
|
1017 |
} else { |
|
1018 |
for (var i = 0; i < _requestMethods.length; i++) { |
|
1019 |
if (typeof _el[_requestMethods[i]] === "function") { |
|
1020 |
_el[_requestMethods[i]](); |
|
1021 |
break; |
|
1022 |
} |
|
1023 |
} |
|
1024 |
} |
|
1025 |
}); |
|
1026 |
this.$.find(".Rk-AddNode-Button").click(function() { |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1027 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1028 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1029 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1030 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1031 |
_this.click_mode = Rkns.Renderer._CLICKMODE_ADDNODE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1032 |
_this.notif_$.html(_renkan.l10n.notif_add_node).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1033 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1034 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1035 |
this.$.find(".Rk-AddEdge-Button").click(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1036 |
if (_this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE || _this.click_mode === Rkns.Renderer._CLICKMODE_ENDEDGE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1037 |
_this.click_mode = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1038 |
_this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1039 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1040 |
_this.click_mode = Rkns.Renderer._CLICKMODE_STARTEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1041 |
_this.notif_$.html(_renkan.l10n.notif_start_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1042 |
} |
| 34 | 1043 |
}); |
1044 |
this.$.find(".Rk-TopBar-Button").mouseover(function() { |
|
1045 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").show(); |
|
1046 |
}).mouseout(function() { |
|
1047 |
Rkns.$(this).find(".Rk-TopBar-Tooltip").hide(); |
|
1048 |
}); |
|
1049 |
|
|
| 2 | 1050 |
paper.view.onResize = function(_event) { |
1051 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
1052 |
_this.redraw(); |
|
1053 |
} |
|
| 23 | 1054 |
|
1055 |
var _thRedraw = Rkns._.throttle(function() { |
|
1056 |
_this.redraw(); |
|
1057 |
},50); |
|
1058 |
|
|
1059 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
1060 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
| 34 | 1061 |
this.renkan.project.get("users").each(function(_user) { |
1062 |
_this.addUser(_user); |
|
1063 |
}) |
|
| 23 | 1064 |
|
| 34 | 1065 |
this.renkan.project.on("add:users", function(_user) { |
1066 |
_this.addUser(_user); |
|
1067 |
}); |
|
| 23 | 1068 |
this.renkan.project.on("add:nodes", function(_node) { |
1069 |
_this.addRepresentation("Node", _node); |
|
1070 |
_thRedraw(); |
|
1071 |
}); |
|
1072 |
this.renkan.project.on("add:edges", function(_edge) { |
|
1073 |
_this.addRepresentation("Edge", _edge); |
|
1074 |
_thRedraw(); |
|
1075 |
}); |
|
1076 |
|
|
1077 |
this.redraw(); |
|
| 2 | 1078 |
} |
1079 |
||
| 20 | 1080 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1081 |
'<div class="Rk-TopBar"><h3 class="Rk-PadTitle"><%=l10n.untitled_project%></h3>' |
| 34 | 1082 |
+ '<div class="Rk-Users"><div class="Rk-CurrentUser"><span class="Rk-CurrentUser-Color"></span><span class="Rk-CurrentUser-Name"><unknown user></span></div><ul class="Rk-UserList"></ul></div>' |
1083 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-FullScreen-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.full_screen%></div></div></div>' |
|
1084 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddNode-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_node%></div></div></div>' |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1085 |
+ '<div class="Rk-TopBar-Separator"></div><div class="Rk-TopBar-Button Rk-AddEdge-Button"><div class="Rk-TopBar-Tooltip"><div class="Rk-TopBar-Tooltip-Tip"></div><div class="Rk-TopBar-Tooltip-Contents"><%=l10n.add_edge%></div></div></div>' |
| 34 | 1086 |
+ '<div class="Rk-TopBar-Separator"></div></div>' |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1087 |
+ '<canvas class="Rk-Canvas" resize></canvas><div class="Rk-Editor"><div class="Rk-Notifications"></div>' |
| 20 | 1088 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
1089 |
+ '</div>' |
|
| 11 | 1090 |
); |
1091 |
||
| 31 | 1092 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
1093 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
1094 |
return ( |
|
1095 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
1096 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
1097 |
); |
|
1098 |
}); |
|
1099 |
if (typeof _bundle !== "undefined") { |
|
1100 |
_bundle.edges.push(_edgeRepr) |
|
1101 |
} else { |
|
1102 |
_bundle = { |
|
1103 |
from: _edgeRepr.from_representation, |
|
1104 |
to: _edgeRepr.to_representation, |
|
1105 |
edges: [ _edgeRepr ], |
|
1106 |
getPosition: function(_er) { |
|
1107 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
1108 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
1109 |
} |
|
1110 |
} |
|
1111 |
this.bundles.push(_bundle); |
|
1112 |
} |
|
1113 |
return _bundle; |
|
1114 |
} |
|
1115 |
||
| 28 | 1116 |
Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { |
1117 |
this.scale = _newScale; |
|
1118 |
this.redraw(); |
|
1119 |
} |
|
1120 |
||
| 25 | 1121 |
Rkns.Renderer.Scene.prototype.autoScale = function() { |
| 26 | 1122 |
if (this.renkan.project.get("nodes").length) { |
1123 |
var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }), |
|
1124 |
_yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }), |
|
1125 |
_minx = Math.min.apply(Math, _xx), |
|
1126 |
_miny = Math.min.apply(Math, _yy), |
|
1127 |
_maxx = Math.max.apply(Math, _xx), |
|
1128 |
_maxy = Math.max.apply(Math, _yy); |
|
| 28 | 1129 |
var _scale = Math.min((paper.view.size.width - 2 * Rkns.Renderer._MARGIN_X) / (_maxx - _minx), (paper.view.size.height - 2 * Rkns.Renderer._MARGIN_Y) / (_maxy - _miny)); |
1130 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(_scale)); |
|
1131 |
this.setScale(_scale); |
|
| 26 | 1132 |
} |
| 25 | 1133 |
} |
1134 |
||
| 7 | 1135 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
| 2 | 1136 |
return _point.multiply(this.scale).add(this.offset); |
1137 |
} |
|
1138 |
||
1139 |
||
| 7 | 1140 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
| 2 | 1141 |
return _point.subtract(this.offset).divide(this.scale); |
| 1 | 1142 |
} |
1143 |
||
| 23 | 1144 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
1145 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
1146 |
this.representations.push(_repr); |
|
1147 |
return _repr; |
|
1148 |
} |
|
1149 |
||
1150 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
1151 |
var _this = this; |
|
1152 |
_collection.forEach(function(_model) { |
|
1153 |
_this.addRepresentation(_type, _model); |
|
| 1 | 1154 |
}); |
1155 |
} |
|
1156 |
||
| 34 | 1157 |
Rkns.Renderer.Scene.prototype.userTemplate = Rkns._.template( |
1158 |
'<li class="Rk-User"><span class="Rk-UserColor" style="background:<%=background%>;"></span><%=name%></li>' |
|
1159 |
); |
|
1160 |
||
1161 |
Rkns.Renderer.Scene.prototype.addUser = function(_user) { |
|
1162 |
if (_user.get("_id") === this.renkan.current_user) { |
|
1163 |
this.$.find(".Rk-CurrentUser-Name").text(_user.get("title")); |
|
1164 |
this.$.find(".Rk-CurrentUser-Color").css("background", _user.get("color")); |
|
1165 |
} else { |
|
1166 |
this.$.find(".Rk-UserList").append( |
|
1167 |
Rkns.$( |
|
1168 |
this.userTemplate({ |
|
1169 |
name: _user.get("title"), |
|
1170 |
background: _user.get("color") |
|
1171 |
}) |
|
1172 |
) |
|
1173 |
); |
|
1174 |
} |
|
1175 |
} |
|
1176 |
||
| 23 | 1177 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
1178 |
_representation.destroy(); |
|
1179 |
this.representations = Rkns._(this.representations).reject( |
|
1180 |
function(_repr) { |
|
1181 |
return _repr == _representation |
|
1182 |
} |
|
1183 |
); |
|
| 4 | 1184 |
} |
1185 |
||
| 23 | 1186 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
1187 |
return Rkns._(this.representations).find(function(_repr) { |
|
1188 |
return _repr.model === _model; |
|
1189 |
}); |
|
| 5 | 1190 |
} |
1191 |
||
| 23 | 1192 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
1193 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
1194 |
return _repr.type == _type; |
|
| 5 | 1195 |
}), |
1196 |
_this = this; |
|
| 23 | 1197 |
Rkns._(_representations).each(function(_repr) { |
1198 |
_this.removeRepresentation(_repr); |
|
| 5 | 1199 |
}); |
1200 |
} |
|
1201 |
||
| 26 | 1202 |
Rkns.Renderer.Scene.prototype.highlightModel = function(_model) { |
1203 |
var _repr = this.getRepresentationByModel(_model); |
|
1204 |
if (_repr) { |
|
1205 |
_repr.highlight(); |
|
1206 |
} |
|
1207 |
} |
|
1208 |
||
1209 |
Rkns.Renderer.Scene.prototype.unhighlightAll = function(_model) { |
|
1210 |
Rkns._(this.representations).each(function(_repr) { |
|
1211 |
_repr.unhighlight(); |
|
1212 |
}); |
|
1213 |
} |
|
1214 |
||
| 7 | 1215 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
| 23 | 1216 |
Rkns._(this.representations).each(function(_representation) { |
1217 |
_representation.redraw(); |
|
| 2 | 1218 |
}); |
1219 |
paper.view.draw(); |
|
1220 |
} |
|
1221 |
||
| 11 | 1222 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
| 23 | 1223 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
| 11 | 1224 |
_tmpEdge.end_pos = _point; |
| 23 | 1225 |
_tmpEdge.from_representation = _from; |
| 11 | 1226 |
_tmpEdge.redraw(); |
1227 |
this.click_target = _tmpEdge; |
|
1228 |
} |
|
1229 |
||
| 21 | 1230 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
| 23 | 1231 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
1232 |
var _newTarget = _hitResult.item.__representation; |
|
1233 |
if (this.selected_target !== _hitResult.item.__representation) { |
|
| 4 | 1234 |
if (this.selected_target) { |
| 7 | 1235 |
this.selected_target.unselect(_newTarget); |
| 4 | 1236 |
} |
| 7 | 1237 |
_newTarget.select(this.selected_target); |
1238 |
this.selected_target = _newTarget; |
|
| 4 | 1239 |
} |
1240 |
} else { |
|
1241 |
if (this.selected_target) { |
|
| 7 | 1242 |
this.selected_target.unselect(null); |
| 4 | 1243 |
} |
1244 |
this.selected_target = null; |
|
1245 |
} |
|
1246 |
} |
|
1247 |
||
| 21 | 1248 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
1249 |
var _hitResult = paper.project.hitTest(_event.point); |
|
1250 |
if (this.is_dragging) { |
|
1251 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
1252 |
this.click_target.paperShift(_event.delta); |
|
1253 |
} else { |
|
1254 |
this.offset = this.offset.add(_event.delta); |
|
1255 |
this.redraw(); |
|
1256 |
} |
|
1257 |
} else { |
|
1258 |
this.findTarget(_hitResult); |
|
1259 |
} |
|
1260 |
} |
|
1261 |
||
| 7 | 1262 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1263 |
if (!this.click_target || this.click_target.type !== "temp-edge") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1264 |
this.is_dragging = false; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1265 |
var _hitResult = paper.project.hitTest(_event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1266 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1267 |
this.click_target = _hitResult.item.__representation; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1268 |
if (this.click_target.type === "Node-link-button") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1269 |
this.removeRepresentationsOfType("editor"); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1270 |
this.addTempEdge(this.click_target.node_representation, _event.point); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1271 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1272 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1273 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1274 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_ADDNODE) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1275 |
var _coords = this.toModelCoords(_event.point), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1276 |
_data = { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1277 |
id: Rkns.Utils.getUID('node'), |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1278 |
created_by: this.renkan.current_user, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1279 |
position: { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1280 |
x: _coords.x, |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1281 |
y: _coords.y |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1282 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1283 |
}; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1284 |
_node = this.renkan.project.addNode(_data); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1285 |
this.getRepresentationByModel(_node).openEditor(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1286 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1287 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1288 |
} |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1289 |
if (this.click_mode) { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1290 |
if (this.click_mode === Rkns.Renderer._CLICKMODE_STARTEDGE && this.click_target && this.click_target.type === "Node") { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1291 |
this.removeRepresentationsOfType("editor"); |
| 11 | 1292 |
this.addTempEdge(this.click_target, _event.point); |
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1293 |
this.click_mode = Rkns.Renderer._CLICKMODE_ENDEDGE; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1294 |
this.notif_$.fadeOut(function() { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1295 |
Rkns.$(this).html(_renkan.l10n.notif_end_edge).fadeIn(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1296 |
}); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1297 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1298 |
this.notif_$.hide(); |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1299 |
this.click_mode = false; |
| 11 | 1300 |
} |
| 2 | 1301 |
} |
| 1 | 1302 |
} |
| 2 | 1303 |
|
| 7 | 1304 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
| 5 | 1305 |
this.is_dragging = true; |
| 21 | 1306 |
this.onMouseMove(_event); |
| 2 | 1307 |
} |
1308 |
||
| 7 | 1309 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
| 5 | 1310 |
if (this.click_target) { |
| 21 | 1311 |
var _off = this.canvas_$.offset(); |
1312 |
this.click_target.mouseup( |
|
1313 |
{ |
|
1314 |
point: new paper.Point([ |
|
1315 |
_event.pageX - _off.left, |
|
1316 |
_event.pageY - _off.top |
|
1317 |
]) |
|
1318 |
} |
|
1319 |
); |
|
|
36
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1320 |
} else { |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1321 |
this.click_target = null; |
|
d249d36ecc37
Add Edge button, French translation and various bugfixes
veltr
parents:
35
diff
changeset
|
1322 |
this.is_dragging = false; |
| 4 | 1323 |
} |
1324 |
} |
|
1325 |
||
| 7 | 1326 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
| 3 | 1327 |
this.totalScroll += _scrolldelta; |
| 2 | 1328 |
if (Math.abs(this.totalScroll) >= 1) { |
| 20 | 1329 |
var _off = this.canvas_$.offset(), |
| 3 | 1330 |
_delta = new paper.Point([ |
1331 |
_event.pageX - _off.left, |
|
1332 |
_event.pageY - _off.top |
|
1333 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
| 2 | 1334 |
if (this.totalScroll > 0) { |
| 3 | 1335 |
this.offset = this.offset.subtract(_delta); |
| 28 | 1336 |
this.setScale( this.scale * Math.SQRT2 ); |
| 2 | 1337 |
} else { |
| 3 | 1338 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
| 28 | 1339 |
this.setScale( this.scale * Math.SQRT1_2); |
| 2 | 1340 |
} |
1341 |
this.totalScroll = 0; |
|
1342 |
this.redraw(); |
|
1343 |
} |
|
1344 |
} |
|
| 4 | 1345 |
|
| 7 | 1346 |
Rkns.Renderer.Scene.prototype.onDoubleClick = function(_event) { |
| 20 | 1347 |
var _off = this.canvas_$.offset(), |
| 4 | 1348 |
_point = new paper.Point([ |
1349 |
_event.pageX - _off.left, |
|
1350 |
_event.pageY - _off.top |
|
1351 |
]); |
|
1352 |
var _hitResult = paper.project.hitTest(_point); |
|
| 23 | 1353 |
if (!_hitResult || typeof _hitResult.item.__representation === "undefined") { |
| 8 | 1354 |
var _coords = this.toModelCoords(_point), |
| 23 | 1355 |
_data = { |
1356 |
id: Rkns.Utils.getUID('node'), |
|
1357 |
created_by: this.renkan.current_user, |
|
| 8 | 1358 |
position: { |
1359 |
x: _coords.x, |
|
1360 |
y: _coords.y |
|
1361 |
} |
|
| 23 | 1362 |
}; |
1363 |
_node = this.renkan.project.addNode(_data); |
|
1364 |
this.getRepresentationByModel(_node).openEditor(); |
|
| 4 | 1365 |
} |
1366 |
paper.view.draw(); |
|
1367 |
} |
|
| 21 | 1368 |
|
1369 |
Rkns.Renderer.Scene.prototype.onMouseEnter = function(_event) { |
|
1370 |
var _newEl = this.renkan.selected_bin_item; |
|
1371 |
if (_newEl) { |
|
1372 |
var _off = this.canvas_$.offset(), |
|
1373 |
_point = new paper.Point([ |
|
1374 |
_event.pageX - _off.left, |
|
1375 |
_event.pageY - _off.top |
|
1376 |
]), |
|
1377 |
_coords = this.toModelCoords(_point), |
|
| 23 | 1378 |
_data = { |
1379 |
id: Rkns.Utils.getUID('node'), |
|
1380 |
created_by: this.renkan.current_user, |
|
| 21 | 1381 |
uri: _newEl.uri, |
1382 |
title: _newEl.title, |
|
1383 |
description: _newEl.description, |
|
| 37 | 1384 |
image: _newEl.image, |
| 21 | 1385 |
position: { |
1386 |
x: _coords.x, |
|
1387 |
y: _coords.y |
|
1388 |
} |
|
| 23 | 1389 |
}; |
1390 |
var _node = this.renkan.project.addNode(_data); |
|
1391 |
this.renkan.selected_bin_item = null; |
|
| 21 | 1392 |
this.is_dragging = true; |
| 23 | 1393 |
this.click_target = this.getRepresentationByModel(_node); |
| 21 | 1394 |
} |
1395 |
} |