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