1 |
1e2b2c27
|
Tomáš Šimandl
|
/**
|
2 |
|
|
* @constructor
|
3 |
|
|
* @param {float} defaultScale Default zoom scale.
|
4 |
|
|
*/
|
5 |
|
|
function Zoom(defaultScale) {
|
6 |
|
|
/** @prop {float} scale Current zoom scale. */
|
7 |
|
|
this.scale = defaultScale || 1;
|
8 |
|
|
|
9 |
|
|
var steps = [ 0.1, 0.25, 0.4, 0.55, 0.7, 0.8, 0.9, 1, 1.1, 1.2, 1.3, 1.45, 1.6, 1.75, 1.9, 2.5, 3.5, 5 ];
|
10 |
|
|
var step = steps.indexOf(this.scale);
|
11 |
|
|
|
12 |
|
|
/**
|
13 |
|
|
* Zoom in. If the current scale is maximal, it does nothing.
|
14 |
|
|
*/
|
15 |
|
|
this.zoomIn = function() {
|
16 |
|
|
if (step === steps.length - 1) return;
|
17 |
|
|
|
18 |
|
|
if (step === 0) {
|
19 |
|
|
document.querySelector('#zoomOut').classList.remove('disabled');
|
20 |
|
|
document.querySelector('#zoomOut img').src = 'images/zoom_out.png';
|
21 |
|
|
}
|
22 |
|
|
|
23 |
|
|
step++;
|
24 |
|
|
zoomChanged.call(this);
|
25 |
|
|
|
26 |
|
|
if (step === steps.length - 1) {
|
27 |
|
|
document.querySelector('#zoomIn').classList.add('disabled');
|
28 |
|
|
document.querySelector('#zoomIn img').src = 'images/zoom_in_disabled.png';
|
29 |
|
|
}
|
30 |
|
|
};
|
31 |
|
|
|
32 |
|
|
/**
|
33 |
|
|
* Zoom out. If the current scale is minimal, it does nothing.
|
34 |
|
|
*/
|
35 |
|
|
this.zoomOut = function() {
|
36 |
|
|
if (step === 0) return;
|
37 |
|
|
|
38 |
|
|
if (step === steps.length - 1) {
|
39 |
|
|
document.querySelector('#zoomIn').classList.remove('disabled');
|
40 |
|
|
document.querySelector('#zoomIn img').src = 'images/zoom_in.png';
|
41 |
|
|
}
|
42 |
|
|
|
43 |
|
|
step--;
|
44 |
|
|
zoomChanged.call(this);
|
45 |
|
|
|
46 |
|
|
if (step === 0) {
|
47 |
|
|
document.querySelector('#zoomOut').classList.add('disabled');
|
48 |
|
|
document.querySelector('#zoomOut img').src = 'images/zoom_out_disabled.png';
|
49 |
|
|
}
|
50 |
|
|
};
|
51 |
|
|
|
52 |
|
|
/**
|
53 |
|
|
* Change current zoom scale according to currently selected step.
|
54 |
|
|
*/
|
55 |
|
|
function zoomChanged() {
|
56 |
|
|
this.scale = steps[step];
|
57 |
|
|
|
58 |
|
|
document.getElementById('zoomValue').innerText = Math.round(this.scale * 100) + '%';
|
59 |
|
|
document.getElementById('graph').setAttribute('transform', 'scale(' + this.scale + ')');
|
60 |
|
|
|
61 |
|
|
// TODO: zoom to mouse position / center
|
62 |
|
|
|
63 |
|
|
app.redrawEdges();
|
64 |
|
|
}
|
65 |
|
|
}
|