X-Git-Url: https://adrianiainlam.tk/git/?a=blobdiff_plain;ds=sidebyside;f=extras%2Fsynchronizer.js;h=ebc9a45709b356ef7e0135cc4cc51d686876a58d;hb=fcf37b294f0f83b799c756017cab8ee0ceeb9a3e;hp=295cef8157a7dcd8c46a72ec51dc7e48cb4767c5;hpb=fab3f9b4dd6f348867ebef8c0c1e9d0a5d698cba;p=dygraphs.git diff --git a/extras/synchronizer.js b/extras/synchronizer.js index 295cef8..ebc9a45 100644 --- a/extras/synchronizer.js +++ b/extras/synchronizer.js @@ -127,6 +127,7 @@ Dygraph.synchronize = function(/* dygraphs..., opts */) { // release references & make subsequent calls throw. dygraphs = null; opts = null; + prevCallbacks = null; } }; }; @@ -164,13 +165,15 @@ function attachSelectionHandlers(gs, prevCallbacks) { prevCallbacks.unhighlight = g.getFunctionOption('unhighlightCallback'); g.updateOptions({ highlightCallback: function(event, x, points, row, seriesName) { - if (prevCallbacks.highlight) prevCallbacks.highlight(event, x, points, row, seriesName); + if (prevCallbacks.highlight) { + prevCallbacks.highlight(event, x, points, row, seriesName); + } if (block) return; block = true; var me = this; for (var i = 0; i < gs.length; i++) { if (me == gs[i]) continue; - var idx = dygraphsBinarySearch(gs[i], x); + var idx = gs[i].getRowForX(x); if (idx !== null) { gs[i].setSelection(idx, seriesName); } @@ -192,25 +195,4 @@ function attachSelectionHandlers(gs, prevCallbacks) { } } -// Returns the index corresponding to xVal, or null if there is none. -function dygraphsBinarySearch(g, xVal) { - var low = 0, - high = g.numRows() - 1; - - while (low < high) { - var idx = (high + low) >> 1; - var x = g.getValue(idx, 0); - if (x < xVal) { - low = idx + 1; - } else if (x > xVal) { - high = idx - 1; - } else { - return idx; - } - } - - // TODO: give an option to find the closest point, i.e. not demand an exact match. - return null; -} - })();