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];
34 table.getElementsBySelector("tbody>tr>th").each(function (cell) {
35 axisy.push(getInnerText(cell));
37 // the timeslot labels
38 table.getElementsBySelector("thead>tr>th").each(function (cell) {
39 /* [0]: timestamp -- [1]: displayable*/
40 axisx.push(getInnerText(cell).split("&"));
42 // leases - expect colspan to describe length in grains
43 table.getElementsBySelector("tbody>tr>td").each(function (cell) {
44 data.push(new Array (getInnerText(cell),cell.colSpan));
46 // slicename : the upper-left cell
47 var this_slicename = getInnerText(table.getElementsBySelector("thead>tr>td")[0]);
49 var nb_nodes = axisy.length, nb_grains = axisx.length;
50 var total_width = x_nodename + nb_grains*x_grain;
51 var total_height = 2*y_header + nb_nodes*(y_node+y_sep);
52 // no radius supported
53 paper = Raphael("leases_area", total_width, total_height);
54 // color = table.css("color");
59 // the time slots legend
61 axisx.each (function (timeslot_spec) {
62 timeslot=timeslot_spec[1];
64 if (col%2 == 0) y += y_header;
66 var timelabel=paper.text(left,y,timeslot).attr(txt_timeslot)
67 .attr({"font-size":y_header, "text-anchor":"middle"});
68 var path_spec="M"+left+" "+(y+y_header/2)+"L"+left+" "+total_height;
69 var rule=paper.path(path_spec).attr({'stroke':1,"fill":color_rules});
73 top += 2*y_header+y_sep;
76 axisy.each(function (node) {
78 var nodelabel = paper.text(x_nodename-x_sep,top+y_node/2,node).attr(txt_nodename)
79 .attr ({"font-size":y_node, "text-anchor":"end","baseline":"bottom"});
83 while (grain < nb_grains) {
84 slicename=data[data_index][0];
85 duration=data[data_index][1];
86 var lease=paper.rect (left,top,x_grain*duration,y_node,radius);
88 if (slicename == "") {
90 lease.click ( function (e) { window.console.log ('free ' + lease.from_time + '--' + lease.until_time); } );
91 } else if (slicename == this_slicename) {
92 color=color_thisslice;
93 lease.click ( function (e) { window.console.log ('mine ' + lease.from_time + '--' + lease.until_time); } );
95 color=color_otherslice;
96 /* to display the name of the slice that owns that lease */
97 var slicelabel = paper.text (left+(x_grain*duration)/2,top+y_node/2,slicename)
99 /* hide it right away */
101 lease.label=slicelabel;
102 lease.hover ( function (e) { this.label.toFront(); this.label.show(); },
103 function (e) { this.label.hide(); } );
105 lease.attr("fill",color);
106 lease.from_time = axisx[grain%nb_grains][0];
108 lease.until_time = axisx[grain%nb_grains][0];
109 left += x_grain*duration;
112 top += y_node + y_sep;
117 r.rect(10, 10, total_width-20, total_height-20, radius).attr({fill: "#888", stroke: "#fff"});
118 for (var i = 0, ii = axisx.length; i < ii; i++) {
119 r.text(leftgutter + X * (i + .5), 294, axisx[i]).attr(txt);
121 for (var i = 0, ii = axisy.length; i < ii; i++) {
122 r.text(10, Y * (i + .5), axisy[i]).attr(txt);
125 for (var i = 0, ii = axisy.length; i < ii; i++) {
126 for (var j = 0, jj = axisx.length; j < jj; j++) {
127 var R = data[o] && Math.min(Math.round(Math.sqrt(data[o] / Math.PI) * 4), max);
129 (function (dx, dy, R, value) {
130 var color = "hsb(" + [(1 - R / max) * .5, 1, .75] + ")";
131 var dt = r.circle(dx + 60 + R, dy + 10, R).attr({stroke: "none", fill: color});
133 var bg = r.circle(dx + 60 + R, dy + 10, 6).attr({stroke: "none", fill: "#000", opacity: .4}).hide();
135 var lbl = r.text(dx + 60 + R, dy + 10, data[o])
136 .attr({"font": '10px Fontin-Sans, Arial', stroke: "none", fill: "#fff"}).hide();
137 var dot = r.circle(dx + 60 + R, dy + 10, max).attr({stroke: "none", fill: "#000", opacity: 0});
138 dot[0].onmouseover = function () {
142 var clr = Raphael.rgb2hsb(color);
144 dt.attr("fill", Raphael.hsb2rgb(clr).hex);
148 dot[0].onmouseout = function () {
152 dt.attr("fill", color);
156 })(leftgutter + X * (j + .5) - 60 - R, Y * (i + .5) - 10, R, data[o]);
165 Event.observe(window, 'load', leases_namespace.init_scheduler);