@pie-lib/plot 2.7.3 → 2.8.1-beta.0

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.
package/CHANGELOG.md CHANGED
@@ -3,34 +3,45 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
- ## [2.7.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.2...@pie-lib/plot@2.7.3) (2023-10-16)
6
+ ## [2.8.1-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.3...@pie-lib/plot@2.8.1-beta.0) (2025-07-20)
7
7
 
8
+ **Note:** Version bump only for package @pie-lib/plot
8
9
 
9
- ### Bug Fixes
10
10
 
11
- * **charting:** refine error message display to prevent overlapping with other elements and other messages PD-3121 ([f2de1ad](https://github.com/pie-framework/pie-lib/commit/f2de1adb4d19a44e403beb3d88cbb333e3c5adb9))
12
- * **charting:** wip PD-3105 ([f2f8234](https://github.com/pie-framework/pie-lib/commit/f2f82343a373ae1a8f669754a061963cbfdbeb08))
13
- * **charting:** wip PD-3105 revert push in develop ([6cce5e2](https://github.com/pie-framework/pie-lib/commit/6cce5e2d25d079c1c3eb195425dc2cf016fcd36e))
14
11
 
15
12
 
16
13
 
14
+ # [2.8.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.3...@pie-lib/plot@2.8.0-beta.0) (2025-07-20)
17
15
 
16
+ **Note:** Version bump only for package @pie-lib/plot
18
17
 
19
- ## [2.7.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.1...@pie-lib/plot@2.7.2) (2023-06-24)
20
18
 
21
- **Note:** Version bump only for package @pie-lib/plot
22
19
 
23
20
 
24
21
 
22
+ # [2.9.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.3...@pie-lib/plot@2.9.0-beta.0) (2025-07-15)
25
23
 
24
+ **Note:** Version bump only for package @pie-lib/plot
26
25
 
27
- ## [2.7.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.0...@pie-lib/plot@2.7.1) (2023-06-13)
26
+ # [2.8.0-beta.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.3...@pie-lib/plot@2.8.0-beta.0) (2025-07-15)
28
27
 
29
28
  **Note:** Version bump only for package @pie-lib/plot
30
29
 
30
+ ## [2.7.3](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.2...@pie-lib/plot@2.7.3) (2023-10-16)
31
31
 
32
+ ### Bug Fixes
33
+
34
+ - **charting:** refine error message display to prevent overlapping with other elements and other messages PD-3121 ([f2de1ad](https://github.com/pie-framework/pie-lib/commit/f2de1adb4d19a44e403beb3d88cbb333e3c5adb9))
35
+ - **charting:** wip PD-3105 ([f2f8234](https://github.com/pie-framework/pie-lib/commit/f2f82343a373ae1a8f669754a061963cbfdbeb08))
36
+ - **charting:** wip PD-3105 revert push in develop ([6cce5e2](https://github.com/pie-framework/pie-lib/commit/6cce5e2d25d079c1c3eb195425dc2cf016fcd36e))
37
+
38
+ ## [2.7.2](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.1...@pie-lib/plot@2.7.2) (2023-06-24)
32
39
 
40
+ **Note:** Version bump only for package @pie-lib/plot
41
+
42
+ ## [2.7.1](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.7.0...@pie-lib/plot@2.7.1) (2023-06-13)
33
43
 
44
+ **Note:** Version bump only for package @pie-lib/plot
34
45
 
35
46
  # [2.7.0](https://github.com/pie-framework/pie-lib/compare/@pie-lib/plot@2.6.13...@pie-lib/plot@2.7.0) (2023-06-12)
36
47
 
@@ -0,0 +1 @@
1
+ []
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "2.7.3",
6
+ "version": "2.8.1-beta.0",
7
7
  "description": "Some underlying components for building charts/graphs",
8
8
  "keywords": [
9
9
  "react",
@@ -18,17 +18,21 @@
18
18
  "dependencies": {
19
19
  "@mapbox/point-geometry": "^0.1.0",
20
20
  "@material-ui/core": "^3.8.3",
21
+ "@pie-lib/editable-html": "beta",
22
+ "@pie-lib/render-ui": "beta",
21
23
  "@vx/axis": "^0.0.183",
22
24
  "@vx/event": "^0.0.182",
23
25
  "@vx/grid": "^0.0.183",
24
26
  "@vx/point": "^0.0.182",
25
27
  "@vx/shape": "^0.0.183",
28
+ "assert": "^1.4.1",
26
29
  "classnames": "^2.2.6",
27
30
  "d3-scale": "^2.1.2",
28
31
  "d3-selection": "^1.3.2",
29
32
  "debug": "^4.1.1",
30
33
  "invariant": "^2.2.4",
31
34
  "lodash": "^4.17.11",
35
+ "prop-types": "^15.7.2",
32
36
  "react": "^16.8.1",
33
37
  "react-draggable": "^3.1.1",
34
38
  "react-redux": "^6.0.0",
@@ -38,6 +42,6 @@
38
42
  "peerDependencies": {
39
43
  "react": "^16.8.1"
40
44
  },
41
- "gitHead": "cda593dd0aedaadb7e1fd85f12d72ca3bb03d375",
45
+ "gitHead": "e2aa3ddac60f49bcb8c2562370f496323642f453",
42
46
  "scripts": {}
43
47
  }
@@ -0,0 +1,185 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`gridDraggable snapshot render with decimals 1`] = `
4
+ <mockConstructor
5
+ axis="both"
6
+ grid={
7
+ Array [
8
+ 1,
9
+ 1,
10
+ ]
11
+ }
12
+ onDrag={[Function]}
13
+ onMouseDown={[Function]}
14
+ onStart={[Function]}
15
+ onStop={[Function]}
16
+ >
17
+ <Component
18
+ domain={
19
+ Object {
20
+ "max": 1.6,
21
+ "min": -1.5,
22
+ "step": 0.3,
23
+ }
24
+ }
25
+ graphProps={
26
+ Object {
27
+ "domain": Object {
28
+ "max": 1,
29
+ "min": 0,
30
+ "step": 1,
31
+ },
32
+ "getRootNode": [Function],
33
+ "range": Object {
34
+ "max": 1,
35
+ "min": 0,
36
+ "step": 1,
37
+ },
38
+ "scale": Object {
39
+ "x": [MockFunction] {
40
+ "calls": Array [
41
+ Array [
42
+ 1,
43
+ ],
44
+ Array [
45
+ 0,
46
+ ],
47
+ ],
48
+ "results": Array [
49
+ Object {
50
+ "type": "return",
51
+ "value": 1,
52
+ },
53
+ Object {
54
+ "type": "return",
55
+ "value": 0,
56
+ },
57
+ ],
58
+ },
59
+ "y": [MockFunction] {
60
+ "calls": Array [
61
+ Array [
62
+ 1,
63
+ ],
64
+ Array [
65
+ 0,
66
+ ],
67
+ ],
68
+ "results": Array [
69
+ Object {
70
+ "type": "return",
71
+ "value": 1,
72
+ },
73
+ Object {
74
+ "type": "return",
75
+ "value": 0,
76
+ },
77
+ ],
78
+ },
79
+ },
80
+ "size": Object {
81
+ "height": 500,
82
+ "width": 500,
83
+ },
84
+ "snap": Object {
85
+ "x": [MockFunction],
86
+ "y": [MockFunction],
87
+ },
88
+ }
89
+ }
90
+ isDragging={false}
91
+ range={
92
+ Object {
93
+ "max": 3,
94
+ "min": -2,
95
+ "step": 0.2,
96
+ }
97
+ }
98
+ />
99
+ </mockConstructor>
100
+ `;
101
+
102
+ exports[`gridDraggable snapshot reqular 1`] = `
103
+ <mockConstructor
104
+ axis="both"
105
+ grid={
106
+ Array [
107
+ 1,
108
+ 1,
109
+ ]
110
+ }
111
+ onDrag={[Function]}
112
+ onMouseDown={[Function]}
113
+ onStart={[Function]}
114
+ onStop={[Function]}
115
+ >
116
+ <Component
117
+ graphProps={
118
+ Object {
119
+ "domain": Object {
120
+ "max": 1,
121
+ "min": 0,
122
+ "step": 1,
123
+ },
124
+ "getRootNode": [Function],
125
+ "range": Object {
126
+ "max": 1,
127
+ "min": 0,
128
+ "step": 1,
129
+ },
130
+ "scale": Object {
131
+ "x": [MockFunction] {
132
+ "calls": Array [
133
+ Array [
134
+ 1,
135
+ ],
136
+ Array [
137
+ 0,
138
+ ],
139
+ ],
140
+ "results": Array [
141
+ Object {
142
+ "type": "return",
143
+ "value": 1,
144
+ },
145
+ Object {
146
+ "type": "return",
147
+ "value": 0,
148
+ },
149
+ ],
150
+ },
151
+ "y": [MockFunction] {
152
+ "calls": Array [
153
+ Array [
154
+ 1,
155
+ ],
156
+ Array [
157
+ 0,
158
+ ],
159
+ ],
160
+ "results": Array [
161
+ Object {
162
+ "type": "return",
163
+ "value": 1,
164
+ },
165
+ Object {
166
+ "type": "return",
167
+ "value": 0,
168
+ },
169
+ ],
170
+ },
171
+ },
172
+ "size": Object {
173
+ "height": 500,
174
+ "width": 500,
175
+ },
176
+ "snap": Object {
177
+ "x": [MockFunction],
178
+ "y": [MockFunction],
179
+ },
180
+ }
181
+ }
182
+ isDragging={false}
183
+ />
184
+ </mockConstructor>
185
+ `;
@@ -0,0 +1,18 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`root snapshot matches 1`] = `
4
+ <div>
5
+ <div>
6
+ <svg
7
+ height={480}
8
+ width={540}
9
+ >
10
+ <g
11
+ transform="translate(70, 40)"
12
+ >
13
+ hi
14
+ </g>
15
+ </svg>
16
+ </div>
17
+ </div>
18
+ `;
@@ -0,0 +1,23 @@
1
+ import React from 'react';
2
+ import { shallow } from 'enzyme';
3
+ import Draggable from '../draggable';
4
+
5
+ const wrapper = () => {
6
+ return shallow(
7
+ <Draggable>
8
+ <div>hellow</div>
9
+ </Draggable>,
10
+ { disableLifecycleMethods: true },
11
+ );
12
+ };
13
+
14
+ describe('draggable', () => {
15
+ describe('local', () => {
16
+ it('resets x/y in state', () => {
17
+ const w = wrapper();
18
+ w.setState({ x: 1, y: 1 });
19
+ w.instance().componentWillReceiveProps({});
20
+ expect(w.state()).toMatchObject({ x: 0, y: 0 });
21
+ });
22
+ });
23
+ });
@@ -0,0 +1,326 @@
1
+ import { shallow } from 'enzyme';
2
+ import React from 'react';
3
+ import { gridDraggable } from '../grid-draggable';
4
+ import { getDelta } from '../utils';
5
+
6
+ import { clientPoint } from 'd3-selection';
7
+
8
+ jest.mock('d3-selection', () => ({
9
+ clientPoint: jest.fn().mockReturnValue([0, 0]),
10
+ }));
11
+
12
+ jest.mock('../draggable', () => ({
13
+ DraggableCore: jest.fn((type, props, children) => children),
14
+ }));
15
+
16
+ jest.mock('../utils', () => ({
17
+ getDelta: jest.fn(),
18
+ }));
19
+
20
+ const xyFn = () => {
21
+ const out = jest.fn((n) => n);
22
+ out.invert = jest.fn((n) => n);
23
+ return out;
24
+ };
25
+ const getGraphProps = () => ({
26
+ scale: {
27
+ x: xyFn(),
28
+ y: xyFn(),
29
+ },
30
+ snap: {
31
+ x: xyFn(),
32
+ y: xyFn(),
33
+ },
34
+ domain: {
35
+ min: 0,
36
+ max: 1,
37
+ step: 1,
38
+ },
39
+ range: {
40
+ min: 0,
41
+ max: 1,
42
+ step: 1,
43
+ },
44
+ size: {
45
+ width: 500,
46
+ height: 500,
47
+ },
48
+ getRootNode: () => ({}),
49
+ });
50
+
51
+ describe('gridDraggable', () => {
52
+ const wrapper = (opts, extras) => {
53
+ const defaults = {
54
+ graphProps: getGraphProps(),
55
+ };
56
+
57
+ defaults.graphProps.scale.x.invert = jest.fn((x) => x);
58
+ defaults.graphProps.scale.y.invert = jest.fn((x) => x);
59
+
60
+ const props = { ...defaults, ...extras };
61
+
62
+ opts = {
63
+ anchorPoint: jest.fn().mockReturnValue({ x: 0, y: 0 }),
64
+ bounds: jest.fn().mockReturnValue({ left: 0, top: 0, bottom: 0, right: 0 }),
65
+ fromDelta: jest.fn(),
66
+ ...opts,
67
+ };
68
+
69
+ const Comp = gridDraggable(opts)(() => <div />);
70
+ return shallow(<Comp {...props} />);
71
+ };
72
+
73
+ describe('snapshot', () => {
74
+ it('reqular', () => {
75
+ const w = wrapper();
76
+ expect(w).toMatchSnapshot();
77
+ });
78
+
79
+ it('render with decimals', () => {
80
+ const w = wrapper(
81
+ {},
82
+ {
83
+ domain: {
84
+ min: -1.5,
85
+ max: 1.6,
86
+ step: 0.3,
87
+ },
88
+ range: {
89
+ min: -2,
90
+ max: 3,
91
+ step: 0.2,
92
+ },
93
+ },
94
+ );
95
+ expect(w).toMatchSnapshot();
96
+ });
97
+ });
98
+
99
+ describe('logic', () => {
100
+ describe('grid', () => {
101
+ it('returns the grid', () => {
102
+ const w = wrapper();
103
+ const g = w.instance().grid();
104
+ expect(g).toEqual({ x: 1, y: 1 });
105
+ });
106
+ });
107
+
108
+ describe('onStart', () => {
109
+ it('sets the drag state', () => {
110
+ const w = wrapper();
111
+ w.instance().onStart({ clientX: 100, clientY: 100 });
112
+ expect(w.state().startX).toEqual(100);
113
+ expect(w.state().startY).toEqual(100);
114
+ });
115
+
116
+ it('calls the handler', () => {
117
+ const onDragStart = jest.fn();
118
+ const w = wrapper(
119
+ {},
120
+ {
121
+ onDragStart,
122
+ },
123
+ );
124
+ w.instance().onStart({ clientX: 100, clientY: 100 });
125
+ expect(onDragStart).toHaveBeenCalled();
126
+ });
127
+ });
128
+
129
+ describe('position', () => {
130
+ it('returns position object', () => {
131
+ const w = wrapper();
132
+ const pos = w.instance().position();
133
+
134
+ const anchorPoint = {
135
+ x: 0,
136
+ y: 0,
137
+ };
138
+ expect(pos).toEqual({
139
+ anchorPoint,
140
+ x: expect.any(Function),
141
+ y: expect.any(Function),
142
+ });
143
+ });
144
+ });
145
+
146
+ describe('tiny', () => {
147
+ it('returns true for 10 ', () => {
148
+ const w = wrapper();
149
+ w.setState({ startX: 0 });
150
+ const result = w.instance().tiny('x', { clientX: 10 });
151
+ expect(result).toBe(false);
152
+ });
153
+ it('returns true for 0.01', () => {
154
+ const w = wrapper();
155
+ w.setState({ startX: 0 });
156
+ const result = w.instance().tiny('x', { clientX: 0.01 });
157
+ expect(result).toBe(true);
158
+ });
159
+ });
160
+
161
+ describe('onDrag', () => {
162
+ let onDrag, w;
163
+
164
+ beforeEach(() => {
165
+ onDrag = jest.fn();
166
+ w = wrapper({}, { onDrag });
167
+ w.instance().applyDelta = jest.fn().mockReturnValue(0);
168
+ w.instance().props.graphProps.getRootNode = jest.fn().mockReturnValue({
169
+ ownerSVGElement: null,
170
+ getBoundingClientRect: jest.fn(() => ({
171
+ left: 0,
172
+ top: 0,
173
+ right: 100,
174
+ bottom: 100,
175
+ })),
176
+ });
177
+ w.instance().getClientPoint = jest.fn().mockReturnValue([50, 50]); // Mocking getClientPoint
178
+ w.instance().onDrag({}, { x: 1, y: 1 });
179
+ });
180
+
181
+ it('calls applyDelta', () => {
182
+ expect(w.instance().applyDelta).toHaveBeenCalled();
183
+ });
184
+
185
+ it('calls callback', () => {
186
+ expect(onDrag).toHaveBeenCalledWith(0);
187
+ });
188
+
189
+ const bounds = (left, right, top, bottom) => ({ left, right, top, bottom });
190
+ describe('bounds', () => {
191
+ const assertEarlyExit = (bounds, dd) => {
192
+ it(`${JSON.stringify(bounds)}, ${dd.deltaX}, ${dd.deltaY} `, () => {
193
+ w = wrapper({}, { onDrag });
194
+ w.instance().getScaledBounds = jest.fn().mockReturnValue(bounds);
195
+ w.instance().getClientPoint = jest.fn().mockReturnValue([50, 50]);
196
+ w.instance().onDrag({}, dd);
197
+ expect(w.instance().getClientPoint).not.toHaveBeenCalled();
198
+ });
199
+ };
200
+ assertEarlyExit(bounds(0, 0, 0, 0), { deltaX: -10 });
201
+ assertEarlyExit(bounds(0, 0, 0, 0), { deltaX: 10 });
202
+ assertEarlyExit(bounds(-100, 100, 0, 0), { deltaY: -10 });
203
+ assertEarlyExit(bounds(-100, 100, -100, 0), { deltaY: 10 });
204
+ it('calls client point if it doesnt exit early bounds', () => {
205
+ w = wrapper({}, { onDrag });
206
+ w.instance().getScaledBounds = jest.fn().mockReturnValue(bounds(100, 100, 100, 100));
207
+ w.instance().getClientPoint = jest.fn().mockReturnValue([50, 50]);
208
+ w.instance().onDrag({}, { deltaX: 10 });
209
+ expect(w.instance().getClientPoint).toHaveBeenCalled(); // Asserting that getClientPoint is called
210
+ });
211
+ });
212
+ });
213
+
214
+ describe('skipDragOutsideOfBounds', () => {
215
+ let w;
216
+ const assertSkipDrag = (dd, rawXFn, rawYFn, expected) => {
217
+ rawXFn = rawXFn || ((x) => x);
218
+ rawYFn = rawYFn || ((y) => y);
219
+
220
+ it(`${dd.deltaX}, ${dd.deltaY}, ${expected}`, () => {
221
+ w = wrapper({});
222
+ const gp = getGraphProps();
223
+
224
+ const mockGetBoundingClientRect = jest.fn(() => ({
225
+ left: 0,
226
+ top: 0,
227
+ right: 100,
228
+ bottom: 100,
229
+ }));
230
+
231
+ w.instance().getClientPoint = jest.fn(() => [
232
+ rawXFn(gp.domain.min, gp.domain.max),
233
+ rawYFn(gp.range.min, gp.range.max),
234
+ ]);
235
+
236
+ const rootNode = {
237
+ ownerSVGElement: null,
238
+ getBoundingClientRect: mockGetBoundingClientRect,
239
+ };
240
+
241
+ const result = w.instance().skipDragOutsideOfBounds(dd, {}, { ...gp, getRootNode: () => rootNode });
242
+ expect(result).toEqual(expected);
243
+ });
244
+ };
245
+ assertSkipDrag(
246
+ { deltaX: 1 },
247
+ (min, max) => min - 1,
248
+ (min, max) => min,
249
+ true,
250
+ );
251
+ assertSkipDrag(
252
+ { deltaX: -1 },
253
+ (min, max) => max + 1,
254
+ (min, max) => min,
255
+ true,
256
+ );
257
+ assertSkipDrag(
258
+ { deltaY: 1 },
259
+ (min, max) => max,
260
+ (min, max) => max + 1,
261
+ true,
262
+ );
263
+ assertSkipDrag(
264
+ { deltaY: -1 },
265
+ (min, max) => max,
266
+ (min, max) => min - 1,
267
+ true,
268
+ );
269
+ assertSkipDrag(
270
+ { deltaY: 1 },
271
+ (min, max) => max,
272
+ (min, max) => max,
273
+ false,
274
+ );
275
+ assertSkipDrag(
276
+ { deltaY: -1 },
277
+ (min, max) => max,
278
+ (min, max) => min,
279
+ false,
280
+ );
281
+ });
282
+
283
+ describe('getDelta', () => {
284
+ it('calls utils.getDelta', () => {
285
+ const w = wrapper();
286
+ w.instance().position = jest.fn().mockReturnValue({
287
+ anchorPoint: {
288
+ x: 0,
289
+ y: 0,
290
+ },
291
+ x: jest.fn((x) => x),
292
+ y: jest.fn((y) => y),
293
+ });
294
+ w.instance().getDelta({ x: 1, y: 1 });
295
+ expect(getDelta).toHaveBeenCalledWith({ x: 0, y: 0 }, { x: 1, y: 1 });
296
+ });
297
+ });
298
+ describe('applyDelta', () => {
299
+ it('calls fromDelta', () => {
300
+ const fromDelta = jest.fn();
301
+ const w = wrapper({ fromDelta });
302
+ w.instance().getDelta = jest.fn();
303
+ w.instance().applyDelta({ x: 1, y: 1 });
304
+ expect(fromDelta).toHaveBeenCalledWith(expect.anything(), undefined);
305
+ });
306
+ });
307
+ describe('onStop', () => {
308
+ it('calls onDragStop', () => {
309
+ const onDragStop = jest.fn();
310
+ const w = wrapper({}, { onDragStop });
311
+ w.setState({ startX: 0, startY: 0 });
312
+ w.instance().onStop({}, {});
313
+ expect(onDragStop).toHaveBeenCalled();
314
+ });
315
+
316
+ it('calls onClick if tiny', () => {
317
+ const onClick = jest.fn();
318
+ const w = wrapper({}, { onClick });
319
+ w.instance().tiny = jest.fn().mockReturnValue(true);
320
+ clientPoint.mockReturnValue([0, 0]);
321
+ w.instance().onStop({}, {});
322
+ expect(onClick).toHaveBeenCalledWith({ x: 0, y: 0 });
323
+ });
324
+ });
325
+ });
326
+ });