f22f8586cecd242149baa56600d8733d03418d1b
1 // Copyright 2006 Dan Vanderkam (danvdk@gmail.com)
2 // All Rights Reserved.
5 * @fileoverview Based on PlotKit, but modified to meet the needs of dygraphs.
6 * In particular, support for:
9 * - dygraphs attribute system
13 * Creates a new DygraphLayout object.
14 * @param {Object} options Options for PlotKit.Layout
15 * @return {Object} The DygraphLayout object
17 DygraphLayout
= function(dygraph
, options
) {
18 this.dygraph_
= dygraph
;
19 this.options
= {}; // TODO(danvk): remove, use attr_ instead.
20 Dygraph
.update(this.options
, options
? options
: {});
21 this.datasets
= new Array();
22 this.annotations
= new Array()
25 DygraphLayout
.prototype.attr_
= function(name
) {
26 return this.dygraph_
.attr_(name
);
29 DygraphLayout
.prototype.addDataset
= function(setname
, set_xy
) {
30 this.datasets
[setname
] = set_xy
;
33 DygraphLayout
.prototype.setAnnotations
= function(ann
) {
34 // The Dygraph object's annotations aren't parsed. We parse them here and
36 var parse
= this.attr_('xValueParser');
37 for (var i
= 0; i
< ann
.length
; i
++) {
39 if (!ann
[i
].xval
&& !ann
[i
].x
) {
40 this.dygraph_
.error("Annotations must have an 'x' property");
44 !(ann
[i
].hasOwnProperty('width') &&
45 ann
[i
].hasOwnProperty('height'))) {
46 this.dygraph_
.error("Must set width and height when setting " +
47 "annotation.icon property");
50 Dygraph
.update(a
, ann
[i
]);
51 if (!a
.xval
) a
.xval
= parse(a
.x
);
52 this.annotations
.push(a
);
56 DygraphLayout
.prototype.evaluate
= function() {
57 this._evaluateLimits();
58 this._evaluateLineCharts();
59 this._evaluateLineTicks();
60 this._evaluateAnnotations();
63 DygraphLayout
.prototype._evaluateLimits
= function() {
64 this.minxval
= this.maxxval
= null;
65 if (this.options
.dateWindow
) {
66 this.minxval
= this.options
.dateWindow
[0];
67 this.maxxval
= this.options
.dateWindow
[1];
69 for (var name
in this.datasets
) {
70 if (!this.datasets
.hasOwnProperty(name
)) continue;
71 var series
= this.datasets
[name
];
72 var x1
= series
[0][0];
73 if (!this.minxval
|| x1
< this.minxval
) this.minxval
= x1
;
75 var x2
= series
[series
.length
- 1][0];
76 if (!this.maxxval
|| x2
> this.maxxval
) this.maxxval
= x2
;
79 this.xrange
= this.maxxval
- this.minxval
;
80 this.xscale
= (this.xrange
!= 0 ? 1/this.xrange
: 1.0);
82 for (var i
= 0; i
< this.options
.yAxes
.length
; i
++) {
83 var axis
= this.options
.yAxes
[i
];
84 axis
.minyval
= axis
.valueRange
[0];
85 axis
.maxyval
= axis
.valueRange
[1];
86 axis
.yrange
= axis
.maxyval
- axis
.minyval
;
87 axis
.yscale
= (axis
.yrange
!= 0 ? 1.0 / axis
.yrange
: 1.0);
91 DygraphLayout
.prototype._evaluateLineCharts
= function() {
93 this.points
= new Array();
94 for (var setName
in this.datasets
) {
95 if (!this.datasets
.hasOwnProperty(setName
)) continue;
97 var dataset
= this.datasets
[setName
];
98 var axis
= this.options
.yAxes
[this.options
.seriesToAxisMap
[setName
]];
100 for (var j
= 0; j
< dataset
.length
; j
++) {
101 var item
= dataset
[j
];
104 x
: ((parseFloat(item
[0]) - this.minxval
) * this.xscale
),
105 y
: 1.0 - ((parseFloat(item
[1]) - axis
.minyval
) * axis
.yscale
),
106 xval
: parseFloat(item
[0]),
107 yval
: parseFloat(item
[1]),
111 // limit the x, y values so they do not overdraw
112 if (point
.y
<= 0.0) {
115 if (point
.y
>= 1.0) {
118 this.points
.push(point
);
123 DygraphLayout
.prototype._evaluateLineTicks
= function() {
124 this.xticks
= new Array();
125 for (var i
= 0; i
< this.options
.xTicks
.length
; i
++) {
126 var tick
= this.options
.xTicks
[i
];
127 var label
= tick
.label
;
128 var pos
= this.xscale
* (tick
.v
- this.minxval
);
129 if ((pos
>= 0.0) && (pos
<= 1.0)) {
130 this.xticks
.push([pos
, label
]);
134 this.yticks
= new Array();
135 for (var i
= 0; i
< 1; i
++ ) {
136 var axis
= this.options
.yAxes
[i
];
137 for (var j
= 0; j
< axis
.ticks
.length
; j
++) {
138 var tick
= axis
.ticks
[j
];
139 var label
= tick
.label
;
140 var pos
= 1.0 - (axis
.yscale
* (tick
.v
- axis
.minyval
));
141 if ((pos
>= 0.0) && (pos
<= 1.0)) {
142 this.yticks
.push([pos
, label
]);
150 * Behaves the same way as PlotKit.Layout, but also copies the errors
153 DygraphLayout
.prototype.evaluateWithError
= function() {
155 if (!this.options
.errorBars
) return;
157 // Copy over the error terms
158 var i
= 0; // index in this.points
159 for (var setName
in this.datasets
) {
160 if (!this.datasets
.hasOwnProperty(setName
)) continue;
162 var dataset
= this.datasets
[setName
];
163 for (var j
= 0; j
< dataset
.length
; j
++, i
++) {
164 var item
= dataset
[j
];
165 var xv
= parseFloat(item
[0]);
166 var yv
= parseFloat(item
[1]);
168 if (xv
== this.points
[i
].xval
&&
169 yv
== this.points
[i
].yval
) {
170 this.points
[i
].errorMinus
= parseFloat(item
[2]);
171 this.points
[i
].errorPlus
= parseFloat(item
[3]);
177 DygraphLayout
.prototype._evaluateAnnotations
= function() {
178 // Add the annotations to the point to which they belong.
179 // Make a map from (setName, xval) to annotation for quick lookups.
180 var annotations
= {};
181 for (var i
= 0; i
< this.annotations
.length
; i
++) {
182 var a
= this.annotations
[i
];
183 annotations
[a
.xval
+ "," + a
.series
] = a
;
186 this.annotated_points
= [];
187 for (var i
= 0; i
< this.points
.length
; i
++) {
188 var p
= this.points
[i
];
189 var k
= p
.xval
+ "," + p
.name
;
190 if (k
in annotations
) {
191 p
.annotation
= annotations
[k
];
192 this.annotated_points
.push(p
);
198 * Convenience function to remove all the data sets from a graph
200 DygraphLayout
.prototype.removeAllDatasets
= function() {
201 delete this.datasets
;
202 this.datasets
= new Array();
206 * Change the values of various layout options
207 * @param {Object} new_options an associative array of new properties
209 DygraphLayout
.prototype.updateOptions
= function(new_options
) {
210 Dygraph
.update(this.options
, new_options
? new_options
: {});
213 // Subclass PlotKit.CanvasRenderer to add:
214 // 1. X/Y grid overlay
215 // 2. Ability to draw error bars (if required)
218 * Sets some PlotKit.CanvasRenderer options
219 * @param {Object} element The canvas to attach to
220 * @param {Layout} layout The DygraphLayout object for this graph.
221 * @param {Object} options Options to pass on to CanvasRenderer
223 DygraphCanvasRenderer
= function(dygraph
, element
, layout
, options
) {
224 // TODO(danvk): remove options, just use dygraph.attr_.
225 this.dygraph_
= dygraph
;
232 "axisLineColor": "black",
233 "axisLineWidth": 0.5,
235 "axisLabelColor": "black",
236 "axisLabelFont": "Arial",
237 "axisLabelFontSize": 9,
238 "axisLabelWidth": 50,
241 "gridLineColor": "rgb(128,128,128)",
243 "underlayCallback": null
245 Dygraph
.update(this.options
, options
);
247 this.layout
= layout
;
248 this.element
= element
;
249 this.container
= this.element
.parentNode
;
251 this.height
= this.element
.height
;
252 this.width
= this.element
.width
;
254 // --- check whether everything is ok before we return
255 if (!this.isIE
&& !(DygraphCanvasRenderer
.isSupported(this.element
)))
256 throw "Canvas is not supported.";
259 this.xlabels
= new Array();
260 this.ylabels
= new Array();
261 this.annotations
= new Array();
263 // TODO(danvk): consider all axes in this computation.
265 x
: this.options
.yAxisLabelWidth
+ 2 * this.options
.axisTickSize
,
268 this.area
.w
= this.width
- this.area
.x
- this.options
.rightGap
;
269 this.area
.h
= this.height
- this.options
.axisLabelFontSize
-
270 2 * this.options
.axisTickSize
;
272 this.container
.style
.position
= "relative";
273 this.container
.style
.width
= this.width
+ "px";
276 DygraphCanvasRenderer
.prototype.clear
= function() {
278 // VML takes a while to start up, so we just poll every this.IEDelay
280 if (this.clearDelay
) {
281 this.clearDelay
.cancel();
282 this.clearDelay
= null;
284 var context
= this.element
.getContext("2d");
287 // TODO(danvk): this is broken, since MochiKit.Async is gone.
288 this.clearDelay
= MochiKit
.Async
.wait(this.IEDelay
);
289 this.clearDelay
.addCallback(bind(this.clear
, this));
294 var context
= this.element
.getContext("2d");
295 context
.clearRect(0, 0, this.width
, this.height
);
297 for (var i
= 0; i
< this.xlabels
.length
; i
++) {
298 var el
= this.xlabels
[i
];
299 el
.parentNode
.removeChild(el
);
301 for (var i
= 0; i
< this.ylabels
.length
; i
++) {
302 var el
= this.ylabels
[i
];
303 el
.parentNode
.removeChild(el
);
305 for (var i
= 0; i
< this.annotations
.length
; i
++) {
306 var el
= this.annotations
[i
];
307 el
.parentNode
.removeChild(el
);
309 this.xlabels
= new Array();
310 this.ylabels
= new Array();
311 this.annotations
= new Array();
315 DygraphCanvasRenderer
.isSupported
= function(canvasName
) {
318 if (typeof(canvasName
) == 'undefined' || canvasName
== null)
319 canvas
= document
.createElement("canvas");
322 var context
= canvas
.getContext("2d");
325 var ie
= navigator
.appVersion
.match(/MSIE (\d\.\d)/);
326 var opera
= (navigator
.userAgent
.toLowerCase().indexOf("opera") != -1);
327 if ((!ie
) || (ie
[1] < 6) || (opera
))
335 * Draw an X/Y grid on top of the existing plot
337 DygraphCanvasRenderer
.prototype.render
= function() {
338 // Draw the new X/Y grid
339 var ctx
= this.element
.getContext("2d");
341 if (this.options
.underlayCallback
) {
342 this.options
.underlayCallback(ctx
, this.area
, this.layout
, this.dygraph_
);
345 if (this.options
.drawYGrid
) {
346 var ticks
= this.layout
.yticks
;
348 ctx
.strokeStyle
= this.options
.gridLineColor
;
349 ctx
.lineWidth
= this.options
.axisLineWidth
;
350 for (var i
= 0; i
< ticks
.length
; i
++) {
352 var y
= this.area
.y
+ ticks
[i
][0] * this.area
.h
;
355 ctx
.lineTo(x
+ this.area
.w
, y
);
361 if (this.options
.drawXGrid
) {
362 var ticks
= this.layout
.xticks
;
364 ctx
.strokeStyle
= this.options
.gridLineColor
;
365 ctx
.lineWidth
= this.options
.axisLineWidth
;
366 for (var i
=0; i
<ticks
.length
; i
++) {
367 var x
= this.area
.x
+ ticks
[i
][0] * this.area
.w
;
368 var y
= this.area
.y
+ this.area
.h
;
371 ctx
.lineTo(x
, this.area
.y
);
377 // Do the ordinary rendering, as before
378 this._renderLineChart();
380 this._renderAnnotations();
384 DygraphCanvasRenderer
.prototype._renderAxis
= function() {
385 if (!this.options
.drawXAxis
&& !this.options
.drawYAxis
)
388 var context
= this.element
.getContext("2d");
391 "position": "absolute",
392 "fontSize": this.options
.axisLabelFontSize
+ "px",
394 "color": this.options
.axisLabelColor
,
395 "width": this.options
.axisLabelWidth
+ "px",
398 var makeDiv
= function(txt
) {
399 var div
= document
.createElement("div");
400 for (var name
in labelStyle
) {
401 if (labelStyle
.hasOwnProperty(name
)) {
402 div
.style
[name
] = labelStyle
[name
];
405 div
.appendChild(document
.createTextNode(txt
));
411 context
.strokeStyle
= this.options
.axisLineColor
;
412 context
.lineWidth
= this.options
.axisLineWidth
;
414 if (this.options
.drawYAxis
) {
415 if (this.layout
.yticks
&& this.layout
.yticks
.length
> 0) {
416 for (var i
= 0; i
< this.layout
.yticks
.length
; i
++) {
417 var tick
= this.layout
.yticks
[i
];
418 if (typeof(tick
) == "function") return;
420 var y
= this.area
.y
+ tick
[0] * this.area
.h
;
422 context
.moveTo(x
, y
);
423 context
.lineTo(x
- this.options
.axisTickSize
, y
);
427 var label
= makeDiv(tick
[1]);
428 var top
= (y
- this.options
.axisLabelFontSize
/ 2);
429 if (top
< 0) top
= 0;
431 if (top
+ this.options
.axisLabelFontSize
+ 3 > this.height
) {
432 label
.style
.bottom
= "0px";
434 label
.style
.top
= top
+ "px";
436 label
.style
.left
= "0px";
437 label
.style
.textAlign
= "right";
438 label
.style
.width
= this.options
.yAxisLabelWidth
+ "px";
439 this.container
.appendChild(label
);
440 this.ylabels
.push(label
);
443 // The lowest tick on the y-axis often overlaps with the leftmost
444 // tick on the x-axis. Shift the bottom tick up a little bit to
445 // compensate if necessary.
446 var bottomTick
= this.ylabels
[0];
447 var fontSize
= this.options
.axisLabelFontSize
;
448 var bottom
= parseInt(bottomTick
.style
.top
) + fontSize
;
449 if (bottom
> this.height
- fontSize
) {
450 bottomTick
.style
.top
= (parseInt(bottomTick
.style
.top
) -
451 fontSize
/ 2) + "px";
456 context
.moveTo(this.area
.x
, this.area
.y
);
457 context
.lineTo(this.area
.x
, this.area
.y
+ this.area
.h
);
462 if (this.options
.drawXAxis
) {
463 if (this.layout
.xticks
) {
464 for (var i
= 0; i
< this.layout
.xticks
.length
; i
++) {
465 var tick
= this.layout
.xticks
[i
];
466 if (typeof(dataset
) == "function") return;
468 var x
= this.area
.x
+ tick
[0] * this.area
.w
;
469 var y
= this.area
.y
+ this.area
.h
;
471 context
.moveTo(x
, y
);
472 context
.lineTo(x
, y
+ this.options
.axisTickSize
);
476 var label
= makeDiv(tick
[1]);
477 label
.style
.textAlign
= "center";
478 label
.style
.bottom
= "0px";
480 var left
= (x
- this.options
.axisLabelWidth
/2);
481 if (left
+ this.options
.axisLabelWidth
> this.width
) {
482 left
= this.width
- this.options
.xAxisLabelWidth
;
483 label
.style
.textAlign
= "right";
487 label
.style
.textAlign
= "left";
490 label
.style
.left
= left
+ "px";
491 label
.style
.width
= this.options
.xAxisLabelWidth
+ "px";
492 this.container
.appendChild(label
);
493 this.xlabels
.push(label
);
498 context
.moveTo(this.area
.x
, this.area
.y
+ this.area
.h
);
499 context
.lineTo(this.area
.x
+ this.area
.w
, this.area
.y
+ this.area
.h
);
508 DygraphCanvasRenderer
.prototype._renderAnnotations
= function() {
509 var annotationStyle
= {
510 "position": "absolute",
511 "fontSize": this.options
.axisLabelFontSize
+ "px",
516 var bindEvt
= function(eventName
, classEventName
, p
, self
) {
518 var a
= p
.annotation
;
519 if (a
.hasOwnProperty(eventName
)) {
520 a
[eventName
](a
, p
, self
.dygraph_
, e
);
521 } else if (self
.dygraph_
.attr_(classEventName
)) {
522 self
.dygraph_
.attr_(classEventName
)(a
, p
, self
.dygraph_
,e
);
527 // Get a list of point with annotations.
528 var points
= this.layout
.annotated_points
;
529 for (var i
= 0; i
< points
.length
; i
++) {
531 if (p
.canvasx
< this.area
.x
|| p
.canvasx
> this.area
.x
+ this.area
.w
) {
535 var a
= p
.annotation
;
537 if (a
.hasOwnProperty("tickHeight")) {
538 tick_height
= a
.tickHeight
;
541 var div
= document
.createElement("div");
542 for (var name
in annotationStyle
) {
543 if (annotationStyle
.hasOwnProperty(name
)) {
544 div
.style
[name
] = annotationStyle
[name
];
547 if (!a
.hasOwnProperty('icon')) {
548 div
.className
= "dygraphDefaultAnnotation";
550 if (a
.hasOwnProperty('cssClass')) {
551 div
.className
+= " " + a
.cssClass
;
554 var width
= a
.hasOwnProperty('width') ? a
.width
: 16;
555 var height
= a
.hasOwnProperty('height') ? a
.height
: 16;
556 if (a
.hasOwnProperty('icon')) {
557 var img
= document
.createElement("img");
561 div
.appendChild(img
);
562 } else if (p
.annotation
.hasOwnProperty('shortText')) {
563 div
.appendChild(document
.createTextNode(p
.annotation
.shortText
));
565 div
.style
.left
= (p
.canvasx
- width
/ 2) + "px";
566 if (a
.attachAtBottom
) {
567 div
.style
.top
= (this.area
.h
- height
- tick_height
) + "px";
569 div
.style
.top
= (p
.canvasy
- height
- tick_height
) + "px";
571 div
.style
.width
= width
+ "px";
572 div
.style
.height
= height
+ "px";
573 div
.title
= p
.annotation
.text
;
574 div
.style
.color
= this.colors
[p
.name
];
575 div
.style
.borderColor
= this.colors
[p
.name
];
578 Dygraph
.addEvent(div
, 'click',
579 bindEvt('clickHandler', 'annotationClickHandler', p
, this));
580 Dygraph
.addEvent(div
, 'mouseover',
581 bindEvt('mouseOverHandler', 'annotationMouseOverHandler', p
, this));
582 Dygraph
.addEvent(div
, 'mouseout',
583 bindEvt('mouseOutHandler', 'annotationMouseOutHandler', p
, this));
584 Dygraph
.addEvent(div
, 'dblclick',
585 bindEvt('dblClickHandler', 'annotationDblClickHandler', p
, this));
587 this.container
.appendChild(div
);
588 this.annotations
.push(div
);
590 var ctx
= this.element
.getContext("2d");
591 ctx
.strokeStyle
= this.colors
[p
.name
];
593 if (!a
.attachAtBottom
) {
594 ctx
.moveTo(p
.canvasx
, p
.canvasy
);
595 ctx
.lineTo(p
.canvasx
, p
.canvasy
- 2 - tick_height
);
597 ctx
.moveTo(p
.canvasx
, this.area
.h
);
598 ctx
.lineTo(p
.canvasx
, this.area
.h
- 2 - tick_height
);
607 * Overrides the CanvasRenderer method to draw error bars
609 DygraphCanvasRenderer
.prototype._renderLineChart
= function() {
610 var context
= this.element
.getContext("2d");
611 var colorCount
= this.options
.colorScheme
.length
;
612 var colorScheme
= this.options
.colorScheme
;
613 var fillAlpha
= this.options
.fillAlpha
;
614 var errorBars
= this.layout
.options
.errorBars
;
615 var fillGraph
= this.layout
.options
.fillGraph
;
616 var stackedGraph
= this.layout
.options
.stackedGraph
;
617 var stepPlot
= this.layout
.options
.stepPlot
;
620 for (var name
in this.layout
.datasets
) {
621 if (this.layout
.datasets
.hasOwnProperty(name
)) {
625 var setCount
= setNames
.length
;
628 for (var i
= 0; i
< setCount
; i
++) {
629 this.colors
[setNames
[i
]] = colorScheme
[i
% colorCount
];
634 for (var i
= 0; i
< this.layout
.points
.length
; i
++) {
635 var point
= this.layout
.points
[i
];
636 point
.canvasx
= this.area
.w
* point
.x
+ this.area
.x
;
637 point
.canvasy
= this.area
.h
* point
.y
+ this.area
.y
;
641 var isOK
= function(x
) { return x
&& !isNaN(x
); };
646 this.dygraph_
.warn("Can't use fillGraph option with error bars");
649 for (var i
= 0; i
< setCount
; i
++) {
650 var setName
= setNames
[i
];
651 var axis
= this.layout
.options
.yAxes
[
652 this.layout
.options
.seriesToAxisMap
[setName
]];
653 var color
= this.colors
[setName
];
655 // setup graphics context
659 var prevYs
= [-1, -1];
660 var yscale
= axis
.yscale
;
661 // should be same color as the lines but only 15% opaque.
662 var rgb
= new RGBColor(color
);
663 var err_color
= 'rgba(' + rgb
.r
+ ',' + rgb
.g
+ ',' + rgb
.b
+ ',' +
665 ctx
.fillStyle
= err_color
;
667 for (var j
= 0; j
< this.layout
.points
.length
; j
++) {
668 var point
= this.layout
.points
[j
];
669 if (point
.name
== setName
) {
670 if (!isOK(point
.y
)) {
677 var newYs
= [ prevY
- point
.errorPlus
* yscale
,
678 prevY
+ point
.errorMinus
* yscale
];
681 var newYs
= [ point
.y
- point
.errorPlus
* yscale
,
682 point
.y
+ point
.errorMinus
* yscale
];
684 newYs
[0] = this.area
.h
* newYs
[0] + this.area
.y
;
685 newYs
[1] = this.area
.h
* newYs
[1] + this.area
.y
;
688 ctx
.moveTo(prevX
, newYs
[0]);
690 ctx
.moveTo(prevX
, prevYs
[0]);
692 ctx
.lineTo(point
.canvasx
, newYs
[0]);
693 ctx
.lineTo(point
.canvasx
, newYs
[1]);
695 ctx
.lineTo(prevX
, newYs
[1]);
697 ctx
.lineTo(prevX
, prevYs
[1]);
702 prevX
= point
.canvasx
;
707 } else if (fillGraph
) {
708 var baseline
= [] // for stacked graphs: baseline for filling
710 // process sets in reverse order (needed for stacked graphs)
711 for (var i
= setCount
- 1; i
>= 0; i
--) {
712 var setName
= setNames
[i
];
713 var color
= this.colors
[setName
];
714 var axis
= this.layout
.options
.yAxes
[
715 this.layout
.options
.seriesToAxisMap
[setName
]];
716 var axisY
= 1.0 + axis
.minyval
* axis
.yscale
;
717 if (axisY
< 0.0) axisY
= 0.0;
718 else if (axisY
> 1.0) axisY
= 1.0;
719 axisY
= this.area
.h
* axisY
+ this.area
.y
;
721 // setup graphics context
724 var prevYs
= [-1, -1];
725 var yscale
= axis
.yscale
;
726 // should be same color as the lines but only 15% opaque.
727 var rgb
= new RGBColor(color
);
728 var err_color
= 'rgba(' + rgb
.r
+ ',' + rgb
.g
+ ',' + rgb
.b
+ ',' +
730 ctx
.fillStyle
= err_color
;
732 for (var j
= 0; j
< this.layout
.points
.length
; j
++) {
733 var point
= this.layout
.points
[j
];
734 if (point
.name
== setName
) {
735 if (!isOK(point
.y
)) {
741 lastY
= baseline
[point
.canvasx
];
742 if (lastY
=== undefined
) lastY
= axisY
;
743 baseline
[point
.canvasx
] = point
.canvasy
;
744 newYs
= [ point
.canvasy
, lastY
];
746 newYs
= [ point
.canvasy
, axisY
];
749 ctx
.moveTo(prevX
, prevYs
[0]);
751 ctx
.lineTo(point
.canvasx
, prevYs
[0]);
753 ctx
.lineTo(point
.canvasx
, newYs
[0]);
755 ctx
.lineTo(point
.canvasx
, newYs
[1]);
756 ctx
.lineTo(prevX
, prevYs
[1]);
760 prevX
= point
.canvasx
;
767 for (var i
= 0; i
< setCount
; i
++) {
768 var setName
= setNames
[i
];
769 var color
= this.colors
[setName
];
770 var strokeWidth
= this.dygraph_
.attr_("strokeWidth", setName
);
772 // setup graphics context
774 var point
= this.layout
.points
[0];
775 var pointSize
= this.dygraph_
.attr_("pointSize", setName
);
776 var prevX
= null, prevY
= null;
777 var drawPoints
= this.dygraph_
.attr_("drawPoints", setName
);
778 var points
= this.layout
.points
;
779 for (var j
= 0; j
< points
.length
; j
++) {
780 var point
= points
[j
];
781 if (point
.name
== setName
) {
782 if (!isOK(point
.canvasy
)) {
783 // this will make us move to the next point, not draw a line to it.
784 prevX
= prevY
= null;
786 // A point is "isolated" if it is non-null but both the previous
787 // and next points are null.
788 var isIsolated
= (!prevX
&& (j
== points
.length
- 1 ||
789 !isOK(points
[j
+1].canvasy
)));
792 prevX
= point
.canvasx
;
793 prevY
= point
.canvasy
;
795 // TODO(danvk): figure out why this conditional is necessary.
798 ctx
.strokeStyle
= color
;
799 ctx
.lineWidth
= strokeWidth
;
800 ctx
.moveTo(prevX
, prevY
);
802 ctx
.lineTo(point
.canvasx
, prevY
);
804 prevX
= point
.canvasx
;
805 prevY
= point
.canvasy
;
806 ctx
.lineTo(prevX
, prevY
);
811 if (drawPoints
|| isIsolated
) {
813 ctx
.fillStyle
= color
;
814 ctx
.arc(point
.canvasx
, point
.canvasy
, pointSize
,
815 0, 2 * Math
.PI
, false);