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