1 /* need to put some place else in CSS ? */
3 var color_otherslice="#f08080";
4 var color_thisslice="#a5e0af";
6 var color_rules="#888";
8 var x_txt = {"font": 'Fontin-Sans, Arial', stroke: "none", fill: "#008"},
9 var y_txt = {"font": 'Fontin-Sans, Arial', stroke: "none", fill: "#800"},
18 var leases_namespace = {
20 init_scheduler: function () {
25 table = $$("table#leases_data")[0];
27 table.getElementsBySelector("tbody>tr>th").each(function (cell) {
28 axisy.push(getInnerText(cell));
30 // the timeslot labels
31 table.getElementsBySelector("thead>tr>th").each(function (cell) {
32 axisx.push(getInnerText(cell));
34 // leases - expect colspan to describe length in grains
35 table.getElementsBySelector("tbody>tr>td").each(function (cell) {
36 data.push(new Array (getInnerText(cell),cell.colSpan));
38 // slicename : the upper-left cell
39 var this_slicename = getInnerText(table.getElementsBySelector("thead>tr>td")[0]);
41 var nb_nodes = axisy.length, nb_grains = axisx.length;
42 var total_width = x_nodename + nb_grains*x_grain;
43 var total_height = 2*y_header + nb_nodes*(y_node+y_sep);
44 paper = Raphael("leases_area", total_width, total_height,10);
45 // color = table.css("color");
50 // the time slots legend
52 axisx.each (function (timeslot) {
54 if (col%2 == 0) y += y_header;
56 var label=paper.text(left,y,timeslot).attr(y_txt).attr({"font-size":y_header,
57 "text-anchor":"middle"});
58 var path_spec="M"+left+" "+(y+y_header/2)+"L"+left+" "+total_height;
59 var rule=paper.path(path_spec).attr({'stroke':1,"fill":color_rules});
63 top += 2*y_header+y_sep;
66 axisy.each(function (node) {
68 var label = paper.text(x_nodename-x_sep,top+y_node/2,node).attr(x_txt).attr ({"font-size":y_node,
70 "baseline":"bottom"});
74 while (grain < nb_grains) {
75 slicename=data[data_index][0];
76 duration=data[data_index][1];
77 var lease=paper.rect (left,top,x_grain*duration,y_node,radius);
79 if (slicename == "") color=color_free;
80 else if (slicename == this_slicename) color=color_thisslice;
82 color=color_otherslice;
83 /* attempt to display the name of the slice that owns that lease - not working too well */
84 var label = paper.text (left+(x_grain*duration)/2,top+y_node/2,slicename).attr("display","none");
86 lease[0].onmouseover = function () { label.show(); }
87 lease[0].onmouseout = function () { label.hide(); }
89 lease.attr("fill",color);
91 left += x_grain*duration;
94 top += y_node + y_sep;
99 r.rect(10, 10, total_width-20, total_height-20, radius).attr({fill: "#888", stroke: "#fff"});
100 for (var i = 0, ii = axisx.length; i < ii; i++) {
101 r.text(leftgutter + X * (i + .5), 294, axisx[i]).attr(txt);
103 for (var i = 0, ii = axisy.length; i < ii; i++) {
104 r.text(10, Y * (i + .5), axisy[i]).attr(txt);
107 for (var i = 0, ii = axisy.length; i < ii; i++) {
108 for (var j = 0, jj = axisx.length; j < jj; j++) {
109 var R = data[o] && Math.min(Math.round(Math.sqrt(data[o] / Math.PI) * 4), max);
111 (function (dx, dy, R, value) {
112 var color = "hsb(" + [(1 - R / max) * .5, 1, .75] + ")";
113 var dt = r.circle(dx + 60 + R, dy + 10, R).attr({stroke: "none", fill: color});
115 var bg = r.circle(dx + 60 + R, dy + 10, 6).attr({stroke: "none", fill: "#000", opacity: .4}).hide();
117 var lbl = r.text(dx + 60 + R, dy + 10, data[o])
118 .attr({"font": '10px Fontin-Sans, Arial', stroke: "none", fill: "#fff"}).hide();
119 var dot = r.circle(dx + 60 + R, dy + 10, max).attr({stroke: "none", fill: "#000", opacity: 0});
120 dot[0].onmouseover = function () {
124 var clr = Raphael.rgb2hsb(color);
126 dt.attr("fill", Raphael.hsb2rgb(clr).hex);
130 dot[0].onmouseout = function () {
134 dt.attr("fill", color);
138 })(leftgutter + X * (j + .5) - 60 - R, Y * (i + .5) - 10, R, data[o]);
147 Event.observe(window, 'load', leases_namespace.init_scheduler);