@pie-lib/plot 3.1.0-next.2 → 3.1.0-next.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,11 @@
1
1
  import { render, cleanup } from '@testing-library/react';
2
2
  import React from 'react';
3
3
  import { Root } from '../root';
4
- import { select, mouse } from 'd3-selection';
4
+ import { select, pointer } from 'd3-selection';
5
5
 
6
6
  jest.mock('d3-selection', () => ({
7
7
  select: jest.fn(),
8
- mouse: jest.fn(),
8
+ pointer: jest.fn(),
9
9
  }));
10
10
 
11
11
  const scaleMock = () => {
@@ -48,7 +48,7 @@ describe('root', () => {
48
48
  select.mockReturnValue({
49
49
  on: mockOn,
50
50
  });
51
- mouse.mockReturnValue([0, 0]);
51
+ pointer.mockReturnValue([0, 0]);
52
52
 
53
53
  defaultProps = {
54
54
  classes: {},
@@ -62,9 +62,7 @@ describe('root', () => {
62
62
  });
63
63
 
64
64
  it('renders with children', () => {
65
- const { container, getByText } = render(
66
- <Root {...defaultProps}>hi</Root>
67
- );
65
+ const { container, getByText } = render(<Root {...defaultProps}>hi</Root>);
68
66
  expect(container.firstChild).toBeInTheDocument();
69
67
  expect(getByText('hi')).toBeInTheDocument();
70
68
  });
@@ -100,7 +98,7 @@ describe('root', () => {
100
98
  });
101
99
 
102
100
  describe('mouseMove function', () => {
103
- it('calls mouse with correct arguments', () => {
101
+ it('calls pointer with correct arguments', () => {
104
102
  const onMouseMove = jest.fn();
105
103
  const gp = graphProps();
106
104
  const props = {
@@ -110,6 +108,7 @@ describe('root', () => {
110
108
  };
111
109
 
112
110
  const mockNode = document.createElement('div');
111
+ const mockEvent = { clientX: 10, clientY: 20 };
113
112
  const mockSelection = {
114
113
  _groups: [[mockNode]],
115
114
  node: () => mockNode,
@@ -122,17 +121,17 @@ describe('root', () => {
122
121
  mockOn(event, handler);
123
122
  // When 'mousemove' is registered, immediately test it
124
123
  if (event === 'mousemove' && handler) {
125
- mouse.mockReturnValue([10, 20]);
126
- // Handler is bound with mockSelection as first arg, so call with no args
127
- handler();
124
+ pointer.mockReturnValue([10, 20]);
125
+ // Handler is bound with mockSelection as first arg, so call with event
126
+ handler(mockEvent);
128
127
  }
129
128
  },
130
129
  });
131
130
 
132
131
  render(<Root {...props}>hi</Root>);
133
132
 
134
- // Verify mouse was called with the correct node
135
- expect(mouse).toHaveBeenCalledWith(mockNode);
133
+ // Verify pointer was called with the event and correct node
134
+ expect(pointer).toHaveBeenCalledWith(mockEvent, mockNode);
136
135
  });
137
136
 
138
137
  it('calls scale.x.invert and scale.y.invert', () => {
@@ -145,6 +144,7 @@ describe('root', () => {
145
144
  };
146
145
 
147
146
  const mockNode = document.createElement('div');
147
+ const mockEvent = { clientX: 15, clientY: 25 };
148
148
  const mockSelection = {
149
149
  _groups: [[mockNode]],
150
150
  node: () => mockNode,
@@ -155,8 +155,8 @@ describe('root', () => {
155
155
  on: (event, handler) => {
156
156
  mockOn(event, handler);
157
157
  if (event === 'mousemove' && handler) {
158
- mouse.mockReturnValue([15, 25]);
159
- handler();
158
+ pointer.mockReturnValue([15, 25]);
159
+ handler(mockEvent);
160
160
  }
161
161
  },
162
162
  });
@@ -179,6 +179,7 @@ describe('root', () => {
179
179
  };
180
180
 
181
181
  const mockNode = document.createElement('div');
182
+ const mockEvent = { clientX: 100, clientY: 200 };
182
183
  const mockSelection = {
183
184
  _groups: [[mockNode]],
184
185
  node: () => mockNode,
@@ -189,7 +190,7 @@ describe('root', () => {
189
190
  on: (event, handler) => {
190
191
  mockOn(event, handler);
191
192
  if (event === 'mousemove' && handler) {
192
- mouse.mockReturnValue([15, 25]);
193
+ pointer.mockReturnValue([100, 200]);
193
194
  handler();
194
195
  }
195
196
  },
@@ -216,6 +217,7 @@ describe('root', () => {
216
217
  };
217
218
 
218
219
  const mockNode = document.createElement('div');
220
+ const mockEvent = { clientX: 100, clientY: 200 };
219
221
  const mockSelection = {
220
222
  _groups: [[mockNode]],
221
223
  node: () => mockNode,
@@ -226,8 +228,8 @@ describe('root', () => {
226
228
  on: (event, handler) => {
227
229
  mockOn(event, handler);
228
230
  if (event === 'mousemove' && handler) {
229
- mouse.mockReturnValue([100, 200]);
230
- handler();
231
+ pointer.mockReturnValue([100, 200]);
232
+ handler(mockEvent);
231
233
  }
232
234
  },
233
235
  });
@@ -245,6 +247,7 @@ describe('root', () => {
245
247
  };
246
248
 
247
249
  const mockNode = document.createElement('div');
250
+ const mockEvent = { clientX: 100, clientY: 200 };
248
251
  const mockSelection = {
249
252
  _groups: [[mockNode]],
250
253
  node: () => mockNode,
@@ -255,9 +258,9 @@ describe('root', () => {
255
258
  on: (event, handler) => {
256
259
  mockOn(event, handler);
257
260
  if (event === 'mousemove' && handler) {
258
- mouse.mockReturnValue([100, 200]);
261
+ pointer.mockReturnValue([100, 200]);
259
262
  // Should not throw error when onMouseMove is not provided
260
- expect(() => handler()).not.toThrow();
263
+ expect(() => handler(mockEvent)).not.toThrow();
261
264
  }
262
265
  },
263
266
  });
@@ -1,4 +1,3 @@
1
- import { AssertionError } from 'assert';
2
1
  import * as utils from '../utils';
3
2
 
4
3
  const xy = utils.xy;
@@ -53,7 +52,7 @@ describe('utils', () => {
53
52
  let scaleFn;
54
53
 
55
54
  beforeEach(() => {
56
- scaleFn = jest.fn(function(v) {
55
+ scaleFn = jest.fn(function (v) {
57
56
  return v;
58
57
  });
59
58
  });
@@ -6,7 +6,7 @@ import debug from 'debug';
6
6
  import * as utils from './utils';
7
7
  import isFunction from 'lodash/isFunction';
8
8
  import invariant from 'invariant';
9
- import { clientPoint } from 'd3-selection';
9
+ import { pointer } from 'd3-selection';
10
10
 
11
11
  const log = debug('pie-lib:plot:grid-draggable');
12
12
 
@@ -235,7 +235,7 @@ export const gridDraggable = (opts) => (Comp) => {
235
235
  this.setState({ startX: null });
236
236
  const { graphProps } = this.props;
237
237
  const { scale, snap } = graphProps;
238
- const [rawX, rawY] = clientPoint(e.target, e);
238
+ const [rawX, rawY] = pointer(e, e.target);
239
239
  let x = scale.x.invert(rawX);
240
240
  let y = scale.y.invert(rawY);
241
241
  x = snap.x(x);
package/src/root.jsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  import { styled } from '@mui/material/styles';
3
3
  import PropTypes from 'prop-types';
4
- import { select, mouse } from 'd3-selection';
4
+ import { select, pointer } from 'd3-selection';
5
5
 
6
6
  import { color, Readable } from '@pie-lib/render-ui';
7
7
  import EditableHtml from '@pie-lib/editable-html-tip-tap';
@@ -126,7 +126,7 @@ export class Root extends React.Component {
126
126
  labelsCharactersLimit: PropTypes.number,
127
127
  };
128
128
 
129
- mouseMove = (g) => {
129
+ mouseMove = (g, event) => {
130
130
  const { graphProps, onMouseMove } = this.props;
131
131
 
132
132
  if (!onMouseMove) {
@@ -134,7 +134,7 @@ export class Root extends React.Component {
134
134
  }
135
135
 
136
136
  const { scale, snap } = graphProps;
137
- const coords = mouse(g.node());
137
+ const coords = pointer(event, g.node());
138
138
  const x = scale.x.invert(coords[0]);
139
139
  const y = scale.y.invert(coords[1]);
140
140