}
};
+/**
+ * Standard plotters. These may be used by clients.
+ * Available plotters are:
+ * - Dygraph.Plotters.linePlotter: draws central lines (most common)
+ * - Dygraph.Plotters.errorPlotter: draws error bars
+ * - Dygraph.Plotters.fillPlotter: draws fills under lines (used with fillGraph)
+ *
+ * By default, the plotter is [fillPlotter, errorPlotter, linePlotter].
+ * This causes all the lines to be drawn over all the fills/error bars.
+ */
+Dygraph.Plotters = DygraphCanvasRenderer._Plotters;
+
// Default attribute values.
Dygraph.DEFAULT_ATTRS = {
rangeSelectorPlotStrokeColor: "#808FAB",
rangeSelectorPlotFillColor: "#A7B1C4",
+ // The ordering here ensures that central lines always appear above any
+ // fill bars/error bars.
+ plotter: [
+ Dygraph.Plotters.fillPlotter,
+ Dygraph.Plotters.errorPlotter,
+ Dygraph.Plotters.linePlotter
+ ],
+
// per-axis options
axes: {
x: {
this.datasetIndex_ = [];
this.registeredEvents_ = [];
+ this.eventListeners_ = {};
// Create the containing DIV and other interactive elements
this.createInterface_();
// At this point, plugins can no longer register event handlers.
// Construct a map from event -> ordered list of [callback, plugin].
- this.eventListeners_ = {};
for (var i = 0; i < this.plugins_.length; i++) {
var plugin_dict = this.plugins_[i];
for (var eventName in plugin_dict.events) {
if (this.attr_('showRangeSelector')) {
// The range selector must be created here so that its canvases and contexts get created here.
// For some reason, if the canvases and contexts don't get created here, things don't work in IE.
- // The range selector also sets xAxisHeight in order to reserve space.
this.rangeSelector_ = new DygraphRangeSelector(this);
}
}
var dygraph = this;
-
+
this.mouseMoveHandler = function(e) {
dygraph.mouseMove_(e);
};
this.addEvent(this.mouseEventElement_, 'mousemove', this.mouseMoveHandler);
-
+
this.mouseOutHandler = function(e) {
dygraph.mouseOut_(e);
};
node.removeChild(node.firstChild);
}
};
-
+
for (var idx = 0; idx < this.registeredEvents_.length; idx++) {
var reg = this.registeredEvents_[idx];
Dygraph.removeEvent(reg.elem, reg.type, reg.fn);
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);
ctx.fillStyle = 'rgba(255,255,255,' + alpha + ')';
ctx.fillRect(0, 0, this.width_, this.height_);
}
- var setIdx = this.datasetIndexFromSetName_(this.highlightSet_);
- this.plotter_._drawLine(ctx, setIdx);
+
+ // Redraw only the highlighted series in the interactive canvas (not the
+ // static plot canvas, which is where series are usually drawn).
+ this.plotter_._renderLineChart(this.highlightSet_, ctx);
} else if (this.previousVerticalX_ >= 0) {
// Determine the maximum highlight circle size.
var maxCircleSize = 0;
* 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);
for (i = num_series; i >= 1; i--) {
if (!this.visibility()[i - 1]) continue;
- // TODO(danvk): is this copy really necessary?
- var series = rolledSeries[i]; // [];
- // for (j = 0; j < rolledSeries[i].length; j++) {
- // series.push(rolledSeries[i][j]);
- // }
+ // Note: this copy _is_ necessary at the moment.
+ // If you remove it, it breaks zooming with error bars on.
+ // TODO(danvk): investigate further & write a test for this.
+ var series = [];
+ for (j = 0; j < rolledSeries[i].length; j++) {
+ series.push(rolledSeries[i][j]);
+ }
// Prune down to the desired range, if necessary (for zooming)
// Because there can be lines going to points outside of the visible area,
* This is where undesirable points (i.e. negative values on log scales and
* missing values through which we wish to connect lines) are dropped.
* TODO(danvk): the "missing values" bit above doesn't seem right.
- *
+ *
* @private
*/
Dygraph.prototype.extractSeries_ = function(rawData, i, logScale) {