projects
/
dygraphs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Get it under 80 chars per line
[dygraphs.git]
/
extras
/
synchronizer.js
diff --git
a/extras/synchronizer.js
b/extras/synchronizer.js
index
ca05a2b
..
f39209b
100644
(file)
--- a/
extras/synchronizer.js
+++ b/
extras/synchronizer.js
@@
-48,6
+48,12
@@
Dygraph.synchronize = function(/* dygraphs..., opts */) {
};
var dygraphs = [];
};
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.';
var parseOpts = function(obj) {
if (!(obj instanceof Object)) {
throw 'Last argument must be either Dygraph or Object.';
@@
-97,11
+103,11
@@
Dygraph.synchronize = function(/* dygraphs..., opts */) {
// Listen for draw, highlight, unhighlight callbacks.
if (opts.zoom) {
// Listen for draw, highlight, unhighlight callbacks.
if (opts.zoom) {
- attachZoomHandlers(dygraphs, opts);
+ attachZoomHandlers(dygraphs, opts
, prevCallbacks
);
}
if (opts.selection) {
}
if (opts.selection) {
- attachSelectionHandlers(dygraphs);
+ attachSelectionHandlers(dygraphs
, prevCallbacks
);
}
return {
}
return {
@@
-109,29
+115,31
@@
Dygraph.synchronize = function(/* dygraphs..., opts */) {
for (var i = 0; i < dygraphs.length; i++) {
var g = dygraphs[i];
if (opts.zoom) {
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({
}
if (opts.selection) {
g.updateOptions({
- highlightCallback:
null
,
- unhighlightCallback:
null
+ highlightCallback:
prevCallbacks.highlight
,
+ unhighlightCallback:
prevCallbacks.unhighlight
});
}
}
// release references & make subsequent calls throw.
dygraphs = null;
opts = null;
});
}
}
// release references & make subsequent calls throw.
dygraphs = null;
opts = null;
+ prevCallbacks = null;
}
};
};
}
};
};
-// TODO: call any `drawCallback`s that were set before this.
-function attachZoomHandlers(gs, syncOpts) {
+function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
+ prevCallbacks.draw = g.getFunctionOption('drawCallback');
g.updateOptions({
drawCallback: function(me, initial) {
g.updateOptions({
drawCallback: function(me, initial) {
+ if (prevCallbacks.draw) prevCallbacks.draw(me, initial);
if (block || initial) return;
block = true;
var opts = {
if (block || initial) return;
block = true;
var opts = {
@@
-149,12
+157,17
@@
function attachZoomHandlers(gs, syncOpts) {
}
}
}
}
-function attachSelectionHandlers(gs) {
+function attachSelectionHandlers(gs
, prevCallbacks
) {
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
var block = false;
for (var i = 0; i < gs.length; i++) {
var g = gs[i];
+ prevCallbacks.highlight = g.getFunctionOption('highlightCallback');
+ prevCallbacks.unhighlight = g.getFunctionOption('unhighlightCallback');
g.updateOptions({
highlightCallback: function(event, x, points, row, seriesName) {
g.updateOptions({
highlightCallback: function(event, x, points, row, seriesName) {
+ if (prevCallbacks.highlight) {
+ prevCallbacks.highlight(event, x, points, row, seriesName);
+ }
if (block) return;
block = true;
var me = this;
if (block) return;
block = true;
var me = this;
@@
-168,6
+181,7
@@
function attachSelectionHandlers(gs) {
block = false;
},
unhighlightCallback: function(event) {
block = false;
},
unhighlightCallback: function(event) {
+ if (prevCallbacks.unhighlight) prevCallbacks.unhighlight(event);
if (block) return;
block = true;
var me = this;
if (block) return;
block = true;
var me = this;