Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 0354f040

Přidáno uživatelem Pavel Fidranský před asi 6 roky(ů)

Viewport minimap

(WIP) minimap may be dragged to move Viewport

viewport Minimap

Zobrazit rozdíly:

sources/src/main/webapp/css/main.css
468 468
	flex-basis: 350px;
469 469
	flex-direction: column;
470 470
	justify-content: space-between;
471
	width: 350px;
472 471
	background-color: #f0f9ff;
473 472
}
474 473

  
......
790 789
	content: "▼";
791 790
}
792 791

  
792
.minimap {
793
	border-top: 1px solid #7db9e8;
794
	background-color: #fff;
795
}
796

  
797
.minimap-viewport {
798
	stroke: #999;
799
	stroke-width: 1px;
800
	fill-opacity: 0;
801
	shape-rendering: crispedges;
802
	transition: stroke .4s;
803
}
804

  
805
.minimap-viewport:hover {
806
	stroke: #000;
807
}
808

  
793 809
.status-bar {
794
    /* position: fixed; */
795
    bottom: 0;
796
    flex-basis: 22px;
797 810
    font-size: 11px;
798 811
    z-index: 1;
799 812
    color: #cceefc;
......
806 819
	padding: 5px;
807 820
}
808 821

  
822
.status-bar .link {
823
	text-decoration: underline;
824
	cursor: pointer;
825
}
826

  
809 827
/**
810 828
 * MODAL WINDOW
811 829
 **/
sources/src/main/webapp/js/app.js
133 133

  
134 134
		self.sidebarComponent = new Sidebar;
135 135
		content.appendChild(self.sidebarComponent.render());
136
		self.sidebarComponent.minimapComponent.setViewportSize(self.viewportComponent.getSize());
136 137

  
137 138
		// context menu
138 139
		document.body.addEventListener('mousedown', function() {
......
279 280
		window.addEventListener('resize', function(e) {
280 281
			self.headerHeight = getHeaderHeight();
281 282
			self.redrawEdges();
283

  
284
			self.sidebarComponent.minimapComponent.setViewportSize(self.viewportComponent.getSize());
282 285
		});
283 286
	}
284 287

  
sources/src/main/webapp/js/components/minimap.js
1
/**
2
 * @constructor
3
 */
4
function Minimap() {
5
	var rootElement;
6
	var viewportElement;
7

  
8
	var zoom = 0.1;
9
	var useElement = '#graph';
10

  
11
	/**
12
	 * 
13
	 * @param {object} size Object holding current dimensions of the viewport component.
14
	 */
15
	this.setViewportSize = function(size) {
16
		viewportElement.setAttribute('width', size.width * zoom);
17
		viewportElement.setAttribute('height', size.height * zoom);
18
	};
19

  
20
	/**
21
	 * @returns {Coordinates} Current coordinates of the viewport.
22
	 */
23
	this.getViewportPosition = function() {
24
		return new Coordinates(
25
			+viewportElement.getAttribute('x'),
26
			+viewportElement.getAttribute('y'),
27
		);
28
	};
29

  
30
	/**
31
	 * TODO: jsDoc
32
	 * @param {Coordinates} coords Coordinates of the viewport.
33
	 */
34
	this.setViewportPosition = function(coords) {
35
		viewportElement.setAttribute('x', coords.x * -1 * zoom);
36
		viewportElement.setAttribute('y', coords.y * -1 * zoom);
37
	};
38

  
39
	/**
40
	 * Creates a new DOM element representing the minimap in memory.
41
	 * @returns {Element} HTML DOM element.
42
	 */
43
	this.render = function() {
44
		rootElement = app.utils.createSvgElement('svg', {
45
			'class': 'minimap',
46
			'id': 'minimapComponent',
47
			'viewBox': '-100 -50 350 200',
48
		});
49

  
50
		var graphElement = app.dom.createSvgElement('use', {
51
			'transform': `scale(${zoom})`,
52
		});
53
		graphElement.setAttributeNS('http://www.w3.org/1999/xlink', 'href', useElement);
54
		rootElement.appendChild(graphElement);
55

  
56
		viewportElement = app.dom.createSvgElement('rect', {
57
			'class': 'minimap-viewport',
58
		});
59
		viewportElement.addEventListener('mousedown', onMouseDown.bind(this));
60
		rootElement.appendChild(viewportElement);
61

  
62
		return rootElement;
63
	};
64

  
65
	function onMouseDown(e) {
66
		var start = new Coordinates(e.clientX, e.clientY);
67
		var minimapViewportPosition = this.getViewportPosition();
68
		var viewportPosition = app.viewportComponent.getPosition();
69

  
70
		viewportElement.addEventListener('mousemove', mouseMove);
71
		viewportElement.addEventListener('mouseup', mouseUp);
72
		
73
		function mouseMove(e) {
74
			e.preventDefault();
75

  
76
			var offset = new Coordinates(start.x - e.clientX, start.y - e.clientY);
77

  
78
			viewportElement.setAttribute('x', minimapViewportPosition.x - offset.x);
79
			viewportElement.setAttribute('y', minimapViewportPosition.y - offset.y);
80

  
81
			app.viewportComponent.setPosition(new Coordinates(viewportPosition.x + (1 / zoom) * offset.x, viewportPosition.y + (1 / zoom) * offset.y));
82
		}
83

  
84
		function mouseUp(e) {
85
			start = null;
86
			minimapViewportPosition = null;
87
			viewportPosition = null;
88

  
89
			viewportElement.removeEventListener('mousemove', mouseMove);
90
			viewportElement.removeEventListener('mouseup', mouseUp);
91
		}
92
	}
93
}
sources/src/main/webapp/js/components/sidebar.js
9 9
	this.unconnectedNodeListComponent = null;
10 10
	/** @prop {SidebarExcludedNodeList} excludedNodeListComponent */
11 11
	this.excludedNodeListComponent = null;
12
	/** @prop {Minimap} minimapComponent */
13
	this.minimapComponent = null;
12 14
	/** @prop {StatusBar} statusBarComponent */
13 15
	this.statusBarComponent = null;
14 16

  
......
38 40
			'id': 'sidebar',
39 41
		});
40 42

  
41

  
42 43
		var sidebarNav = app.utils.createHtmlElement('nav', {
43 44
			'class': 'sidebar-navbar',
44 45
			'id': 'uploadMenu',
......
75 76
		});
76 77
		sidebarContainer.appendChild(this.unconnectedNodeListComponent.render());
77 78

  
78

  
79 79
		// excluded nodes
80 80
		this.excludedNodeListComponent = new SidebarExcludedNodeList({
81 81
			'id': 'excludedNodeListComponent',
......
83 83
		rootElement.appendChild(this.excludedNodeListComponent.render());
84 84

  
85 85

  
86
		var sidebarBottom = app.utils.createHtmlElement('div', {
87
			'class': 'sidebar-bottom',
88
		});
89
		rootElement.appendChild(sidebarBottom);
90

  
91
		// minimap
92
		this.minimapComponent = new Minimap;
93
		sidebarBottom.appendChild(this.minimapComponent.render());
94

  
86 95
		// status bar
87 96
		this.statusBarComponent = new StatusBar;
88
		rootElement.appendChild(this.statusBarComponent.render());
89

  
97
		sidebarBottom.appendChild(this.statusBarComponent.render());
90 98

  
91 99
		return rootElement;
92 100
	};
sources/src/main/webapp/js/components/statusBar.js
29 29
		});
30 30
		rootElement.appendChild(componentCounterElement);
31 31

  
32
		minimapToggleElement = app.dom.createHtmlElement('span', {
33
			'class': 'link',
34
		});
35
		minimapToggleElement.appendChild(app.dom.createTextElement('toggle minimap'));
36
		minimapToggleElement.addEventListener('click', toggleMinimap.bind(this));
37
		rootElement.appendChild(minimapToggleElement);
38

  
32 39
		return rootElement;
33 40
	};
34 41

  
......
38 45
	this.reset = function() {
39 46
		componentCounterElement.innerHTML = '';
40 47
	};
48

  
49
	function toggleMinimap(e) {
50
		e.preventDefault();
51

  
52
		document.getElementById('minimapComponent').classList.toggle('hidden');
53
	}
41 54
}
sources/src/main/webapp/js/components/viewport.js
94 94
		return groupList;
95 95
	};
96 96

  
97
	this.getSize = function() {
98
		return {
99
			'width': rootElement.offsetWidth,
100
			'height': rootElement.offsetHeight,
101
		};
102
	};
103

  
97 104
	this.getPosition = function() {
98 105
		return new Coordinates(
99 106
			+innerSvgElement.getAttribute('x'),
......
101 108
		);
102 109
	};
103 110

  
111
	this.setPosition = function(coords) {
112
		innerSvgElement.setAttribute('x', coords.x);
113
		innerSvgElement.setAttribute('y', coords.y);
114
	};
115

  
104 116
	this.center = function() {
105 117
		var sumOfCenters = new Coordinates(0, 0);
106 118
		var bbox = rootElement.getBoundingClientRect();
......
222 234
		
223 235
		function mouseMove(e) {
224 236
			if (!pan) return;
225
			
237

  
226 238
			e.preventDefault();
227
			
228
			innerSvgElement.setAttribute('x', position.x - (start.x - e.clientX));
229
			innerSvgElement.setAttribute('y', position.y - (start.y - e.clientY));
239

  
240
			var coords = new Coordinates(position.x - (start.x - e.clientX), position.y - (start.y - e.clientY));
241

  
242
			innerSvgElement.setAttribute('x', coords.x);
243
			innerSvgElement.setAttribute('y', coords.y);
244

  
245
			app.sidebarComponent.minimapComponent.setViewportPosition(coords);
230 246
		}
231 247

  
232 248
		function mouseUp(e) {
sources/src/main/webapp/showGraph.jsp
26 26
		<script src="js/components/floatingPoint.js"></script>
27 27
		<script src="js/components/group.js"></script>
28 28
		<script src="js/components/groupVertexList.js"></script>
29
		<script src="js/components/minimap.js"></script>
29 30
		<script src="js/components/sidebar.js"></script>
30 31
		<script src="js/components/sidebarExcludedNodeList.js"></script>
31 32
		<script src="js/components/sidebarUnconnectedNodeList.js"></script>

Také k dispozici: Unified diff