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