1 /* need to put some place else in CSS ? */
3 /* decorations / headers */
5 var txt_nodename = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#008"};
6 var txt_timeslot = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#008"};
7 var color_rules="#888";
13 /* lease dimensions and colors */
17 var color_otherslice="#f08080";
18 var color_thisslice="#a5e0af";
19 var color_free="#f0fcd4";
21 /* other slices name */
22 var txt_slice = {"font": '"Trebuchet MS", Verdana, Arial, Helvetica, sans-serif', stroke: "none", fill: "#444",
25 var leases_namespace = {
27 init_scheduler: function () {
32 table = $$("table#leases_data")[0];
33 // no reservable nodes - no data
36 table.getElementsBySelector("tbody>tr>th").each(function (cell) {
37 axisy.push(getInnerText(cell));
39 // the timeslot labels
40 table.getElementsBySelector("thead>tr>th").each(function (cell) {
41 /* [0]: timestamp -- [1]: displayable*/
42 axisx.push(getInnerText(cell).split("&"));
44 // leases - expect colspan to describe length in grains
45 table.getElementsBySelector("tbody>tr>td").each(function (cell) {
46 data.push(new Array (getInnerText(cell),cell.colSpan));
48 // slicename : the upper-left cell
49 var this_slicename = getInnerText(table.getElementsBySelector("thead>tr>td")[0]);
51 var nb_nodes = axisy.length, nb_grains = axisx.length;
52 var total_width = x_nodename + nb_grains*x_grain;
53 var total_height = 2*y_header + nb_nodes*(y_node+y_sep);
54 // no radius supported
55 paper = Raphael("leases_area", total_width, total_height);
56 // color = table.css("color");
61 // the time slots legend
63 axisx.each (function (timeslot_spec) {
64 timeslot=timeslot_spec[1];
66 if (col%2 == 0) y += y_header;
68 var timelabel=paper.text(left,y,timeslot).attr(txt_timeslot)
69 .attr({"font-size":y_header, "text-anchor":"middle"});
70 var path_spec="M"+left+" "+(y+y_header/2)+"L"+left+" "+total_height;
71 var rule=paper.path(path_spec).attr({'stroke':1,"fill":color_rules});
75 top += 2*y_header+y_sep;
78 axisy.each(function (node) {
80 var nodelabel = paper.text(x_nodename-x_sep,top+y_node/2,node).attr(txt_nodename)
81 .attr ({"font-size":y_node, "text-anchor":"end","baseline":"bottom"});
85 while (grain < nb_grains) {
86 slicename=data[data_index][0];
87 duration=data[data_index][1];
88 var lease=paper.rect (left,top,x_grain*duration,y_node,radius);
90 if (slicename == "") {
92 lease.click ( function (e) { window.console.log ('free ' + lease.from_time + '--' + lease.until_time); } );
93 } else if (slicename == this_slicename) {
94 color=color_thisslice;
95 lease.click ( function (e) { window.console.log ('mine ' + lease.from_time + '--' + lease.until_time); } );
97 color=color_otherslice;
98 /* to display the name of the slice that owns that lease */
99 var slicelabel = paper.text (left+(x_grain*duration)/2,top+y_node/2,slicename)
101 /* hide it right away */
103 lease.label=slicelabel;
104 lease.hover ( function (e) { this.label.toFront(); this.label.show(); },
105 function (e) { this.label.hide(); } );
107 lease.attr("fill",color);
108 lease.from_time = axisx[grain%nb_grains][0];
110 lease.until_time = axisx[grain%nb_grains][0];
111 left += x_grain*duration;
114 top += y_node + y_sep;
119 r.rect(10, 10, total_width-20, total_height-20, radius).attr({fill: "#888", stroke: "#fff"});
120 for (var i = 0, ii = axisx.length; i < ii; i++) {
121 r.text(leftgutter + X * (i + .5), 294, axisx[i]).attr(txt);
123 for (var i = 0, ii = axisy.length; i < ii; i++) {
124 r.text(10, Y * (i + .5), axisy[i]).attr(txt);
127 for (var i = 0, ii = axisy.length; i < ii; i++) {
128 for (var j = 0, jj = axisx.length; j < jj; j++) {
129 var R = data[o] && Math.min(Math.round(Math.sqrt(data[o] / Math.PI) * 4), max);
131 (function (dx, dy, R, value) {
132 var color = "hsb(" + [(1 - R / max) * .5, 1, .75] + ")";
133 var dt = r.circle(dx + 60 + R, dy + 10, R).attr({stroke: "none", fill: color});
135 var bg = r.circle(dx + 60 + R, dy + 10, 6).attr({stroke: "none", fill: "#000", opacity: .4}).hide();
137 var lbl = r.text(dx + 60 + R, dy + 10, data[o])
138 .attr({"font": '10px Fontin-Sans, Arial', stroke: "none", fill: "#fff"}).hide();
139 var dot = r.circle(dx + 60 + R, dy + 10, max).attr({stroke: "none", fill: "#000", opacity: 0});
140 dot[0].onmouseover = function () {
144 var clr = Raphael.rgb2hsb(color);
146 dt.attr("fill", Raphael.hsb2rgb(clr).hex);
150 dot[0].onmouseout = function () {
154 dt.attr("fill", color);
158 })(leftgutter + X * (j + .5) - 60 - R, Y * (i + .5) - 10, R, data[o]);
167 Event.observe(window, 'load', leases_namespace.init_scheduler);