Skip to content

Commit 284f5f1

Browse files
committed
fix: eventHandler
Misleading comments/docs, both eventHandler versions are used in d3@v6
1 parent 521db82 commit 284f5f1

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/core/d3compat-v5.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@ const majorVer = +version[0];
1010
if (majorVer < 6) {
1111
Object.assign(config._d3compat, {
1212
eventHandler: handler => function eventHandler (a ,b) {
13-
handler.call(this, a, event);
13+
if (a && a.target) {
14+
// d3@v6 - b is __data__, a is the event
15+
handler.call(this, b, a);
16+
} else {
17+
// older d3 - a is __data__, event from global d3.event
18+
handler.call(this, a, event);
19+
}
1420
},
1521
nester: ({key, sortKeys, sortValues, entries}) => {
1622
const nester = nest().key(key);

src/core/d3compat-v6.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ const majorVer = +version[0];
99

1010
if (majorVer > 5) {
1111
Object.assign(config._d3compat, {
12-
eventHandler: handler => function eventHandler (a, b) {
13-
handler.call(this, b, a);
12+
eventHandler: handler => function (a, b) {
13+
if (a && a.target) {
14+
// d3@v6 - b is __data__, a is the event
15+
handler.call(this, b, a);
16+
} else {
17+
// older d3 - a is __data__, event from global d3.event
18+
handler.call(this, a);
19+
}
1420
},
1521
nester: ({key, sortKeys, sortValues, entries}) => {
1622
if (sortValues) {

0 commit comments

Comments
 (0)