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