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