Revize 8a357c6f
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/webapp/js/components/edge.js | ||
---|---|---|
76 | 76 |
line.setAttribute('y1', start.y); |
77 | 77 |
}); |
78 | 78 |
|
79 |
// lollipop position and rotation
|
|
80 |
var position = getLollipopPosition.call(this);
|
|
81 |
var rotation = getLollipopRotation.call(this);
|
|
79 |
// arrow position and rotation
|
|
80 |
var position = getArrowPosition.call(this);
|
|
81 |
var rotation = getArrowRotation.call(this);
|
|
82 | 82 |
|
83 |
var lollipop = rootElement.querySelector('.lollipop');
|
|
84 |
lollipop.setAttribute('transform', `rotate(${rotation}, ${position.x},${position.y}) translate(${position.x},${position.y})`);
|
|
83 |
var arrow = rootElement.querySelector('.arrow');
|
|
84 |
arrow.setAttribute('transform', `rotate(${rotation}, ${position.x},${position.y}) translate(${position.x},${position.y})`);
|
|
85 | 85 |
}; |
86 | 86 |
|
87 | 87 |
/** |
88 |
* Moved ending point of the edge to new coordinates and rotates the lollipop.
|
|
88 |
* Moved ending point of the edge to new coordinates and rotates the arrow.
|
|
89 | 89 |
* @param {Coordinates} coords New ending coordinates of the edge. |
90 | 90 |
*/ |
91 | 91 |
this.moveEnd = function(coords) { |
... | ... | |
97 | 97 |
line.setAttribute('y2', end.y); |
98 | 98 |
}); |
99 | 99 |
|
100 |
// lollipop position and rotation
|
|
101 |
var position = getLollipopPosition.call(this);
|
|
102 |
var rotation = getLollipopRotation.call(this);
|
|
100 |
// arrow position and rotation
|
|
101 |
var position = getArrowPosition.call(this);
|
|
102 |
var rotation = getArrowRotation.call(this);
|
|
103 | 103 |
|
104 |
var lollipop = rootElement.querySelector('.lollipop');
|
|
105 |
lollipop.setAttribute('transform', `rotate(${rotation}, ${position.x},${position.y}) translate(${position.x},${position.y})`);
|
|
104 |
var arrow = rootElement.querySelector('.arrow');
|
|
105 |
arrow.setAttribute('transform', `rotate(${rotation}, ${position.x},${position.y}) translate(${position.x},${position.y})`);
|
|
106 | 106 |
}; |
107 | 107 |
|
108 | 108 |
/** |
... | ... | |
209 | 209 |
'y2': end.y, |
210 | 210 |
})); |
211 | 211 |
|
212 |
// lollipop position and rotation
|
|
213 |
var position = getLollipopPosition.call(this);
|
|
214 |
var rotation = getLollipopRotation.call(this);
|
|
212 |
// arrow position and rotation
|
|
213 |
var position = getArrowPosition.call(this);
|
|
214 |
var rotation = getArrowRotation.call(this);
|
|
215 | 215 |
|
216 |
// lollipop |
|
217 |
var lollipop = app.utils.createSvgElement('g', { |
|
218 |
'class': 'lollipop lollipop--cross', |
|
216 |
// arrow |
|
217 |
var arrow = app.utils.createSvgElement('g', { |
|
218 |
'class': 'arrow', |
|
219 |
'data-edgeId': this.id, |
|
219 | 220 |
'transform': `rotate(${rotation}, ${position.x},${position.y}) translate(${position.x},${position.y})`, |
220 | 221 |
}); |
221 |
lollipop.appendChild(app.utils.createSvgElement('path', { |
|
222 |
'd': 'M0,-12 C16,-12 16,12 0,12', |
|
223 |
})); |
|
224 |
lollipop.appendChild(app.utils.createSvgElement('circle', { |
|
225 |
'cx': 0, |
|
226 |
'cy': 0, |
|
227 |
'r': 8, |
|
228 |
})); |
|
229 |
lollipop.addEventListener('click', click.bind(this)); |
|
230 |
rootElement.appendChild(lollipop); |
|
231 |
|
|
232 |
if (compatible) { |
|
233 |
// tick |
|
234 |
lollipop.appendChild(app.utils.createSvgElement('line', { |
|
235 |
'x1': 6, |
|
236 |
'y1': -4, |
|
237 |
'x2': -4, |
|
238 |
'y2': 6, |
|
239 |
'transform': 'rotate(90)', |
|
240 |
})); |
|
241 |
lollipop.appendChild(app.utils.createSvgElement('line', { |
|
242 |
'x1': -5, |
|
243 |
'y1': -3, |
|
244 |
'x2': -4, |
|
245 |
'y2': 5, |
|
246 |
'transform': 'rotate(90)', |
|
247 |
})); |
|
222 |
arrow.appendChild(app.utils.createSvgElement('polygon', { |
|
223 |
'points': '0,-10 30,0 0,10', |
|
248 | 224 |
|
249 |
} else { |
|
250 |
// cross |
|
251 |
lollipop.appendChild(app.utils.createSvgElement('line', { |
|
252 |
'x1': -5, |
|
253 |
'y1': -5, |
|
254 |
'x2': 5, |
|
255 |
'y2': 5, |
|
256 |
})); |
|
257 |
lollipop.appendChild(app.utils.createSvgElement('line', { |
|
258 |
'x1': -5, |
|
259 |
'y1': 5, |
|
260 |
'x2': 5, |
|
261 |
'y2': -5, |
|
262 |
})); |
|
263 |
} |
|
225 |
})); |
|
226 |
arrow.addEventListener('click', click.bind(this)); |
|
227 |
rootElement.appendChild(arrow); |
|
264 | 228 |
|
265 | 229 |
return rootElement; |
266 | 230 |
}; |
... | ... | |
318 | 282 |
} |
319 | 283 |
|
320 | 284 |
/** |
321 |
* @returns {Coordinates} Current position of the lollipop.
|
|
285 |
* @returns {Coordinates} Current position of the arrow.
|
|
322 | 286 |
*/ |
323 |
function getLollipopPosition() {
|
|
324 |
// lollipop is placed at 1/3 of the distance from start to end
|
|
287 |
function getArrowPosition() {
|
|
288 |
// arrow is placed at 2/3 of the distance from start to end
|
|
325 | 289 |
return new Coordinates( |
326 |
(2 * start.x + end.x) / 3,
|
|
327 |
(2 * start.y + end.y) / 3,
|
|
290 |
(start.x + 2 * end.x) / 3,
|
|
291 |
(start.y + 2 * end.y) / 3,
|
|
328 | 292 |
); |
329 | 293 |
} |
330 | 294 |
|
331 | 295 |
/** |
332 |
* @returns {float} Current rotation of the lollipop in degrees.
|
|
296 |
* @returns {float} Current rotation of the arrow in degrees.
|
|
333 | 297 |
*/ |
334 |
function getLollipopRotation() {
|
|
298 |
function getArrowRotation() {
|
|
335 | 299 |
return -1 * Math.atan2(end.x - start.x, end.y - start.y) * 180 / Math.PI + 90; |
336 | 300 |
} |
337 | 301 |
} |
Také k dispozici: Unified diff
replaced Edge lollipop by arrow