Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ba4e8154

Přidáno uživatelem Pavel Fidranský před téměř 6 roky(ů)

create NodeSymbol value object, display Group symbol list on correct position, prevent duplicate symbols in list

Zobrazit rozdíly:

sources/src/main/webapp/js/components/group.js
229 229
				height: this.size.height,
230 230
				x: 1,
231 231
				y: 1,
232
				fill: this.symbol[1],
232
				fill: this.symbol.color,
233 233
				stroke: 'black',
234 234
				'stroke-width': 1,
235 235
			}),
......
252 252
				x: 10,
253 253
				y: 60,
254 254
			}, [
255
				DOM.t(this.symbol[0]),
255
				DOM.t(this.symbol.character),
256 256
			]),
257 257
			// dissolve button
258 258
			DOM.s('g', {
......
309 309
			// symbol
310 310
			DOM.h('span', {
311 311
				class: 'group-symbol',
312
				style: 'background-color: ' + this.symbol[1] + ';',
312
				style: 'background-color: ' + this.symbol.color + ';',
313 313
				x: 10,
314 314
				y: 55,
315
				innerText: this.symbol[0],
315
				innerText: this.symbol.character,
316 316
				onClick: this._onNodeClick.bind(this),
317 317
			}),
318 318
			// name
......
330 330
				// show symbol button
331 331
				DOM.h('button', {
332 332
					class: 'show-symbol-button button',
333
					style: 'background-color: ' + this.symbol[1] + ';',
333
					style: 'background-color: ' + this.symbol.color + ';',
334 334
					title: 'Show symbol next to all neighbouring components',
335
					innerText: this.symbol[0],
335
					innerText: this.symbol.character,
336 336
					onClick: this._onShowNeighbourIconsClick.bind(this),
337 337
				}),
338 338
				// include button
sources/src/main/webapp/js/components/node.js
17 17
		this.removeFromSidebarList = Utils.noop;
18 18

  
19 19
		// components
20
		this._symbolListComponent = new NodeSymbolList;
20
		this._symbolListComponent = new NodeSymbolList(this);
21 21
		this._relatedArchetypeListComponent = new NodeRelatedArchetypeList(this);
22 22

  
23 23
		this._position = null;
sources/src/main/webapp/js/components/nodeSymbolList.js
5 5
class NodeSymbolList {
6 6
	/**
7 7
	 * @constructor
8
	 * @param {Node} node Node this symbol list is bound to.
8 9
	 */
9
	constructor() {
10
		this._symbolList = [];
10
	constructor(node) {
11
		this._node = node;
12
		this._symbolList = new Set;
11 13

  
12
		this._width = 20;
13
		this._height = 20;
14
		this._symbolSize = 20;
15
	}
16

  
17
	/**
18
	 * Adds a new symbol to the list.
19
	 * @public
20
	 * @param {array} symbol Symbol to be added to the list.
21
	 */
22
	add(symbol) {
23
		this._symbolList.add(symbol);
24

  
25
		this._rerender();
26
	}
27

  
28
	/**
29
	 * Removes a symbol from the list.
30
	 * @public
31
	 * @param {array} symbol Symbol to be removed from the list.
32
	 */
33
	remove(symbol) {
34
		this._symbolList.delete(symbol);
35

  
36
		this._rerender();
14 37
	}
15 38

  
16 39
	/**
......
20 43
	 */
21 44
	render() {
22 45
		this._rootElement = DOM.s('g', {
23
			transform: 'translate(0, 30)',
46
			transform: `translate(0, ${this._node.size.height})`,
24 47
		});
25 48

  
26 49
		return this._rootElement;
27 50
	}
28 51

  
29
	/**
30
	 * Adds a new symbol to the list.
31
	 * @public
32
	 * @param {array} symbol Symbol to be added to the list.
33
	 */
34
	add(symbol) {
35
		this._symbolList.push(symbol);
52
	_rerender() {
53
		this._rootElement.innerHTML = '';
54

  
55
		this._symbolList.forEach(symbol => {
56
			this._rootElement.appendChild(this._renderNodeSymbol(symbol));
57
		});
58
	}
36 59

  
37
		this._rootElement.appendChild(DOM.s('g', {
38
			class: 'neighbour-node-symbol ' + symbol[2],
60
	_renderNodeSymbol(symbol) {
61
		return DOM.s('g', {
62
			class: 'neighbour-node-symbol ' + symbol.cssClass,
63
			transform: `translate(${1 + this._rootElement.childNodes.length * this._symbolSize}, 1)`,
39 64
		}, [
40 65
			DOM.s('rect', {
41 66
				x: 0,
42 67
				y: 0,
43
				width: this._width,
44
				height: this._height,
45
				fill: symbol[1],
68
				width: this._symbolSize,
69
				height: this._symbolSize,
70
				fill: symbol.color,
46 71
			}),
47 72
			DOM.s('text', {
48 73
				x: 6,
49 74
				y: 15,
50 75
			}, [
51
				DOM.t(symbol[0]),
76
				DOM.t(symbol.character),
52 77
			]),
53
		]));
54

  
55
		this._reorderSymbols();
56
	}
57

  
58
	/**
59
	 * Removes a symbol from the list.
60
	 * @public
61
	 * @param {array} symbol Symbol to be removed from the list.
62
	 */
63
	remove(symbol) {
64
		this._symbolList.splice(this._symbolList.indexOf(symbol), 1);
65

  
66
		let symbolGroup = this._rootElement.querySelector('.' + symbol[2]);
67

  
68
		symbolGroup.remove();
69

  
70
		this._reorderSymbols();
71
	}
72

  
73
	/**
74
	 * Changes the order of symbols displayed in the list. It is used to refresh their position after one is added or removed.
75
	 * @private
76
	 */
77
	_reorderSymbols() {
78
		for (var i = 0; i < this._rootElement.children.length; i++) {
79
			let symbolGroup = this._rootElement.children[i];
80

  
81
			symbolGroup.setAttribute('transform', `translate(${i * this._width + 1}, 1)`);
82
		}
78
		]);
83 79
	}
84 80
}
sources/src/main/webapp/js/components/vertex.js
284 284
			}, [
285 285
				DOM.h('button', {
286 286
					class: 'show-symbol-button button',
287
					style: 'background-color: ' + this.symbol[1] + ';',
287
					style: 'background-color: ' + this.symbol.color + ';',
288 288
					title: 'Show symbol next to all neighbouring components',
289
					innerText: this.symbol[0],
289
					innerText: this.symbol.character,
290 290
					onClick: this._onShowNeighbourIconsClick.bind(this),
291 291
				}),
292 292
				DOM.h('button', {
sources/src/main/webapp/js/components/vertexContextMenuList.js
64 64
		}, [
65 65
			DOM.h('span', {
66 66
				class: 'group-symbol',
67
				style: 'background-color: ' + node.symbol[1] + ';',
68
				innerText: node.symbol[0],
67
				style: 'background-color: ' + node.symbol.color + ';',
68
				innerText: node.symbol.character,
69 69
			}),
70 70
			DOM.h('span', {
71 71
				class: 'group-name',
sources/src/main/webapp/js/services/markSymbol.js
38 38
			this._colorIndex = this._startColorIndex;
39 39
		}
40 40
		
41
		return [
41
		return new NodeSymbol(
42 42
			MarkSymbol.CONST_MARK_SYMBOLS[this._symbolIndex],
43 43
			MarkSymbol.CONST_MARK_COLORS[this._colorIndex],
44 44
			'symbol-' + this._index++,
45
		];
45
		);
46 46
	}
47 47

  
48 48
	/**
sources/src/main/webapp/js/valueObjects/nodeSymbol.js
1
/**
2
 * Class representing a node symbol.
3
 */
4
class NodeSymbol {
5
	/**
6
	 * @constructor
7
	 * @param {string} character Symbol character.
8
	 * @param {string} color Symbol color.
9
	 * @param {string} cssClass Symbol CSS class.
10
	 */
11
	constructor(character, color, cssClass) {
12
		this.character = character;
13
		this.color = color;
14
		this.cssClass = cssClass;
15
	}
16
}
sources/src/main/webapp/showGraph.jsp
88 88
		<script src="js/valueObjects/coordinates.js"></script>
89 89
		<script src="js/valueObjects/diagram.js"></script>
90 90
		<script src="js/valueObjects/dimensions.js"></script>
91
		<script src="js/valueObjects/nodeSymbol.js"></script>
91 92

  
92 93
		<script src="js/constants.js"></script>
93 94

  

Také k dispozici: Unified diff