|
938
|
1 |
/* |
|
|
2 |
* Copyright 2012 Institut de recherche et d'innovation |
|
|
3 |
* contributor(s) : Yves-Marie Haussonne, Raphael Velt, Samuel Huron |
|
|
4 |
* |
|
|
5 |
* contact@iri.centrepompidou.fr |
|
|
6 |
* http://www.iri.centrepompidou.fr |
|
|
7 |
* |
|
|
8 |
* This software is a computer program whose purpose is to show and add annotations on a video . |
|
|
9 |
* This software is governed by the CeCILL-C license under French law and |
|
|
10 |
* abiding by the rules of distribution of free software. You can use, |
|
|
11 |
* modify and/ or redistribute the software under the terms of the CeCILL-C |
|
|
12 |
* license as circulated by CEA, CNRS and INRIA at the following URL |
|
|
13 |
* "http://www.cecill.info". |
|
|
14 |
* |
|
|
15 |
* The fact that you are presently reading this means that you have had |
|
|
16 |
* knowledge of the CeCILL-C license and that you accept its terms. |
|
|
17 |
*/ |
|
|
18 |
|
|
|
19 |
if (typeof Rkns !== "object") { |
|
|
20 |
Rkns = {} |
|
|
21 |
} |
|
|
22 |
|
|
|
23 |
Rkns.$ = jQuery; |
|
|
24 |
|
|
|
25 |
Rkns._ = _; |
|
|
26 |
|
|
|
27 |
Rkns.i18n = { |
|
|
28 |
en: { |
|
|
29 |
zoom_in: "Zoom In", |
|
|
30 |
zoom_out: "Zoom Out" |
|
|
31 |
} |
|
|
32 |
} |
|
|
33 |
|
|
|
34 |
Rkns.Utils = { |
|
|
35 |
inherit : function(_baseClass) { |
|
|
36 |
var _class = function() { |
|
|
37 |
_baseClass.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
38 |
if (typeof this._init == "function") { |
|
|
39 |
this._init.apply(this, Array.prototype.slice.call(arguments, 0)); |
|
|
40 |
} |
|
|
41 |
} |
|
|
42 |
_class.prototype = new _baseClass(); |
|
|
43 |
return _class; |
|
|
44 |
} |
|
|
45 |
} |
|
|
46 |
|
|
|
47 |
Rkns.Models = {}; |
|
|
48 |
|
|
|
49 |
Rkns.Models.getUID = function(obj) { |
|
|
50 |
var guid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { |
|
|
51 |
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); |
|
|
52 |
return v.toString(16); |
|
|
53 |
}); |
|
|
54 |
return obj.type + "-" + guid; |
|
|
55 |
}; |
|
|
56 |
|
|
|
57 |
Rkns.Models.RenkanModel = Backbone.RelationalModel.extend({ |
|
|
58 |
idAttribute : "_id", |
|
|
59 |
constructor: function(options) { |
|
|
60 |
|
|
|
61 |
if (typeof options !== "undefined") { |
|
|
62 |
options._id = options._id || options.id || Rkns.Models.getUID(this); |
|
|
63 |
options.title = options.title || "(untitled " + this.type + ")"; |
|
|
64 |
options.description = options.description || ""; |
|
|
65 |
options.uri = options.uri || ""; |
|
|
66 |
|
|
|
67 |
if(typeof this.prepare === "function") { |
|
|
68 |
options = this.prepare(options); |
|
|
69 |
} |
|
|
70 |
} |
|
|
71 |
Backbone.RelationalModel.prototype.constructor.call(this, options); |
|
|
72 |
}, |
|
|
73 |
validate: function() { |
|
|
74 |
if(!this.type) { |
|
|
75 |
return "object has no type"; |
|
|
76 |
} |
|
|
77 |
}, |
|
|
78 |
addReference : function(_options, _propName, _list, _id, _default) { |
|
|
79 |
var _element = _list.get(_id); |
|
|
80 |
if (typeof _element === "undefined" && typeof _default !== "undefined") { |
|
|
81 |
_options[_propName ] = _default; |
|
|
82 |
} |
|
|
83 |
else { |
|
|
84 |
_options[_propName ] = _element; |
|
|
85 |
} |
|
|
86 |
} |
|
|
87 |
}); |
|
|
88 |
|
|
|
89 |
// USER |
|
|
90 |
Rkns.Models.User = Rkns.Models.RenkanModel.extend({ |
|
|
91 |
type: "user", |
|
|
92 |
prepare: function(options) { |
|
|
93 |
options.color = options.color || "#666666"; |
|
|
94 |
return options; |
|
|
95 |
}, |
|
|
96 |
toJSON: function() { |
|
|
97 |
return { |
|
|
98 |
id: this.get("_id"), |
|
|
99 |
title: this.get("title"), |
|
|
100 |
uri: this.get("uri"), |
|
|
101 |
description: this.get("description"), |
|
|
102 |
color: this.get("color"), |
|
|
103 |
} |
|
|
104 |
}, |
|
|
105 |
}); |
|
|
106 |
|
|
|
107 |
// NODE |
|
|
108 |
Rkns.Models.Node = Rkns.Models.RenkanModel.extend({ |
|
|
109 |
type: "node", |
|
|
110 |
relations: [{ |
|
|
111 |
type: Backbone.HasOne, |
|
|
112 |
key: "created_by", |
|
|
113 |
relatedModel: Rkns.Models.User |
|
|
114 |
}], |
|
|
115 |
prepare: function(options) { |
|
|
116 |
project = options.project; |
|
|
117 |
this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user); |
|
|
118 |
options.description = options.description || ""; |
|
|
119 |
return options; |
|
|
120 |
}, |
|
|
121 |
toJSON: function() { |
|
|
122 |
return { |
|
|
123 |
id: this.get("_id"), |
|
|
124 |
title: this.get("title"), |
|
|
125 |
uri: this.get("uri"), |
|
|
126 |
description: this.get("description"), |
|
|
127 |
position: this.get("position"), |
|
|
128 |
created_by: this.get("created_by").get("_id") |
|
|
129 |
} |
|
|
130 |
}, |
|
|
131 |
}); |
|
|
132 |
|
|
|
133 |
// EDGE |
|
|
134 |
Rkns.Models.Edge = Rkns.Models.RenkanModel.extend({ |
|
|
135 |
type: "edge", |
|
|
136 |
relations: [ |
|
|
137 |
{ |
|
|
138 |
type: Backbone.HasOne, |
|
|
139 |
key: "created_by", |
|
|
140 |
relatedModel: Rkns.Models.User |
|
|
141 |
}, |
|
|
142 |
{ |
|
|
143 |
type: Backbone.HasOne, |
|
|
144 |
key: "from", |
|
|
145 |
relatedModel: Rkns.Models.Node |
|
|
146 |
}, |
|
|
147 |
{ |
|
|
148 |
type: Backbone.HasOne, |
|
|
149 |
key: "to", |
|
|
150 |
relatedModel: Rkns.Models.Node |
|
|
151 |
}, |
|
|
152 |
], |
|
|
153 |
prepare: function(options) { |
|
|
154 |
project = options.project; |
|
|
155 |
this.addReference(options, "created_by", project.get("users"), options.created_by, project.current_user); |
|
|
156 |
this.addReference(options, "from", project.get("nodes"), options.from); |
|
|
157 |
this.addReference(options, "to", project.get("nodes"), options.to); |
|
|
158 |
return options; |
|
|
159 |
}, |
|
|
160 |
toJSON: function() { |
|
|
161 |
return { |
|
|
162 |
id: this.get("_id"), |
|
|
163 |
title: this.get("title"), |
|
|
164 |
uri: this.get("uri"), |
|
|
165 |
description: this.get("description"), |
|
|
166 |
from: this.get("from").get("_id"), |
|
|
167 |
to: this.get("to").get("_id"), |
|
|
168 |
created_by: this.get("created_by").get("_id"), |
|
|
169 |
} |
|
|
170 |
}, |
|
|
171 |
}); |
|
|
172 |
|
|
|
173 |
// PROJECT |
|
|
174 |
Rkns.Models.Project = Rkns.Models.RenkanModel.extend({ |
|
|
175 |
type: "project", |
|
|
176 |
relations: [ |
|
|
177 |
{ |
|
|
178 |
type: Backbone.HasMany, |
|
|
179 |
key: "users", |
|
|
180 |
relatedModel: Rkns.Models.User, |
|
|
181 |
reverseRelation: { |
|
|
182 |
key: 'project', |
|
|
183 |
includeInJSON: '_id' |
|
|
184 |
}, |
|
|
185 |
}, |
|
|
186 |
{ |
|
|
187 |
type: Backbone.HasMany, |
|
|
188 |
key: "nodes", |
|
|
189 |
relatedModel: Rkns.Models.Node, |
|
|
190 |
reverseRelation: { |
|
|
191 |
key: 'project', |
|
|
192 |
includeInJSON: '_id' |
|
|
193 |
}, |
|
|
194 |
}, |
|
|
195 |
{ |
|
|
196 |
type: Backbone.HasMany, |
|
|
197 |
key: "edges", |
|
|
198 |
relatedModel: Rkns.Models.Edge, |
|
|
199 |
reverseRelation: { |
|
|
200 |
key: 'project', |
|
|
201 |
includeInJSON: '_id' |
|
|
202 |
}, |
|
|
203 |
} |
|
|
204 |
], |
|
|
205 |
addUser: function(_props) { |
|
|
206 |
_props.project = this; |
|
|
207 |
var _user = new Rkns.Models.User(_props); |
|
|
208 |
this.get("users").push(_user); |
|
|
209 |
return _user; |
|
|
210 |
}, |
|
|
211 |
addNode: function(_props) { |
|
|
212 |
_props.project = this; |
|
|
213 |
var _node = new Rkns.Models.Node(_props); |
|
|
214 |
this.get("nodes").push(_node); |
|
|
215 |
return _node; |
|
|
216 |
}, |
|
|
217 |
addEdge: function(_props) { |
|
|
218 |
_props.project = this; |
|
|
219 |
var _edge = new Rkns.Models.Edge(_props); |
|
|
220 |
this.get("edges").push(_edge); |
|
|
221 |
return _edge; |
|
|
222 |
}, |
|
|
223 |
removeNode: function(_model) { |
|
|
224 |
this.get("nodes").remove(_model); |
|
|
225 |
}, |
|
|
226 |
removeEdge: function(_model) { |
|
|
227 |
this.get("edges").remove(_model); |
|
|
228 |
}, |
|
|
229 |
validate: function(options) { |
|
|
230 |
var _project = this; |
|
|
231 |
Rkns._(options.users).each(function(_item) { |
|
|
232 |
_item.project = _project; |
|
|
233 |
}); |
|
|
234 |
Rkns._(options.nodes).each(function(_item) { |
|
|
235 |
_item.project = _project; |
|
|
236 |
}); |
|
|
237 |
Rkns._(options.edges).each(function(_item) { |
|
|
238 |
_item.project = _project; |
|
|
239 |
}); |
|
|
240 |
}, |
|
|
241 |
// Add event handler to remove edges when a node is removed |
|
|
242 |
initialize: function() { |
|
|
243 |
var _this = this; |
|
|
244 |
this.on("remove:nodes", function(_node) { |
|
|
245 |
_this.get("edges").remove( |
|
|
246 |
_this.get("edges").filter(function(_edge) { |
|
|
247 |
return _edge.get("from") == _node || _edge.get("to") == _node; |
|
|
248 |
}) |
|
|
249 |
); |
|
|
250 |
}); |
|
|
251 |
} |
|
|
252 |
}); |
|
|
253 |
|
|
|
254 |
/* Point of entry */ |
|
|
255 |
|
|
|
256 |
Rkns.Renkan = function(_opts) { |
|
|
257 |
if (typeof _opts.language !== "string" || typeof Rkns.i18n[_opts.language] == "undefined") { |
|
|
258 |
_opts.language = "en"; |
|
|
259 |
} |
|
|
260 |
if (typeof _opts.container !== "string") { |
|
|
261 |
_opts.container = "renkan"; |
|
|
262 |
} |
|
|
263 |
if (typeof _opts.search !== "object" || !_opts.search) { |
|
|
264 |
_opts.search = []; |
|
|
265 |
} |
|
|
266 |
this.project = new Rkns.Models.Project(); |
|
|
267 |
this.l10n = Rkns.i18n[_opts.language]; |
|
|
268 |
this.$ = Rkns.$("#" + _opts.container); |
|
|
269 |
this.$.html(this.template()); |
|
|
270 |
this.renderer = new Rkns.Renderer.Scene(this); |
|
|
271 |
} |
|
|
272 |
Rkns.Renkan.prototype.template = Rkns._.template( |
|
|
273 |
'<div class="Rk-Render Rk-Render-Full"></div>' |
|
|
274 |
); |
|
|
275 |
|
|
|
276 |
Rkns.jsonImport = function(_renkan, _opts) { |
|
|
277 |
var _proj = _renkan.project; |
|
|
278 |
if (typeof _opts.http_method == "undefined") { |
|
|
279 |
_opts.http_method = 'PUT'; |
|
|
280 |
} |
|
|
281 |
var _load = function() { |
|
|
282 |
Rkns.$.getJSON(_opts.url, function(_data) { |
|
|
283 |
_proj.set(_data); |
|
|
284 |
_renkan.renderer.autoScale(); |
|
|
285 |
}); |
|
|
286 |
} |
|
|
287 |
_load(); |
|
|
288 |
} |
|
|
289 |
|
|
|
290 |
Rkns.Renderer = { |
|
|
291 |
_MARGIN_X: 80, |
|
|
292 |
_MARGIN_Y: 50, |
|
|
293 |
_MIN_DRAG_DISTANCE: 2, |
|
|
294 |
_NODE_RADIUS: 15, |
|
|
295 |
_NODE_FONT_SIZE: 10, |
|
|
296 |
_EDGE_FONT_SIZE: 9, |
|
|
297 |
_NODE_MAX_CHAR: 30, |
|
|
298 |
_EDGE_MAX_CHAR: 20, |
|
|
299 |
_ARROW_LENGTH: 16, |
|
|
300 |
_ARROW_WIDTH: 8, |
|
|
301 |
_TOOLTIP_ARROW_LENGTH : 15, |
|
|
302 |
_TOOLTIP_ARROW_WIDTH : 26, |
|
|
303 |
_TOOLTIP_MARGIN : 10, |
|
|
304 |
_TOOLTIP_PADDING : 8, |
|
|
305 |
_TOOLTIP_GRADIENT : new paper.Gradient(['#f0f0f0', '#d0d0d0']) |
|
|
306 |
} |
|
|
307 |
|
|
|
308 |
Rkns.Renderer.Utils = { |
|
|
309 |
shortenText : function(_text,_length) { |
|
|
310 |
var _rgxp = new RegExp('^(.{' + _length + '}).+$'); |
|
|
311 |
return _text.replace(/(\n|\r|\r\n)/mg,' ').replace(_rgxp,'$1…'); |
|
|
312 |
}, |
|
|
313 |
drawTooltip : function(_coords, _path, _width, _xmargin, _selector) { |
|
|
314 |
_selector.css({ |
|
|
315 |
width: (_width - 2* Rkns.Renderer._TOOLTIP_PADDING), |
|
|
316 |
}); |
|
|
317 |
var _height = _selector.outerHeight() + 2* Rkns.Renderer._TOOLTIP_PADDING, |
|
|
318 |
_isLeft = (_coords.x < paper.view.center.x ? 1 : -1), |
|
|
319 |
_left = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._TOOLTIP_ARROW_LENGTH ), |
|
|
320 |
_right = _coords.x + _isLeft * ( _xmargin + Rkns.Renderer._TOOLTIP_ARROW_LENGTH + _width ), |
|
|
321 |
_top = _coords.y - _height / 2; |
|
|
322 |
if (_top < Rkns.Renderer._TOOLTIP_MARGIN) { |
|
|
323 |
_top = Math.min( Rkns.Renderer._TOOLTIP_MARGIN, _coords.y - Rkns.Renderer._TOOLTIP_ARROW_WIDTH / 2 ); |
|
|
324 |
} |
|
|
325 |
var _bottom = _top + _height; |
|
|
326 |
if (_bottom > (paper.view.size.height - Rkns.Renderer._TOOLTIP_MARGIN)) { |
|
|
327 |
_bottom = Math.max( paper.view.size.height - Rkns.Renderer._TOOLTIP_MARGIN, _coords.y + Rkns.Renderer._TOOLTIP_ARROW_WIDTH / 2 ); |
|
|
328 |
_top = _bottom - _height; |
|
|
329 |
} |
|
|
330 |
_path.segments[0].point |
|
|
331 |
= _path.segments[7].point |
|
|
332 |
= _coords.add([_isLeft * _xmargin, 0]); |
|
|
333 |
_path.segments[1].point.x |
|
|
334 |
= _path.segments[2].point.x |
|
|
335 |
= _path.segments[5].point.x |
|
|
336 |
= _path.segments[6].point.x |
|
|
337 |
= _left; |
|
|
338 |
_path.segments[3].point.x |
|
|
339 |
= _path.segments[4].point.x |
|
|
340 |
= _right; |
|
|
341 |
_path.segments[2].point.y |
|
|
342 |
= _path.segments[3].point.y |
|
|
343 |
= _top; |
|
|
344 |
_path.segments[4].point.y |
|
|
345 |
= _path.segments[5].point.y |
|
|
346 |
= _bottom; |
|
|
347 |
_path.segments[1].point.y = _coords.y - Rkns.Renderer._TOOLTIP_ARROW_WIDTH / 2; |
|
|
348 |
_path.segments[6].point.y = _coords.y + Rkns.Renderer._TOOLTIP_ARROW_WIDTH / 2; |
|
|
349 |
_path.closed = true; |
|
|
350 |
_path.fillColor = new paper.GradientColor(Rkns.Renderer._TOOLTIP_GRADIENT, [0,_top], [0, _bottom]); |
|
|
351 |
_selector.css({ |
|
|
352 |
left: (Rkns.Renderer._TOOLTIP_PADDING + Math.min(_left, _right)), |
|
|
353 |
top: (Rkns.Renderer._TOOLTIP_PADDING + _top) |
|
|
354 |
}); |
|
|
355 |
} |
|
|
356 |
} |
|
|
357 |
|
|
|
358 |
Rkns.Renderer._BaseRepresentation = function(_renderer, _model) { |
|
|
359 |
if (typeof _renderer !== "undefined") { |
|
|
360 |
this.renderer = _renderer; |
|
|
361 |
this.project = _renderer.renkan.project; |
|
|
362 |
this.model = _model; |
|
|
363 |
if (_model) { |
|
|
364 |
var _this = this; |
|
|
365 |
_model.on("select", function() { |
|
|
366 |
_this.select(); |
|
|
367 |
}); |
|
|
368 |
_model.on("unselect", function() { |
|
|
369 |
_this.unselect(); |
|
|
370 |
}); |
|
|
371 |
} |
|
|
372 |
} |
|
|
373 |
} |
|
|
374 |
|
|
|
375 |
Rkns.Renderer._BaseRepresentation.prototype.select = function() {} |
|
|
376 |
|
|
|
377 |
Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {} |
|
|
378 |
|
|
|
379 |
Rkns.Renderer._BaseRepresentation.prototype.highlight = function() {} |
|
|
380 |
|
|
|
381 |
Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {} |
|
|
382 |
|
|
|
383 |
Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {} |
|
|
384 |
|
|
|
385 |
Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {} |
|
|
386 |
|
|
|
387 |
Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
|
|
388 |
|
|
|
389 |
Rkns.Renderer.Node.prototype._init = function() { |
|
|
390 |
this.renderer.node_layer.activate(); |
|
|
391 |
this.type = "Node"; |
|
|
392 |
this.circle = new paper.Path.Circle([0, 0], Rkns.Renderer._NODE_RADIUS); |
|
|
393 |
this.circle.fillColor = '#ffffff'; |
|
|
394 |
this.circle.__representation = this; |
|
|
395 |
this.title = new paper.PointText([0,0]); |
|
|
396 |
this.title.characterStyle = { |
|
|
397 |
fontSize: Rkns.Renderer._NODE_FONT_SIZE, |
|
|
398 |
fillColor: 'black' |
|
|
399 |
}; |
|
|
400 |
this.title.paragraphStyle.justification = 'center'; |
|
|
401 |
this.title.__representation = this; |
|
|
402 |
this.model_coords = new paper.Point(this.model.get("position")); |
|
|
403 |
} |
|
|
404 |
|
|
|
405 |
Rkns.Renderer.Node.prototype.redraw = function() { |
|
|
406 |
this.paper_coords = this.renderer.toPaperCoords(this.model_coords); |
|
|
407 |
this.circle.position = this.paper_coords; |
|
|
408 |
this.title.content = Rkns.Renderer.Utils.shortenText(this.model.get("title"), Rkns.Renderer._NODE_MAX_CHAR); |
|
|
409 |
this.title.position = this.paper_coords.add([0, 2 * Rkns.Renderer._NODE_RADIUS]); |
|
|
410 |
this.circle.strokeColor = this.model.get("created_by").get("color"); |
|
|
411 |
} |
|
|
412 |
|
|
|
413 |
Rkns.Renderer.Node.prototype.paperShift = function(_delta) { |
|
|
414 |
this.paper_coords = this.paper_coords.add(_delta); |
|
|
415 |
this.model_coords = this.renderer.toModelCoords(this.paper_coords); |
|
|
416 |
this.renderer.redraw(); |
|
|
417 |
} |
|
|
418 |
|
|
|
419 |
Rkns.Renderer.Node.prototype.openTooltip = function() { |
|
|
420 |
this.renderer.removeRepresentationsOfType("tooltip"); |
|
|
421 |
var _tooltip = this.renderer.addRepresentation("NodeTooltip",null); |
|
|
422 |
_tooltip.node_representation = this; |
|
|
423 |
_tooltip.redraw(); |
|
|
424 |
} |
|
|
425 |
|
|
|
426 |
Rkns.Renderer.Node.prototype.select = function() { |
|
|
427 |
this.circle.strokeWidth = 3; |
|
|
428 |
this.circle.fillColor = "#ffffc0"; |
|
|
429 |
paper.view.draw(); |
|
|
430 |
} |
|
|
431 |
|
|
|
432 |
Rkns.Renderer.Node.prototype.unselect = function() { |
|
|
433 |
this.circle.strokeWidth = 1; |
|
|
434 |
this.circle.fillColor = "#ffffff"; |
|
|
435 |
paper.view.draw(); |
|
|
436 |
} |
|
|
437 |
|
|
|
438 |
Rkns.Renderer.Node.prototype.mouseup = function(_event) { |
|
|
439 |
} |
|
|
440 |
|
|
|
441 |
Rkns.Renderer.Node.prototype.destroy = function(_event) { |
|
|
442 |
this.circle.remove(); |
|
|
443 |
this.title.remove(); |
|
|
444 |
} |
|
|
445 |
|
|
|
446 |
/* */ |
|
|
447 |
|
|
|
448 |
Rkns.Renderer.Edge = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
|
|
449 |
|
|
|
450 |
Rkns.Renderer.Edge.prototype._init = function() { |
|
|
451 |
this.renderer.edge_layer.activate(); |
|
|
452 |
this.type = "Edge"; |
|
|
453 |
this.from_representation = this.renderer.getRepresentationByModel(this.model.get("from")); |
|
|
454 |
this.to_representation = this.renderer.getRepresentationByModel(this.model.get("to")); |
|
950
|
455 |
this.bundle = this.renderer.addToBundles(this); |
|
938
|
456 |
this.line = new paper.Path(); |
|
950
|
457 |
this.line.add([0,0],[0,0],[0,0]); |
|
938
|
458 |
this.line.__representation = this; |
|
|
459 |
this.arrow = new paper.Path(); |
|
|
460 |
this.arrow.add([0,0],[Rkns.Renderer._ARROW_LENGTH,Rkns.Renderer._ARROW_WIDTH / 2],[0,Rkns.Renderer._ARROW_WIDTH]); |
|
|
461 |
this.arrow.__representation = this; |
|
|
462 |
this.text = new paper.PointText(); |
|
|
463 |
this.text.characterStyle = { |
|
|
464 |
fontSize: Rkns.Renderer._EDGE_FONT_SIZE, |
|
|
465 |
fillColor: 'black' |
|
|
466 |
}; |
|
|
467 |
this.text.paragraphStyle.justification = 'center'; |
|
|
468 |
this.text.__representation = this; |
|
|
469 |
this.text_angle = 0; |
|
|
470 |
this.arrow_angle = 0; |
|
|
471 |
} |
|
|
472 |
|
|
|
473 |
Rkns.Renderer.Edge.prototype.redraw = function() { |
|
950
|
474 |
var _p0a = this.from_representation.paper_coords, |
|
|
475 |
_p1a = this.to_representation.paper_coords, |
|
|
476 |
_v = _p1a.subtract(_p0a), |
|
938
|
477 |
_r = _v.length, |
|
|
478 |
_u = _v.divide(_r), |
|
950
|
479 |
_group_pos = this.bundle.getPosition(this), |
|
|
480 |
_delta = new paper.Point([- _u.y, _u.x]).multiply( 12 * _group_pos ), |
|
|
481 |
_p0b = _p0a.add(_delta), /* Adding a 4 px difference */ |
|
|
482 |
_p1b = _p1a.add(_delta), /* to differentiate inbound and outbound links */ |
|
938
|
483 |
_a = _v.angle, |
|
950
|
484 |
_handle = _v.divide(3), |
|
938
|
485 |
_color = this.model.get("created_by").get("color"); |
|
950
|
486 |
this.paper_coords = _p0b.add(_p1b).divide(2); |
|
938
|
487 |
this.line.strokeColor = _color; |
|
950
|
488 |
this.line.segments[0].point = _p0a; |
|
|
489 |
this.line.segments[1].point = this.paper_coords; |
|
|
490 |
this.line.segments[1].handleIn = _handle.multiply(-1); |
|
|
491 |
this.line.segments[1].handleOut = _handle; |
|
|
492 |
this.line.segments[2].point = _p1a; |
|
938
|
493 |
this.arrow.rotate(_a - this.arrow_angle); |
|
|
494 |
this.arrow.fillColor = _color; |
|
|
495 |
this.arrow.position = this.paper_coords.subtract(_u.multiply(4)); |
|
|
496 |
this.arrow_angle = _a; |
|
|
497 |
if (_a > 90) { |
|
|
498 |
_a -= 180; |
|
|
499 |
} |
|
|
500 |
if (_a < -90) { |
|
|
501 |
_a += 180; |
|
|
502 |
} |
|
|
503 |
this.text.rotate(_a - this.text_angle); |
|
|
504 |
this.text.content = Rkns.Renderer.Utils.shortenText(this.model.get("title"), Rkns.Renderer._EDGE_MAX_CHAR); |
|
|
505 |
this.text.position = this.paper_coords; |
|
|
506 |
this.text_angle = _a; |
|
|
507 |
} |
|
|
508 |
|
|
|
509 |
Rkns.Renderer.Edge.prototype.openTooltip = function() { |
|
|
510 |
this.renderer.removeRepresentationsOfType("tooltip"); |
|
|
511 |
var _tooltip = this.renderer.addRepresentation("EdgeTooltip",null); |
|
|
512 |
_tooltip.edge_representation = this; |
|
|
513 |
_tooltip.redraw(); |
|
|
514 |
} |
|
|
515 |
|
|
|
516 |
Rkns.Renderer.Edge.prototype.select = function() { |
|
|
517 |
this.line.strokeWidth = 3; |
|
|
518 |
this.openTooltip(); |
|
|
519 |
paper.view.draw(); |
|
|
520 |
} |
|
|
521 |
|
|
|
522 |
Rkns.Renderer.Edge.prototype.unselect = function() { |
|
|
523 |
this.line.strokeWidth = 1; |
|
|
524 |
paper.view.draw(); |
|
|
525 |
} |
|
|
526 |
|
|
|
527 |
Rkns.Renderer.Edge.prototype.mouseup = function(_event) { |
|
|
528 |
} |
|
|
529 |
|
|
|
530 |
Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { |
|
|
531 |
this.from_representation.paperShift(_delta); |
|
|
532 |
this.to_representation.paperShift(_delta); |
|
|
533 |
this.renderer.redraw(); |
|
|
534 |
} |
|
|
535 |
|
|
|
536 |
Rkns.Renderer.Edge.prototype.destroy = function() { |
|
|
537 |
this.line.remove(); |
|
|
538 |
this.arrow.remove(); |
|
|
539 |
this.text.remove(); |
|
950
|
540 |
var _this = this; |
|
|
541 |
this.bundle.edges = Rkns._(this.bundle.edges).reject(function(_edge) { |
|
|
542 |
return _edge === _this; |
|
|
543 |
}); |
|
938
|
544 |
} |
|
|
545 |
|
|
|
546 |
/* */ |
|
|
547 |
|
|
|
548 |
Rkns.Renderer.NodeTooltip = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
|
|
549 |
|
|
|
550 |
Rkns.Renderer.NodeTooltip.prototype._init = function() { |
|
|
551 |
this.renderer.overlay_layer.activate(); |
|
|
552 |
this.type = "tooltip"; |
|
|
553 |
this.tooltip_block = new paper.Path(); |
|
|
554 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
555 |
this.tooltip_block.add.apply(this.tooltip_block, _pts); |
|
|
556 |
this.tooltip_block.strokeWidth = 2; |
|
|
557 |
this.tooltip_block.strokeColor = "#999999"; |
|
|
558 |
this.tooltip_block.fillColor = "#e0e0e0"; |
|
|
559 |
this.tooltip_block.opacity = .8; |
|
|
560 |
this.tooltip_$ = Rkns.$('<div>') |
|
|
561 |
.appendTo(this.renderer.tooltip_$) |
|
|
562 |
.css({ |
|
|
563 |
position: "absolute", |
|
|
564 |
opacity: .8 |
|
|
565 |
}) |
|
|
566 |
.hide(); |
|
|
567 |
} |
|
|
568 |
|
|
|
569 |
Rkns.Renderer.NodeTooltip.prototype.template = Rkns._.template( |
|
|
570 |
'<h2><span class="Rk-CloseX">×</span><%=a%></h2>' |
|
|
571 |
+ '<p><%=description%></p>' |
|
|
572 |
); |
|
|
573 |
|
|
|
574 |
Rkns.Renderer.NodeTooltip.prototype.redraw = function() { |
|
|
575 |
var _coords = this.node_representation.paper_coords, |
|
|
576 |
_model = this.node_representation.model, |
|
|
577 |
_title = _model.get("title"), |
|
|
578 |
_uri = _model.get("uri"); |
|
|
579 |
this.tooltip_$ |
|
|
580 |
.html(this.template({ |
|
|
581 |
a: (_uri ? '<a href="' + _uri + '" target="_blank">' : '' ) + _title + (_uri ? '</a>' : '' ), |
|
|
582 |
description: _model.get("description").replace(/(\n|\r|\r\n)/mg,' ').substr(0,180).replace(/(^.{150,179})[\s].+$/m,'$1…') |
|
|
583 |
})) |
|
|
584 |
.show(); |
|
|
585 |
Rkns.Renderer.Utils.drawTooltip(_coords, this.tooltip_block, 250, 15, this.tooltip_$); |
|
|
586 |
var _this = this; |
|
|
587 |
this.tooltip_$.find(".Rk-CloseX").click(function() { |
|
|
588 |
_this.renderer.removeRepresentation(_this); |
|
|
589 |
paper.view.draw(); |
|
|
590 |
}); |
|
|
591 |
this.tooltip_$.find("input, textarea").bind("keyup change", function() { |
|
|
592 |
_this.tooltip_$.find(".Rk-Edit-Goto").attr("href",_this.tooltip_$.find(".Rk-Edit-URI").val()); |
|
|
593 |
}); |
|
|
594 |
paper.view.draw(); |
|
|
595 |
} |
|
|
596 |
|
|
|
597 |
Rkns.Renderer.NodeTooltip.prototype.destroy = function() { |
|
|
598 |
this.tooltip_block.remove(); |
|
|
599 |
this.tooltip_$.detach(); |
|
|
600 |
} |
|
|
601 |
|
|
|
602 |
/* */ |
|
|
603 |
|
|
|
604 |
Rkns.Renderer.EdgeTooltip = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); |
|
|
605 |
|
|
|
606 |
Rkns.Renderer.EdgeTooltip.prototype._init = function() { |
|
|
607 |
this.renderer.overlay_layer.activate(); |
|
|
608 |
this.type = "tooltip"; |
|
|
609 |
this.tooltip_block = new paper.Path(); |
|
|
610 |
var _pts = Rkns._(Rkns._.range(8)).map(function() {return [0,0]}); |
|
|
611 |
this.tooltip_block.add.apply(this.tooltip_block, _pts); |
|
|
612 |
this.tooltip_block.strokeWidth = 2; |
|
|
613 |
this.tooltip_block.strokeColor = "#999999"; |
|
|
614 |
this.tooltip_block.fillColor = "#e0e0e0"; |
|
|
615 |
this.tooltip_block.opacity = .8; |
|
|
616 |
this.tooltip_$ = Rkns.$('<div>') |
|
|
617 |
.appendTo(this.renderer.tooltip_$) |
|
|
618 |
.css({ |
|
|
619 |
position: "absolute", |
|
|
620 |
opacity: .8 |
|
|
621 |
}) |
|
|
622 |
.hide(); |
|
|
623 |
} |
|
|
624 |
|
|
|
625 |
Rkns.Renderer.EdgeTooltip.prototype.template = Rkns._.template( |
|
|
626 |
'<h2><span class="Rk-CloseX">×</span><%=a%></h2>' |
|
|
627 |
+ '<p><%=description%></p>' |
|
|
628 |
); |
|
|
629 |
|
|
|
630 |
Rkns.Renderer.EdgeTooltip.prototype.redraw = function() { |
|
|
631 |
var _coords = this.edge_representation.paper_coords, |
|
|
632 |
_model = this.edge_representation.model, |
|
|
633 |
_title = _model.get("title"), |
|
|
634 |
_uri = _model.get("uri"); |
|
|
635 |
this.tooltip_$ |
|
|
636 |
.html(this.template({ |
|
|
637 |
a: (_uri ? '<a href="' + _uri + '" target="_blank">' : '' ) + _title + (_uri ? '</a>' : '' ), |
|
|
638 |
description: _model.get("description").replace(/(\n|\r|\r\n)/mg,' ').substr(0,180).replace(/(^.{150,179})[\s].+$/m,'$1…') |
|
|
639 |
})) |
|
|
640 |
.show(); |
|
|
641 |
Rkns.Renderer.Utils.drawTooltip(_coords, this.tooltip_block, 250, 5, this.tooltip_$); |
|
|
642 |
var _this = this; |
|
|
643 |
this.tooltip_$.find(".Rk-CloseX").click(function() { |
|
|
644 |
_this.renderer.removeRepresentation(_this); |
|
|
645 |
paper.view.draw(); |
|
|
646 |
}); |
|
|
647 |
paper.view.draw(); |
|
|
648 |
} |
|
|
649 |
|
|
|
650 |
Rkns.Renderer.EdgeTooltip.prototype.destroy = function() { |
|
|
651 |
this.tooltip_block.remove(); |
|
|
652 |
this.tooltip_$.detach(); |
|
|
653 |
} |
|
|
654 |
|
|
|
655 |
/* */ |
|
|
656 |
|
|
|
657 |
Rkns.Renderer.Scene = function(_renkan) { |
|
|
658 |
this.renkan = _renkan; |
|
|
659 |
this.$ = Rkns.$(".Rk-Render"); |
|
|
660 |
this.representations = []; |
|
|
661 |
this.$.html(this.template({ |
|
|
662 |
width: this.$.width(), |
|
|
663 |
height: this.$.height(), |
|
|
664 |
l10n: _renkan.l10n |
|
|
665 |
})) |
|
|
666 |
this.canvas_$ = this.$.find(".Rk-Canvas"); |
|
|
667 |
this.tooltip_$ = this.$.find(".Rk-Editor"); |
|
|
668 |
paper.setup(this.canvas_$[0]); |
|
|
669 |
this.scale = 1; |
|
|
670 |
this.offset = paper.view.center; |
|
|
671 |
this.totalScroll = 0; |
|
|
672 |
this.click_target = null; |
|
|
673 |
this.selected_target = null; |
|
|
674 |
this.edge_layer = new paper.Layer(); |
|
|
675 |
this.node_layer = new paper.Layer(); |
|
|
676 |
this.overlay_layer = new paper.Layer(); |
|
950
|
677 |
this.bundles = []; |
|
938
|
678 |
var _tool = new paper.Tool(), |
|
|
679 |
_this = this; |
|
|
680 |
_tool.minDistance = Rkns.Renderer._MIN_DRAG_DISTANCE; |
|
|
681 |
_tool.onMouseMove = function(_event) { |
|
|
682 |
_this.onMouseMove(_event); |
|
|
683 |
} |
|
|
684 |
_tool.onMouseDown = function(_event) { |
|
|
685 |
_this.onMouseDown(_event); |
|
|
686 |
} |
|
|
687 |
_tool.onMouseDrag = function(_event) { |
|
|
688 |
_this.onMouseDrag(_event); |
|
|
689 |
} |
|
|
690 |
this.canvas_$.mouseup(function(_event) { |
|
|
691 |
_this.onMouseUp(_event); |
|
|
692 |
}); |
|
|
693 |
this.canvas_$.mousewheel(function(_event, _delta) { |
|
|
694 |
_this.onScroll(_event, _delta); |
|
|
695 |
}); |
|
|
696 |
this.tooltip_$.find(".Rk-ZoomOut").click(function() { |
|
|
697 |
_this.offset = new paper.Point([ |
|
|
698 |
_this.canvas_$.width(), |
|
|
699 |
_this.canvas_$.height() |
|
|
700 |
]).multiply( .5 * ( 1 - Math.SQRT1_2 ) ).add(_this.offset.multiply( Math.SQRT1_2 )); |
|
|
701 |
_this.scale *= Math.SQRT1_2; |
|
|
702 |
_this.redraw(); |
|
|
703 |
}); |
|
|
704 |
this.tooltip_$.find(".Rk-ZoomIn").click(function() { |
|
|
705 |
_this.offset = new paper.Point([ |
|
|
706 |
_this.canvas_$.width(), |
|
|
707 |
_this.canvas_$.height() |
|
|
708 |
]).multiply( .5 * ( 1 - Math.SQRT2 ) ).add(_this.offset.multiply( Math.SQRT2 )); |
|
|
709 |
_this.scale *= Math.SQRT2; |
|
|
710 |
_this.redraw(); |
|
|
711 |
}); |
|
|
712 |
paper.view.onResize = function(_event) { |
|
|
713 |
_this.offset = _this.offset.add(_event.delta.divide(2)); |
|
|
714 |
_this.redraw(); |
|
|
715 |
} |
|
|
716 |
|
|
|
717 |
var _thRedraw = Rkns._.throttle(function() { |
|
|
718 |
_this.redraw(); |
|
|
719 |
},50); |
|
|
720 |
|
|
|
721 |
this.addRepresentations("Node", this.renkan.project.get("nodes")); |
|
|
722 |
this.addRepresentations("Edge", this.renkan.project.get("edges")); |
|
|
723 |
|
|
|
724 |
this.renkan.project.on("add:nodes", function(_node) { |
|
|
725 |
_this.addRepresentation("Node", _node); |
|
|
726 |
_thRedraw(); |
|
|
727 |
}); |
|
|
728 |
this.renkan.project.on("add:edges", function(_edge) { |
|
|
729 |
_this.addRepresentation("Edge", _edge); |
|
|
730 |
_thRedraw(); |
|
|
731 |
}); |
|
|
732 |
|
|
|
733 |
this.redraw(); |
|
|
734 |
} |
|
|
735 |
|
|
|
736 |
Rkns.Renderer.Scene.prototype.template = Rkns._.template( |
|
|
737 |
'<canvas class="Rk-Canvas" width="<%=width%>" height="<%=height%>"></canvas><div class="Rk-Editor">' |
|
|
738 |
+ '<div class="Rk-ZoomButtons"><div class="Rk-ZoomIn" title="<%=l10n.zoom_in%>"></div><div class="Rk-ZoomOut" title="<%=l10n.zoom_out%>"></div></div>' |
|
|
739 |
+ '</div>' |
|
|
740 |
); |
|
|
741 |
|
|
950
|
742 |
Rkns.Renderer.Scene.prototype.addToBundles = function(_edgeRepr) { |
|
|
743 |
var _bundle = Rkns._(this.bundles).find(function(_bundle) { |
|
|
744 |
return ( |
|
|
745 |
( _bundle.from === _edgeRepr.from_representation && _bundle.to === _edgeRepr.to_representation ) |
|
|
746 |
|| ( _bundle.from === _edgeRepr.to_representation && _bundle.to === _edgeRepr.from_representation ) |
|
|
747 |
); |
|
|
748 |
}); |
|
|
749 |
if (typeof _bundle !== "undefined") { |
|
|
750 |
_bundle.edges.push(_edgeRepr) |
|
|
751 |
} else { |
|
|
752 |
_bundle = { |
|
|
753 |
from: _edgeRepr.from_representation, |
|
|
754 |
to: _edgeRepr.to_representation, |
|
|
755 |
edges: [ _edgeRepr ], |
|
|
756 |
getPosition: function(_er) { |
|
|
757 |
var _dir = (_er.from_representation === this.from) ? 1 : -1; |
|
|
758 |
return _dir * ( Rkns._(this.edges).indexOf(_er) - (this.edges.length - 1) / 2 ); |
|
|
759 |
} |
|
|
760 |
} |
|
|
761 |
this.bundles.push(_bundle); |
|
|
762 |
} |
|
|
763 |
return _bundle; |
|
|
764 |
} |
|
|
765 |
|
|
938
|
766 |
Rkns.Renderer.Scene.prototype.autoScale = function() { |
|
|
767 |
if (this.renkan.project.get("nodes").length) { |
|
|
768 |
var _xx = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").x }), |
|
|
769 |
_yy = this.renkan.project.get("nodes").map(function(_node) { return _node.get("position").y }), |
|
|
770 |
_minx = Math.min.apply(Math, _xx), |
|
|
771 |
_miny = Math.min.apply(Math, _yy), |
|
|
772 |
_maxx = Math.max.apply(Math, _xx), |
|
|
773 |
_maxy = Math.max.apply(Math, _yy); |
|
|
774 |
this.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)); |
|
|
775 |
this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale)); |
|
|
776 |
this.redraw(); |
|
|
777 |
} |
|
|
778 |
} |
|
|
779 |
|
|
|
780 |
Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { |
|
|
781 |
return _point.multiply(this.scale).add(this.offset); |
|
|
782 |
} |
|
|
783 |
|
|
|
784 |
|
|
|
785 |
Rkns.Renderer.Scene.prototype.toModelCoords = function(_point) { |
|
|
786 |
return _point.subtract(this.offset).divide(this.scale); |
|
|
787 |
} |
|
|
788 |
|
|
|
789 |
Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) { |
|
|
790 |
var _repr = new Rkns.Renderer[_type](this, _model); |
|
|
791 |
this.representations.push(_repr); |
|
|
792 |
if (_model) { |
|
|
793 |
var _this = this; |
|
|
794 |
_model.on("change", function() { |
|
|
795 |
_repr.redraw(); |
|
|
796 |
}); |
|
|
797 |
_model.on("remove", function() { |
|
|
798 |
_this.removeRepresentation(_repr); |
|
|
799 |
_this.redraw(); |
|
|
800 |
}); |
|
|
801 |
} |
|
|
802 |
return _repr; |
|
|
803 |
} |
|
|
804 |
|
|
|
805 |
Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) { |
|
|
806 |
var _this = this; |
|
|
807 |
_collection.forEach(function(_model) { |
|
|
808 |
_this.addRepresentation(_type, _model); |
|
|
809 |
}); |
|
|
810 |
} |
|
|
811 |
|
|
|
812 |
Rkns.Renderer.Scene.prototype.removeRepresentation = function(_representation) { |
|
|
813 |
_representation.destroy(); |
|
|
814 |
this.representations = Rkns._(this.representations).reject( |
|
|
815 |
function(_repr) { |
|
|
816 |
return _repr == _representation |
|
|
817 |
} |
|
|
818 |
); |
|
|
819 |
} |
|
|
820 |
|
|
|
821 |
Rkns.Renderer.Scene.prototype.getRepresentationByModel = function(_model) { |
|
|
822 |
return Rkns._(this.representations).find(function(_repr) { |
|
|
823 |
return _repr.model === _model; |
|
|
824 |
}); |
|
|
825 |
} |
|
|
826 |
|
|
|
827 |
Rkns.Renderer.Scene.prototype.removeRepresentationsOfType = function(_type) { |
|
|
828 |
var _representations = Rkns._(this.representations).filter(function(_repr) { |
|
|
829 |
return _repr.type == _type; |
|
|
830 |
}), |
|
|
831 |
_this = this; |
|
|
832 |
Rkns._(_representations).each(function(_repr) { |
|
|
833 |
_this.removeRepresentation(_repr); |
|
|
834 |
}); |
|
|
835 |
} |
|
|
836 |
|
|
|
837 |
Rkns.Renderer.Scene.prototype.unselectAll = function() { |
|
|
838 |
Rkns._(this.representations).each(function(_repr) { |
|
|
839 |
_repr.model.trigger("unselect"); |
|
|
840 |
}); |
|
|
841 |
} |
|
|
842 |
|
|
|
843 |
Rkns.Renderer.Scene.prototype.redraw = function() { |
|
|
844 |
Rkns._(this.representations).each(function(_representation) { |
|
|
845 |
_representation.redraw(); |
|
|
846 |
}); |
|
|
847 |
paper.view.draw(); |
|
|
848 |
} |
|
|
849 |
|
|
|
850 |
Rkns.Renderer.Scene.prototype.addTempEdge = function(_from, _point) { |
|
|
851 |
var _tmpEdge = this.addRepresentation("TempEdge",null); |
|
|
852 |
_tmpEdge.end_pos = _point; |
|
|
853 |
_tmpEdge.from_representation = _from; |
|
|
854 |
_tmpEdge.redraw(); |
|
|
855 |
this.click_target = _tmpEdge; |
|
|
856 |
} |
|
|
857 |
|
|
|
858 |
Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) { |
|
|
859 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
|
860 |
var _newTarget = _hitResult.item.__representation; |
|
|
861 |
if (this.selected_target !== _newTarget && _newTarget.model) { |
|
|
862 |
if (this.selected_target) { |
|
|
863 |
this.selected_target.model.trigger("unselect"); |
|
|
864 |
} |
|
|
865 |
_newTarget.model.trigger("select"); |
|
|
866 |
if (typeof _newTarget.openTooltip === "function") { |
|
|
867 |
_newTarget.openTooltip(); |
|
|
868 |
} |
|
|
869 |
this.selected_target = _newTarget; |
|
|
870 |
} |
|
|
871 |
} else { |
|
|
872 |
if (!_hitResult) { |
|
|
873 |
this.removeRepresentationsOfType("tooltip"); |
|
|
874 |
} |
|
|
875 |
if (this.selected_target) { |
|
|
876 |
this.selected_target.model.trigger("unselect"); |
|
|
877 |
} |
|
|
878 |
this.selected_target = null; |
|
|
879 |
} |
|
|
880 |
} |
|
|
881 |
|
|
|
882 |
Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) { |
|
|
883 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
884 |
if (this.is_dragging) { |
|
|
885 |
if (this.click_target && typeof this.click_target.paperShift === "function") { |
|
|
886 |
this.click_target.paperShift(_event.delta); |
|
|
887 |
} else { |
|
|
888 |
this.offset = this.offset.add(_event.delta); |
|
|
889 |
this.redraw(); |
|
|
890 |
} |
|
|
891 |
} else { |
|
|
892 |
this.findTarget(_hitResult); |
|
|
893 |
} |
|
|
894 |
} |
|
|
895 |
|
|
|
896 |
Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) { |
|
|
897 |
this.is_dragging = false; |
|
|
898 |
var _hitResult = paper.project.hitTest(_event.point); |
|
|
899 |
if (_hitResult && typeof _hitResult.item.__representation !== "undefined") { |
|
|
900 |
this.click_target = _hitResult.item.__representation; |
|
|
901 |
} else { |
|
|
902 |
this.click_target = null; |
|
|
903 |
} |
|
|
904 |
} |
|
|
905 |
|
|
|
906 |
Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) { |
|
|
907 |
this.is_dragging = true; |
|
|
908 |
this.onMouseMove(_event); |
|
|
909 |
} |
|
|
910 |
|
|
|
911 |
Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) { |
|
|
912 |
if (this.click_target) { |
|
|
913 |
var _off = this.canvas_$.offset(); |
|
|
914 |
if (this.click_target.model) { |
|
|
915 |
this.click_target.model.trigger("click"); |
|
|
916 |
} |
|
|
917 |
} |
|
|
918 |
this.is_dragging = false; |
|
|
919 |
this.click_target = null; |
|
|
920 |
} |
|
|
921 |
|
|
|
922 |
Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) { |
|
|
923 |
this.totalScroll += _scrolldelta; |
|
|
924 |
if (Math.abs(this.totalScroll) >= 1) { |
|
|
925 |
var _off = this.canvas_$.offset(), |
|
|
926 |
_delta = new paper.Point([ |
|
|
927 |
_event.pageX - _off.left, |
|
|
928 |
_event.pageY - _off.top |
|
|
929 |
]).subtract(this.offset).multiply( Math.SQRT2 - 1 ); |
|
|
930 |
if (this.totalScroll > 0) { |
|
|
931 |
this.offset = this.offset.subtract(_delta); |
|
|
932 |
this.scale *= Math.SQRT2; |
|
|
933 |
} else { |
|
|
934 |
this.offset = this.offset.add(_delta.divide( Math.SQRT2 )); |
|
|
935 |
this.scale *= Math.SQRT1_2; |
|
|
936 |
} |
|
|
937 |
this.totalScroll = 0; |
|
|
938 |
this.redraw(); |
|
|
939 |
} |
|
|
940 |
} |