1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
var mouse_move = function (e) {
if (this.rrdgraph.mousedown) {
var factor = (this.rrdgraph.end - this.rrdgraph.start) / this.rrdgraph.xsize;
var x = e.pageX - this.offsetLeft;
var diff = x - this.rrdgraph.mousex;
var difffactor = Math.abs(Math.round(diff*factor));
if (diff > 0) {
this.rrdgraph.end -= difffactor;
this.rrdgraph.start -= difffactor;
} else {
this.rrdgraph.end += difffactor;
this.rrdgraph.start += difffactor;
}
this.rrdgraph.mousex = x;
try {
this.rrdgraph.graph_paint();
} catch (e) {
alert(e+"\n"+e.stack);
}
}
};
var mouse_up = function (e) {
this.rrdgraph.mousedown = false;
this.style.cursor="default";
};
var mouse_down = function (e) {
var x = e.pageX - this.offsetLeft;
this.rrdgraph.mousedown = true;
this.rrdgraph.mousex = x;
this.style.cursor="move";
};
var mouse_scroll = function (e) {
e = e ? e : window.event;
var wheel = e.detail ? e.detail * -1 : e.wheelDelta / 40;
var cstime = this.stime[this.stidx];
if (wheel < 0) {
this.stidx++;
if (this.stidx >= this.stlen) this.stidx = this.stlen-1;
} else {
this.stidx--;
if (this.stidx < 0) this.stidx = 0;
}
if (cstime !== this.stime[this.stidx]) {
var middle = this.rrdgraph.start + Math.abs(Math.round((this.rrdgraph.end - this.rrdgraph.start)/2));
this.rrdgraph.start = Math.round(middle - this.stime[this.stidx]/2);
this.rrdgraph.end = this.rrdgraph.start + this.stime[this.stidx];
try {
this.rrdgraph.graph_paint();
} catch (e) {
alert(e+"\n"+e.stack);
}
}
if(e.stopPropagation)
e.stopPropagation();
if(e.preventDefault)
e.preventDefault();
e.cancelBubble = true;
e.cancel = true;
e.returnValue = false;
return false;
};
function prepare_draw(id) {
RrdGraph.prototype.mousex = 0;
RrdGraph.prototype.mousedown = false;
var cmdline = document.getElementById(id).textContent;
var gfx = new RrdGfxCanvas(id);
var fetch = new RrdDataFile();
var rrdcmdline = null;
try {
rrdcmdline = new RrdCmdLine(gfx, fetch, cmdline);
} catch (e) {
alert(e+"\n"+e.stack);
}
var rrdgraph = rrdcmdline.graph;
gfx.canvas.stime = [ 300, 600, 900, 1200, 1800, 3600, 7200, 21600, 43200, 86400, 172800, 604800, 2592000, 5184000, 15768000, 31536000 ];
gfx.canvas.stlen = gfx.canvas.stime.length;
gfx.canvas.stidx = 0;
gfx.canvas.rrdgraph = rrdgraph;
gfx.canvas.removeEventListener('mousemove', mouse_move, false);
gfx.canvas.addEventListener('mousemove', mouse_move, false);
gfx.canvas.removeEventListener('mouseup', mouse_up, false);
gfx.canvas.addEventListener('mouseup', mouse_up, false);
gfx.canvas.removeEventListener('mousedown', mouse_down, false);
gfx.canvas.addEventListener('mousedown', mouse_down, false);
gfx.canvas.removeEventListener('mouseout', mouse_up, false);
gfx.canvas.addEventListener('mouseout', mouse_up, false);
gfx.canvas.removeEventListener('DOMMouseScroll', mouse_scroll, false);
gfx.canvas.addEventListener('DOMMouseScroll', mouse_scroll, false);
gfx.canvas.removeEventListener('mousewheel', mouse_scroll, false);
gfx.canvas.addEventListener('mousewheel', mouse_scroll, false);
var diff = rrdgraph.end - rrdgraph.start;
for (var i=0; i < gfx.canvas.stlen; i++) {
if (gfx.canvas.stime[i] >= diff) break;
}
if (i === gfx.canvas.stlen) gfx.canvas.stidx = gfx.canvas.stlen-1;
else gfx.canvas.stidx = i;
return rrdgraph;
}
|