};
var dygraphs = [];
+ var prevCallbacks = {
+ draw: null,
+ highlight: null,
+ unhighlight: null
+ };
+
var parseOpts = function(obj) {
if (!(obj instanceof Object)) {
throw 'Last argument must be either Dygraph or Object.';
// Listen for draw, highlight, unhighlight callbacks.
if (opts.zoom) {
- attachZoomHandlers(dygraphs);
+ attachZoomHandlers(dygraphs, opts, prevCallbacks);
}
if (opts.selection) {
- attachSelectionHandlers(dygraphs);
+ attachSelectionHandlers(dygraphs, prevCallbacks);
}
return {
for (var i = 0; i < dygraphs.length; i++) {
var g = dygraphs[i];
if (opts.zoom) {
- g.updateOptions({drawCallback: null});
+ g.updateOptions({drawCallback: prevCallbacks.draw});
}
if (opts.selection) {
g.updateOptions({
- highlightCallback: null,
- unhighlightCallback: null
+ highlightCallback: prevCallbacks.highlight,
+ unhighlightCallback: prevCallbacks.unhighlight
});
}
}
};
};
-// TODO: call any `drawCallback`s that were set before this.
-function attachZoomHandlers(gs) {
+function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
- var oldDC = g.getFunctionOption('drawCallback');
+ prevCallbacks.draw = g.getFunctionOption('drawCallback');
g.updateOptions({
drawCallback: function(me, initial) {
- if (oldDC) oldDC(me, initial);
+ if (prevCallbacks.draw) prevCallbacks.draw(me, initial);
if (block || initial) return;
block = true;
var range = me.xAxisRange();
}
}
-function attachSelectionHandlers(gs) {
+function attachSelectionHandlers(gs, prevCallbacks) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
- var oldHC = g.getFunctionOption('highlightCallback');
- var oldUHC = g.getFunctionOption('unhighlightCallback');
+ prevCallbacks.highlight = g.getFunctionOption('highlightCallback');
+ prevCallbacks.unhighlight = g.getFunctionOption('unhighlightCallback');
g.updateOptions({
highlightCallback: function(event, x, points, row, seriesName) {
- if (oldHC) oldHC(event, x, points, row, seriesName);
+ if (prevCallbacks.highlight) prevCallbacks.highlight(event, x, points, row, seriesName);
if (block) return;
block = true;
var me = this;
block = false;
},
unhighlightCallback: function(event) {
- if (oldUHC) oldUHC(event);
+ if (prevCallbacks.unhighlight) prevCallbacks.unhighlight(event);
if (block) return;
block = true;
var me = this;