Revize 6e6b3160
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/webapp/js/components/vertexSymbolList.js | ||
---|---|---|
1 | 1 |
/** |
2 | 2 |
* Class representing list of symbols displayed next to a vertex to marks its relation to other an other, excluded vertices. |
3 | 3 |
* @see Vertex |
4 |
* @constructor |
|
5 | 4 |
*/ |
6 |
function VertexSymbolList() { |
|
7 |
var rootElement; |
|
8 |
|
|
9 |
var width = 20; |
|
5 |
class VertexSymbolList { |
|
6 |
/** |
|
7 |
* @constructor |
|
8 |
*/ |
|
9 |
constructor() { |
|
10 |
this._width = 20; |
|
11 |
this._height = 20; |
|
12 |
} |
|
10 | 13 |
|
11 | 14 |
/** |
12 |
* Adds a new symbol to the list. |
|
13 |
* @param {array} symbol Symbol to be added to the list. |
|
15 |
* Creates a new DOM element representing the list of symbols in memory. |
|
16 |
* @public |
|
17 |
* @returns {SVGElement} SVG DOM element. |
|
14 | 18 |
*/ |
15 |
this.appendChild = function(symbol) {
|
|
16 |
var symbolGroup = DOM.createSvgElement('g', {
|
|
17 |
'class': `neighbour-node-symbol symbol-${symbol[0]}`,
|
|
19 |
render() {
|
|
20 |
this._rootElement = DOM.s('g', {
|
|
21 |
transform: 'translate(0, 30)',
|
|
18 | 22 |
}); |
19 |
rootElement.appendChild(symbolGroup); |
|
20 | 23 |
|
21 |
symbolGroup.appendChild(DOM.createSvgElement('rect', { |
|
22 |
'x': 0, |
|
23 |
'y': 0, |
|
24 |
'width': width, |
|
25 |
'height': 20, |
|
26 |
'fill': symbol[1], |
|
27 |
})); |
|
24 |
return this._rootElement; |
|
25 |
} |
|
28 | 26 |
|
29 |
var symbolText = DOM.createSvgElement('text', { |
|
30 |
'x': 6, |
|
31 |
'y': 15, |
|
32 |
}); |
|
33 |
symbolText.appendChild(document.createTextNode(symbol[0])); |
|
34 |
symbolGroup.appendChild(symbolText); |
|
27 |
/** |
|
28 |
* Adds a new symbol to the list. |
|
29 |
* @public |
|
30 |
* @param {array} symbol Symbol to be added to the list. |
|
31 |
*/ |
|
32 |
appendChild(symbol) { |
|
33 |
this._rootElement.appendChild(DOM.s('g', { |
|
34 |
class: 'neighbour-node-symbol ' + symbol[2], |
|
35 |
}, [ |
|
36 |
DOM.s('rect', { |
|
37 |
x: 0, |
|
38 |
y: 0, |
|
39 |
width: this._width, |
|
40 |
height: this._height, |
|
41 |
fill: symbol[1], |
|
42 |
}), |
|
43 |
DOM.s('text', { |
|
44 |
x: 6, |
|
45 |
y: 15, |
|
46 |
}, [ |
|
47 |
DOM.t(symbol[0]), |
|
48 |
]), |
|
49 |
])); |
|
35 | 50 |
|
36 |
reorderSymbols(); |
|
37 |
};
|
|
51 |
this._reorderSymbols();
|
|
52 |
} |
|
38 | 53 |
|
39 | 54 |
/** |
40 | 55 |
* Removes a symbol from the list. |
56 |
* @public |
|
41 | 57 |
* @param {array} symbol Symbol to be removed from the list. |
42 | 58 |
*/ |
43 |
this.removeChild = function(symbol) {
|
|
44 |
var symbolGroup = rootElement.querySelector(`.symbol-${symbol[0]}`)
|
|
59 |
removeChild(symbol) {
|
|
60 |
let symbolGroup = this._rootElement.querySelector('.' + symbol[2]);
|
|
45 | 61 |
|
46 | 62 |
symbolGroup.remove(); |
47 | 63 |
|
48 |
reorderSymbols(); |
|
49 |
}; |
|
50 |
|
|
51 |
/** |
|
52 |
* Creates a new DOM element representing the list of symbols in memory. |
|
53 |
* @param {Element} symbol SVG DOM element. |
|
54 |
*/ |
|
55 |
this.render = function(symbol) { |
|
56 |
rootElement = DOM.createSvgElement('g', { |
|
57 |
'transform': 'translate(0, 30)', |
|
58 |
}); |
|
59 |
|
|
60 |
return rootElement; |
|
61 |
}; |
|
64 |
this._reorderSymbols(); |
|
65 |
} |
|
62 | 66 |
|
63 | 67 |
/** |
64 | 68 |
* Changes the order of symbols displayed in the list. It is used to refresh their position after one is added or removed. |
69 |
* @private |
|
65 | 70 |
*/ |
66 |
function reorderSymbols() {
|
|
67 |
for (var i = 0; i < rootElement.children.length; i++) { |
|
68 |
var symbolGroup = rootElement.children[i];
|
|
71 |
_reorderSymbols() {
|
|
72 |
for (var i = 0; i < this._rootElement.children.length; i++) {
|
|
73 |
let symbolGroup = this._rootElement.children[i];
|
|
69 | 74 |
|
70 |
symbolGroup.setAttribute('transform', `translate(${i * width + 1}, 1)`); |
|
75 |
symbolGroup.setAttribute('transform', `translate(${i * this._width + 1}, 1)`);
|
|
71 | 76 |
} |
72 | 77 |
} |
73 | 78 |
} |
sources/src/main/webapp/js/markSymbol.js | ||
---|---|---|
1 |
/** |
|
2 |
* This class represents creation of symbols. |
|
3 |
* @constructor |
|
4 |
*/ |
|
5 |
function MarkSymbol() { |
|
6 |
var CONST_MARK_SYMBOLS = ["☺", "☻", "♥", "♦", "♣", "♠", "♫", "☼", "►", "◄", |
|
7 |
"▲", "▼", "■", "▬", "░", "▒", "↕", "↑", "↓", "→", "←", "↔", "╣", "╩", "╠", |
|
8 |
"╚", "╝", "║", "╔", "╦", "═", "╬", "╗", "┴", "┬", "∟", "┌", "├", "┤", |
|
9 |
"⌂", "+", "-", "*", "÷", "×", "=", "±", "Ø", "~", "«", "»", "¤", "¶", "§", |
|
10 |
"‼", "!", "#", "$", "%", "&", "@", "A", "B", "C", "D", "E", "F", "G", "H", |
|
11 |
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", |
|
12 |
"X", "Y", "Z", "©", "®", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", |
|
13 |
"λ", "μ", "ν", "ξ", "π", "ρ", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "Ω", "Φ", |
|
14 |
"Σ", "Λ", "Δ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; |
|
15 |
|
|
16 |
var CONST_MARK_COLORS = ["#DC143C", "#B23AEE", "#63B8FF", "#3D9140", "#B3EE3A", |
|
17 |
"#FFD700", "#B7B7B7", "#FF8000"]; |
|
18 |
|
|
19 |
var removeMarkSymbolList = []; |
|
20 |
var symbolIndex = -1; |
|
21 |
var colorIndex = -1; |
|
22 |
var startColorIndex = 0; |
|
23 |
|
|
24 |
/** |
|
25 |
* Returns symbol with unique char and color. |
|
26 |
*/ |
|
27 |
this.getMarkSymbol = function() { |
|
28 |
if (removeMarkSymbolList.length > 0) { |
|
29 |
return removeMarkSymbolList.shift(); |
|
30 |
} |
|
31 |
|
|
32 |
symbolIndex++; |
|
33 |
colorIndex++; |
|
34 |
|
|
35 |
if (colorIndex === CONST_MARK_COLORS.length) { |
|
36 |
colorIndex = 0; |
|
37 |
} |
|
38 |
|
|
39 |
if (symbolIndex === CONST_MARK_SYMBOLS.length) { |
|
40 |
if (startColorIndex === CONST_MARK_COLORS.length) { |
|
41 |
startColorIndex = 0; |
|
42 |
} |
|
43 |
|
|
44 |
symbolIndex = 0; |
|
45 |
startColorIndex++; |
|
46 |
colorIndex = startColorIndex; |
|
47 |
} |
|
48 |
|
|
49 |
return [CONST_MARK_SYMBOLS[symbolIndex], CONST_MARK_COLORS[colorIndex]]; |
|
50 |
}; |
|
51 |
|
|
52 |
/** |
|
53 |
* Save removed symbol (char + color) to the list of removes symbols. |
|
54 |
* |
|
55 |
* @param symbol symbol to be removed |
|
56 |
*/ |
|
57 |
this.removeSymbol = function(symbol) { |
|
58 |
removeMarkSymbolList.push(symbol); |
|
59 |
}; |
|
60 |
} |
sources/src/main/webapp/js/services/markSymbol.js | ||
---|---|---|
1 |
/** |
|
2 |
* This class represents creation of symbols. |
|
3 |
* @constructor |
|
4 |
*/ |
|
5 |
function MarkSymbol() { |
|
6 |
var CONST_MARK_SYMBOLS = ["☺", "☻", "♥", "♦", "♣", "♠", "♫", "☼", "►", "◄", |
|
7 |
"▲", "▼", "■", "▬", "░", "▒", "↕", "↑", "↓", "→", "←", "↔", "╣", "╩", "╠", |
|
8 |
"╚", "╝", "║", "╔", "╦", "═", "╬", "╗", "┴", "┬", "∟", "┌", "├", "┤", |
|
9 |
"⌂", "+", "-", "*", "÷", "×", "=", "±", "Ø", "~", "«", "»", "¤", "¶", "§", |
|
10 |
"‼", "!", "#", "$", "%", "&", "@", "A", "B", "C", "D", "E", "F", "G", "H", |
|
11 |
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", |
|
12 |
"X", "Y", "Z", "©", "®", "α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", |
|
13 |
"λ", "μ", "ν", "ξ", "π", "ρ", "σ", "τ", "υ", "φ", "χ", "ψ", "ω", "Ω", "Φ", |
|
14 |
"Σ", "Λ", "Δ", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"]; |
|
15 |
|
|
16 |
var CONST_MARK_COLORS = ["#DC143C", "#B23AEE", "#63B8FF", "#3D9140", "#B3EE3A", |
|
17 |
"#FFD700", "#B7B7B7", "#FF8000"]; |
|
18 |
|
|
19 |
var removeMarkSymbolList = []; |
|
20 |
var index = 0; |
|
21 |
var symbolIndex = -1; |
|
22 |
var colorIndex = -1; |
|
23 |
var startColorIndex = 0; |
|
24 |
|
|
25 |
/** |
|
26 |
* Returns symbol with unique char and color. |
|
27 |
*/ |
|
28 |
this.getMarkSymbol = function() { |
|
29 |
if (removeMarkSymbolList.length > 0) { |
|
30 |
return removeMarkSymbolList.shift(); |
|
31 |
} |
|
32 |
|
|
33 |
symbolIndex++; |
|
34 |
colorIndex++; |
|
35 |
|
|
36 |
if (colorIndex === CONST_MARK_COLORS.length) { |
|
37 |
colorIndex = 0; |
|
38 |
} |
|
39 |
|
|
40 |
if (symbolIndex === CONST_MARK_SYMBOLS.length) { |
|
41 |
if (startColorIndex === CONST_MARK_COLORS.length) { |
|
42 |
startColorIndex = 0; |
|
43 |
} |
|
44 |
|
|
45 |
symbolIndex = 0; |
|
46 |
startColorIndex++; |
|
47 |
colorIndex = startColorIndex; |
|
48 |
} |
|
49 |
|
|
50 |
return [CONST_MARK_SYMBOLS[symbolIndex], CONST_MARK_COLORS[colorIndex], 'symbol-' + index++]; |
|
51 |
}; |
|
52 |
|
|
53 |
/** |
|
54 |
* Save removed symbol (char + color) to the list of removes symbols. |
|
55 |
* |
|
56 |
* @param symbol symbol to be removed |
|
57 |
*/ |
|
58 |
this.removeSymbol = function(symbol) { |
|
59 |
removeMarkSymbolList.push(symbol); |
|
60 |
}; |
|
61 |
} |
sources/src/main/webapp/showGraph.jsp | ||
---|---|---|
59 | 59 |
<script src="js/services/graphLoader.js"></script> |
60 | 60 |
<script src="js/services/graphExporter.js"></script> |
61 | 61 |
<script src="js/services/loader.js"></script> |
62 |
<script src="js/services/markSymbol.js"></script> |
|
62 | 63 |
<script src="js/services/zoom.js"></script> |
63 | 64 |
|
64 | 65 |
<script src="js/utils/ajax.js"></script> |
... | ... | |
70 | 71 |
<script src="js/valueObjects/diagram.js"></script> |
71 | 72 |
<script src="js/valueObjects/dimensions.js"></script> |
72 | 73 |
|
73 |
<script src="js/markSymbol.js"></script> |
|
74 | 74 |
<script src="js/constants.js"></script> |
75 | 75 |
|
76 | 76 |
<script src="js/app.js"></script> |
Také k dispozici: Unified diff
reworked VertexSymbolList to ES6 class, fixed CSS class of a symbol to be always valid