Subversion Repositories Applications.papyrus

Compare Revisions

Ignore whitespace Rev 1987 → Rev 1988

/branches/v5.0-ouadji/api/js/dojo/src/charting/vml/Plotters.js
New file
0,0 → 1,889
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.vml.Plotters");
dojo.require("dojo.lang.common");
if (dojo.render.vml.capable) {
dojo.mixin(dojo.charting.Plotters, {_group:function (plotarea) {
var group = document.createElement("div");
group.style.position = "absolute";
group.style.top = "0px";
group.style.left = "0px";
group.style.width = plotarea.size.width + "px";
group.style.height = plotarea.size.height + "px";
return group;
}, Bar:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 8;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var width = ((area.right - area.left) - (space * (nPoints - 1))) / nPoints;
var barWidth = Math.round(width / n);
var yOrigin = plot.axisY.getCoord(plot.axisX.origin, plotarea, plot);
for (var i = 0; i < nPoints; i++) {
var xStart = area.left + (width * i) + (space * i);
for (var j = 0; j < n; j++) {
var value = data[j][i].y;
var yA = yOrigin;
var x = xStart + (barWidth * j);
var y = plot.axisY.getCoord(value, plotarea, plot);
var h = Math.abs(yA - y);
if (value < plot.axisX.origin) {
yA = y;
y = yOrigin;
}
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = barWidth + "px";
bar.style.height = h + "px";
bar.setAttribute("fillColor", data[j][i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
return group;
}, HorizontalBar:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 6;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var h = ((area.bottom - area.top) - (space * (nPoints - 1))) / nPoints;
var barH = h / n;
var xOrigin = plot.axisX.getCoord(0, plotarea, plot);
for (var i = 0; i < nPoints; i++) {
var yStart = area.top + (h * i) + (space * i);
for (var j = 0; j < n; j++) {
var value = data[j][i].y;
var y = yStart + (barH * j);
var xA = xOrigin;
var x = plot.axisX.getCoord(value, plotarea, plot);
var w = Math.abs(x - xA);
if (value > 0) {
x = xOrigin;
}
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = xA + "px";
bar.style.width = w + "px";
bar.style.height = barH + "px";
bar.setAttribute("fillColor", data[j][i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
var space = 4;
var n = plot.series.length;
var h = ((area.bottom - area.top) - (space * (n - 1))) / n;
var xOrigin = plot.axisX.getCoord(0, plotarea, plot);
for (var i = 0; i < n; i++) {
var series = plot.series[i];
var data = series.data.evaluate(kwArgs);
var y = area.top + (h * i) + (space * i);
var value = data[data.length - 1].y;
var xA = xOrigin;
var x = plot.axisX.getCoord(value, plotarea, plot);
var w = Math.abs(xA - x);
if (value > 0) {
xA = x;
x = xOrigin;
}
}
return group;
}, Gantt:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 2;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var h = ((area.bottom - area.top) - (space * (nPoints - 1))) / nPoints;
var barH = h / n;
for (var i = 0; i < nPoints; i++) {
var yStart = area.top + (h * i) + (space * i);
for (var j = 0; j < n; j++) {
var high = data[j][i].high;
var low = data[j][i].low;
if (low > high) {
var t = high;
high = low;
low = t;
}
var x = plot.axisX.getCoord(low, plotarea, plot);
var w = plot.axisX.getCoord(high, plotarea, plot) - x;
var y = yStart + (barH * j);
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = w + "px";
bar.style.height = barH + "px";
bar.setAttribute("fillColor", data[j][i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
return group;
}, StackedArea:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = plot.series.length;
var data = [];
var totals = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
for (var j = 0; j < tmp.length; j++) {
if (i == 0) {
totals.push(tmp[j].y);
} else {
totals[j] += tmp[j].y;
}
tmp[j].y = totals[j];
}
data.push(tmp);
}
for (var i = n - 1; i >= 0; i--) {
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "1px");
path.setAttribute("strokecolor", data[i][0].series.color);
path.setAttribute("fillcolor", data[i][0].series.color);
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.4");
path.appendChild(fill);
var cmd = [];
var r = 3;
for (var j = 0; j < data[i].length; j++) {
var values = data[i];
var x = Math.round(plot.axisX.getCoord(values[j].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(values[j].y, plotarea, plot));
if (j == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
cmd.push("l");
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", values[j].series.color);
c.setAttribute("fillcolor", values[j].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[j].src);
}
}
if (i == 0) {
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
cmd.push("l");
cmd.push(Math.round(plot.axisX.getCoord(data[0][0].x, plotarea, plot)) + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
} else {
var values = data[i - 1];
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(values[values.length - 1].y, plotarea, plot)));
for (var j = values.length - 2; j >= 0; j--) {
var x = Math.round(plot.axisX.getCoord(values[j].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(values[j].y, plotarea, plot));
cmd.push("l");
cmd.push(x + "," + y);
}
}
path.setAttribute("path", cmd.join(" ") + " x e");
group.appendChild(path);
}
return group;
}, StackedCurvedArea:function (plotarea, plot, kwArgs, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = plot.series.length;
var data = [];
var totals = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
for (var j = 0; j < tmp.length; j++) {
if (i == 0) {
totals.push(tmp[j].y);
} else {
totals[j] += tmp[j].y;
}
tmp[j].y = totals[j];
}
data.push(tmp);
}
for (var i = n - 1; i >= 0; i--) {
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "1px");
path.setAttribute("strokecolor", data[i][0].series.color);
path.setAttribute("fillcolor", data[i][0].series.color);
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.4");
path.appendChild(fill);
var cmd = [];
var r = 3;
for (var j = 0; j < data[i].length; j++) {
var values = data[i];
var x = Math.round(plot.axisX.getCoord(values[j].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(values[j].y, plotarea, plot));
if (j == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
var lastx = Math.round(plot.axisX.getCoord(values[j - 1].x, plotarea, plot));
var lasty = Math.round(plot.axisY.getCoord(values[j - 1].y, plotarea, plot));
var dx = x - lastx;
var dy = y - lasty;
cmd.push("c");
var cx = Math.round((x - (tension - 1) * (dx / tension)));
cmd.push(cx + "," + lasty);
cx = Math.round((x - (dx / tension)));
cmd.push(cx + "," + y);
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", values[j].series.color);
c.setAttribute("fillcolor", values[j].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[j].src);
}
}
if (i == 0) {
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
cmd.push("l");
cmd.push(Math.round(plot.axisX.getCoord(data[0][0].x, plotarea, plot)) + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
} else {
var values = data[i - 1];
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(values[values.length - 1].y, plotarea, plot)));
for (var j = values.length - 2; j >= 0; j--) {
var x = Math.round(plot.axisX.getCoord(values[j].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(values[j].y, plotarea, plot));
var lastx = Math.round(plot.axisX.getCoord(values[j + 1].x, plotarea, plot));
var lasty = Math.round(plot.axisY.getCoord(values[j + 1].y, plotarea, plot));
var dx = x - lastx;
var dy = y - lasty;
cmd.push("c");
var cx = Math.round((x - (tension - 1) * (dx / tension)));
cmd.push(cx + "," + lasty);
cx = Math.round((x - (dx / tension)));
cmd.push(cx + "," + y);
cmd.push(x + "," + y);
}
}
path.setAttribute("path", cmd.join(" ") + " x e");
group.appendChild(path);
}
return group;
}, DataBar:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = data.length;
var w = (area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower);
var yOrigin = plot.axisY.getCoord(plot.axisX.origin, plotarea, plot);
for (var i = 0; i < n; i++) {
var value = data[i].y;
var yA = yOrigin;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2) + 1;
var y = plot.axisY.getCoord(value, plotarea, plot);
var h = Math.abs(yA - y);
if (value < plot.axisX.origin) {
yA = y;
y = yOrigin;
}
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = w + "px";
bar.style.height = h + "px";
bar.setAttribute("fillColor", data[i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
if (applyTo) {
applyTo(bar, data[i].src);
}
group.appendChild(bar);
}
return group;
}, Line:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
if (data.length == 0) {
return group;
}
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "2px");
path.setAttribute("strokecolor", data[0].series.color);
path.setAttribute("fillcolor", "none");
path.setAttribute("filled", "false");
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var cmd = [];
var r = 3;
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
if (i == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
cmd.push("l");
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", data[i].series.color);
c.setAttribute("fillcolor", data[i].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
path.setAttribute("path", cmd.join(" ") + " e");
group.appendChild(path);
return group;
}, CurvedLine:function (data, plotarea, plot, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
if (data.length == 0) {
return group;
}
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "2px");
path.setAttribute("strokecolor", data[0].series.color);
path.setAttribute("fillcolor", "none");
path.setAttribute("filled", "false");
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var cmd = [];
var r = 3;
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
if (i == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
var lastx = Math.round(plot.axisX.getCoord(data[i - 1].x, plotarea, plot));
var lasty = Math.round(plot.axisY.getCoord(data[i - 1].y, plotarea, plot));
var dx = x - lastx;
var dy = y - lasty;
cmd.push("c");
var cx = Math.round((x - (tension - 1) * (dx / tension)));
cmd.push(cx + "," + lasty);
cx = Math.round((x - (dx / tension)));
cmd.push(cx + "," + y);
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", data[i].series.color);
c.setAttribute("fillcolor", data[i].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
path.setAttribute("path", cmd.join(" ") + " e");
group.appendChild(path);
return group;
}, Area:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
if (data.length == 0) {
return group;
}
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "1px");
path.setAttribute("strokecolor", data[0].series.color);
path.setAttribute("fillcolor", data[0].series.color);
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.4");
path.appendChild(fill);
var cmd = [];
var r = 3;
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
if (i == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
cmd.push("l");
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", data[i].series.color);
c.setAttribute("fillcolor", data[i].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
cmd.push("l");
cmd.push(Math.round(plot.axisX.getCoord(data[0].x, plotarea, plot)) + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
path.setAttribute("path", cmd.join(" ") + " x e");
group.appendChild(path);
return group;
}, CurvedArea:function (data, plotarea, plot, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
if (data.length == 0) {
return group;
}
var path = document.createElement("v:shape");
path.setAttribute("strokeweight", "1px");
path.setAttribute("strokecolor", data[0].series.color);
path.setAttribute("fillcolor", data[0].series.color);
path.setAttribute("coordsize", (area.right - area.left) + "," + (area.bottom - area.top));
path.style.position = "absolute";
path.style.top = "0px";
path.style.left = "0px";
path.style.width = area.right - area.left + "px";
path.style.height = area.bottom - area.top + "px";
var stroke = document.createElement("v:stroke");
stroke.setAttribute("opacity", "0.8");
path.appendChild(stroke);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.4");
path.appendChild(fill);
var cmd = [];
var r = 3;
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
if (i == 0) {
cmd.push("m");
cmd.push(x + "," + y);
} else {
var lastx = Math.round(plot.axisX.getCoord(data[i - 1].x, plotarea, plot));
var lasty = Math.round(plot.axisY.getCoord(data[i - 1].y, plotarea, plot));
var dx = x - lastx;
var dy = y - lasty;
cmd.push("c");
var cx = Math.round((x - (tension - 1) * (dx / tension)));
cmd.push(cx + "," + lasty);
cx = Math.round((x - (dx / tension)));
cmd.push(cx + "," + y);
cmd.push(x + "," + y);
}
var c = document.createElement("v:oval");
c.setAttribute("strokeweight", "1px");
c.setAttribute("strokecolor", data[i].series.color);
c.setAttribute("fillcolor", data[i].series.color);
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.8");
c.appendChild(str);
str = document.createElement("v:fill");
str.setAttribute("opacity", "0.6");
c.appendChild(str);
var s = c.style;
s.position = "absolute";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
cmd.push("l");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
cmd.push("l");
cmd.push(Math.round(plot.axisX.getCoord(data[0].x, plotarea, plot)) + "," + Math.round(plot.axisY.getCoord(plot.axisX.origin, plotarea, plot)));
path.setAttribute("path", cmd.join(" ") + " x e");
group.appendChild(path);
return group;
}, HighLow:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = w + "px";
bar.style.height = h + "px";
bar.setAttribute("fillColor", data[i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
if (applyTo) {
applyTo(bar, data[i].src);
}
group.appendChild(bar);
}
return group;
}, HighLowClose:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var c = data[i].close;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var close = plot.axisY.getCoord(c, plotarea, plot);
var g = document.createElement("div");
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = w + "px";
bar.style.height = h + "px";
bar.setAttribute("fillColor", data[i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
g.appendChild(bar);
var line = document.createElement("v:line");
line.setAttribute("strokecolor", data[i].series.color);
line.setAttribute("strokeweight", "1px");
line.setAttribute("from", x + "px," + close + "px");
line.setAttribute("to", (x + w + (part * 2) - 2) + "px," + close + "px");
var s = line.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.6");
line.appendChild(str);
g.appendChild(line);
if (applyTo) {
applyTo(g, data[i].src);
}
group.appendChild(g);
}
return group;
}, HighLowOpenClose:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var o = data[i].open;
var c = data[i].close;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var open = plot.axisY.getCoord(o, plotarea, plot);
var close = plot.axisY.getCoord(c, plotarea, plot);
var g = document.createElement("div");
var bar = document.createElement("v:rect");
bar.style.position = "absolute";
bar.style.top = y + 1 + "px";
bar.style.left = x + "px";
bar.style.width = w + "px";
bar.style.height = h + "px";
bar.setAttribute("fillColor", data[i].series.color);
bar.setAttribute("stroked", "false");
bar.style.antialias = "false";
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
bar.appendChild(fill);
g.appendChild(bar);
var line = document.createElement("v:line");
line.setAttribute("strokecolor", data[i].series.color);
line.setAttribute("strokeweight", "1px");
line.setAttribute("from", (x - (part * 2)) + "px," + open + "px");
line.setAttribute("to", (x + w - 2) + "px," + open + "px");
var s = line.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.6");
line.appendChild(str);
g.appendChild(line);
var line = document.createElement("v:line");
line.setAttribute("strokecolor", data[i].series.color);
line.setAttribute("strokeweight", "1px");
line.setAttribute("from", x + "px," + close + "px");
line.setAttribute("to", (x + w + (part * 2) - 2) + "px," + close + "px");
var s = line.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
var str = document.createElement("v:stroke");
str.setAttribute("opacity", "0.6");
line.appendChild(str);
g.appendChild(line);
if (applyTo) {
applyTo(g, data[i].src);
}
group.appendChild(g);
}
return group;
}, Scatter:function (data, plotarea, plot, applyTo) {
var r = 6;
var mod = r / 2;
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
var point = document.createElement("v:rect");
point.setAttribute("strokecolor", data[i].series.color);
point.setAttribute("fillcolor", data[i].series.color);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
point.appendChild(fill);
var s = point.style;
s.position = "absolute";
s.rotation = "45";
s.top = (y - mod) + "px";
s.left = (x - mod) + "px";
s.width = r + "px";
s.height = r + "px";
group.appendChild(point);
if (applyTo) {
applyTo(point, data[i].src);
}
}
return group;
}, Bubble:function (data, plotarea, plot, applyTo) {
var sizeFactor = 1;
var area = plotarea.getArea();
var group = dojo.charting.Plotters._group(plotarea);
for (var i = 0; i < data.length; i++) {
var x = Math.round(plot.axisX.getCoord(data[i].x, plotarea, plot));
var y = Math.round(plot.axisY.getCoord(data[i].y, plotarea, plot));
if (i == 0) {
var raw = data[i].size;
var dy = plot.axisY.getCoord(data[i].y + raw, plotarea, plot) - y;
sizeFactor = dy / raw;
}
if (sizeFactor < 1) {
sizeFactor = 1;
}
var r = (data[i].size / 2) * sizeFactor;
var point = document.createElement("v:oval");
point.setAttribute("strokecolor", data[i].series.color);
point.setAttribute("fillcolor", data[i].series.color);
var fill = document.createElement("v:fill");
fill.setAttribute("opacity", "0.6");
point.appendChild(fill);
var s = point.style;
s.position = "absolute";
s.rotation = "45";
s.top = (y - r) + "px";
s.left = (x - r) + "px";
s.width = (r * 2) + "px";
s.height = (r * 2) + "px";
group.appendChild(point);
if (applyTo) {
applyTo(point, data[i].src);
}
}
return group;
}});
dojo.charting.Plotters["Default"] = dojo.charting.Plotters.Line;
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/vml/Axis.js
New file
0,0 → 1,239
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.vml.Axis");
dojo.require("dojo.lang.common");
if (dojo.render.vml.capable) {
dojo.extend(dojo.charting.Axis, {renderLines:function (plotArea, plot, plane) {
if (this.nodes.lines) {
while (this.nodes.lines.childNodes.length > 0) {
this.nodes.lines.removeChild(this.nodes.lines.childNodes[0]);
}
if (this.nodes.lines.parentNode) {
this.nodes.lines.parentNode.removeChild(this.nodes.lines);
this.nodes.lines = null;
}
}
var area = plotArea.getArea();
var g = this.nodes.lines = document.createElement("div");
g.setAttribute("id", this.getId() + "-lines");
for (var i = 0; i < this._labels.length; i++) {
if (this._labels[i].value == this.origin) {
continue;
}
var v = this.getCoord(this._labels[i].value, plotArea, plot);
var l = document.createElement("v:line");
var str = document.createElement("v:stroke");
str.dashstyle = "dot";
l.appendChild(str);
l.setAttribute("strokecolor", "#666");
l.setAttribute("strokeweight", "1px");
var s = l.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
if (plane == "x") {
l.setAttribute("from", v + "px," + area.top + "px");
l.setAttribute("to", v + "px," + area.bottom + "px");
} else {
if (plane == "y") {
l.setAttribute("from", area.left + "px," + v + "px");
l.setAttribute("to", area.right + "px," + v + "px");
}
}
g.appendChild(l);
}
return g;
}, renderTicks:function (plotArea, plot, plane, coord) {
if (this.nodes.ticks) {
while (this.nodes.ticks.childNodes.length > 0) {
this.nodes.ticks.removeChild(this.nodes.ticks.childNodes[0]);
}
if (this.nodes.ticks.parentNode) {
this.nodes.ticks.parentNode.removeChild(this.nodes.ticks);
this.nodes.ticks = null;
}
}
var g = this.nodes.ticks = document.createElement("div");
g.setAttribute("id", this.getId() + "-ticks");
for (var i = 0; i < this._labels.length; i++) {
var v = this.getCoord(this._labels[i].value, plotArea, plot);
var l = document.createElement("v:line");
l.setAttribute("strokecolor", "#000");
l.setAttribute("strokeweight", "1px");
var s = l.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
if (plane == "x") {
l.setAttribute("from", v + "px," + coord + "px");
l.setAttribute("to", v + "px," + (coord + 3) + "px");
} else {
if (plane == "y") {
l.setAttribute("from", (coord - 2) + "px," + v + "px");
l.setAttribute("to", (coord + 2) + "px," + v + "px");
}
}
g.appendChild(l);
}
return g;
}, renderLabels:function (plotArea, plot, plane, coord, textSize, anchor) {
function createLabel(label, x, y, textSize, anchor) {
var text = document.createElement("div");
var s = text.style;
text.innerHTML = label;
s.fontSize = textSize + "px";
s.fontFamily = "sans-serif";
s.position = "absolute";
s.top = y + "px";
if (anchor == "center") {
s.left = x + "px";
s.textAlign = "center";
} else {
if (anchor == "left") {
s.left = x + "px";
s.textAlign = "left";
} else {
if (anchor == "right") {
s.right = x + "px";
s.textAlign = "right";
}
}
}
return text;
}
if (this.nodes.labels) {
while (this.nodes.labels.childNodes.length > 0) {
this.nodes.labels.removeChild(this.nodes.labels.childNodes[0]);
}
if (this.nodes.labels.parentNode) {
this.nodes.labels.parentNode.removeChild(this.nodes.labels);
this.nodes.labels = null;
}
}
var g = this.nodes.labels = document.createElement("div");
g.setAttribute("id", this.getId() + "-labels");
for (var i = 0; i < this._labels.length; i++) {
var v = this.getCoord(this._labels[i].value, plotArea, plot);
if (plane == "x") {
var node = createLabel(this._labels[i].label, v, coord, textSize, anchor);
document.body.appendChild(node);
node.style.left = v - (node.offsetWidth / 2) + "px";
g.appendChild(node);
} else {
if (plane == "y") {
var node = createLabel(this._labels[i].label, coord, v, textSize, anchor);
document.body.appendChild(node);
node.style.top = v - (node.offsetHeight / 2) + "px";
g.appendChild(node);
}
}
}
return g;
}, render:function (plotArea, plot, drawAgainst, plane) {
if (!this._rerender && this.nodes.main) {
return this.nodes.main;
}
this._rerender = false;
var area = plotArea.getArea();
var stroke = 1;
var style = "stroke:#000;stroke-width:" + stroke + "px;";
var textSize = 10;
var coord = drawAgainst.getCoord(this.origin, plotArea, plot);
var g = this.nodes.main = document.createElement("div");
g.setAttribute("id", this.getId());
var line = this.nodes.axis = document.createElement("v:line");
line.setAttribute("strokecolor", "#000");
line.setAttribute("strokeweight", stroke + "px");
var s = line.style;
s.position = "absolute";
s.top = "0px";
s.left = "0px";
s.antialias = "false";
if (plane == "x") {
line.setAttribute("from", area.left + "px," + coord + "px");
line.setAttribute("to", area.right + "px," + coord + "px");
var y = coord + Math.floor(textSize / 2);
if (this.showLines) {
g.appendChild(this.renderLines(plotArea, plot, plane, y));
}
if (this.showTicks) {
g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
}
if (this.showLabels) {
g.appendChild(this.renderLabels(plotArea, plot, plane, y, textSize, "center"));
}
if (this.showLabel && this.label) {
var x = plotArea.size.width / 2;
var y = coord + Math.round(textSize * 1.5);
var text = document.createElement("div");
var s = text.style;
text.innerHTML = this.label;
s.fontSize = (textSize + 2) + "px";
s.fontFamily = "sans-serif";
s.fontWeight = "bold";
s.position = "absolute";
s.top = y + "px";
s.left = x + "px";
s.textAlign = "center";
document.body.appendChild(text);
text.style.left = x - (text.offsetWidth / 2) + "px";
g.appendChild(text);
}
} else {
line.setAttribute("from", coord + "px," + area.top + "px");
line.setAttribute("to", coord + "px," + area.bottom + "px");
var isMax = this.origin == drawAgainst.range.upper;
var x = coord + 4;
var anchor = "left";
if (!isMax) {
x = area.right - coord + textSize + 4;
anchor = "right";
if (coord == area.left) {
x += (textSize * 2) - (textSize / 2);
}
}
if (this.showLines) {
g.appendChild(this.renderLines(plotArea, plot, plane, x));
}
if (this.showTicks) {
g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
}
if (this.showLabels) {
g.appendChild(this.renderLabels(plotArea, plot, plane, x, textSize, anchor));
}
if (this.showLabel && this.label) {
x += (textSize * 2) - 2;
var y = plotArea.size.height / 2;
var text = document.createElement("div");
var s = text.style;
text.innerHTML = this.label;
s.fontSize = (textSize + 2) + "px";
s.fontFamily = "sans-serif";
s.fontWeight = "bold";
s.position = "absolute";
s.height = plotArea.size.height + "px";
s.writingMode = "tb-rl";
s.textAlign = "center";
s[anchor] = x + "px";
document.body.appendChild(text);
s.top = y - (text.offsetHeight / 2) + "px";
g.appendChild(text);
}
}
g.appendChild(line);
return g;
}});
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/vml/PlotArea.js
New file
0,0 → 1,69
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.vml.PlotArea");
dojo.require("dojo.lang.common");
if (dojo.render.vml.capable) {
dojo.extend(dojo.charting.PlotArea, {resize:function () {
var a = this.getArea();
this.nodes.area.style.width = this.size.width + "px";
this.nodes.area.style.height = this.size.height + "px";
this.nodes.background.style.width = this.size.width + "px";
this.nodes.background.style.height = this.size.height + "px";
this.nodes.plots.width = this.size.width + "px";
this.nodes.plots.height = this.size.height + "px";
this.nodes.plots.style.clip = "rect(" + a.top + " " + a.right + " " + a.bottom + " " + a.left + ")";
if (this.nodes.axes) {
this.nodes.area.removeChild(this.nodes.axes);
}
var axes = this.nodes.axes = document.createElement("div");
axes.id = this.getId() + "-axes";
this.nodes.area.appendChild(axes);
var ax = this.getAxes();
for (var p in ax) {
var obj = ax[p];
axes.appendChild(obj.axis.initialize(this, obj.plot, obj.drawAgainst, obj.plane));
}
}, initializePlot:function (plot) {
plot.destroy();
plot.dataNode = document.createElement("div");
plot.dataNode.id = plot.getId();
return plot.dataNode;
}, initialize:function () {
this.destroy();
var main = this.nodes.main = document.createElement("div");
var area = this.nodes.area = document.createElement("div");
area.id = this.getId();
area.style.position = "absolute";
main.appendChild(area);
var bg = this.nodes.background = document.createElement("div");
bg.id = this.getId() + "-background";
bg.style.position = "absolute";
bg.style.top = "0px";
bg.style.left = "0px";
bg.style.backgroundColor = "#fff";
area.appendChild(bg);
var a = this.getArea();
var plots = this.nodes.plots = document.createElement("div");
plots.id = this.getId() + "-plots";
plots.style.position = "absolute";
plots.style.top = "0px";
plots.style.left = "0px";
area.appendChild(plots);
for (var i = 0; i < this.plots.length; i++) {
plots.appendChild(this.initializePlot(this.plots[i]));
}
this.resize();
return main;
}});
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/Axis.js
New file
0,0 → 1,132
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.Axis");
dojo.require("dojo.lang.common");
dojo.charting.Axis = function (label, scale, labels) {
var id = "dojo-charting-axis-" + dojo.charting.Axis.count++;
this.getId = function () {
return id;
};
this.setId = function (key) {
id = key;
};
this.scale = scale || "linear";
this.label = label || "";
this.showLabel = true;
this.showLabels = true;
this.showLines = false;
this.showTicks = false;
this.range = {upper:100, lower:0};
this.origin = "min";
this._origin = null;
this.labels = labels || [];
this._labels = [];
this.nodes = {main:null, axis:null, label:null, labels:null, lines:null, ticks:null};
this._rerender = false;
};
dojo.charting.Axis.count = 0;
dojo.extend(dojo.charting.Axis, {getCoord:function (val, plotArea, plot) {
val = parseFloat(val, 10);
var area = plotArea.getArea();
if (plot.axisX == this) {
var offset = 0 - this.range.lower;
var min = this.range.lower + offset;
var max = this.range.upper + offset;
val += offset;
return (val * ((area.right - area.left) / max)) + area.left;
} else {
var max = this.range.upper;
var min = this.range.lower;
var offset = 0;
if (min < 0) {
offset += Math.abs(min);
}
max += offset;
min += offset;
val += offset;
var pmin = area.bottom;
var pmax = area.top;
return (((pmin - pmax) / (max - min)) * (max - val)) + pmax;
}
}, initializeOrigin:function (drawAgainst, plane) {
if (this._origin == null) {
this._origin = this.origin;
}
if (isNaN(this._origin)) {
if (this._origin.toLowerCase() == "max") {
this.origin = drawAgainst.range[(plane == "y") ? "upper" : "lower"];
} else {
if (this._origin.toLowerCase() == "min") {
this.origin = drawAgainst.range[(plane == "y") ? "lower" : "upper"];
} else {
this.origin = 0;
}
}
}
}, initializeLabels:function () {
this._labels = [];
if (this.labels.length == 0) {
this.showLabels = false;
this.showLines = false;
this.showTicks = false;
} else {
if (this.labels[0].label && this.labels[0].value != null) {
for (var i = 0; i < this.labels.length; i++) {
this._labels.push(this.labels[i]);
}
} else {
if (!isNaN(this.labels[0])) {
for (var i = 0; i < this.labels.length; i++) {
this._labels.push({label:this.labels[i], value:this.labels[i]});
}
} else {
var a = [];
for (var i = 0; i < this.labels.length; i++) {
a.push(this.labels[i]);
}
var s = a.shift();
this._labels.push({label:s, value:this.range.lower});
if (a.length > 0) {
var s = a.pop();
this._labels.push({label:s, value:this.range.upper});
}
if (a.length > 0) {
var range = this.range.upper - this.range.lower;
var step = range / (this.labels.length - 1);
for (var i = 1; i <= a.length; i++) {
this._labels.push({label:a[i - 1], value:this.range.lower + (step * i)});
}
}
}
}
}
}, initialize:function (plotArea, plot, drawAgainst, plane) {
this.destroy();
this.initializeOrigin(drawAgainst, plane);
this.initializeLabels();
var node = this.render(plotArea, plot, drawAgainst, plane);
return node;
}, destroy:function () {
for (var p in this.nodes) {
while (this.nodes[p] && this.nodes[p].childNodes.length > 0) {
this.nodes[p].removeChild(this.nodes[p].childNodes[0]);
}
if (this.nodes[p] && this.nodes[p].parentNode) {
this.nodes[p].parentNode.removeChild(this.nodes[p]);
}
this.nodes[p] = null;
}
}});
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.Axis");
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.Axis");
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/svg/Plotters.js
New file
0,0 → 1,702
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.svg.Plotters");
dojo.require("dojo.lang.common");
if (dojo.render.svg.capable) {
dojo.require("dojo.svg");
dojo.mixin(dojo.charting.Plotters, {Bar:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 8;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var width = ((area.right - area.left) - (space * (nPoints - 1))) / nPoints;
var barWidth = width / n;
var yOrigin = plot.axisY.getCoord(plot.axisX.origin, plotarea, plot);
for (var i = 0; i < nPoints; i++) {
var xStart = area.left + (width * i) + (space * i);
for (var j = 0; j < n; j++) {
var value = data[j][i].y;
var yA = yOrigin;
var x = xStart + (barWidth * j);
var y = plot.axisY.getCoord(value, plotarea, plot);
var h = Math.abs(yA - y);
if (value < plot.axisX.origin) {
yA = y;
y = yOrigin;
}
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[j][i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", barWidth);
bar.setAttribute("height", h);
bar.setAttribute("fill-opacity", "0.6");
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
return group;
}, HorizontalBar:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 6;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var h = ((area.bottom - area.top) - (space * (nPoints - 1))) / nPoints;
var barH = h / n;
var xOrigin = plot.axisX.getCoord(0, plotarea, plot);
for (var i = 0; i < nPoints; i++) {
var yStart = area.top + (h * i) + (space * i);
for (var j = 0; j < n; j++) {
var value = data[j][i].y;
var y = yStart + (barH * j);
var xA = xOrigin;
var x = plot.axisX.getCoord(value, plotarea, plot);
var w = Math.abs(x - xA);
if (value > 0) {
x = xOrigin;
}
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[j][i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", xA);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", barH);
bar.setAttribute("fill-opacity", "0.6");
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
return group;
}, Gantt:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = plot.series.length;
var data = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
data.push(tmp);
}
var space = 2;
var nPoints = data[0].length;
if (nPoints == 0) {
return group;
}
var h = ((area.bottom - area.top) - (space * (nPoints - 1))) / nPoints;
var barH = h / n;
for (var i = 0; i < nPoints; i++) {
var yStart = area.top + (h * i) + (space * i);
for (var j = 0; j < n; j++) {
var high = data[j][i].high;
var low = data[j][i].low;
if (low > high) {
var t = high;
high = low;
low = t;
}
var x = plot.axisX.getCoord(low, plotarea, plot);
var w = plot.axisX.getCoord(high, plotarea, plot) - x;
var y = yStart + (barH * j);
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[j][i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", barH);
bar.setAttribute("fill-opacity", "0.6");
if (applyTo) {
applyTo(bar, data[j][i].src);
}
group.appendChild(bar);
}
}
return group;
}, StackedArea:function (plotarea, plot, kwArgs, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = plot.series.length;
var data = [];
var totals = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
for (var j = 0; j < tmp.length; j++) {
if (i == 0) {
totals.push(tmp[j].y);
} else {
totals[j] += tmp[j].y;
}
tmp[j].y = totals[j];
}
data.push(tmp);
}
for (var i = n - 1; i >= 0; i--) {
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
path.setAttribute("fill", data[i][0].series.color);
path.setAttribute("fill-opacity", "0.4");
path.setAttribute("stroke", data[i][0].series.color);
path.setAttribute("stroke-width", "1");
path.setAttribute("stroke-opacity", "0.85");
var cmd = [];
var r = 3;
for (var j = 0; j < data[i].length; j++) {
var values = data[i];
var x = plot.axisX.getCoord(values[j].x, plotarea, plot);
var y = plot.axisY.getCoord(values[j].y, plotarea, plot);
if (j == 0) {
cmd.push("M");
} else {
cmd.push("L");
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", values[j].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
if (i == 0) {
cmd.push("L");
cmd.push(x + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("L");
cmd.push(plot.axisX.getCoord(data[0][0].x, plotarea, plot) + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("Z");
} else {
var values = data[i - 1];
cmd.push("L");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(values[values.length - 1].y, plotarea, plot)));
for (var j = values.length - 2; j >= 0; j--) {
var x = plot.axisX.getCoord(values[j].x, plotarea, plot);
var y = plot.axisY.getCoord(values[j].y, plotarea, plot);
cmd.push("L");
cmd.push(x + "," + y);
}
}
path.setAttribute("d", cmd.join(" ") + " Z");
group.appendChild(path);
}
return group;
}, StackedCurvedArea:function (plotarea, plot, kwArgs, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = plot.series.length;
var data = [];
var totals = [];
for (var i = 0; i < n; i++) {
var tmp = plot.series[i].data.evaluate(kwArgs);
for (var j = 0; j < tmp.length; j++) {
if (i == 0) {
totals.push(tmp[j].y);
} else {
totals[j] += tmp[j].y;
}
tmp[j].y = totals[j];
}
data.push(tmp);
}
for (var i = n - 1; i >= 0; i--) {
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
path.setAttribute("fill", data[i][0].series.color);
path.setAttribute("fill-opacity", "0.4");
path.setAttribute("stroke", data[i][0].series.color);
path.setAttribute("stroke-width", "1");
path.setAttribute("stroke-opacity", "0.85");
var cmd = [];
var r = 3;
for (var j = 0; j < data[i].length; j++) {
var values = data[i];
var x = plot.axisX.getCoord(values[j].x, plotarea, plot);
var y = plot.axisY.getCoord(values[j].y, plotarea, plot);
var dx = area.left + 1;
var dy = area.bottom;
if (j > 0) {
dx = x - plot.axisX.getCoord(values[j - 1].x, plotarea, plot);
dy = plot.axisY.getCoord(values[j - 1].y, plotarea, plot);
}
if (j == 0) {
cmd.push("M");
} else {
cmd.push("C");
var cx = x - (tension - 1) * (dx / tension);
cmd.push(cx + "," + dy);
cx = x - (dx / tension);
cmd.push(cx + "," + y);
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", values[j].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
group.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
if (i == 0) {
cmd.push("L");
cmd.push(x + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("L");
cmd.push(plot.axisX.getCoord(data[0][0].x, plotarea, plot) + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("Z");
} else {
var values = data[i - 1];
cmd.push("L");
cmd.push(x + "," + Math.round(plot.axisY.getCoord(values[values.length - 1].y, plotarea, plot)));
for (var j = values.length - 2; j >= 0; j--) {
var x = plot.axisX.getCoord(values[j].x, plotarea, plot);
var y = plot.axisY.getCoord(values[j].y, plotarea, plot);
var dx = x - plot.axisX.getCoord(values[j + 1].x, plotarea, plot);
var dy = plot.axisY.getCoord(values[j + 1].y, plotarea, plot);
cmd.push("C");
var cx = x - (tension - 1) * (dx / tension);
cmd.push(cx + "," + dy);
cx = x - (dx / tension);
cmd.push(cx + "," + y);
cmd.push(x + "," + y);
}
}
path.setAttribute("d", cmd.join(" ") + " Z");
group.appendChild(path);
}
return group;
}, DataBar:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = data.length;
var w = (area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower);
var yOrigin = plot.axisY.getCoord(plot.axisX.origin, plotarea, plot);
for (var i = 0; i < n; i++) {
var value = data[i].y;
var yA = yOrigin;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(value, plotarea, plot);
var h = Math.abs(yA - y);
if (value < plot.axisX.origin) {
yA = y;
y = yOrigin;
}
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", h);
bar.setAttribute("fill-opacity", "0.6");
if (applyTo) {
applyTo(bar, data[i].src);
}
group.appendChild(bar);
}
return group;
}, Line:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var line = document.createElementNS(dojo.svg.xmlns.svg, "g");
if (data.length == 0) {
return line;
}
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
line.appendChild(path);
path.setAttribute("fill", "none");
path.setAttribute("stroke", data[0].series.color);
path.setAttribute("stroke-width", "2");
path.setAttribute("stroke-opacity", "0.85");
if (data[0].series.label != null) {
path.setAttribute("title", data[0].series.label);
}
var cmd = [];
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
if (i == 0) {
cmd.push("M");
} else {
cmd.push("L");
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", data[i].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
line.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
path.setAttribute("d", cmd.join(" "));
return line;
}, CurvedLine:function (data, plotarea, plot, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var line = document.createElementNS(dojo.svg.xmlns.svg, "g");
if (data.length == 0) {
return line;
}
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
line.appendChild(path);
path.setAttribute("fill", "none");
path.setAttribute("stroke", data[0].series.color);
path.setAttribute("stroke-width", "2");
path.setAttribute("stroke-opacity", "0.85");
if (data[0].series.label != null) {
path.setAttribute("title", data[0].series.label);
}
var cmd = [];
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
var dx = area.left + 1;
var dy = area.bottom;
if (i > 0) {
dx = x - plot.axisX.getCoord(data[i - 1].x, plotarea, plot);
dy = plot.axisY.getCoord(data[i - 1].y, plotarea, plot);
}
if (i == 0) {
cmd.push("M");
} else {
cmd.push("C");
var cx = x - (tension - 1) * (dx / tension);
cmd.push(cx + "," + dy);
cx = x - (dx / tension);
cmd.push(cx + "," + y);
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", data[i].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
line.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
path.setAttribute("d", cmd.join(" "));
return line;
}, Area:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var line = document.createElementNS(dojo.svg.xmlns.svg, "g");
if (data.length == 0) {
return line;
}
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
line.appendChild(path);
path.setAttribute("fill", data[0].series.color);
path.setAttribute("fill-opacity", "0.4");
path.setAttribute("stroke", data[0].series.color);
path.setAttribute("stroke-width", "1");
path.setAttribute("stroke-opacity", "0.85");
if (data[0].series.label != null) {
path.setAttribute("title", data[0].series.label);
}
var cmd = [];
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
if (i == 0) {
cmd.push("M");
} else {
cmd.push("L");
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", data[i].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
line.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
cmd.push("L");
cmd.push(x + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("L");
cmd.push(plot.axisX.getCoord(data[0].x, plotarea, plot) + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("Z");
path.setAttribute("d", cmd.join(" "));
return line;
}, CurvedArea:function (data, plotarea, plot, applyTo) {
var tension = 3;
var area = plotarea.getArea();
var line = document.createElementNS(dojo.svg.xmlns.svg, "g");
if (data.length == 0) {
return line;
}
var path = document.createElementNS(dojo.svg.xmlns.svg, "path");
line.appendChild(path);
path.setAttribute("fill", data[0].series.color);
path.setAttribute("fill-opacity", "0.4");
path.setAttribute("stroke", data[0].series.color);
path.setAttribute("stroke-width", "1");
path.setAttribute("stroke-opacity", "0.85");
if (data[0].series.label != null) {
path.setAttribute("title", data[0].series.label);
}
var cmd = [];
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
var dx = area.left + 1;
var dy = area.bottom;
if (i > 0) {
dx = x - plot.axisX.getCoord(data[i - 1].x, plotarea, plot);
dy = plot.axisY.getCoord(data[i - 1].y, plotarea, plot);
}
if (i == 0) {
cmd.push("M");
} else {
cmd.push("C");
var cx = x - (tension - 1) * (dx / tension);
cmd.push(cx + "," + dy);
cx = x - (dx / tension);
cmd.push(cx + "," + y);
}
cmd.push(x + "," + y);
var c = document.createElementNS(dojo.svg.xmlns.svg, "circle");
c.setAttribute("cx", x);
c.setAttribute("cy", y);
c.setAttribute("r", "3");
c.setAttribute("fill", data[i].series.color);
c.setAttribute("fill-opacity", "0.6");
c.setAttribute("stroke-width", "1");
c.setAttribute("stroke-opacity", "0.85");
line.appendChild(c);
if (applyTo) {
applyTo(c, data[i].src);
}
}
cmd.push("L");
cmd.push(x + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("L");
cmd.push(plot.axisX.getCoord(data[0].x, plotarea, plot) + "," + plot.axisY.getCoord(plot.axisX.origin, plotarea, plot));
cmd.push("Z");
path.setAttribute("d", cmd.join(" "));
return line;
}, HighLow:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", h);
bar.setAttribute("fill-opacity", "0.6");
if (applyTo) {
applyTo(bar, data[i].src);
}
group.appendChild(bar);
}
return group;
}, HighLowClose:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var c = data[i].close;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var close = plot.axisY.getCoord(c, plotarea, plot);
var g = document.createElementNS(dojo.svg.xmlns.svg, "g");
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", h);
bar.setAttribute("fill-opacity", "0.6");
g.appendChild(bar);
var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
line.setAttribute("x1", x);
line.setAttribute("x2", x + w + (part * 2));
line.setAttribute("y1", close);
line.setAttribute("y2", close);
line.setAttribute("style", "stroke:" + data[i].series.color + ";stroke-width:1px;stroke-opacity:0.6;");
g.appendChild(line);
if (applyTo) {
applyTo(g, data[i].src);
}
group.appendChild(g);
}
return group;
}, HighLowOpenClose:function (data, plotarea, plot, applyTo) {
var area = plotarea.getArea();
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var n = data.length;
var part = ((area.right - area.left) / (plot.axisX.range.upper - plot.axisX.range.lower)) / 4;
var w = part * 2;
for (var i = 0; i < n; i++) {
var high = data[i].high;
var low = data[i].low;
if (low > high) {
var t = low;
low = high;
high = t;
}
var o = data[i].open;
var c = data[i].close;
var x = plot.axisX.getCoord(data[i].x, plotarea, plot) - (w / 2);
var y = plot.axisY.getCoord(high, plotarea, plot);
var h = plot.axisY.getCoord(low, plotarea, plot) - y;
var open = plot.axisY.getCoord(o, plotarea, plot);
var close = plot.axisY.getCoord(c, plotarea, plot);
var g = document.createElementNS(dojo.svg.xmlns.svg, "g");
var bar = document.createElementNS(dojo.svg.xmlns.svg, "rect");
bar.setAttribute("fill", data[i].series.color);
bar.setAttribute("stroke-width", "0");
bar.setAttribute("x", x);
bar.setAttribute("y", y);
bar.setAttribute("width", w);
bar.setAttribute("height", h);
bar.setAttribute("fill-opacity", "0.6");
g.appendChild(bar);
var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
line.setAttribute("x1", x - (part * 2));
line.setAttribute("x2", x + w);
line.setAttribute("y1", open);
line.setAttribute("y2", open);
line.setAttribute("style", "stroke:" + data[i].series.color + ";stroke-width:1px;stroke-opacity:0.6;");
g.appendChild(line);
var line = document.createElementNS(dojo.svg.xmlns.svg, "line");
line.setAttribute("x1", x);
line.setAttribute("x2", x + w + (part * 2));
line.setAttribute("y1", close);
line.setAttribute("y2", close);
line.setAttribute("style", "stroke:" + data[i].series.color + ";stroke-width:1px;stroke-opacity:0.6;");
g.appendChild(line);
if (applyTo) {
applyTo(g, data[i].src);
}
group.appendChild(g);
}
return group;
}, Scatter:function (data, plotarea, plot, applyTo) {
var r = 7;
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
var point = document.createElementNS(dojo.svg.xmlns.svg, "path");
point.setAttribute("fill", data[i].series.color);
point.setAttribute("stroke-width", "0");
point.setAttribute("d", "M " + x + "," + (y - r) + " " + "Q " + x + "," + y + " " + (x + r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y + r) + " " + "Q " + x + "," + y + " " + (x - r) + "," + y + " " + "Q " + x + "," + y + " " + x + "," + (y - r) + " " + "Z");
if (applyTo) {
applyTo(point, data[i].src);
}
group.appendChild(point);
}
return group;
}, Bubble:function (data, plotarea, plot, applyTo) {
var group = document.createElementNS(dojo.svg.xmlns.svg, "g");
var sizeFactor = 1;
for (var i = 0; i < data.length; i++) {
var x = plot.axisX.getCoord(data[i].x, plotarea, plot);
var y = plot.axisY.getCoord(data[i].y, plotarea, plot);
if (i == 0) {
var raw = data[i].size;
var dy = plot.axisY.getCoord(data[i].y + raw, plotarea, plot) - y;
sizeFactor = dy / raw;
}
if (sizeFactor < 1) {
sizeFactor = 1;
}
var point = document.createElementNS(dojo.svg.xmlns.svg, "circle");
point.setAttribute("fill", data[i].series.color);
point.setAttribute("fill-opacity", "0.8");
point.setAttribute("stroke", data[i].series.color);
point.setAttribute("stroke-width", "1");
point.setAttribute("cx", x);
point.setAttribute("cy", y);
point.setAttribute("r", (data[i].size / 2) * sizeFactor);
if (applyTo) {
applyTo(point, data[i].src);
}
group.appendChild(point);
}
return group;
}});
dojo.charting.Plotters["Default"] = dojo.charting.Plotters.Line;
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/svg/Axis.js
New file
0,0 → 1,188
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.svg.Axis");
dojo.require("dojo.lang.common");
if (dojo.render.svg.capable) {
dojo.extend(dojo.charting.Axis, {renderLines:function (plotArea, plot, plane) {
if (this.nodes.lines) {
while (this.nodes.lines.childNodes.length > 0) {
this.nodes.lines.removeChild(this.nodes.lines.childNodes[0]);
}
if (this.nodes.lines.parentNode) {
this.nodes.lines.parentNode.removeChild(this.nodes.lines);
this.nodes.lines = null;
}
}
var area = plotArea.getArea();
var g = this.nodes.lines = document.createElementNS(dojo.svg.xmlns.svg, "g");
g.setAttribute("id", this.getId() + "-lines");
for (var i = 0; i < this._labels.length; i++) {
if (this._labels[i].value == this.origin) {
continue;
}
var v = this.getCoord(this._labels[i].value, plotArea, plot);
var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
l.setAttribute("style", "stroke:#999;stroke-width:1px;stroke-dasharray:1,4;");
if (plane == "x") {
l.setAttribute("y1", area.top);
l.setAttribute("y2", area.bottom);
l.setAttribute("x1", v);
l.setAttribute("x2", v);
} else {
if (plane == "y") {
l.setAttribute("y1", v);
l.setAttribute("y2", v);
l.setAttribute("x1", area.left);
l.setAttribute("x2", area.right);
}
}
g.appendChild(l);
}
return g;
}, renderTicks:function (plotArea, plot, plane, coord) {
if (this.nodes.ticks) {
while (this.nodes.ticks.childNodes.length > 0) {
this.nodes.ticks.removeChild(this.nodes.ticks.childNodes[0]);
}
if (this.nodes.ticks.parentNode) {
this.nodes.ticks.parentNode.removeChild(this.nodes.ticks);
this.nodes.ticks = null;
}
}
var g = this.nodes.ticks = document.createElementNS(dojo.svg.xmlns.svg, "g");
g.setAttribute("id", this.getId() + "-ticks");
for (var i = 0; i < this._labels.length; i++) {
var v = this.getCoord(this._labels[i].value, plotArea, plot);
var l = document.createElementNS(dojo.svg.xmlns.svg, "line");
l.setAttribute("style", "stroke:#000;stroke-width:1pt;");
if (plane == "x") {
l.setAttribute("y1", coord);
l.setAttribute("y2", coord + 3);
l.setAttribute("x1", v);
l.setAttribute("x2", v);
} else {
if (plane == "y") {
l.setAttribute("y1", v);
l.setAttribute("y2", v);
l.setAttribute("x1", coord - 2);
l.setAttribute("x2", coord + 2);
}
}
g.appendChild(l);
}
return g;
}, renderLabels:function (plotArea, plot, plane, coord, textSize, anchor) {
function createLabel(label, x, y, textSize, anchor) {
var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
text.setAttribute("x", x);
text.setAttribute("y", (plane == "x" ? y : y + 2));
text.setAttribute("style", "text-anchor:" + anchor + ";font-family:sans-serif;font-size:" + textSize + "px;fill:#000;");
text.appendChild(document.createTextNode(label));
return text;
}
if (this.nodes.labels) {
while (this.nodes.labels.childNodes.length > 0) {
this.nodes.labels.removeChild(this.nodes.labels.childNodes[0]);
}
if (this.nodes.labels.parentNode) {
this.nodes.labels.parentNode.removeChild(this.nodes.labels);
this.nodes.labels = null;
}
}
var g = this.nodes.labels = document.createElementNS(dojo.svg.xmlns.svg, "g");
g.setAttribute("id", this.getId() + "-labels");
for (var i = 0; i < this._labels.length; i++) {
var v = this.getCoord(this._labels[i].value, plotArea, plot);
if (plane == "x") {
g.appendChild(createLabel(this._labels[i].label, v, coord, textSize, anchor));
} else {
if (plane == "y") {
g.appendChild(createLabel(this._labels[i].label, coord, v, textSize, anchor));
}
}
}
return g;
}, render:function (plotArea, plot, drawAgainst, plane) {
if (!this._rerender && this.nodes.main) {
return this.nodes.main;
}
this._rerender = false;
var area = plotArea.getArea();
var stroke = 1;
var style = "stroke:#000;stroke-width:" + stroke + "px;";
var textSize = 10;
var coord = drawAgainst.getCoord(this.origin, plotArea, plot);
this.nodes.main = document.createElementNS(dojo.svg.xmlns.svg, "g");
var g = this.nodes.main;
g.setAttribute("id", this.getId());
var line = this.nodes.axis = document.createElementNS(dojo.svg.xmlns.svg, "line");
if (plane == "x") {
line.setAttribute("y1", coord);
line.setAttribute("y2", coord);
line.setAttribute("x1", area.left - stroke);
line.setAttribute("x2", area.right + stroke);
line.setAttribute("style", style);
var y = coord + textSize + 2;
if (this.showLines) {
g.appendChild(this.renderLines(plotArea, plot, plane, y));
}
if (this.showTicks) {
g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
}
if (this.showLabels) {
g.appendChild(this.renderLabels(plotArea, plot, plane, y, textSize, "middle"));
}
if (this.showLabel && this.label) {
var x = plotArea.size.width / 2;
var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
text.setAttribute("x", x);
text.setAttribute("y", (coord + (textSize * 2) + (textSize / 2)));
text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
text.appendChild(document.createTextNode(this.label));
g.appendChild(text);
}
} else {
line.setAttribute("x1", coord);
line.setAttribute("x2", coord);
line.setAttribute("y1", area.top);
line.setAttribute("y2", area.bottom);
line.setAttribute("style", style);
var isMax = this.origin == drawAgainst.range.upper;
var x = coord + (isMax ? 4 : -4);
var anchor = isMax ? "start" : "end";
if (this.showLines) {
g.appendChild(this.renderLines(plotArea, plot, plane, x));
}
if (this.showTicks) {
g.appendChild(this.renderTicks(plotArea, plot, plane, coord));
}
if (this.showLabels) {
g.appendChild(this.renderLabels(plotArea, plot, plane, x, textSize, anchor));
}
if (this.showLabel && this.label) {
var x = isMax ? (coord + (textSize * 2) + (textSize / 2)) : (coord - (textSize * 4));
var y = plotArea.size.height / 2;
var text = document.createElementNS(dojo.svg.xmlns.svg, "text");
text.setAttribute("x", x);
text.setAttribute("y", y);
text.setAttribute("transform", "rotate(90, " + x + ", " + y + ")");
text.setAttribute("style", "text-anchor:middle;font-family:sans-serif;font-weight:bold;font-size:" + (textSize + 2) + "px;fill:#000;");
text.appendChild(document.createTextNode(this.label));
g.appendChild(text);
}
}
g.appendChild(line);
return g;
}});
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/svg/PlotArea.js
New file
0,0 → 1,77
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.svg.PlotArea");
dojo.require("dojo.lang.common");
if (dojo.render.svg.capable) {
dojo.require("dojo.svg");
dojo.extend(dojo.charting.PlotArea, {resize:function () {
var area = this.getArea();
this.nodes.area.setAttribute("width", this.size.width);
this.nodes.area.setAttribute("height", this.size.height);
var rect = this.nodes.area.getElementsByTagName("rect")[0];
rect.setAttribute("x", area.left);
rect.setAttribute("y", area.top);
rect.setAttribute("width", area.right - area.left);
rect.setAttribute("height", area.bottom - area.top);
this.nodes.background.setAttribute("width", this.size.width);
this.nodes.background.setAttribute("height", this.size.height);
if (this.nodes.plots) {
this.nodes.area.removeChild(this.nodes.plots);
this.nodes.plots = null;
}
this.nodes.plots = document.createElementNS(dojo.svg.xmlns.svg, "g");
this.nodes.plots.setAttribute("id", this.getId() + "-plots");
this.nodes.plots.setAttribute("style", "clip-path:url(#" + this.getId() + "-clip);");
this.nodes.area.appendChild(this.nodes.plots);
for (var i = 0; i < this.plots.length; i++) {
this.nodes.plots.appendChild(this.initializePlot(this.plots[i]));
}
if (this.nodes.axes) {
this.nodes.area.removeChild(this.nodes.axes);
this.nodes.axes = null;
}
this.nodes.axes = document.createElementNS(dojo.svg.xmlns.svg, "g");
this.nodes.axes.setAttribute("id", this.getId() + "-axes");
this.nodes.area.appendChild(this.nodes.axes);
var axes = this.getAxes();
for (var p in axes) {
var obj = axes[p];
this.nodes.axes.appendChild(obj.axis.initialize(this, obj.plot, obj.drawAgainst, obj.plane));
}
}, initializePlot:function (plot) {
plot.destroy();
plot.dataNode = document.createElementNS(dojo.svg.xmlns.svg, "g");
plot.dataNode.setAttribute("id", plot.getId());
return plot.dataNode;
}, initialize:function () {
this.destroy();
this.nodes.main = document.createElement("div");
this.nodes.area = document.createElementNS(dojo.svg.xmlns.svg, "svg");
this.nodes.area.setAttribute("id", this.getId());
this.nodes.main.appendChild(this.nodes.area);
var defs = document.createElementNS(dojo.svg.xmlns.svg, "defs");
var clip = document.createElementNS(dojo.svg.xmlns.svg, "clipPath");
clip.setAttribute("id", this.getId() + "-clip");
var rect = document.createElementNS(dojo.svg.xmlns.svg, "rect");
clip.appendChild(rect);
defs.appendChild(clip);
this.nodes.area.appendChild(defs);
this.nodes.background = document.createElementNS(dojo.svg.xmlns.svg, "rect");
this.nodes.background.setAttribute("id", this.getId() + "-background");
this.nodes.background.setAttribute("fill", "#fff");
this.nodes.area.appendChild(this.nodes.background);
this.resize();
return this.nodes.main;
}});
}
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/PlotArea.js
New file
0,0 → 1,137
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.PlotArea");
dojo.require("dojo.lang.common");
dojo.require("dojo.gfx.color");
dojo.require("dojo.gfx.color.hsl");
dojo.require("dojo.charting.Plot");
dojo.charting.PlotArea = function () {
var id = "dojo-charting-plotarea-" + dojo.charting.PlotArea.count++;
this.getId = function () {
return id;
};
this.setId = function (key) {
id = key;
};
this.areaType = "standard";
this.plots = [];
this.size = {width:600, height:400};
this.padding = {top:10, right:10, bottom:20, left:20};
this.nodes = {main:null, area:null, background:null, axes:null, plots:null};
this._color = {h:140, s:120, l:120, step:27};
};
dojo.charting.PlotArea.count = 0;
dojo.extend(dojo.charting.PlotArea, {nextColor:function () {
var rgb = dojo.gfx.color.hsl2rgb(this._color.h, this._color.s, this._color.l);
this._color.h = (this._color.h + this._color.step) % 360;
while (this._color.h < 140) {
this._color.h += this._color.step;
}
return dojo.gfx.color.rgb2hex(rgb[0], rgb[1], rgb[2]);
}, getArea:function () {
return {left:this.padding.left, right:this.size.width - this.padding.right, top:this.padding.top, bottom:this.size.height - this.padding.bottom, toString:function () {
var a = [this.top, this.right, this.bottom, this.left];
return "[" + a.join() + "]";
}};
}, getAxes:function () {
var axes = {};
for (var i = 0; i < this.plots.length; i++) {
var plot = this.plots[i];
axes[plot.axisX.getId()] = {axis:plot.axisX, drawAgainst:plot.axisY, plot:plot, plane:"x"};
axes[plot.axisY.getId()] = {axis:plot.axisY, drawAgainst:plot.axisX, plot:plot, plane:"y"};
}
return axes;
}, getLegendInfo:function () {
var a = [];
for (var i = 0; i < this.plots.length; i++) {
for (var j = 0; j < this.plots[i].series.length; j++) {
var data = this.plots[i].series[j].data;
a.push({label:data.label, color:data.color});
}
}
return a;
}, setAxesRanges:function () {
var ranges = {};
var axes = {};
for (var i = 0; i < this.plots.length; i++) {
var plot = this.plots[i];
var ranges = plot.getRanges();
var x = ranges.x;
var y = ranges.y;
var ax, ay;
if (!axes[plot.axisX.getId()]) {
axes[plot.axisX.getId()] = plot.axisX;
ranges[plot.axisX.getId()] = {upper:x.upper, lower:x.lower};
}
ax = ranges[plot.axisX.getId()];
ax.upper = Math.max(ax.upper, x.upper);
ax.lower = Math.min(ax.lower, x.lower);
if (!axes[plot.axisY.getId()]) {
axes[plot.axisY.getId()] = plot.axisY;
ranges[plot.axisY.getId()] = {upper:y.upper, lower:y.lower};
}
ay = ranges[plot.axisY.getId()];
ay.upper = Math.max(ay.upper, y.upper);
ay.lower = Math.min(ay.lower, y.lower);
}
for (var p in axes) {
axes[p].range = ranges[p];
}
}, render:function (kwArgs, applyToData) {
if (!this.nodes.main || !this.nodes.area || !this.nodes.background || !this.nodes.plots || !this.nodes.axes) {
this.initialize();
}
this.resize();
for (var i = 0; i < this.plots.length; i++) {
var plot = this.plots[i];
if (plot.dataNode) {
this.nodes.plots.removeChild(plot.dataNode);
}
var target = this.initializePlot(plot);
switch (plot.renderType) {
case dojo.charting.RenderPlotSeries.Grouped:
if (plot.series[0]) {
target.appendChild(plot.series[0].plotter(this, plot, kwArgs, applyToData));
}
break;
case dojo.charting.RenderPlotSeries.Singly:
default:
for (var j = 0; j < plot.series.length; j++) {
var series = plot.series[j];
var data = series.data.evaluate(kwArgs);
target.appendChild(series.plotter(data, this, plot, applyToData));
}
}
this.nodes.plots.appendChild(target);
}
}, destroy:function () {
for (var i = 0; i < this.plots.length; i++) {
this.plots[i].destroy();
}
for (var p in this.nodes) {
var node = this.nodes[p];
if (!node) {
continue;
}
if (!node.childNodes) {
continue;
}
while (node.childNodes.length > 0) {
node.removeChild(node.childNodes[0]);
}
this.nodes[p] = null;
}
}});
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.PlotArea");
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.PlotArea");
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/__package__.js
New file
0,0 → 1,14
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.*");
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/Series.js
New file
0,0 → 1,194
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.Series");
dojo.require("dojo.lang.common");
dojo.require("dojo.charting.Plotters");
dojo.charting.Series = function (kwArgs) {
var args = kwArgs || {length:1};
this.dataSource = args.dataSource || null;
this.bindings = {};
this.color = args.color;
this.label = args.label;
if (args.bindings) {
for (var p in args.bindings) {
this.addBinding(p, args.bindings[p]);
}
}
};
dojo.extend(dojo.charting.Series, {bind:function (src, bindings) {
this.dataSource = src;
this.bindings = bindings;
}, addBinding:function (name, binding) {
this.bindings[name] = binding;
}, evaluate:function (kwArgs) {
var ret = [];
var a = this.dataSource.getData();
var l = a.length;
var start = 0;
var end = l;
if (kwArgs) {
if (kwArgs.between) {
for (var i = 0; i < l; i++) {
var fld = this.dataSource.getField(a[i], kwArgs.between.field);
if (fld >= kwArgs.between.low && fld <= kwArgs.between.high) {
var o = {src:a[i], series:this};
for (var p in this.bindings) {
o[p] = this.dataSource.getField(a[i], this.bindings[p]);
}
ret.push(o);
}
}
} else {
if (kwArgs.from || kwArgs.length) {
if (kwArgs.from) {
start = Math.max(kwArgs.from, 0);
if (kwArgs.to) {
end = Math.min(kwArgs.to, end);
}
} else {
if (kwArgs.length < 0) {
start = Math.max((end + length), 0);
} else {
end = Math.min((start + length), end);
}
}
for (var i = start; i < end; i++) {
var o = {src:a[i], series:this};
for (var p in this.bindings) {
o[p] = this.dataSource.getField(a[i], this.bindings[p]);
}
ret.push(o);
}
}
}
} else {
for (var i = start; i < end; i++) {
var o = {src:a[i], series:this};
for (var p in this.bindings) {
o[p] = this.dataSource.getField(a[i], this.bindings[p]);
}
ret.push(o);
}
}
if (ret.length > 0 && typeof (ret[0].x) != "undefined") {
ret.sort(function (a, b) {
if (a.x > b.x) {
return 1;
}
if (a.x < b.x) {
return -1;
}
return 0;
});
}
return ret;
}, trends:{createRange:function (values, len) {
var idx = values.length - 1;
var length = (len || values.length);
return {"index":idx, "length":length, "start":Math.max(idx - length, 0)};
}, mean:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var total = 0;
var count = 0;
for (var i = range.index; i >= range.start; i--) {
total += values[i].y;
count++;
}
total /= Math.max(count, 1);
return total;
}, variance:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var total = 0;
var square = 0;
var count = 0;
for (var i = range.index; i >= range.start; i--) {
total += values[i].y;
square += Math.pow(values[i].y, 2);
count++;
}
return (square / count) - Math.pow(total / count, 2);
}, standardDeviation:function (values, len) {
return Math.sqrt(this.getVariance(values, len));
}, max:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var max = Number.MIN_VALUE;
for (var i = range.index; i >= range.start; i--) {
max = Math.max(values[i].y, max);
}
return max;
}, min:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var min = Number.MAX_VALUE;
for (var i = range.index; i >= range.start; i--) {
min = Math.min(values[i].y, min);
}
return min;
}, median:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var a = [];
for (var i = range.index; i >= range.start; i--) {
var b = false;
for (var j = 0; j < a.length; j++) {
if (values[i].y == a[j]) {
b = true;
break;
}
}
if (!b) {
a.push(values[i].y);
}
}
a.sort();
if (a.length > 0) {
return a[Math.ceil(a.length / 2)];
}
return 0;
}, mode:function (values, len) {
var range = this.createRange(values, len);
if (range.index < 0) {
return 0;
}
var o = {};
var ret = 0;
var median = Number.MIN_VALUE;
for (var i = range.index; i >= range.start; i--) {
if (!o[values[i].y]) {
o[values[i].y] = 1;
} else {
o[values[i].y]++;
}
}
for (var p in o) {
if (median < o[p]) {
median = o[p];
ret = p;
}
}
return ret;
}}});
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/Plotters.js
New file
0,0 → 1,16
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.Plotters");
dojo.requireIf(dojo.render.svg.capable, "dojo.charting.svg.Plotters");
dojo.requireIf(dojo.render.vml.capable, "dojo.charting.vml.Plotters");
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/Plot.js
New file
0,0 → 1,82
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.Plot");
dojo.require("dojo.lang.common");
dojo.require("dojo.charting.Axis");
dojo.require("dojo.charting.Series");
dojo.charting.RenderPlotSeries = {Singly:"single", Grouped:"grouped"};
dojo.charting.Plot = function (xaxis, yaxis, series) {
var id = "dojo-charting-plot-" + dojo.charting.Plot.count++;
this.getId = function () {
return id;
};
this.setId = function (key) {
id = key;
};
this.axisX = null;
this.axisY = null;
this.series = [];
this.dataNode = null;
this.renderType = dojo.charting.RenderPlotSeries.Singly;
if (xaxis) {
this.setAxis(xaxis, "x");
}
if (yaxis) {
this.setAxis(yaxis, "y");
}
if (series) {
for (var i = 0; i < series.length; i++) {
this.addSeries(series[i]);
}
}
};
dojo.charting.Plot.count = 0;
dojo.extend(dojo.charting.Plot, {addSeries:function (series, plotter) {
if (series.plotter) {
this.series.push(series);
} else {
this.series.push({data:series, plotter:plotter || dojo.charting.Plotters["Default"]});
}
}, setAxis:function (axis, which) {
if (which.toLowerCase() == "x") {
this.axisX = axis;
} else {
if (which.toLowerCase() == "y") {
this.axisY = axis;
}
}
}, getRanges:function () {
var xmin, xmax, ymin, ymax;
xmin = ymin = Number.MAX_VALUE;
xmax = ymax = Number.MIN_VALUE;
for (var i = 0; i < this.series.length; i++) {
var values = this.series[i].data.evaluate();
for (var j = 0; j < values.length; j++) {
var comp = values[j];
xmin = Math.min(comp.x, xmin);
ymin = Math.min(comp.y, ymin);
xmax = Math.max(comp.x, xmax);
ymax = Math.max(comp.y, ymax);
}
}
return {x:{upper:xmax, lower:xmin}, y:{upper:ymax, lower:ymin}, toString:function () {
return "[ x:" + xmax + " - " + xmin + ", y:" + ymax + " - " + ymin + "]";
}};
}, destroy:function () {
var node = this.dataNode;
while (node && node.childNodes && node.childNodes.length > 0) {
node.removeChild(node.childNodes[0]);
}
this.dataNode = null;
}});
 
/branches/v5.0-ouadji/api/js/dojo/src/charting/README.txt
New file
0,0 → 1,46
Dojo Charting Engine
=========================================================================
The Dojo Charting Engine is a (fairly) complex object structure, designed
to provide as much flexibility as possible in terms of chart construction.
To this end, the engine details the following structure:
 
Chart
---PlotArea[]
------Plot[]
---------Axis (axisX)
---------Axis (axisY)
---------Series[]
 
 
A Chart object is the main entity; it is the entire graphic. A Chart may
have any number of PlotArea objects, which are the basic canvas against
which data is plotted. A PlotArea may have any number of Plot objects,
which is a container representing up to 2 axes and any number of series
to be plotted against those axes; a Series represents a binding against
two fields from a data source (initial rev, this data source is always of
type dojo.collections.Store but this will probably change once dojo.data
is in production).
 
The point of this structure is to allow for as much flexibility as possible
in terms of what kinds of charts can be represented by the engine. The
current plan is to accomodate up to analytical financial charts, which tend
to have 3 plot areas and any number of different types of axes on each one.
 
The main exception to this is the pie chart, which will have it's own
custom codebase. Also, 3D charts are not accounted for at this time,
although the only thing that will probably need to be altered to make
that work would be Plot and Series (to accomodate the additional Z axis).
 
Finally, a Plot will render its series[] through the use of Plotters, which
are custom methods to render specific types of charts.
-------------------------------------------------------------------------
In terms of widgets, the basic concept is that there is a central, super-
flexible Chart widget (Chart, oddly enough), and then any number of preset
chart type widgets, that are basically built to serve a simple, easy
purpose. For instance, if someone just needs to plot a series of lines,
they would be better off using the LineChart widget; but if someone needed
to plot a combo chart, that has 2 Y Axes (one linear, one log) against the
same X Axis, using lines and areas, then they will want to use a Chart widget.
Note also that unlike other widgets, the Charting engine *can* be called
directly from script *without* the need for the actual widget engine to be
loaded; the Chart widgets are thin wrappers around the charting engine.
/branches/v5.0-ouadji/api/js/dojo/src/charting/Chart.js
New file
0,0 → 1,64
/*
Copyright (c) 2004-2006, The Dojo Foundation
All Rights Reserved.
 
Licensed under the Academic Free License version 2.1 or above OR the
modified BSD license. For more information on Dojo licensing, see:
 
http://dojotoolkit.org/community/licensing.shtml
*/
 
 
 
dojo.provide("dojo.charting.Chart");
dojo.require("dojo.lang.common");
dojo.require("dojo.charting.PlotArea");
dojo.charting.Chart = function (node, title, description) {
this.node = node || null;
this.title = title || "Chart";
this.description = description || "";
this.plotAreas = [];
};
dojo.extend(dojo.charting.Chart, {addPlotArea:function (obj, doRender) {
if (obj.x != null && obj.left == null) {
obj.left = obj.x;
}
if (obj.y != null && obj.top == null) {
obj.top = obj.y;
}
this.plotAreas.push(obj);
if (doRender) {
this.render();
}
}, onInitialize:function (chart) {
}, onRender:function (chart) {
}, onDestroy:function (chart) {
}, initialize:function () {
if (!this.node) {
dojo.raise("dojo.charting.Chart.initialize: there must be a root node defined for the Chart.");
}
this.destroy();
this.render();
this.onInitialize(this);
}, render:function () {
if (this.node.style.position != "absolute") {
this.node.style.position = "relative";
}
for (var i = 0; i < this.plotAreas.length; i++) {
var area = this.plotAreas[i].plotArea;
var node = area.initialize();
node.style.position = "absolute";
node.style.top = this.plotAreas[i].top + "px";
node.style.left = this.plotAreas[i].left + "px";
this.node.appendChild(node);
area.render();
}
}, destroy:function () {
for (var i = 0; i < this.plotAreas.length; i++) {
this.plotAreas[i].plotArea.destroy();
}
while (this.node && this.node.childNodes && this.node.childNodes.length > 0) {
this.node.removeChild(this.node.childNodes[0]);
}
}});