Revize 30af40fd
Přidáno uživatelem Pavel Fidranský před více než 6 roky(ů)
sources/src/main/webapp/js/components/minimap.js | ||
---|---|---|
6 | 6 |
var rootElement; |
7 | 7 |
var viewportElement; |
8 | 8 |
|
9 |
var width = 350; |
|
10 |
var height = 200; |
|
9 | 11 |
var scale = 0.1; |
10 | 12 |
var useElement = '#graph'; |
11 | 13 |
|
... | ... | |
45 | 47 |
rootElement = app.utils.createSvgElement('svg', { |
46 | 48 |
'class': 'minimap', |
47 | 49 |
'id': 'minimapComponent', |
48 |
'viewBox': '-100 -50 350 200',
|
|
50 |
'viewBox': `-100 -50 ${width} ${height}`,
|
|
49 | 51 |
}); |
52 |
rootElement.addEventListener('mousedown', onRootMouseDown.bind(this)); |
|
50 | 53 |
|
51 | 54 |
var graphElement = app.dom.createSvgElement('use', { |
52 | 55 |
'transform': `scale(${scale})`, |
... | ... | |
63 | 66 |
return rootElement; |
64 | 67 |
}; |
65 | 68 |
|
69 |
function onRootMouseDown(e) { |
|
70 |
var start = new Coordinates(e.clientX, e.clientY); |
|
71 |
|
|
72 |
var viewBox = rootElement.getAttribute('viewBox').split(' '); |
|
73 |
var minimapRootPosition = new Coordinates(parseInt(viewBox[0]), parseInt(viewBox[1])); |
|
74 |
|
|
75 |
document.body.addEventListener('mousemove', mouseMove); |
|
76 |
document.body.addEventListener('mouseup', mouseUp); |
|
77 |
|
|
78 |
function mouseMove(e) { |
|
79 |
e.preventDefault(); |
|
80 |
|
|
81 |
var offset = new Coordinates(start.x - e.clientX, start.y - e.clientY); |
|
82 |
|
|
83 |
rootElement.setAttribute('viewBox', `${minimapRootPosition.x + offset.x} ${minimapRootPosition.y + offset.y} ${width} ${height}`); |
|
84 |
} |
|
85 |
|
|
86 |
function mouseUp(e) { |
|
87 |
start = null; |
|
88 |
|
|
89 |
document.body.removeEventListener('mousemove', mouseMove); |
|
90 |
document.body.removeEventListener('mouseup', mouseUp); |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
66 | 94 |
function onViewportMouseDown(e) { |
95 |
e.stopPropagation(); |
|
96 |
|
|
67 | 97 |
var start = new Coordinates(e.clientX, e.clientY); |
68 | 98 |
var minimapViewportPosition = this.getViewportPosition(); |
69 | 99 |
var viewportPosition = app.viewportComponent.getPosition(); |
Také k dispozici: Unified diff
improved Minimap to allow moving its canvas within its container