diff options
author | Pim van den Berg | 2013-05-18 16:05:43 +0200 |
---|---|---|
committer | Pim van den Berg | 2013-05-18 16:08:09 +0200 |
commit | 5793a8cd003643974206e44ea752ab0966cfa8c0 (patch) | |
tree | 387a6a327af9834f2986ad3316be2183949d897a /js | |
parent | jsrrdgraph: RrdGraph.js: fix undefined 2nd argument of RrdVdef function (diff) | |
download | apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.zip apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.gz apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.bz2 apt-panopticon_cgp-5793a8cd003643974206e44ea752ab0966cfa8c0.tar.xz |
integrate jsrrdgraph in CGP
Diffstat (limited to 'js')
-rw-r--r-- | js/CGP.js | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/js/CGP.js b/js/CGP.js new file mode 100644 index 0000000..3c9ea90 --- /dev/null +++ b/js/CGP.js | |||
@@ -0,0 +1,124 @@ | |||
1 | var mouse_move = function (e) { | ||
2 | if (this.rrdgraph.mousedown) { | ||
3 | var factor = (this.rrdgraph.end - this.rrdgraph.start) / this.rrdgraph.xsize; | ||
4 | var x = e.pageX - this.offsetLeft; | ||
5 | var diff = x - this.rrdgraph.mousex; | ||
6 | var difffactor = Math.abs(Math.round(diff*factor)); | ||
7 | if (diff > 0) { | ||
8 | this.rrdgraph.end -= difffactor; | ||
9 | this.rrdgraph.start -= difffactor; | ||
10 | } else { | ||
11 | this.rrdgraph.end += difffactor; | ||
12 | this.rrdgraph.start += difffactor; | ||
13 | } | ||
14 | this.rrdgraph.mousex = x; | ||
15 | try { | ||
16 | this.rrdgraph.graph_paint(); | ||
17 | } catch (e) { | ||
18 | alert(e+"\n"+e.stack); | ||
19 | } | ||
20 | } | ||
21 | }; | ||
22 | var mouse_up = function (e) { | ||
23 | this.rrdgraph.mousedown = false; | ||
24 | this.style.cursor="default"; | ||
25 | }; | ||
26 | var mouse_down = function (e) { | ||
27 | var x = e.pageX - this.offsetLeft; | ||
28 | this.rrdgraph.mousedown = true; | ||
29 | this.rrdgraph.mousex = x; | ||
30 | this.style.cursor="move"; | ||
31 | }; | ||
32 | var mouse_scroll = function (e) { | ||
33 | e = e ? e : window.event; | ||
34 | var wheel = e.detail ? e.detail * -1 : e.wheelDelta / 40; | ||
35 | var cstime = this.stime[this.stidx]; | ||
36 | if (wheel < 0) { | ||
37 | this.stidx++; | ||
38 | if (this.stidx >= this.stlen) this.stidx = this.stlen-1; | ||
39 | } else { | ||
40 | this.stidx--; | ||
41 | if (this.stidx < 0) this.stidx = 0; | ||
42 | } | ||
43 | if (cstime !== this.stime[this.stidx]) { | ||
44 | var middle = this.rrdgraph.start + Math.abs(Math.round((this.rrdgraph.end - this.rrdgraph.start)/2)); | ||
45 | this.rrdgraph.start = Math.round(middle - this.stime[this.stidx]/2); | ||
46 | this.rrdgraph.end = this.rrdgraph.start + this.stime[this.stidx]; | ||
47 | |||
48 | try { | ||
49 | this.rrdgraph.graph_paint(); | ||
50 | } catch (e) { | ||
51 | alert(e+"\n"+e.stack); | ||
52 | } | ||
53 | } | ||
54 | |||
55 | if(e.stopPropagation) | ||
56 | e.stopPropagation(); | ||
57 | if(e.preventDefault) | ||
58 | e.preventDefault(); | ||
59 | e.cancelBubble = true; | ||
60 | e.cancel = true; | ||
61 | e.returnValue = false; | ||
62 | return false; | ||
63 | }; | ||
64 | |||
65 | function draw(id) { | ||
66 | RrdGraph.prototype.mousex = 0; | ||
67 | RrdGraph.prototype.mousedown = false; | ||
68 | |||
69 | var cmdline = document.getElementById(id).innerHTML; | ||
70 | var gfx = new RrdGfxCanvas(id); | ||
71 | var fetch = new RrdDataFile(); | ||
72 | var rrdcmdline = null; | ||
73 | |||
74 | try { | ||
75 | rrdcmdline = new RrdCmdLine(gfx, fetch, cmdline); | ||
76 | } catch (e) { | ||
77 | alert(e+"\n"+e.stack); | ||
78 | } | ||
79 | |||
80 | var rrdgraph = rrdcmdline.graph; | ||
81 | |||
82 | gfx.canvas.stime = [ 300, 600, 900, 1200, 1800, 3600, 7200, 21600, 43200, 86400, 172800, 604800, 2592000, 5184000, 15768000, 31536000 ]; | ||
83 | gfx.canvas.stlen = gfx.canvas.stime.length; | ||
84 | gfx.canvas.stidx = 0; | ||
85 | |||
86 | gfx.canvas.rrdgraph = rrdgraph; | ||
87 | gfx.canvas.removeEventListener('mousemove', mouse_move, false); | ||
88 | gfx.canvas.addEventListener('mousemove', mouse_move, false); | ||
89 | gfx.canvas.removeEventListener('mouseup', mouse_up, false); | ||
90 | gfx.canvas.addEventListener('mouseup', mouse_up, false); | ||
91 | gfx.canvas.removeEventListener('mousedown', mouse_down, false); | ||
92 | gfx.canvas.addEventListener('mousedown', mouse_down, false); | ||
93 | gfx.canvas.removeEventListener('mouseout', mouse_up, false); | ||
94 | gfx.canvas.addEventListener('mouseout', mouse_up, false); | ||
95 | gfx.canvas.removeEventListener('DOMMouseScroll', mouse_scroll, false); | ||
96 | gfx.canvas.addEventListener('DOMMouseScroll', mouse_scroll, false); | ||
97 | gfx.canvas.removeEventListener('mousewheel', mouse_scroll, false); | ||
98 | gfx.canvas.addEventListener('mousewheel', mouse_scroll, false); | ||
99 | |||
100 | var diff = rrdgraph.end - rrdgraph.start; | ||
101 | for (var i=0; i < gfx.canvas.stlen; i++) { | ||
102 | if (gfx.canvas.stime[i] >= diff) break; | ||
103 | } | ||
104 | if (i === gfx.canvas.stlen) gfx.canvas.stidx = gfx.canvas.stlen-1; | ||
105 | else gfx.canvas.stidx = i; | ||
106 | |||
107 | try { | ||
108 | rrdgraph.graph_paint(); | ||
109 | } catch (e) { | ||
110 | alert(e+"\n"+e.stack); | ||
111 | } | ||
112 | } | ||
113 | |||
114 | function drawAll() | ||
115 | { | ||
116 | var list=[]; | ||
117 | var a=document.getElementsByClassName('rrd'); | ||
118 | for (var i=0,l=a.length;i<l;i++) | ||
119 | { | ||
120 | draw(a[i].getAttribute('id')) | ||
121 | } | ||
122 | } | ||
123 | |||
124 | window.onload = drawAll() | ||