this.datasets[setname] = set_xy;
};
+// TODO(danvk): CONTRACT remove
+DygraphLayout.prototype.addAnnotation = function() {
+ // Add an annotation to one series.
+ this.annotations = [];
+ for (var x = 10; x < 30; x += 2) {
+ this.annotations.push( {
+ series: 'sine wave',
+ xval: this.attr_('xValueParser')("200610" + x),
+ shortText: x,
+ text: 'Stock Market Crash ' + x
+ } );
+ }
+ this.annotations.push( {
+ series: 'another line',
+ xval: this.attr_('xValueParser')("20061013"),
+ shortText: 'X',
+ text: 'Another one'
+ } );
+};
+
DygraphLayout.prototype.evaluate = function() {
this._evaluateLimits();
this._evaluateLineCharts();
this._evaluateLineTicks();
+ this._evaluateAnnotations();
};
DygraphLayout.prototype._evaluateLimits = function() {
}
};
+DygraphLayout.prototype._evaluateAnnotations = function() {
+ // Add the annotations to the point to which they belong.
+ // Make a map from (setName, xval) to annotation for quick lookups.
+ var annotations = {};
+ for (var i = 0; i < this.annotations.length; i++) {
+ var a = this.annotations[i];
+ annotations[a.xval + "," + a.series] = a;
+ }
+
+ this.annotated_points = [];
+ for (var i = 0; i < this.points.length; i++) {
+ var p = this.points[i];
+ var k = p.xval + "," + p.name;
+ if (k in annotations) {
+ p.annotation = annotations[k];
+ this.annotated_points.push(p);
+ }
+ }
+};
+
/**
* Convenience function to remove all the data sets from a graph
*/
// internal state
this.xlabels = new Array();
this.ylabels = new Array();
+ this.annotations = new Array();
this.area = {
x: this.options.yAxisLabelWidth + 2 * this.options.axisTickSize,
var el = this.ylabels[i];
el.parentNode.removeChild(el);
}
+ for (var i = 0; i < this.annotations.length; i++) {
+ var el = this.annotations[i];
+ el.parentNode.removeChild(el);
+ }
this.xlabels = new Array();
this.ylabels = new Array();
+ this.annotations = new Array();
};
// Do the ordinary rendering, as before
this._renderLineChart();
this._renderAxis();
+ this._renderAnnotations();
};
};
+DygraphCanvasRenderer.prototype._renderAnnotations = function() {
+ var annotationStyle = {
+ "position": "absolute",
+ "fontSize": this.options.axisLabelFontSize + "px",
+ "zIndex": 10,
+ "width": "20px",
+ "overflow": "hidden",
+ "border": "1px solid black",
+ "background-color": "white",
+ "text-align": "center"
+ };
+
+ // Get a list of point with annotations.
+ var points = this.layout.annotated_points;
+ for (var i = 0; i < points.length; i++) {
+ var p = points[i];
+ var div = document.createElement("div");
+ for (var name in annotationStyle) {
+ if (annotationStyle.hasOwnProperty(name)) {
+ div.style[name] = annotationStyle[name];
+ }
+ }
+ div.appendChild(document.createTextNode(p.annotation.shortText));
+ div.style.left = (p.canvasx - 10) + "px";
+ div.style.top = p.canvasy + "px";
+ div.title = p.annotation.text;
+ div.style.color = this.colors[p.name];
+ div.style.borderColor = this.colors[p.name];
+ this.container.appendChild(div);
+ this.annotations.push(div);
+ }
+};
+
+
/**
* Overrides the CanvasRenderer method to draw error bars
*/
prevX = NaN;
continue;
}
+
// TODO(danvk): here
if (stepPlot) {
var newYs = [ prevY - point.errorPlus * yscale,
--- /dev/null
+<html>
+ <head>
+ <title>demo</title>
+ <!--[if IE]>
+ <script type="text/javascript" src="excanvas.js"></script>
+ <![endif]-->
+ <script type="text/javascript" src="../strftime/strftime-min.js"></script>
+ <script type="text/javascript" src="../rgbcolor/rgbcolor.js"></script>
+ <script type="text/javascript" src="../dygraph-canvas.js"></script>
+ <script type="text/javascript" src="../dygraph.js"></script>
+ </head>
+ <body>
+ <div id="g"></div>
+
+ <script type="text/javascript">
+ g = new DateGraph(
+ document.getElementById("g"),
+ function() {
+ var zp = function(x) { if (x < 10) return "0"+x; else return x; };
+ var r = "date,parabola,line,another line,sine wave\n";
+ for (var i=1; i<=31; i++) {
+ r += "200610" + zp(i);
+ r += "," + 10*(i*(31-i));
+ r += "," + 10*(8*i);
+ r += "," + 10*(250 - 8*i);
+ r += "," + 10*(125 + 125 * Math.sin(0.3*i));
+ r += "\n";
+ }
+ return r;
+ },
+ {
+ rollPeriod: 1,
+ width: 480,
+ height: 320
+ }
+ );
+ </script>
+</body>
+</html>