- var width = a.hasOwnProperty('width') ? a.width : 16;
- var height = a.hasOwnProperty('height') ? a.height : 16;
- if (a.hasOwnProperty('icon')) {
- var img = document.createElement("img");
- img.src = a.icon;
- img.width = width;
- img.height = height;
- div.appendChild(img);
- } else if (p.annotation.hasOwnProperty('shortText')) {
- div.appendChild(document.createTextNode(p.annotation.shortText));
- }
- div.style.left = (p.canvasx - width / 2) + "px";
- if (a.attachAtBottom) {
- div.style.top = (this.area.h - height - tick_height) + "px";
- } else {
- div.style.top = (p.canvasy - height - tick_height) + "px";
- }
- div.style.width = width + "px";
- div.style.height = height + "px";
- div.title = p.annotation.text;
- div.style.color = this.colors[p.name];
- div.style.borderColor = this.colors[p.name];
- a.div = div;
-
- this.dygraph_.addEvent(div, 'click',
- bindEvt('clickHandler', 'annotationClickHandler', p, this));
- this.dygraph_.addEvent(div, 'mouseover',
- bindEvt('mouseOverHandler', 'annotationMouseOverHandler', p, this));
- this.dygraph_.addEvent(div, 'mouseout',
- bindEvt('mouseOutHandler', 'annotationMouseOutHandler', p, this));
- this.dygraph_.addEvent(div, 'dblclick',
- bindEvt('dblClickHandler', 'annotationDblClickHandler', p, this));
-
- this.container.appendChild(div);
- this.annotations.push(div);
-
- var ctx = this.elementContext;
- ctx.strokeStyle = this.colors[p.name];
- ctx.beginPath();
- if (!a.attachAtBottom) {
- ctx.moveTo(p.canvasx, p.canvasy);
- ctx.lineTo(p.canvasx, p.canvasy - 2 - tick_height);
- } else {
- ctx.moveTo(p.canvasx, this.area.h);
- ctx.lineTo(p.canvasx, this.area.h - 2 - tick_height);
- }
- ctx.closePath();
- ctx.stroke();
- }
-};
-
-DygraphCanvasRenderer.makeNextPointStep_ = function(
- connect, points, start, end) {
- if (connect) {
- return function(j) {
- while (++j + start < end) {
- if (!(points[start + j].yval === null)) break;
- }
- return j;
- }
- } else {
- return function(j) { return j + 1 };
- }
-};
-
-DygraphCanvasRenderer.isNullOrNaN_ = function(x) {
- return (x === null || isNaN(x));
-};
-
-DygraphCanvasRenderer.prototype._drawStyledLine = function(
- ctx, i, setName, color, strokeWidth, strokePattern, drawPoints,
- drawPointCallback, pointSize) {
- // TODO(konigsberg): Compute attributes outside this method call.
- var stepPlot = this.attr_("stepPlot");
- var firstIndexInSet = this.layout.setPointsOffsets[i];
- var setLength = this.layout.setPointsLengths[i];
- var points = this.layout.points;
- if (!Dygraph.isArrayLike(strokePattern)) {
- strokePattern = null;
- }
- var drawGapPoints = this.dygraph_.attr_('drawGapEdgePoints', setName);
-
- ctx.save();
- if (strokeWidth && !stepPlot && (!strokePattern || strokePattern.length <= 1)) {
- this._drawTrivialLine(ctx, points, setLength, firstIndexInSet, setName, color, strokeWidth, drawPointCallback, pointSize, drawPoints, drawGapPoints);
- } else {
- this._drawNonTrivialLine(ctx, points, setLength, firstIndexInSet, setName, color, strokeWidth, strokePattern, drawPointCallback, pointSize, drawPoints, drawGapPoints, stepPlot);
- }
- ctx.restore();
-};
-
-DygraphCanvasRenderer.prototype._drawNonTrivialLine = function(
- ctx, points, setLength, firstIndexInSet, setName, color, strokeWidth, strokePattern, drawPointCallback, pointSize, drawPoints, drawGapPoints, stepPlot) {
- var prevX = null;
- var prevY = null;
- var nextY = null;
- var point, nextPoint;
- var pointsOnLine = []; // Array of [canvasx, canvasy] pairs.
- var next = DygraphCanvasRenderer.makeNextPointStep_(
- this.attr_('connectSeparatedPoints'), points, firstIndexInSet,
- firstIndexInSet + setLength);
- for (var j = 0; j < setLength; j = next(j)) {
- point = points[firstIndexInSet + j];
- nextY = (next(j) < setLength) ?
- points[firstIndexInSet + next(j)].canvasy : null;
- if (DygraphCanvasRenderer.isNullOrNaN_(point.canvasy)) {
- if (stepPlot && prevX !== null) {