Projekt

Obecné

Profil

« Předchozí | Další » 

Revize ba4eea92

Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)

reusing Vertex archetype icons in order to decrease number of DOM nodes

Zobrazit rozdíly:

sources/src/main/webapp/js/components/group.js
609 609
			relatedArchetype.appendChild(relatedArchetypeCounter);
610 610

  
611 611
			// icon
612
			var relatedArchetypeIcon = app.dom.createSvgElement('g', {
612
			var relatedArchetypeIcon = app.dom.createSvgElement('use', {
613
				'href': '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
613 614
				'class': 'archetype-icon',
614 615
				'transform': `translate(15, -10)`,
615 616
			});
616 617
			relatedArchetypeIcon.addEventListener('click', relatedArchetypeClick.bind(this, parseInt(archetypeIndex))); // TODO when icon == null can not click on item
617
			relatedArchetypeIcon.innerHTML = app.archetype.vertex[archetypeIndex].icon;
618 618
			relatedArchetype.appendChild(relatedArchetypeIcon);
619 619

  
620 620
			// line
sources/src/main/webapp/js/components/vertex.js
521 521
		}));
522 522

  
523 523
		// archetype icon
524
		var archetypeIcon = app.dom.createSvgElement('g', {
524
		var archetypeIcon = app.dom.createSvgElement('use', {
525
			'href': '#vertexArchetypeIcon-' + app.archetype.vertex[this.archetype].name,
525 526
			'class': 'archetype-icon',
526 527
			'transform': 'translate(8, 8)',
527 528
		});
528 529
		archetypeIcon.addEventListener('click', archetypeClick.bind(this)); // TODO when icon == null can not click on item
529 530

  
530
		archetypeIcon.innerHTML = app.archetype.vertex[this.archetype].icon;
531

  
532 531
		rootElement.appendChild(archetypeIcon);
533 532

  
534 533
		// name
......
548 547

  
549 548
		var archetypeIconOrder = 0;
550 549
		for (var archetypeIndex in relatedArchetypeMap) {
551
			var relatedArchetype = app.utils.createSvgElement('g', {
550
			var relatedArchetypeIcon = app.utils.createSvgElement('use', {
551
				'href': '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
552 552
				'class': 'archetype-icon',
553 553
				'transform': `translate(${archetypeIconOrder * relatedArchetypeIconWidth}, 8)`,
554 554
			});
555
			relatedArchetype.addEventListener('click', relatedArchetypeClick.bind(this, parseInt(archetypeIndex))); // TODO when icon == null can not click on item
556

  
557
			relatedArchetype.innerHTML = app.archetype.vertex[archetypeIndex].icon;
555
			relatedArchetypeIcon.addEventListener('click', relatedArchetypeClick.bind(this, parseInt(archetypeIndex))); // TODO when icon == null can not click on item
558 556

  
559
			relatedArchetypeListContainer.appendChild(relatedArchetype);
557
			relatedArchetypeListContainer.appendChild(relatedArchetypeIcon);
560 558

  
561 559
			archetypeIconOrder++;
562 560
		}
......
608 606
			relatedArchetype.appendChild(relatedArchetypeCounter);
609 607

  
610 608
			// icon
611
			var relatedArchetypeIcon = app.dom.createSvgElement('g', {
609
			var relatedArchetypeIcon = app.dom.createSvgElement('use', {
610
				'href': '#vertexArchetypeIcon-' + app.archetype.vertex[archetypeIndex].name,
612 611
				'class': 'archetype-icon',
613 612
				'transform': `translate(15, -10)`,
614 613
			});
615 614
			relatedArchetypeIcon.addEventListener('click', relatedArchetypeClick.bind(this, parseInt(archetypeIndex))); // TODO when icon == null can not click on item
616
			relatedArchetypeIcon.innerHTML = app.archetype.vertex[archetypeIndex].icon;
617 615
			relatedArchetype.appendChild(relatedArchetypeIcon);
618 616

  
619 617
			// line
sources/src/main/webapp/js/components/viewport.js
17 17
	var edgesContainer;
18 18
	var verticesContainer;
19 19
	var groupsContainer;
20
	var definitions;
20 21

  
21 22
	var pan = false;
22 23

  
......
94 95
		return groupList;
95 96
	};
96 97

  
98
	this.addSvgDefinition = function(id, svgString) {
99
		var g = app.dom.createSvgElement('g', {
100
			'id': id,
101
		});
102
		g.innerHTML = svgString;
103
		definitions.appendChild(g);
104
	};
105

  
97 106
	this.getSize = function() {
98 107
		return {
99 108
			'width': rootElement.offsetWidth,
......
173 182
		groupsContainer.setAttribute('data-id', 'groups');
174 183
		graph.appendChild(groupsContainer);
175 184

  
176
		var defs = app.utils.createSvgElement('defs', {});
177
		mainSvg.appendChild(defs);
185
		definitions = app.utils.createSvgElement('defs', {});
186
		mainSvg.appendChild(definitions);
178 187

  
179 188
		var linearGradient = app.utils.createSvgElement('linearGradient', {
180 189
			'id': 'node--highlighted-required-provided',
......
187 196
			'offset': '100%',
188 197
			'stop-color': '#5896ff',
189 198
		}));
190
		defs.appendChild(linearGradient);
199
		definitions.appendChild(linearGradient);
191 200

  
192 201
		this.contextMenuComponent = new VertexContextMenuList;
193 202
		rootElement.appendChild(this.contextMenuComponent.render());
sources/src/main/webapp/js/graphLoader.js
22 22
		app.attributeTypeList = data.attributeTypes;
23 23
		app.possibleEnumValues = data.possibleEnumValues;
24 24

  
25
		app.archetype.vertex.filter(function(vertexArchetype) {
26
			return app.utils.isDefined(vertexArchetype.icon);
27
		}).forEach(function(vertexArchetype) {
28
			app.viewportComponent.addSvgDefinition('vertexArchetypeIcon-' + vertexArchetype.name, vertexArchetype.icon);
29
		});
30

  
25 31
        var highlightedNodeId;
26 32
        var highlightedNodeType;
27 33
        if (app.utils.isDefined(data.highlightedVertex) && data.highlightedVertex.length > 0) {

Také k dispozici: Unified diff