Skip to content

Commit e7a1ff7

Browse files
committed
Only notify when extent changes.
This avoids unnecessary work and some infinite loops.
1 parent fb4f262 commit e7a1ff7

3 files changed

Lines changed: 25 additions & 11 deletions

File tree

d3.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7975,13 +7975,20 @@ d3 = function() {
79757975
});
79767976
});
79777977
});
7978-
} else {
7978+
} else if (extent0 !== extent) {
79797979
extent0 = extent;
79807980
g.each(function() {
7981-
event.of(this, arguments)({
7981+
var event_ = event.of(this, arguments);
7982+
event_({
7983+
type: "brushstart"
7984+
});
7985+
event_({
79827986
type: "brush",
79837987
mode: "resize"
79847988
});
7989+
event_({
7990+
type: "brushend"
7991+
});
79857992
});
79867993
}
79877994
}
@@ -8128,7 +8135,7 @@ d3 = function() {
81288135
return brush;
81298136
};
81308137
brush.extent = function(z) {
8131-
var x0, x1, y0, y1, t;
8138+
var x0, x1, y0, y1, t, dirty;
81328139
if (!arguments.length) {
81338140
z = extentDomain || extent;
81348141
if (x) {
@@ -8156,20 +8163,22 @@ d3 = function() {
81568163
extentDomain[0][0] = x0, extentDomain[1][0] = x1;
81578164
if (x.invert) x0 = x(x0), x1 = x(x1);
81588165
if (x1 < x0) t = x0, x0 = x1, x1 = t;
8166+
dirty |= x0 ^ extent[0][0] | x1 ^ extent[1][0];
81598167
}
81608168
if (y) {
81618169
y0 = z[0], y1 = z[1];
81628170
if (x) y0 = y0[1], y1 = y1[1];
81638171
extentDomain[0][1] = y0, extentDomain[1][1] = y1;
81648172
if (y.invert) y0 = y(y0), y1 = y(y1);
81658173
if (y1 < y0) t = y0, y0 = y1, y1 = t;
8174+
dirty |= y0 ^ extent[0][1] | y1 ^ extent[1][1];
81668175
}
8167-
extent = [ [ x0 | 0, y0 | 0 ], [ x1 | 0, y1 | 0 ] ];
8176+
if (dirty) extent = [ [ x0 | 0, y0 | 0 ], [ x1 | 0, y1 | 0 ] ];
81688177
return brush;
81698178
};
81708179
brush.clear = function() {
81718180
extentDomain = null;
8172-
extent = [ [ 0, 0 ], [ 0, 0 ] ];
8181+
if (!brush.empty()) extent = [ [ 0, 0 ], [ 0, 0 ] ];
81738182
return brush;
81748183
};
81758184
brush.empty = function() {

0 commit comments

Comments
 (0)