/**
* 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 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);
};