| author | rougeronj |
| Wed, 20 May 2015 10:53:40 +0200 | |
| changeset 451 | 278f8da09c04 |
| parent 450 | 88e8673aaeeb |
| child 453 | 04b7d46e9d67 |
| permissions | -rw-r--r-- |
| 326 | 1 |
define(['jquery', 'underscore', 'requtils', 'renderer/baserepresentation', 'renderer/shapebuilder'], function ($, _, requtils, BaseRepresentation, ShapeBuilder) { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
2 |
'use strict'; |
|
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
3 |
|
| 284 | 4 |
var Utils = requtils.getUtils(); |
5 |
||
6 |
/* Rkns.Renderer.Node Class */ |
|
7 |
||
8 |
/* The representation for the node : A circle, with an image inside and a text label underneath. |
|
9 |
* The circle and the image are drawn on canvas and managed by Paper.js. |
|
10 |
* The text label is an HTML node, managed by jQuery. */ |
|
11 |
||
12 |
//var NodeRepr = Renderer.Node = Utils.inherit(Renderer._BaseRepresentation); |
|
13 |
var NodeRepr = Utils.inherit(BaseRepresentation); |
|
14 |
||
15 |
_(NodeRepr.prototype).extend({ |
|
16 |
_init: function() { |
|
17 |
this.renderer.node_layer.activate(); |
|
18 |
this.type = "Node"; |
|
| 330 | 19 |
this.buildShape(); |
| 450 | 20 |
this.hidden = false; |
21 |
this.ghost= false; |
|
| 284 | 22 |
if (this.options.show_node_circles) { |
23 |
this.circle.strokeWidth = this.options.node_stroke_width; |
|
24 |
this.h_ratio = 1; |
|
25 |
} else { |
|
26 |
this.h_ratio = 0; |
|
27 |
} |
|
28 |
this.title = $('<div class="Rk-Label">').appendTo(this.renderer.labels_$); |
|
| 396 | 29 |
|
| 284 | 30 |
if (this.options.editor_mode) { |
31 |
var Renderer = requtils.getRenderer(); |
|
32 |
this.normal_buttons = [ |
|
33 |
new Renderer.NodeEditButton(this.renderer, null), |
|
34 |
new Renderer.NodeRemoveButton(this.renderer, null), |
|
| 450 | 35 |
new Renderer.NodeHideButton(this.renderer, null), |
| 284 | 36 |
new Renderer.NodeLinkButton(this.renderer, null), |
37 |
new Renderer.NodeEnlargeButton(this.renderer, null), |
|
38 |
new Renderer.NodeShrinkButton(this.renderer, null) |
|
39 |
]; |
|
40 |
this.pending_delete_buttons = [ |
|
41 |
new Renderer.NodeRevertButton(this.renderer, null) |
|
42 |
]; |
|
43 |
this.all_buttons = this.normal_buttons.concat(this.pending_delete_buttons); |
|
| 396 | 44 |
|
| 284 | 45 |
for (var i = 0; i < this.all_buttons.length; i++) { |
46 |
this.all_buttons[i].source_representation = this; |
|
47 |
} |
|
48 |
this.active_buttons = []; |
|
49 |
} else { |
|
50 |
this.active_buttons = this.all_buttons = []; |
|
51 |
} |
|
52 |
this.last_circle_radius = 1; |
|
53 |
||
54 |
if (this.renderer.minimap) { |
|
55 |
this.renderer.minimap.node_layer.activate(); |
|
56 |
this.minimap_circle = new paper.Path.Circle([0, 0], 1); |
|
57 |
this.minimap_circle.__representation = this.renderer.minimap.miniframe.__representation; |
|
58 |
this.renderer.minimap.node_group.addChild(this.minimap_circle); |
|
59 |
} |
|
60 |
}, |
|
| 330 | 61 |
buildShape: function(){ |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
62 |
if( 'shape' in this.model.changed ) { |
| 331 | 63 |
delete this.img; |
| 330 | 64 |
} |
65 |
if(this.circle){ |
|
66 |
this.circle.remove(); |
|
67 |
delete this.circle; |
|
68 |
} |
|
69 |
// "circle" "rectangle" "ellipse" "polygon" "star" "diamond" |
|
70 |
this.shapeBuilder = new ShapeBuilder(this.model.get("shape")); |
|
71 |
this.circle = this.shapeBuilder.getShape(); |
|
72 |
this.circle.__representation = this; |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
73 |
this.circle.sendToBack(); |
| 330 | 74 |
this.last_circle_radius = 1; |
75 |
}, |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
76 |
redraw: function(options) { |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
77 |
if( 'shape' in this.model.changed && 'change' in options && options.change ) { |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
78 |
//if( 'shape' in this.model.changed ) { |
| 330 | 79 |
this.buildShape(); |
80 |
} |
|
| 284 | 81 |
var _model_coords = new paper.Point(this.model.get("position")), |
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
82 |
_baseRadius = this.options.node_size_base * Math.exp((this.model.get("size") || 0) * Utils._NODE_SIZE_STEP); |
| 284 | 83 |
if (!this.is_dragging || !this.paper_coords) { |
84 |
this.paper_coords = this.renderer.toPaperCoords(_model_coords); |
|
85 |
} |
|
86 |
this.circle_radius = _baseRadius * this.renderer.scale; |
|
87 |
if (this.last_circle_radius !== this.circle_radius) { |
|
88 |
this.all_buttons.forEach(function(b) { |
|
89 |
b.setSectorSize(); |
|
90 |
}); |
|
91 |
this.circle.scale(this.circle_radius / this.last_circle_radius); |
|
92 |
if (this.node_image) { |
|
93 |
this.node_image.scale(this.circle_radius / this.last_circle_radius); |
|
94 |
} |
|
95 |
} |
|
96 |
this.circle.position = this.paper_coords; |
|
97 |
if (this.node_image) { |
|
98 |
this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius)); |
|
99 |
} |
|
100 |
this.last_circle_radius = this.circle_radius; |
|
101 |
||
102 |
var old_act_btn = this.active_buttons; |
|
| 450 | 103 |
|
| 284 | 104 |
var opacity = 1; |
105 |
if (this.model.get("delete_scheduled")) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
106 |
opacity = 0.5; |
| 284 | 107 |
this.active_buttons = this.pending_delete_buttons; |
108 |
this.circle.dashArray = [2,2]; |
|
109 |
} else { |
|
110 |
opacity = 1; |
|
111 |
this.active_buttons = this.normal_buttons; |
|
112 |
this.circle.dashArray = null; |
|
113 |
} |
|
| 450 | 114 |
if (this.selected && this.renderer.isEditable() && !this.ghost) { |
| 284 | 115 |
if (old_act_btn !== this.active_buttons) { |
116 |
old_act_btn.forEach(function(b) { |
|
117 |
b.hide(); |
|
118 |
}); |
|
119 |
} |
|
120 |
this.active_buttons.forEach(function(b) { |
|
121 |
b.show(); |
|
122 |
}); |
|
123 |
} |
|
124 |
||
125 |
if (this.node_image) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
126 |
this.node_image.opacity = this.highlighted ? opacity * 0.5 : (opacity - 0.01); |
| 284 | 127 |
} |
128 |
||
129 |
this.circle.fillColor = this.highlighted ? this.options.highlighted_node_fill_color : this.options.node_fill_color; |
|
130 |
||
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
131 |
this.circle.opacity = this.options.show_node_circles ? opacity : 0.01; |
| 284 | 132 |
|
133 |
var _text = this.model.get("title") || this.renkan.translate(this.options.label_untitled_nodes) || ""; |
|
134 |
_text = Utils.shortenText(_text, this.options.node_label_max_length); |
|
135 |
||
136 |
if (typeof this.highlighted === "object") { |
|
137 |
this.title.html(this.highlighted.replace(_(_text).escape(),'<span class="Rk-Highlighted">$1</span>')); |
|
138 |
} else { |
|
139 |
this.title.text(_text); |
|
140 |
} |
|
141 |
this.title.css({ |
|
142 |
left: this.paper_coords.x, |
|
143 |
top: this.paper_coords.y + this.circle_radius * this.h_ratio + this.options.node_label_distance, |
|
144 |
opacity: opacity |
|
145 |
}); |
|
146 |
var _color = this.model.get("color") || (this.model.get("created_by") || Utils._USER_PLACEHOLDER(this.renkan)).get("color"); |
|
147 |
this.circle.strokeColor = _color; |
|
148 |
var _pc = this.paper_coords; |
|
149 |
this.all_buttons.forEach(function(b) { |
|
150 |
b.moveTo(_pc); |
|
151 |
}); |
|
152 |
var lastImage = this.img; |
|
153 |
this.img = this.model.get("image"); |
|
154 |
if (this.img && this.img !== lastImage) { |
|
155 |
this.showImage(); |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
156 |
if(this.circle) { |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
157 |
this.circle.sendToBack(); |
|
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
158 |
} |
| 284 | 159 |
} |
160 |
if (this.node_image && !this.img) { |
|
161 |
this.node_image.remove(); |
|
162 |
delete this.node_image; |
|
163 |
} |
|
| 450 | 164 |
|
165 |
|
|
| 284 | 166 |
if (this.renderer.minimap) { |
167 |
this.minimap_circle.fillColor = _color; |
|
168 |
var minipos = this.renderer.toMinimapCoords(_model_coords), |
|
169 |
miniradius = this.renderer.minimap.scale * _baseRadius, |
|
170 |
minisize = new paper.Size([miniradius, miniradius]); |
|
171 |
this.minimap_circle.fitBounds(minipos.subtract(minisize), minisize.multiply(2)); |
|
172 |
} |
|
173 |
||
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
174 |
if (typeof options === 'undefined' || !('dontRedrawEdges' in options) || !options.dontRedrawEdges) { |
| 284 | 175 |
var _this = this; |
176 |
_.each( |
|
177 |
this.project.get("edges").filter( |
|
178 |
function (ed) { |
|
179 |
return ((ed.get("to") === _this.model) || (ed.get("from") === _this.model)); |
|
180 |
} |
|
181 |
), |
|
182 |
function(edge, index, list) { |
|
183 |
var repr = _this.renderer.getRepresentationByModel(edge); |
|
184 |
if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
185 |
repr.redraw(); |
|
186 |
} |
|
187 |
} |
|
188 |
); |
|
189 |
} |
|
| 450 | 190 |
if (this.ghost){ |
191 |
this.show(true); |
|
192 |
} else { |
|
193 |
if (this.hidden) { this.hide(); } |
|
194 |
} |
|
| 284 | 195 |
}, |
196 |
showImage: function() { |
|
197 |
var _image = null; |
|
198 |
if (typeof this.renderer.image_cache[this.img] === "undefined") { |
|
199 |
_image = new Image(); |
|
200 |
this.renderer.image_cache[this.img] = _image; |
|
201 |
_image.src = this.img; |
|
202 |
} else { |
|
203 |
_image = this.renderer.image_cache[this.img]; |
|
204 |
} |
|
205 |
if (_image.width) { |
|
206 |
if (this.node_image) { |
|
207 |
this.node_image.remove(); |
|
208 |
} |
|
209 |
this.renderer.node_layer.activate(); |
|
210 |
var width = _image.width, |
|
|
403
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
211 |
height = _image.height, |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
212 |
clipPath = this.model.get("clip_path"), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
213 |
hasClipPath = (typeof clipPath !== "undefined" && clipPath), |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
214 |
_clip = null, |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
215 |
baseRadius = null, |
|
96781c1a8bbe
correct resizing problems especially in next firefox
ymh <ymh.work@gmail.com>
parents:
396
diff
changeset
|
216 |
centerPoint = null; |
| 396 | 217 |
|
| 284 | 218 |
if (hasClipPath) { |
219 |
_clip = new paper.Path(); |
|
220 |
var instructions = clipPath.match(/[a-z][^a-z]+/gi) || [], |
|
221 |
lastCoords = [0,0], |
|
222 |
minX = Infinity, |
|
223 |
minY = Infinity, |
|
224 |
maxX = -Infinity, |
|
225 |
maxY = -Infinity; |
|
226 |
||
227 |
var transformCoords = function(tabc, relative) { |
|
228 |
var newCoords = tabc.slice(1).map(function(v, k) { |
|
229 |
var res = parseFloat(v), |
|
230 |
isY = k % 2; |
|
231 |
if (isY) { |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
232 |
res = ( res - 0.5 ) * height; |
| 284 | 233 |
} else { |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
234 |
res = ( res - 0.5 ) * width; |
| 284 | 235 |
} |
236 |
if (relative) { |
|
237 |
res += lastCoords[isY]; |
|
238 |
} |
|
239 |
if (isY) { |
|
240 |
minY = Math.min(minY, res); |
|
241 |
maxY = Math.max(maxY, res); |
|
242 |
} else { |
|
243 |
minX = Math.min(minX, res); |
|
244 |
maxX = Math.max(maxX, res); |
|
245 |
} |
|
246 |
return res; |
|
247 |
}); |
|
248 |
lastCoords = newCoords.slice(-2); |
|
249 |
return newCoords; |
|
250 |
}; |
|
251 |
||
252 |
instructions.forEach(function(instr) { |
|
253 |
var coords = instr.match(/([a-z]|[0-9.-]+)/ig) || [""]; |
|
254 |
switch(coords[0]) { |
|
255 |
case "M": |
|
256 |
_clip.moveTo(transformCoords(coords)); |
|
257 |
break; |
|
258 |
case "m": |
|
259 |
_clip.moveTo(transformCoords(coords, true)); |
|
260 |
break; |
|
261 |
case "L": |
|
262 |
_clip.lineTo(transformCoords(coords)); |
|
263 |
break; |
|
264 |
case "l": |
|
265 |
_clip.lineTo(transformCoords(coords, true)); |
|
266 |
break; |
|
267 |
case "C": |
|
268 |
_clip.cubicCurveTo(transformCoords(coords)); |
|
269 |
break; |
|
270 |
case "c": |
|
271 |
_clip.cubicCurveTo(transformCoords(coords, true)); |
|
272 |
break; |
|
273 |
case "Q": |
|
274 |
_clip.quadraticCurveTo(transformCoords(coords)); |
|
275 |
break; |
|
276 |
case "q": |
|
277 |
_clip.quadraticCurveTo(transformCoords(coords, true)); |
|
278 |
break; |
|
279 |
} |
|
280 |
}); |
|
281 |
||
282 |
baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](maxX - minX, maxY - minY) / 2; |
|
283 |
centerPoint = new paper.Point((maxX + minX) / 2, (maxY + minY) / 2); |
|
284 |
if (!this.options.show_node_circles) { |
|
285 |
this.h_ratio = (maxY - minY) / (2 * baseRadius); |
|
286 |
} |
|
287 |
} else { |
|
288 |
baseRadius = Math[this.options.node_images_fill_mode ? "min" : "max"](width, height) / 2; |
|
289 |
centerPoint = new paper.Point(0,0); |
|
290 |
if (!this.options.show_node_circles) { |
|
291 |
this.h_ratio = height / (2 * baseRadius); |
|
292 |
} |
|
293 |
} |
|
294 |
var _raster = new paper.Raster(_image); |
|
295 |
_raster.locked = true; // Disable mouse events on icon |
|
296 |
if (hasClipPath) { |
|
297 |
_raster = new paper.Group(_clip, _raster); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
298 |
_raster.opacity = 0.99; |
| 284 | 299 |
/* This is a workaround to allow clipping at group level |
300 |
* If opacity was set to 1, paper.js would merge all clipping groups in one (known bug). |
|
301 |
*/ |
|
302 |
_raster.clipped = true; |
|
303 |
_clip.__representation = this; |
|
304 |
} |
|
305 |
if (this.options.clip_node_images) { |
|
| 326 | 306 |
var _circleClip = this.shapeBuilder.getImageShape(centerPoint, baseRadius); |
| 284 | 307 |
_raster = new paper.Group(_circleClip, _raster); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
308 |
_raster.opacity = 0.99; |
| 284 | 309 |
_raster.clipped = true; |
310 |
_circleClip.__representation = this; |
|
311 |
} |
|
312 |
this.image_delta = centerPoint.divide(baseRadius); |
|
313 |
this.node_image = _raster; |
|
314 |
this.node_image.__representation = _this; |
|
315 |
this.node_image.scale(this.circle_radius / baseRadius); |
|
316 |
this.node_image.position = this.paper_coords.subtract(this.image_delta.multiply(this.circle_radius)); |
|
|
435
e529b633c339
Add shape management, correction on shape manip[ulation on the client, correct 404 error on space creation, increment version
ymh <ymh.work@gmail.com>
parents:
434
diff
changeset
|
317 |
this.node_image.insertAbove(this.circle); |
| 284 | 318 |
} else { |
319 |
var _this = this; |
|
320 |
$(_image).on("load", function() { |
|
321 |
_this.showImage(); |
|
322 |
}); |
|
323 |
} |
|
324 |
}, |
|
325 |
paperShift: function(_delta) { |
|
326 |
if (this.options.editor_mode) { |
|
327 |
if (!this.renkan.read_only) { |
|
328 |
this.is_dragging = true; |
|
329 |
this.paper_coords = this.paper_coords.add(_delta); |
|
330 |
this.redraw(); |
|
331 |
} |
|
332 |
} else { |
|
333 |
this.renderer.paperShift(_delta); |
|
334 |
} |
|
335 |
}, |
|
336 |
openEditor: function() { |
|
337 |
this.renderer.removeRepresentationsOfType("editor"); |
|
338 |
var _editor = this.renderer.addRepresentation("NodeEditor",null); |
|
339 |
_editor.source_representation = this; |
|
340 |
_editor.draw(); |
|
341 |
}, |
|
342 |
select: function() { |
|
343 |
this.selected = true; |
|
344 |
this.circle.strokeWidth = this.options.selected_node_stroke_width; |
|
| 450 | 345 |
if (this.renderer.isEditable() && !this.hidden) { |
| 284 | 346 |
this.active_buttons.forEach(function(b) { |
347 |
b.show(); |
|
348 |
}); |
|
349 |
} |
|
350 |
var _uri = this.model.get("uri"); |
|
351 |
if (_uri) { |
|
352 |
$('.Rk-Bin-Item').each(function() { |
|
353 |
var _el = $(this); |
|
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
354 |
if (_el.attr("data-uri") === _uri) { |
| 284 | 355 |
_el.addClass("selected"); |
356 |
} |
|
357 |
}); |
|
358 |
} |
|
359 |
if (!this.options.editor_mode) { |
|
360 |
this.openEditor(); |
|
361 |
} |
|
362 |
||
363 |
if (this.renderer.minimap) { |
|
364 |
this.minimap_circle.strokeWidth = this.options.minimap_highlight_weight; |
|
365 |
this.minimap_circle.strokeColor = this.options.minimap_highlight_color; |
|
366 |
} |
|
| 450 | 367 |
//if the node is hidden and the mouse hover it, it appears as a ghost |
368 |
if (this.hidden){ |
|
369 |
this.show(true); |
|
370 |
} |
|
| 284 | 371 |
this._super("select"); |
372 |
}, |
|
| 396 | 373 |
hideButtons: function() { |
374 |
this.all_buttons.forEach(function(b) { |
|
375 |
b.hide(); |
|
376 |
}); |
|
377 |
delete(this.buttonTimeout); |
|
378 |
}, |
|
| 284 | 379 |
unselect: function(_newTarget) { |
380 |
if (!_newTarget || _newTarget.source_representation !== this) { |
|
381 |
this.selected = false; |
|
| 396 | 382 |
var _this = this; |
383 |
this.buttons_timeout = setTimeout(function() { _this.hideButtons(); }, 200); |
|
| 284 | 384 |
this.circle.strokeWidth = this.options.node_stroke_width; |
385 |
$('.Rk-Bin-Item').removeClass("selected"); |
|
386 |
if (this.renderer.minimap) { |
|
387 |
this.minimap_circle.strokeColor = undefined; |
|
388 |
} |
|
| 450 | 389 |
//when the mouse don't hover the node anymore, we hide it |
390 |
if (this.hidden){ |
|
391 |
this.hide(); |
|
392 |
} |
|
| 284 | 393 |
this._super("unselect"); |
394 |
} |
|
395 |
}, |
|
| 450 | 396 |
hide: function(){ |
397 |
var _this = this; |
|
398 |
this.ghost = false; |
|
399 |
this.hidden = true; |
|
400 |
if (typeof this.node_image !== 'undefined'){ |
|
401 |
this.node_image.opacity = 0; |
|
402 |
} |
|
403 |
this.hideButtons(); |
|
404 |
this.circle.opacity = 0; |
|
405 |
this.title.css('opacity', 0); |
|
406 |
this.minimap_circle.opacity = 0; |
|
407 |
|
|
408 |
|
|
409 |
_.each( |
|
410 |
this.project.get("edges").filter( |
|
411 |
function (ed) { |
|
412 |
return ((ed.get("to") === _this.model) || (ed.get("from") === _this.model)); |
|
413 |
} |
|
414 |
), |
|
415 |
function(edge, index, list) { |
|
416 |
var repr = _this.renderer.getRepresentationByModel(edge); |
|
417 |
if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
418 |
repr.hide(); |
|
419 |
} |
|
420 |
} |
|
421 |
); |
|
422 |
}, |
|
423 |
show: function(ghost){ |
|
424 |
var _this = this; |
|
425 |
this.ghost = ghost; |
|
426 |
if (this.ghost){ |
|
427 |
if (typeof this.node_image !== 'undefined'){ |
|
428 |
this.node_image.opacity = 0.3; |
|
429 |
} |
|
430 |
this.circle.opacity = 0.3; |
|
431 |
this.title.css('opacity', 0.3); |
|
432 |
this.minimap_circle.opacity = 0.3; |
|
433 |
} else { |
|
434 |
this.hidden = false; |
|
435 |
this.redraw(); |
|
436 |
} |
|
437 |
|
|
438 |
_.each( |
|
439 |
this.project.get("edges").filter( |
|
440 |
function (ed) { |
|
441 |
return ((ed.get("to") === _this.model) || (ed.get("from") === _this.model)); |
|
442 |
} |
|
443 |
), |
|
444 |
function(edge, index, list) { |
|
445 |
var repr = _this.renderer.getRepresentationByModel(edge); |
|
446 |
if (repr && typeof repr.from_representation !== "undefined" && typeof repr.from_representation.paper_coords !== "undefined" && typeof repr.to_representation !== "undefined" && typeof repr.to_representation.paper_coords !== "undefined") { |
|
447 |
repr.show(_this.ghost); |
|
448 |
} |
|
449 |
} |
|
450 |
); |
|
451 |
}, |
|
| 284 | 452 |
highlight: function(textToReplace) { |
453 |
var hlvalue = textToReplace || true; |
|
454 |
if (this.highlighted === hlvalue) { |
|
455 |
return; |
|
456 |
} |
|
457 |
this.highlighted = hlvalue; |
|
458 |
this.redraw(); |
|
459 |
this.renderer.throttledPaperDraw(); |
|
460 |
}, |
|
461 |
unhighlight: function() { |
|
462 |
if (!this.highlighted) { |
|
463 |
return; |
|
464 |
} |
|
465 |
this.highlighted = false; |
|
466 |
this.redraw(); |
|
467 |
this.renderer.throttledPaperDraw(); |
|
468 |
}, |
|
469 |
saveCoords: function() { |
|
470 |
var _coords = this.renderer.toModelCoords(this.paper_coords), |
|
471 |
_data = { |
|
472 |
position: { |
|
473 |
x: _coords.x, |
|
474 |
y: _coords.y |
|
475 |
} |
|
476 |
}; |
|
477 |
if (this.renderer.isEditable()) { |
|
478 |
this.model.set(_data); |
|
479 |
} |
|
480 |
}, |
|
481 |
mousedown: function(_event, _isTouch) { |
|
482 |
if (_isTouch) { |
|
483 |
this.renderer.unselectAll(); |
|
484 |
this.select(); |
|
485 |
} |
|
486 |
}, |
|
487 |
mouseup: function(_event, _isTouch) { |
|
488 |
if (this.renderer.is_dragging && this.renderer.isEditable()) { |
|
489 |
this.saveCoords(); |
|
490 |
} else { |
|
| 450 | 491 |
if (this.hidden){ |
492 |
var index = this.renderer.hiddenNodes.indexOf(this.model.id); |
|
493 |
if (index !== -1){ |
|
494 |
this.renderer.hiddenNodes.splice(index, 1); |
|
495 |
} |
|
496 |
this.show(false); |
|
497 |
this.select(); |
|
498 |
}else{ |
|
499 |
if (!_isTouch && !this.model.get("delete_scheduled")) { |
|
500 |
this.openEditor(); |
|
501 |
} |
|
502 |
this.model.trigger("clicked"); |
|
| 284 | 503 |
} |
504 |
} |
|
505 |
this.renderer.click_target = null; |
|
506 |
this.renderer.is_dragging = false; |
|
507 |
this.is_dragging = false; |
|
508 |
}, |
|
509 |
destroy: function(_event) { |
|
510 |
this._super("destroy"); |
|
511 |
this.all_buttons.forEach(function(b) { |
|
512 |
b.destroy(); |
|
513 |
}); |
|
514 |
this.circle.remove(); |
|
515 |
this.title.remove(); |
|
516 |
if (this.renderer.minimap) { |
|
517 |
this.minimap_circle.remove(); |
|
518 |
} |
|
519 |
if (this.node_image) { |
|
520 |
this.node_image.remove(); |
|
521 |
} |
|
522 |
} |
|
| 433 | 523 |
}).value(); |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
524 |
|
| 284 | 525 |
return NodeRepr; |
|
293
fba23fde14ba
Correct jshint errors and force it on build
ymh <ymh.work@gmail.com>
parents:
284
diff
changeset
|
526 |
|
| 284 | 527 |
}); |