/**
* Closest-point highlighting with locked series.
*/
-CallbackTestCase.prototype.testClosestPointCallbackCss1 = function() {
+CallbackTestCase.prototype.testSetSelectionLocking = function() {
var g = runClosestTest(false, 2, 4);
// Default behavior, 'b' is closest
var graph = document.getElementById("graph");
var g = new Dygraph(graph, data, opts);
};
+
+pathologicalCasesTestCase.prototype.testDivAsString = function() {
+ var data = "X,Y\n" +
+ "1,2\n";
+
+ var g = new Dygraph('graph', data, {});
+}
return;
}
+ var stepPlot = this.attr_('stepPlot');
+
var combinedSeriesData = this.computeCombinedSeriesAndLimits_();
var yRange = combinedSeriesData.yMax - combinedSeriesData.yMin;
var canvasWidth = this.canvasRect_.w - margin;
var canvasHeight = this.canvasRect_.h - margin;
+ var prevX = null, prevY = null;
+
ctx.beginPath();
ctx.moveTo(margin, canvasHeight);
for (var i = 0; i < combinedSeriesData.data.length; i++) {
var dataPoint = combinedSeriesData.data[i];
- var x = (dataPoint[0] - xExtremes[0])*xFact;
- var y = canvasHeight - (dataPoint[1] - combinedSeriesData.yMin)*yFact;
+ var x = ((dataPoint[0] !== null) ? ((dataPoint[0] - xExtremes[0])*xFact) : NaN);
+ var y = ((dataPoint[1] !== null) ? (canvasHeight - (dataPoint[1] - combinedSeriesData.yMin)*yFact) : NaN);
if (isFinite(x) && isFinite(y)) {
+ if(prevX === null) {
+ ctx.lineTo(x, canvasHeight);
+ }
+ else if (stepPlot) {
+ ctx.lineTo(x, prevY);
+ }
ctx.lineTo(x, y);
+ prevX = x;
+ prevY = y;
+ }
+ else {
+ if(prevX !== null) {
+ if (stepPlot) {
+ ctx.lineTo(x, prevY);
+ ctx.lineTo(x, canvasHeight);
+ }
+ else {
+ ctx.lineTo(prevX, canvasHeight);
+ }
+ }
+ prevX = prevY = null;
}
}
ctx.lineTo(canvasWidth, canvasHeight);
attrs = Dygraph.mapLegacyOptions_(attrs);
+ if (typeof(div) == 'string') {
+ div = document.getElementById(div);
+ }
+
if (!div) {
Dygraph.error("Constructing dygraph with a non-existent div!");
return;
var minDist = Infinity;
var idx = -1;
var dist, dx, dy, point, closestPoint, closestSeries;
- for (var setIdx = 0; setIdx < this.layout_.datasets.length; ++setIdx) {
+ for ( var setIdx = this.layout_.datasets.length - 1 ; setIdx >= 0 ; --setIdx ) {
var points = this.layout_.points[setIdx];
for (var i = 0; i < points.length; ++i) {
var point = points[i];
var highlightSeriesOpts = this.attr_("highlightSeriesOpts");
var selectionChanged = false;
- if (highlightSeriesOpts && !this.lockedSet_) {
+ if (highlightSeriesOpts && !this.isSeriesLocked()) {
var closest;
if (this.attr_("stackedGraph")) {
closest = this.findStackedPoint(canvasx, canvasy);
};
/**
+ * Returns true if the currently-highlighted series was locked
+ * via setSelection(..., seriesName, true).
+ */
+Dygraph.prototype.isSeriesLocked = function() {
+ return this.lockedSet_;
+};
+
+/**
* Fires when there's data available to be graphed.
* @param {String} data Raw CSV data to be plotted
* @private
return data;
};
-var makeClickCallback = function(graph) {
- var isLocked = false;
- return function(ev) {
- if (isLocked) {
- graph.clearSelection();
- isLocked = false;
- } else {
- graph.setSelection(graph.getSelection(), graph.getHighlightSeries(), true);
- isLocked = true;
- }
- };
-};
-
var makeGraph = function(className, numSeries, numRows, isStacked) {
var demo = document.getElementById('demo');
var div = document.createElement('div');
highlightCircleSize: 5,
},
});
- g.updateOptions({clickCallback: makeClickCallback(g)}, true);
+ var onclick = function(ev) {
+ if (g.isSeriesLocked()) {
+ g.clearSelection();
+ } else {
+ g.setSelection(g.getSelection(), g.getHighlightSeries(), true);
+ }
+ };
+ g.updateOptions({clickCallback: onclick}, true);
g.setSelection(false, 's005');
//console.log(g);
};