Skip to content

Commit

Permalink
fix useless resynchronisation when range isn’t used
Browse files Browse the repository at this point in the history
  • Loading branch information
mirabilos committed Feb 7, 2023
1 parent cd76f83 commit 3034672
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/extras/synchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,11 @@ var synchronize = function(/* dygraphs..., opts */) {
};
};

function arraysAreEqual(a, b) {
if (!Array.isArray(a) || !Array.isArray(b)) return false;
function arraysAreEqualOrBothNULL(a, b) {
if (a === null && b === null)
return true;
if (!Array.isArray(a) || !Array.isArray(b))
return false;
var i = a.length;
if (i !== b.length) return false;
while (i--) {
Expand All @@ -177,9 +180,9 @@ function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
if (block || initial) return;
block = true;
var opts = {
valueRange: syncOpts.range ? me.yAxisRange() : null,
dateWindow: me.xAxisRange()
};
if (syncOpts.range) opts.valueRange = me.yAxisRange();

for (var j = 0; j < gs.length; j++) {
if (gs[j] == me) {
Expand All @@ -190,8 +193,8 @@ function attachZoomHandlers(gs, syncOpts, prevCallbacks) {
}

// Only redraw if there are new options
if (arraysAreEqual(opts.dateWindow, gs[j].getOption('dateWindow')) &&
arraysAreEqual(opts.valueRange, gs[j].getOption('valueRange'))) {
if (arraysAreEqualOrBothNULL(opts.dateWindow, gs[j].getOption('dateWindow')) &&
arraysAreEqualOrBothNULL(opts.valueRange, gs[j].getOption('valueRange'))) {
continue;
}

Expand Down

0 comments on commit 3034672

Please sign in to comment.