root / templates / munstrap / static / js / dynazoom.js @ 8589c6df
Historique | Voir | Annoter | Télécharger (6,41 ko)
| 1 |
function refreshZoom(query, form, image, divOverlay) { |
|---|---|
| 2 |
//INIT
|
| 3 |
var qs = new Querystring(query); |
| 4 |
init(); |
| 5 |
|
| 6 |
var scale = refreshImg();
|
| 7 |
var start_epoch = (+qs.get("rst_start_epoch", form.start_epoch.value)); |
| 8 |
var stop_epoch = (+qs.get("rst_stop_epoch", form.stop_epoch.value)); |
| 9 |
var initial_left;
|
| 10 |
var initial_top;
|
| 11 |
|
| 12 |
//form.btnMaj.onclick = majDates;
|
| 13 |
form.plugin_name.onblur = refreshImg; |
| 14 |
form.start_iso8601.onblur = majDates; |
| 15 |
form.stop_iso8601.onblur = majDates; |
| 16 |
form.start_epoch.onblur = refreshImg; |
| 17 |
form.stop_epoch.onblur = refreshImg; |
| 18 |
form.lower_limit.onblur = refreshImg; |
| 19 |
form.upper_limit.onblur = refreshImg; |
| 20 |
form.size_x.onblur = refreshImg; |
| 21 |
form.size_y.onblur = refreshImg; |
| 22 |
form.btnReset.onclick = reset; |
| 23 |
|
| 24 |
// Sets the onClick handler
|
| 25 |
image.onclick = click; |
| 26 |
var clickCounter = 0; |
| 27 |
|
| 28 |
//FUNCTIONS
|
| 29 |
function init() { |
| 30 |
form.plugin_name.value = qs.get("plugin_name", "localdomain/localhost.localdomain/if_eth0"); |
| 31 |
form.start_epoch.value = qs.get("start_epoch", "1236561663"); |
| 32 |
form.stop_epoch.value = qs.get("stop_epoch", "1237561663"); |
| 33 |
form.lower_limit.value = qs.get("lower_limit", ""); |
| 34 |
form.upper_limit.value = qs.get("upper_limit", ""); |
| 35 |
form.size_x.value = qs.get("size_x", ""); |
| 36 |
form.size_y.value = qs.get("size_y", ""); |
| 37 |
|
| 38 |
updateStartStop(); |
| 39 |
} |
| 40 |
|
| 41 |
function reset(event) { |
| 42 |
init(); |
| 43 |
|
| 44 |
//Can be not the initial ones in case of manual refresh
|
| 45 |
form.start_epoch.value = start_epoch; |
| 46 |
form.stop_epoch.value = stop_epoch; |
| 47 |
updateStartStop(); |
| 48 |
|
| 49 |
//Redraw
|
| 50 |
scale = refreshImg(); |
| 51 |
|
| 52 |
//Reset gui
|
| 53 |
clickCounter = 0;
|
| 54 |
initial_left = 0;
|
| 55 |
initial_top = 0;
|
| 56 |
|
| 57 |
image.onmousemove = undefined;
|
| 58 |
form.start_iso8601.disabled = false;
|
| 59 |
form.stop_iso8601.disabled = false;
|
| 60 |
form.start_epoch.disabled = false;
|
| 61 |
form.stop_epoch.disabled = false;
|
| 62 |
} |
| 63 |
|
| 64 |
function refreshImg(event) { |
| 65 |
image.src = qs.get("cgiurl_graph", "/munin-cgi/munin-cgi-graph") + "/" |
| 66 |
+ form.plugin_name.value |
| 67 |
+ "-pinpoint=" + parseInt(form.start_epoch.value) + "," + parseInt(form.stop_epoch.value) |
| 68 |
+ ".png"
|
| 69 |
+ "?"
|
| 70 |
+ "&lower_limit=" + form.lower_limit.value
|
| 71 |
+ "&upper_limit=" + form.upper_limit.value
|
| 72 |
+ "&size_x=" + form.size_x.value
|
| 73 |
+ "&size_y=" + form.size_y.value
|
| 74 |
; |
| 75 |
|
| 76 |
return ((+form.stop_epoch.value) - (+form.start_epoch.value)) / (+form.size_x.value);
|
| 77 |
} |
| 78 |
|
| 79 |
function updateStartStop() { |
| 80 |
form.start_iso8601.value = new Date(form.start_epoch.value * 1000).formatDate(Date.DATE_ISO8601); |
| 81 |
form.stop_iso8601.value = new Date(form.stop_epoch.value * 1000).formatDate(Date.DATE_ISO8601); |
| 82 |
} |
| 83 |
|
| 84 |
function divMouseMove(event) { |
| 85 |
var delta_x;
|
| 86 |
var size_x;
|
| 87 |
|
| 88 |
// Handling the borders (X1>X2 ou X1<X2)
|
| 89 |
var posX = getCoordinatesOnImage(event)[0]; |
| 90 |
var current_width = posX - initial_left;
|
| 91 |
if (current_width < 0) { |
| 92 |
delta_x = posX - 63; // the Y Axis is 63px from the left border |
| 93 |
size_x = -current_width; |
| 94 |
} else {
|
| 95 |
delta_x = initial_left - 63; // the Y Axis is 63px from the left border |
| 96 |
size_x = current_width; |
| 97 |
} |
| 98 |
|
| 99 |
// Compute the epochs UNIX (only for horizontal)
|
| 100 |
form.start_epoch.value = start_epoch + scale * delta_x; |
| 101 |
form.stop_epoch.value = start_epoch + scale * ( delta_x + size_x ); |
| 102 |
|
| 103 |
// update !
|
| 104 |
updateStartStop(); |
| 105 |
} |
| 106 |
|
| 107 |
function startZoom(event) { |
| 108 |
var pos = getCoordinatesOnImage(event);
|
| 109 |
initial_left = pos[0];
|
| 110 |
initial_top = pos[1];
|
| 111 |
|
| 112 |
// Fix the handles
|
| 113 |
form.start_iso8601.disabled = true;
|
| 114 |
form.stop_iso8601.disabled = true;
|
| 115 |
form.start_epoch.disabled = true;
|
| 116 |
form.stop_epoch.disabled = true;
|
| 117 |
image.onmousemove = divMouseMove; |
| 118 |
} |
| 119 |
|
| 120 |
function endZoom(event) { |
| 121 |
image.onmousemove = undefined;
|
| 122 |
form.start_iso8601.disabled = false;
|
| 123 |
form.stop_iso8601.disabled = false;
|
| 124 |
form.start_epoch.disabled = false;
|
| 125 |
form.stop_epoch.disabled = false;
|
| 126 |
} |
| 127 |
|
| 128 |
function fillDate(date, default_date) { |
| 129 |
return date + default_date.substring(date.length, default_date.length);
|
| 130 |
} |
| 131 |
|
| 132 |
function majDates(event) { |
| 133 |
var default_date = "2009-01-01T00:00:00+0100"; |
| 134 |
|
| 135 |
var start_manual = fillDate(form.start_iso8601.value, default_date);
|
| 136 |
var stop_manual = fillDate(form.stop_iso8601.value, default_date);
|
| 137 |
|
| 138 |
var dateRegex = /(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{4})/; |
| 139 |
|
| 140 |
if (dateRegex.test(start_manual)) {
|
| 141 |
var date_parsed = new Date(start_manual.replace(dateRegex, "$2 $3, $1 $4:$5:$6")); |
| 142 |
form.start_epoch.value = date_parsed.getTime() / 1000;
|
| 143 |
} |
| 144 |
|
| 145 |
if (dateRegex.test(stop_manual)) {
|
| 146 |
var date_parsed = new Date(stop_manual.replace(dateRegex, "$2 $3, $1 $4:$5:$6")); |
| 147 |
form.stop_epoch.value = date_parsed.getTime() / 1000;
|
| 148 |
} |
| 149 |
|
| 150 |
//form.submit();
|
| 151 |
refreshImg(); |
| 152 |
} |
| 153 |
|
| 154 |
function click(event) { |
| 155 |
switch ((clickCounter++) % 2) { |
| 156 |
case 0: |
| 157 |
startZoom(event); |
| 158 |
break;
|
| 159 |
case 1: |
| 160 |
endZoom(event); |
| 161 |
break;
|
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
//Coordinates on image
|
| 166 |
function findPosition(oElement) { |
| 167 |
if (typeof( oElement.offsetParent ) != "undefined") { |
| 168 |
for (var posX = 0, posY = 0; oElement; oElement = oElement.offsetParent) { |
| 169 |
posX += oElement.offsetLeft; |
| 170 |
posY += oElement.offsetTop; |
| 171 |
} |
| 172 |
return [posX, posY];
|
| 173 |
} |
| 174 |
else {
|
| 175 |
return [oElement.x, oElement.y];
|
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
function getCoordinatesOnImage(event) { |
| 180 |
var posX = 0; |
| 181 |
var posY = 0; |
| 182 |
var imgPos;
|
| 183 |
imgPos = findPosition(image); |
| 184 |
if (!event) var event = window.event; |
| 185 |
if (event.pageX || event.pageY) {
|
| 186 |
posX = event.pageX; |
| 187 |
posY = event.pageY; |
| 188 |
} |
| 189 |
else if (event.clientX || event.clientY) { |
| 190 |
posX = event.clientX + document.body.scrollLeft |
| 191 |
+ document.documentElement.scrollLeft; |
| 192 |
posY = event.clientY + document.body.scrollTop |
| 193 |
+ document.documentElement.scrollTop; |
| 194 |
} |
| 195 |
posX = posX - imgPos[0];
|
| 196 |
posY = posY - imgPos[1];
|
| 197 |
return [posX, posY];
|
| 198 |
} |
| 199 |
}; |
