Skip to content

Commit

Permalink
d3v6 compat, d3.mouse vs d3.pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
kum-deepak committed Jan 16, 2021
1 parent 03e9f5d commit e3ccf17
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
10 changes: 4 additions & 6 deletions src/charts/bubble-overlay.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import {mouse} from 'd3-selection';

import {BaseMixin} from '../base/base-mixin';
import {BubbleMixin} from '../base/bubble-mixin';
import {transition} from '../core/core';
import {constants} from '../core/constants';
import {utils} from '../core/utils';
import {adaptHandler} from '../core/d3compat';
import {adaptHandler, d3compatPointer} from '../core/d3compat';

const BUBBLE_OVERLAY_CLASS = 'bubble-overlay';
const BUBBLE_NODE_CLASS = 'node';
Expand Down Expand Up @@ -202,11 +200,11 @@ export class BubbleOverlay extends BubbleMixin(BaseMixin) {
.append('rect')
.attr('width', this.width())
.attr('height', this.height())
.on('mousemove', () => {
const position = mouse(debugG.node());
.on('mousemove', adaptHandler((d, evt) => {
const position = d3compatPointer(evt, debugG.node());
const msg = `${position[0]}, ${position[1]}`;
debugText.text(msg);
});
}));
} else {
this.selectAll('.debug').remove();
}
Expand Down
6 changes: 5 additions & 1 deletion src/core/d3compat.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import {event} from 'd3-selection';
import {event, mouse, pointer} from 'd3-selection';
import {nest} from 'd3-collection';
import {groups} from 'd3-array';

// d3v6 has removed `d3.mouse` in favor of `d3.pointer`
export const d3compatPointer =
typeof pointer === 'function' ? (evt, elem) => pointer(evt, elem) : (evt, elem) => mouse(elem);

// d3v6 has changed the arguments for event handlers.
// We are creating a wrapper which detects if the first argument is an event, which indicated d3@v6
// Otherwise we assume lower versions of d3.
Expand Down

0 comments on commit e3ccf17

Please sign in to comment.