// default options
this.options = {
- "strokeWidth": 0.5,
- "drawXAxis": true,
- "drawYAxis": true,
- "axisLineColor": Color.blackColor(),
- "axisLineWidth": 0.5,
- "axisTickSize": 3,
- "axisLabelColor": Color.blackColor(),
- "axisLabelFont": "Arial",
- "axisLabelFontSize": 9,
- "axisLabelWidth": 50,
- "drawYGrid": true,
- "drawXGrid": true,
- "gridLineColor": MochiKit.Color.Color.grayColor()
+ "strokeWidth": 0.5,
+ "drawXAxis": true,
+ "drawYAxis": true,
+ "axisLineColor": "black",
+ "axisLineWidth": 0.5,
+ "axisTickSize": 3,
+ "axisLabelColor": "black",
+ "axisLabelFont": "Arial",
+ "axisLabelFontSize": 9,
+ "axisLabelWidth": 50,
+ "drawYGrid": true,
+ "drawXGrid": true,
+ "gridLineColor": "rgb(128,128,128)"
};
MochiKit.Base.update(this.options, options);
DygraphCanvasRenderer.isSupported = function(canvasName) {
var canvas = null;
try {
- if (MochiKit.Base.isUndefinedOrNull(canvasName))
+ if (typeof(canvasName) == 'undefined' || canvasName == null)
canvas = document.createElement("canvas");
else
canvas = canvasName;
if (this.options.drawYGrid) {
var ticks = this.layout.yticks;
ctx.save();
- ctx.strokeStyle = this.options.gridLineColor.toRGBString();
+ ctx.strokeStyle = this.options.gridLineColor;
ctx.lineWidth = this.options.axisLineWidth;
for (var i = 0; i < ticks.length; i++) {
var x = this.area.x;
if (this.options.drawXGrid) {
var ticks = this.layout.xticks;
ctx.save();
- ctx.strokeStyle = this.options.gridLineColor.toRGBString();
+ ctx.strokeStyle = this.options.gridLineColor;
ctx.lineWidth = this.options.axisLineWidth;
for (var i=0; i<ticks.length; i++) {
var x = this.area.x + ticks[i][0] * this.area.w;
}
// Do the ordinary rendering, as before
- // TODO(danvk) Call super.render()
this._renderLineChart();
this._renderAxis();
};
"position": "absolute",
"fontSize": this.options.axisLabelFontSize + "px",
"zIndex": 10,
- "color": this.options.axisLabelColor.toRGBString(),
+ "color": this.options.axisLabelColor,
"width": this.options.axisLabelWidth + "px",
"overflow": "hidden"
};
// axis lines
context.save();
- context.strokeStyle = this.options.axisLineColor.toRGBString();
+ context.strokeStyle = this.options.axisLineColor;
context.lineWidth = this.options.axisLineWidth;
if (this.options.drawYAxis) {
var context = this.element.getContext("2d");
var colorCount = this.options.colorScheme.length;
var colorScheme = this.options.colorScheme;
- var setNames = MochiKit.Base.keys(this.layout.datasets);
var errorBars = this.layout.options.errorBars;
+
+ var setNames = [];
+ for (var name in this.layout.datasets) setNames.push(name);
var setCount = setNames.length;
- var bind = MochiKit.Base.bind;
- var partial = MochiKit.Base.partial;
//Update Points
for (var i = 0; i < this.layout.points.length; i++) {
// create paths
var isOK = function(x) { return x && !isNaN(x); };
- var makePath = function(ctx) {
- for (var i = 0; i < setCount; i++) {
- var setName = setNames[i];
- var color = colorScheme[i%colorCount];
- var strokeX = this.options.strokeColorTransform;
-
- // setup graphics context
- context.save();
- context.strokeStyle = color.toRGBString();
- context.lineWidth = this.options.strokeWidth;
- var point = this.layout.points[0];
- var pointSize = this.dygraph_.attr_("pointSize");
- var prevX = null, prevY = null;
- var drawPoints = this.dygraph_.attr_("drawPoints");
- var points = this.layout.points;
- for (var j = 0; j < points.length; j++) {
- var point = points[j];
- if (point.name == setName) {
- if (!isOK(point.canvasy)) {
- // this will make us move to the next point, not draw a line to it.
- prevX = prevY = null;
- } else {
- // A point is "isolated" if it is non-null but both the previous
- // and next points are null.
- var isIsolated = (!prevX && (j == points.length - 1 ||
- !isOK(points[j+1].canvasy)));
-
- if (!prevX) {
- prevX = point.canvasx;
- prevY = point.canvasy;
- } else {
- ctx.beginPath();
- ctx.moveTo(prevX, prevY);
- prevX = point.canvasx;
- prevY = point.canvasy;
- ctx.lineTo(prevX, prevY);
- ctx.stroke();
- }
-
- if (drawPoints || isIsolated) {
- ctx.beginPath();
- ctx.fillStyle = color.toRGBString();
- ctx.arc(point.canvasx, point.canvasy, pointSize, 0, 360, false);
- ctx.fill();
- }
- }
- }
- }
- }
- };
- var makeErrorBars = function(ctx) {
+ var ctx = context;
+ if (errorBars) {
for (var i = 0; i < setCount; i++) {
var setName = setNames[i];
var color = colorScheme[i % colorCount];
- var strokeX = this.options.strokeColorTransform;
// setup graphics context
- context.save();
- context.strokeStyle = color.toRGBString();
- context.lineWidth = this.options.strokeWidth;
+ ctx.save();
+ ctx.strokeStyle = color;
+ ctx.lineWidth = this.options.strokeWidth;
var prevX = -1;
var prevYs = [-1, -1];
var count = 0;
var yscale = this.layout.yscale;
- // should be same color as the lines
- var err_color = color.colorWithAlpha(0.15);
- ctx.fillStyle = err_color.toRGBString();
+ // should be same color as the lines but only 15% opaque.
+ var rgb = new RGBColor(color);
+ var err_color = 'rgba(' + rgb.r + ',' + rgb.g + ',' + rgb.b + ',0.15)';
+ ctx.fillStyle = err_color;
ctx.beginPath();
for (var j = 0; j < this.layout.points.length; j++) {
var point = this.layout.points[j];
}
ctx.fill();
}
- };
+ }
+
+ for (var i = 0; i < setCount; i++) {
+ var setName = setNames[i];
+ var color = colorScheme[i%colorCount];
+
+ // setup graphics context
+ context.save();
+ var point = this.layout.points[0];
+ var pointSize = this.dygraph_.attr_("pointSize");
+ var prevX = null, prevY = null;
+ var drawPoints = this.dygraph_.attr_("drawPoints");
+ var points = this.layout.points;
+ for (var j = 0; j < points.length; j++) {
+ var point = points[j];
+ if (point.name == setName) {
+ if (!isOK(point.canvasy)) {
+ // this will make us move to the next point, not draw a line to it.
+ prevX = prevY = null;
+ } else {
+ // A point is "isolated" if it is non-null but both the previous
+ // and next points are null.
+ var isIsolated = (!prevX && (j == points.length - 1 ||
+ !isOK(points[j+1].canvasy)));
+
+ if (!prevX) {
+ prevX = point.canvasx;
+ prevY = point.canvasy;
+ } else {
+ ctx.beginPath();
+ ctx.strokeStyle = color;
+ ctx.lineWidth = this.options.strokeWidth;
+ ctx.moveTo(prevX, prevY);
+ prevX = point.canvasx;
+ prevY = point.canvasy;
+ ctx.lineTo(prevX, prevY);
+ ctx.stroke();
+ }
+
+ if (drawPoints || isIsolated) {
+ ctx.beginPath();
+ ctx.fillStyle = color;
+ ctx.arc(point.canvasx, point.canvasy, pointSize, 0, 360, false);
+ ctx.fill();
+ }
+ }
+ }
+ }
+ }
- if (errorBars)
- bind(makeErrorBars, this)(context);
- bind(makePath, this)(context);
context.restore();
};