1
|
/**
|
2
|
* Function set height of elements #content,#proposal,#rightPanel
|
3
|
*/
|
4
|
function setHeight() {
|
5
|
var headerHeight = $('#header').height() + $('#navigation').height() + 5; /* magic 5, dunno where it comes from */
|
6
|
var contentHeight = $(window).height() - headerHeight;
|
7
|
|
8
|
$('#viewport').height(contentHeight);
|
9
|
$('#rightPanel').height(contentHeight - 40); /* 40px is the sidebar-navbar */
|
10
|
}
|
11
|
|
12
|
/**
|
13
|
* Convert radian to degrees.
|
14
|
*
|
15
|
* @param radian - radian which will be converted
|
16
|
*/
|
17
|
function radianToDegrees(radian){
|
18
|
return radian*(180.0/Math.PI);
|
19
|
}
|
20
|
|
21
|
/**
|
22
|
* Return position and direction of lollipop.
|
23
|
*
|
24
|
* @param x1 - x coordinate of the first point
|
25
|
* @param y1 - y coordinate of the first point
|
26
|
* @param x2 - x coordinate of the second point
|
27
|
* @param y2 - y coordinate of the second point
|
28
|
*/
|
29
|
function getLollipopPosition(x1, y1, x2, y2){
|
30
|
var lollipop = {},
|
31
|
vector1 = {};
|
32
|
|
33
|
vector1.x = x2 - x1;
|
34
|
vector1.y = y2 - y1;
|
35
|
|
36
|
var lengthX = vector1.x*0.25,
|
37
|
lengthY = vector1.y*0.25;
|
38
|
|
39
|
lollipop.x = (x1 + lengthX);
|
40
|
lollipop.y = (y1 + lengthY);
|
41
|
// lollipop.x = (x1 + x2)/2;
|
42
|
// lollipop.y = (y1 + y2)/2;
|
43
|
|
44
|
lollipop.angle = -radianToDegrees(Math.atan2(vector1.x, vector1.y))+90;
|
45
|
|
46
|
return lollipop;
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Return id, which is parsed from string.
|
51
|
*
|
52
|
* @param idStr string which will be parsed
|
53
|
* @param indexFrom index
|
54
|
* @returns {Number} ID in int form
|
55
|
*/
|
56
|
function getIndexFromId(idStr, indexFrom){
|
57
|
return parseInt(idStr.substr(indexFrom));
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Remove item from array
|
62
|
*
|
63
|
* @param array array from which will be removed
|
64
|
* @param myKey item which will be removed
|
65
|
* @returns {ArrayBuffer|Array.<T>|*|string|Blob} Array without removed item
|
66
|
*/
|
67
|
function removeItem(array,myKey) {
|
68
|
var i = 0;
|
69
|
|
70
|
for (var key in array){
|
71
|
if (array.hasOwnProperty(key)) {
|
72
|
if (key == myKey) {
|
73
|
var del = array.slice(i, 1);
|
74
|
return del;
|
75
|
}
|
76
|
}
|
77
|
i++;
|
78
|
}
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* Create svg element.
|
83
|
*
|
84
|
* @param tag type of element (circle, rect, ...)
|
85
|
* @param attrs attributes of element
|
86
|
* @returns {Element} svg element.
|
87
|
*/
|
88
|
function createSvgElement(tag, attrs) {
|
89
|
var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
|
90
|
for (var k in attrs) {
|
91
|
el.setAttribute(k, attrs[k]);
|
92
|
}
|
93
|
return el;
|
94
|
}
|
95
|
|
96
|
/**
|
97
|
* Compute size of rectangle on the basic count of chars.7
|
98
|
*
|
99
|
* @param name name
|
100
|
* @returns {number} size of rectangle
|
101
|
*/
|
102
|
function getSizeOfRectangle(name){
|
103
|
return name.length * 8 + 35;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* Cut two last character from string.
|
108
|
*
|
109
|
* @param string string which will be cutted.
|
110
|
* @returns {*} cutted string.
|
111
|
*/
|
112
|
function cutTwoLastCharacters(string){
|
113
|
return string.substring(0,string.length-2);
|
114
|
}
|
115
|
|
116
|
/**
|
117
|
* Parse string to int.
|
118
|
*
|
119
|
* @param string string which will be converted to int
|
120
|
* @returns {Number} int
|
121
|
*/
|
122
|
function stringToInt(string){
|
123
|
return parseInt(string);
|
124
|
}
|
125
|
|
126
|
/**
|
127
|
* Parse string to float.
|
128
|
*
|
129
|
* @param string string which will be converted to float
|
130
|
* @returns {Number} float
|
131
|
*/
|
132
|
function stringToFloat(string){
|
133
|
return parseFloat(string);
|
134
|
}
|
135
|
|
136
|
/**
|
137
|
* Set size of svg element.
|
138
|
*
|
139
|
* @param bbox bounding box of svg element
|
140
|
*/
|
141
|
function setSizeSvg(bbox){
|
142
|
$("#svg1").css('width', bbox.width);
|
143
|
$("#svg1").css('height', bbox.height);
|
144
|
}
|
145
|
|
146
|
/**
|
147
|
* Set position of svg element with id #graph.
|
148
|
*
|
149
|
* @param x x axe position
|
150
|
* @param y y axe position
|
151
|
*/
|
152
|
function setPositionSvg(x, y){
|
153
|
$("#graph").attr('transform', 'translate('+ (-x) + ", " + (-y) + ')');
|
154
|
}
|
155
|
|
156
|
/**
|
157
|
* Extract coordinates from string stored in transform attribute.
|
158
|
*
|
159
|
* @param transform string contained in the attribute
|
160
|
* @return object with x and y coordinates
|
161
|
*/
|
162
|
function getCoordinates(transform) {
|
163
|
var parts = /translate\(\s*([^\s,)]+)[ ,]([^\s,)]+)/.exec(transform);
|
164
|
|
165
|
return {
|
166
|
x: stringToFloat(parts[1]),
|
167
|
y: stringToFloat(parts[2]),
|
168
|
};
|
169
|
}
|
170
|
|
171
|
/**
|
172
|
* Finds identifier of the component.
|
173
|
*
|
174
|
* @param {any} element
|
175
|
* @returns
|
176
|
*/
|
177
|
function findId(element) {
|
178
|
while (element.getAttribute('data-id') === null) {
|
179
|
element = element.parentElement;
|
180
|
}
|
181
|
|
182
|
return element.getAttribute('data-id');
|
183
|
}
|
184
|
|
185
|
/**
|
186
|
* Move element to SVG
|
187
|
*
|
188
|
* @param id_parent_element parent element
|
189
|
* @param id_element_to_move where to move element
|
190
|
*/
|
191
|
function moveElementTopSVG(id_parent_element, id_element_to_move){
|
192
|
var graph_elmnt = document.getElementById(id_parent_element),
|
193
|
item = document.getElementById(id_element_to_move);
|
194
|
|
195
|
graph_elmnt.removeChild(item);
|
196
|
graph_elmnt.appendChild(item);
|
197
|
}
|
198
|
|
199
|
var TimeBarrier = {
|
200
|
lastTime: 0,
|
201
|
CONST_WAITING_TIME: 50,
|
202
|
|
203
|
wait: function(){
|
204
|
var currentTime = new Date().getTime();
|
205
|
|
206
|
if ((currentTime - this.lastTime) > this.CONST_WAITING_TIME){
|
207
|
this.lastTime = new Date().getTime();
|
208
|
return false;
|
209
|
}
|
210
|
return true;
|
211
|
}
|
212
|
};
|
213
|
|
214
|
/**
|
215
|
* Usage:
|
216
|
* - for plain JS DOM element: element.isVisible()
|
217
|
* - for jQuery-wrapped element: element[0].isVisible()
|
218
|
*
|
219
|
* @returns true if SVG element is visible, otherwise false
|
220
|
*/
|
221
|
SVGElement.prototype.isVisible = function() {
|
222
|
return $(this).css('display') !== 'none';
|
223
|
};
|
224
|
|
225
|
/**
|
226
|
* @returns true if SVG element is not visible, otherwise false
|
227
|
*/
|
228
|
SVGElement.prototype.isHidden = function() {
|
229
|
return $(this).css('display') === 'none';
|
230
|
};
|