5 |
5 |
class NodeRelatedArchetypeList {
|
6 |
6 |
/**
|
7 |
7 |
* @constructor
|
|
8 |
* @param {Node} node Node this archetype list is bound to.
|
8 |
9 |
*/
|
9 |
10 |
constructor(node) {
|
10 |
11 |
this._node = node;
|
11 |
12 |
this._map = new Map;
|
|
13 |
|
12 |
14 |
this._iconSize = 20;
|
13 |
15 |
}
|
14 |
16 |
|
15 |
|
get map() {
|
|
17 |
get data() {
|
16 |
18 |
return this._map;
|
17 |
19 |
}
|
18 |
20 |
|
... | ... | |
32 |
34 |
}
|
33 |
35 |
|
34 |
36 |
this._map.set(key, currentValue + value);
|
35 |
|
|
36 |
|
this._renderIcons();
|
|
37 |
|
|
38 |
if (this.isRendered) {
|
|
39 |
this._rerender();
|
|
40 |
}
|
37 |
41 |
}
|
38 |
42 |
|
39 |
43 |
remove(key, value = 1) {
|
... | ... | |
46 |
50 |
|
47 |
51 |
this._map.set(key, currentValue - value);
|
48 |
52 |
|
49 |
|
this._renderIcons();
|
|
53 |
if (this.isRendered) {
|
|
54 |
this._rerender();
|
|
55 |
}
|
50 |
56 |
}
|
51 |
57 |
|
|
58 |
/**
|
|
59 |
* Creates a new DOM element representing the list in memory.
|
|
60 |
* @public
|
|
61 |
* @returns {SVGElement} SVG DOM element
|
|
62 |
*/
|
52 |
63 |
render() {
|
53 |
|
if (this._node.isExcluded === true) {
|
54 |
|
this._rootElement = DOM.s('g', {
|
55 |
|
transform: 'translate(10, 15)',
|
56 |
|
});
|
57 |
|
} else {
|
58 |
|
this._rootElement = DOM.s('g', {
|
59 |
|
transform: `translate(${this._node.size.width}, 0)`,
|
60 |
|
});
|
61 |
|
}
|
|
64 |
this._rootElement = this._renderRoot();
|
62 |
65 |
|
63 |
|
this._renderIcons();
|
|
66 |
this._map.forEach((value, key) => {
|
|
67 |
this._rootElement.appendChild(this._renderArchetypeIcon(key, value));
|
|
68 |
});
|
64 |
69 |
|
65 |
70 |
return this._rootElement;
|
66 |
71 |
}
|
67 |
|
|
68 |
|
_renderIcons() {
|
69 |
|
if (Utils.isUndefined(this._rootElement)) return;
|
70 |
|
|
|
72 |
|
|
73 |
/**
|
|
74 |
* @returns {boolean} true if this component has been already rendered, otherwise false
|
|
75 |
*/
|
|
76 |
get isRendered() {
|
|
77 |
return Utils.isDefined(this._rootElement);
|
|
78 |
}
|
|
79 |
|
|
80 |
_rerender() {
|
71 |
81 |
this._rootElement.innerHTML = '';
|
72 |
82 |
|
73 |
|
let iconOrder = 0;
|
74 |
83 |
this._map.forEach((value, key) => {
|
75 |
|
if (this._node.isExcluded === true) {
|
76 |
|
this._rootElement.appendChild(DOM.s('g', {
|
77 |
|
class: 'related-archetype',
|
78 |
|
transform: `translate(0, ${iconOrder * this._iconSize})`,
|
79 |
|
}, [
|
80 |
|
// counter
|
81 |
|
DOM.s('text', {}, [
|
82 |
|
DOM.t(value),
|
83 |
|
]),
|
84 |
|
// icon
|
85 |
|
DOM.s('use', {
|
86 |
|
href: '#vertexArchetypeIcon-' + app.archetype.vertex[key].name,
|
87 |
|
class: 'archetype-icon',
|
88 |
|
transform: `translate(15, -10)`,
|
89 |
|
onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, key), // TODO: when icon == null can not click on item
|
90 |
|
}),
|
91 |
|
// line
|
92 |
|
DOM.s('line', {
|
93 |
|
x1: 30,
|
94 |
|
y1: -5,
|
95 |
|
x2: 36,
|
96 |
|
y2: -5,
|
97 |
|
}),
|
98 |
|
]));
|
99 |
|
} else {
|
100 |
|
this._rootElement.appendChild(DOM.s('use', {
|
101 |
|
href: '#vertexArchetypeIcon-' + app.archetype.vertex[key].name,
|
|
84 |
this._rootElement.appendChild(this._renderArchetypeIcon(key, value));
|
|
85 |
});
|
|
86 |
|
|
87 |
if (this._node.isExcluded) {
|
|
88 |
this._rootElement.setAttribute('height', this.size.height);
|
|
89 |
}
|
|
90 |
}
|
|
91 |
|
|
92 |
_renderRoot() {
|
|
93 |
if (this._node.isExcluded) {
|
|
94 |
return DOM.s('svg', {
|
|
95 |
height: this.size.height,
|
|
96 |
width: 46,
|
|
97 |
});
|
|
98 |
|
|
99 |
} else {
|
|
100 |
return DOM.s('g', {
|
|
101 |
transform: `translate(${this._node.size.width}, 0)`,
|
|
102 |
});
|
|
103 |
}
|
|
104 |
}
|
|
105 |
|
|
106 |
_renderArchetypeIcon(archetypeIndex, counter) {
|
|
107 |
if (this._node.isExcluded) {
|
|
108 |
return DOM.s('g', {
|
|
109 |
class: 'related-archetype',
|
|
110 |
'data-index': archetypeIndex,
|
|
111 |
transform: `translate(10, ${15 + this._rootElement.childNodes.length * this._iconSize})`,
|
|
112 |
}, [
|
|
113 |
// counter
|
|
114 |
DOM.s('text', {}, [
|
|
115 |
DOM.t(counter),
|
|
116 |
]),
|
|
117 |
// icon
|
|
118 |
DOM.s('use', {
|
|
119 |
href: '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
|
102 |
120 |
class: 'archetype-icon',
|
103 |
|
transform: `translate(${iconOrder * this._iconSize}, 8)`,
|
104 |
|
onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, key), // TODO: when icon == null can not click on item
|
105 |
|
}));
|
106 |
|
}
|
|
121 |
transform: `translate(15, -10)`,
|
|
122 |
onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, archetypeIndex), // TODO: when icon == null can not click on item
|
|
123 |
}),
|
|
124 |
// line
|
|
125 |
DOM.s('line', {
|
|
126 |
x1: 30,
|
|
127 |
y1: -5,
|
|
128 |
x2: 36,
|
|
129 |
y2: -5,
|
|
130 |
}),
|
|
131 |
]);
|
107 |
132 |
|
108 |
|
iconOrder++;
|
109 |
|
});
|
|
133 |
} else {
|
|
134 |
// icon
|
|
135 |
return DOM.s('use', {
|
|
136 |
href: '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
|
|
137 |
class: 'archetype-icon',
|
|
138 |
'data-index': archetypeIndex,
|
|
139 |
transform: `translate(${this._rootElement.childNodes.length * this._iconSize}, 8)`,
|
|
140 |
onClick: this._node.onRelatedArchetypeIconClick.bind(this._node, archetypeIndex), // TODO: when icon == null can not click on item
|
|
141 |
});
|
|
142 |
}
|
110 |
143 |
}
|
111 |
144 |
}
|
make related archetype list always fully visible