}
/**
+ * Closest-point highlighting with locked series.
+ */
+CallbackTestCase.prototype.testClosestPointCallbackCss1 = function() {
+ var g = runClosestTest(false, 2, 4);
+
+ // Default behavior, 'b' is closest
+ DygraphOps.dispatchMouseMove(g, 11, 4);
+ assertEquals('b', g.getHighlightSeries());
+
+ // Now lock selection to 'c'
+ g.setSelection(false, 'c', true);
+ DygraphOps.dispatchMouseMove(g, 11, 4);
+ assertEquals('c', g.getHighlightSeries());
+
+ // Unlock, should be back to 'b'
+ g.clearSelection();
+ DygraphOps.dispatchMouseMove(g, 11, 4);
+ assertEquals('b', g.getHighlightSeries());
+}
+
+/**
* This tests that closest point searches work for data containing NaNs.
*
* It's intended to catch a regression where a NaN Y value confuses the
var highlightSeriesOpts = this.attr_("highlightSeriesOpts");
var selectionChanged = false;
- if (highlightSeriesOpts) {
+ if (highlightSeriesOpts && !this.lockedSet_) {
var closest;
if (this.attr_("stackedGraph")) {
closest = this.findStackedPoint(canvasx, canvasy);
* hover dots on the chart). Set to false to clear any selection.
* @param { seriesName } optional series name to highlight that series with the
* the highlightSeriesOpts setting.
+ * @param { locked } optional If true, keep seriesName selected when mousing
+ * over the graph, disabling closest-series highlighting. Call clearSelection()
+ * to unlock it.
*/
-Dygraph.prototype.setSelection = function(row, opt_seriesName) {
+Dygraph.prototype.setSelection = function(row, opt_seriesName, opt_locked) {
// Extract the points we've selected
this.selPoints_ = [];
this.highlightSet_ = opt_seriesName;
}
+ if (opt_locked !== undefined) {
+ this.lockedSet_ = opt_locked;
+ }
+
if (changed) {
this.updateSelection_(undefined);
}
this.attr_("unhighlightCallback")(event);
}
- if (this.attr_("hideOverlayOnMouseOut")) {
+ if (this.attr_("hideOverlayOnMouseOut") && !this.lockedSet_) {
this.clearSelection();
}
};
Dygraph.prototype.clearSelection = function() {
this.cascadeEvents_('deselect', {});
+ this.lockedSet_ = false;
// Get rid of the overlay data
if (this.fadeLevel) {
this.animateSelection_(-1);
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);
g.setSelection(false, 's005');
//console.log(g);
};