@pie-lib/plot 4.0.4-next.3 → 4.0.4-next.31

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.
Files changed (59) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +20 -0
  2. package/dist/draggable.d.ts +13 -0
  3. package/dist/draggable.js +13 -0
  4. package/dist/graph-props.d.ts +22 -0
  5. package/dist/graph-props.js +29 -0
  6. package/dist/grid-draggable.d.ts +91 -0
  7. package/dist/grid-draggable.js +168 -0
  8. package/dist/index.d.ts +16 -0
  9. package/dist/index.js +8 -0
  10. package/dist/label.d.ts +30 -0
  11. package/dist/label.js +132 -0
  12. package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +16 -0
  13. package/dist/node_modules/.bun/invariant@2.2.4/node_modules/invariant/browser.js +28 -0
  14. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/chunk-D5BXCJ5G.js +503 -0
  15. package/dist/node_modules/.bun/react-draggable@4.6.0_6dbf9a050bc9aadb/node_modules/react-draggable/build/cjs/cjs.js +5 -0
  16. package/dist/root.d.ts +68 -0
  17. package/dist/root.js +302 -0
  18. package/dist/trig.d.ts +41 -0
  19. package/dist/trig.js +47 -0
  20. package/dist/types.d.ts +125 -0
  21. package/dist/types.js +46 -0
  22. package/dist/utils.d.ts +44 -0
  23. package/dist/utils.js +82 -0
  24. package/package.json +35 -25
  25. package/CHANGELOG.json +0 -17
  26. package/CHANGELOG.md +0 -838
  27. package/LICENSE.md +0 -5
  28. package/lib/draggable.js +0 -44
  29. package/lib/draggable.js.map +0 -1
  30. package/lib/graph-props.js +0 -46
  31. package/lib/graph-props.js.map +0 -1
  32. package/lib/grid-draggable.js +0 -361
  33. package/lib/grid-draggable.js.map +0 -1
  34. package/lib/index.js +0 -44
  35. package/lib/index.js.map +0 -1
  36. package/lib/label.js +0 -173
  37. package/lib/label.js.map +0 -1
  38. package/lib/root.js +0 -474
  39. package/lib/root.js.map +0 -1
  40. package/lib/trig.js +0 -149
  41. package/lib/trig.js.map +0 -1
  42. package/lib/types.js +0 -40
  43. package/lib/types.js.map +0 -1
  44. package/lib/utils.js +0 -165
  45. package/lib/utils.js.map +0 -1
  46. package/src/__tests__/draggable.test.jsx +0 -41
  47. package/src/__tests__/grid-draggable.test.jsx +0 -487
  48. package/src/__tests__/root.test.jsx +0 -277
  49. package/src/__tests__/trig.test.js +0 -163
  50. package/src/__tests__/utils.test.js +0 -229
  51. package/src/draggable.jsx +0 -11
  52. package/src/graph-props.js +0 -34
  53. package/src/grid-draggable.jsx +0 -332
  54. package/src/index.js +0 -9
  55. package/src/label.jsx +0 -199
  56. package/src/root.jsx +0 -485
  57. package/src/trig.js +0 -151
  58. package/src/types.js +0 -41
  59. package/src/utils.js +0 -167
@@ -1,277 +0,0 @@
1
- import { cleanup, render } from '@testing-library/react';
2
- import React from 'react';
3
- import { Root } from '../root';
4
- import { pointer, select } from 'd3-selection';
5
-
6
- jest.mock('d3-selection', () => ({
7
- select: jest.fn(),
8
- pointer: jest.fn(),
9
- }));
10
-
11
- const scaleMock = () => {
12
- const fn = jest.fn((n) => n);
13
- fn.invert = jest.fn((n) => n);
14
- return fn;
15
- };
16
-
17
- const graphProps = () => ({
18
- scale: {
19
- x: scaleMock(),
20
- y: scaleMock(),
21
- },
22
- snap: {
23
- x: jest.fn((n) => n),
24
- y: jest.fn((n) => n),
25
- },
26
- domain: {
27
- min: 0,
28
- max: 1,
29
- step: 1,
30
- },
31
- range: {
32
- min: 0,
33
- max: 1,
34
- step: 1,
35
- },
36
- size: {
37
- width: 400,
38
- height: 400,
39
- },
40
- });
41
-
42
- describe('root', () => {
43
- let mockOn;
44
- let defaultProps;
45
-
46
- beforeEach(() => {
47
- mockOn = jest.fn();
48
- select.mockReturnValue({
49
- on: mockOn,
50
- });
51
- pointer.mockReturnValue([0, 0]);
52
-
53
- defaultProps = {
54
- classes: {},
55
- graphProps: graphProps(),
56
- };
57
- });
58
-
59
- afterEach(() => {
60
- cleanup();
61
- jest.clearAllMocks();
62
- });
63
-
64
- it('renders with children', () => {
65
- const { container, getByText } = render(<Root {...defaultProps}>hi</Root>);
66
- expect(container.firstChild).toBeInTheDocument();
67
- expect(getByText('hi')).toBeInTheDocument();
68
- });
69
-
70
- describe('logic', () => {
71
- describe('mousemove', () => {
72
- describe('mount/unmount', () => {
73
- it('adds mousemove listener on componentDidMount', () => {
74
- render(<Root {...defaultProps}>hi</Root>);
75
-
76
- // Verify that select was called with the g element
77
- expect(select).toHaveBeenCalled();
78
-
79
- // Verify that on() was called with 'mousemove' and a function
80
- expect(mockOn).toHaveBeenCalledWith('mousemove', expect.any(Function));
81
- });
82
-
83
- it('removes mousemove listener on componentWillUnmount', () => {
84
- const { unmount } = render(<Root {...defaultProps}>hi</Root>);
85
-
86
- // Clear previous calls to isolate unmount behavior
87
- mockOn.mockClear();
88
- select.mockClear();
89
-
90
- unmount();
91
-
92
- // Verify that select was called during unmount
93
- expect(select).toHaveBeenCalled();
94
-
95
- // Verify that on() was called with 'mousemove' and null to remove the listener
96
- expect(mockOn).toHaveBeenCalledWith('mousemove', null);
97
- });
98
- });
99
-
100
- describe('mouseMove function', () => {
101
- it('calls pointer with correct arguments', () => {
102
- const onMouseMove = jest.fn();
103
- const gp = graphProps();
104
- const props = {
105
- ...defaultProps,
106
- onMouseMove,
107
- graphProps: gp,
108
- };
109
-
110
- const mockNode = document.createElement('div');
111
- const mockEvent = { clientX: 10, clientY: 20 };
112
- const mockSelection = {
113
- _groups: [[mockNode]],
114
- node: () => mockNode,
115
- };
116
-
117
- // Mock select to return our mockSelection
118
- select.mockReturnValue({
119
- ...mockSelection,
120
- on: (event, handler) => {
121
- mockOn(event, handler);
122
- // When 'mousemove' is registered, immediately test it
123
- if (event === 'mousemove' && handler) {
124
- pointer.mockReturnValue([10, 20]);
125
- // Handler is bound with mockSelection as first arg, so call with event
126
- handler(mockEvent);
127
- }
128
- },
129
- });
130
-
131
- render(<Root {...props}>hi</Root>);
132
-
133
- // Verify pointer was called with the event and correct node
134
- expect(pointer).toHaveBeenCalledWith(mockEvent, mockNode);
135
- });
136
-
137
- it('calls scale.x.invert and scale.y.invert', () => {
138
- const onMouseMove = jest.fn();
139
- const gp = graphProps();
140
- const props = {
141
- ...defaultProps,
142
- onMouseMove,
143
- graphProps: gp,
144
- };
145
-
146
- const mockNode = document.createElement('div');
147
- const mockEvent = { clientX: 15, clientY: 25 };
148
- const mockSelection = {
149
- _groups: [[mockNode]],
150
- node: () => mockNode,
151
- };
152
-
153
- select.mockReturnValue({
154
- ...mockSelection,
155
- on: (event, handler) => {
156
- mockOn(event, handler);
157
- if (event === 'mousemove' && handler) {
158
- pointer.mockReturnValue([15, 25]);
159
- handler(mockEvent);
160
- }
161
- },
162
- });
163
-
164
- render(<Root {...props}>hi</Root>);
165
-
166
- expect(gp.scale.x.invert).toHaveBeenCalledWith(15);
167
- expect(gp.scale.y.invert).toHaveBeenCalledWith(25);
168
- });
169
-
170
- it('calls snap.x and snap.y with inverted coordinates', () => {
171
- const onMouseMove = jest.fn();
172
- const gp = graphProps();
173
- gp.scale.x.invert = jest.fn().mockReturnValue(5);
174
- gp.scale.y.invert = jest.fn().mockReturnValue(10);
175
- const props = {
176
- ...defaultProps,
177
- onMouseMove,
178
- graphProps: gp,
179
- };
180
-
181
- const mockNode = document.createElement('div');
182
- const mockEvent = { clientX: 100, clientY: 200 };
183
- const mockSelection = {
184
- _groups: [[mockNode]],
185
- node: () => mockNode,
186
- };
187
-
188
- select.mockReturnValue({
189
- ...mockSelection,
190
- on: (event, handler) => {
191
- mockOn(event, handler);
192
- if (event === 'mousemove' && handler) {
193
- pointer.mockReturnValue([100, 200]);
194
- handler();
195
- }
196
- },
197
- });
198
-
199
- render(<Root {...props}>hi</Root>);
200
-
201
- expect(gp.snap.x).toHaveBeenCalledWith(5);
202
- expect(gp.snap.y).toHaveBeenCalledWith(10);
203
- });
204
-
205
- it('calls onMouseMove handler with snapped coordinates', () => {
206
- const onMouseMove = jest.fn();
207
- const gp = graphProps();
208
- gp.scale.x.invert = jest.fn().mockReturnValue(7);
209
- gp.scale.y.invert = jest.fn().mockReturnValue(14);
210
- gp.snap.x = jest.fn().mockReturnValue(10);
211
- gp.snap.y = jest.fn().mockReturnValue(15);
212
-
213
- const props = {
214
- ...defaultProps,
215
- onMouseMove,
216
- graphProps: gp,
217
- };
218
-
219
- const mockNode = document.createElement('div');
220
- const mockEvent = { clientX: 100, clientY: 200 };
221
- const mockSelection = {
222
- _groups: [[mockNode]],
223
- node: () => mockNode,
224
- };
225
-
226
- select.mockReturnValue({
227
- ...mockSelection,
228
- on: (event, handler) => {
229
- mockOn(event, handler);
230
- if (event === 'mousemove' && handler) {
231
- pointer.mockReturnValue([100, 200]);
232
- handler(mockEvent);
233
- }
234
- },
235
- });
236
-
237
- render(<Root {...props}>hi</Root>);
238
-
239
- expect(onMouseMove).toHaveBeenCalledWith({ x: 10, y: 15 });
240
- });
241
-
242
- it('does not call onMouseMove when handler is not provided', () => {
243
- const gp = graphProps();
244
- const props = {
245
- ...defaultProps,
246
- graphProps: gp,
247
- };
248
-
249
- const mockNode = document.createElement('div');
250
- const mockEvent = { clientX: 100, clientY: 200 };
251
- const mockSelection = {
252
- _groups: [[mockNode]],
253
- node: () => mockNode,
254
- };
255
-
256
- select.mockReturnValue({
257
- ...mockSelection,
258
- on: (event, handler) => {
259
- mockOn(event, handler);
260
- if (event === 'mousemove' && handler) {
261
- pointer.mockReturnValue([100, 200]);
262
- // Should not throw error when onMouseMove is not provided
263
- expect(() => handler(mockEvent)).not.toThrow();
264
- }
265
- },
266
- });
267
-
268
- render(<Root {...props}>hi</Root>);
269
-
270
- // Verify scale methods were not called (early return in mouseMove)
271
- expect(gp.scale.x.invert).not.toHaveBeenCalled();
272
- expect(gp.scale.y.invert).not.toHaveBeenCalled();
273
- });
274
- });
275
- });
276
- });
277
- });
@@ -1,163 +0,0 @@
1
- import { acuteXAngle, acuteYAngle, angle, diffEdge, edges, getOpposingSide, toDegrees, toRadians } from '../trig';
2
- import { xy } from '../utils';
3
- import debug from 'debug';
4
-
5
- const log = debug('pie-lib:plot:trig:test');
6
-
7
- const vs = (v) => {
8
- if (!v) {
9
- return '';
10
- }
11
-
12
- if (Number.isFinite(v.x) && Number.isFinite(v.y)) {
13
- return `[${v.x},${v.y}]`;
14
- }
15
- return JSON.stringify(v);
16
- };
17
- const p = (strings, ...values) => {
18
- return strings.reduce((acc, s, index) => {
19
- return `${acc}${s}${vs(values[index])}`;
20
- }, '');
21
- };
22
- describe('trig', () => {
23
- describe('angle', () => {
24
- const assertAngle = (a, b, expected) => {
25
- it(p`${a}, ${b} => ${toDegrees(expected)}`, () => {
26
- const result = angle(a, b);
27
- expect(result).toBeCloseTo(expected);
28
- });
29
- };
30
-
31
- assertAngle(xy(0, 0), xy(1, 1), toRadians(45));
32
- assertAngle(xy(0, 0), xy(0, 1), toRadians(90));
33
- assertAngle(xy(0, 0), xy(-1, 1), toRadians(135));
34
- assertAngle(xy(0, 0), xy(-1, 0), toRadians(180));
35
- assertAngle(xy(0, 0), xy(-1, -1), toRadians(225));
36
- assertAngle(xy(0, 0), xy(0, -1), toRadians(270));
37
- assertAngle(xy(0, 0), xy(1, -1), toRadians(315));
38
- assertAngle(xy(1, 1), xy(0, 0), toRadians(225));
39
- assertAngle(xy(0, 0), xy(1, 1), toRadians(45));
40
- assertAngle(xy(0, 0), xy(2, 1), toRadians(26.565));
41
- assertAngle(xy(0, 0), xy(3, 1), toRadians(18.434));
42
- assertAngle(xy(0, 0), xy(4, 1), toRadians(14.036));
43
- assertAngle(xy(0, 0), xy(5, 1), toRadians(11.309));
44
- });
45
-
46
- describe('acuteXAngle', () => {
47
- const assertAcute = (input, expected) => {
48
- it(`${toDegrees(input)} => ${toDegrees(expected)}`, () => {
49
- const result = acuteXAngle(input);
50
- log(`result: ${toDegrees(result)}`);
51
- expect(result).toBeCloseTo(expected);
52
- });
53
- };
54
-
55
- assertAcute(toRadians(45), toRadians(45));
56
- assertAcute(toRadians(100), toRadians(80));
57
- assertAcute(toRadians(190), toRadians(10));
58
- assertAcute(toRadians(350), toRadians(10));
59
- });
60
-
61
- describe('acuteYAngle', () => {
62
- const assertAcute = (input, expected) => {
63
- it(`${toDegrees(input)} => ${toDegrees(expected)}`, () => {
64
- const result = acuteYAngle(input);
65
- log(`result: ${toDegrees(result)}`);
66
- expect(result).toBeCloseTo(expected);
67
- });
68
- };
69
-
70
- assertAcute(toRadians(45), toRadians(45));
71
- assertAcute(toRadians(100), toRadians(10));
72
- assertAcute(toRadians(190), toRadians(80));
73
- assertAcute(toRadians(350), toRadians(80));
74
- });
75
-
76
- describe('edges', () => {
77
- const assertEdges = (domain, range) => (from, to, expected) => {
78
- it(p`${domain}, ${range} + ${from} -> ${to} => ${expected[0]}${expected[1]}`, () => {
79
- const result = edges(domain, range)(from, to);
80
- expect(result[0].x).toBeCloseTo(expected[0].x);
81
- expect(result[0].y).toBeCloseTo(expected[0].y);
82
- expect(result[1].x).toBeCloseTo(expected[1].x);
83
- expect(result[1].y).toBeCloseTo(expected[1].y);
84
- });
85
- };
86
-
87
- const one = assertEdges({ min: -4, max: 4 }, { min: -4, max: 4 });
88
- one(xy(0, 0), xy(1, 1), [xy(4, 4), xy(-4, -4)]);
89
- one(xy(0, 0), xy(2, 1), [xy(4, 2), xy(-4, -2)]);
90
- one(xy(1, 1), xy(2, 2), [xy(4, 4), xy(-4, -4)]);
91
- one(xy(1, 0), xy(2, 0), [xy(4, 0), xy(-4, 0)]);
92
- one(xy(1, 0), xy(-2, 0), [xy(-4, 0), xy(4, 0)]);
93
-
94
- /**
95
- * domain {min: -5, max: 5, padding: 0, step: 1, labelStep: 1}labelStep: 1max: 5min: -5padding: 0step: 1__proto__: Object range: {min: -5, max: 5, padding: 0, step: 1, labelStep: 1} a: {x: -5, y: 0} b: {x: -5, y: 2} edges: Point {x: -5, y: 5} Point {x: -5, y: 2}
96
- */
97
- const lineIssue = assertEdges({ min: -5, max: 5 }, { min: -5, max: 5 });
98
- lineIssue(xy(-5, -0), xy(-5, 2), [xy(-5, 5), xy(-5, -5)]);
99
- });
100
-
101
- describe('diffEdge', () => {
102
- const assertDiffEdge = (bounds, from, to, expected) => {
103
- it(p`<${bounds}> ${from} -> ${to} => ${expected}`, () => {
104
- const result = diffEdge(bounds, from, to);
105
- expect(result.x).toBeCloseTo(expected.x);
106
- expect(result.y).toBeCloseTo(expected.y);
107
- });
108
- };
109
-
110
- const twoTwo = assertDiffEdge.bind(null, xy(2, 2));
111
- twoTwo(xy(0, 0), xy(1, 1), xy(2, 2));
112
- twoTwo(xy(0, 0), xy(1, 2), xy(1, 2));
113
- twoTwo(xy(0, 0), xy(2, 2), xy(2, 2));
114
- twoTwo(xy(0, 0), xy(2, 2), xy(2, 2));
115
- twoTwo(xy(0, 0), xy(-1, 1), xy(-2, 2));
116
- twoTwo(xy(0, 0), xy(-1, -1), xy(-2, -2));
117
- const fourFour = assertDiffEdge.bind(null, xy(4, 4));
118
-
119
- fourFour(xy(0, 0), xy(1, 1), xy(4, 4));
120
- fourFour(xy(0, 0), xy(1, 2), xy(2, 4));
121
- fourFour(xy(0, 0), xy(2, 1), xy(4, 2));
122
- fourFour(xy(0, 0), xy(-1, 1), xy(-4, 4));
123
- fourFour(xy(0, 0), xy(-1, 1), xy(-4, 4));
124
-
125
- assertDiffEdge(xy(-4, -4), xy(0, 0), xy(-1, -1), xy(-4, -4));
126
- assertDiffEdge(xy(4, 4), xy(1, 1), xy(2, 2), xy(4, 4));
127
- assertDiffEdge(xy(4, 4), xy(2, 2), xy(3, 3), xy(4, 4));
128
- assertDiffEdge(xy(-4, -4), xy(-1, -1), xy(-2, -2), xy(-4, -4));
129
- assertDiffEdge(xy(-4, 4), xy(-1, -1), xy(-2, 0), xy(-4, 2));
130
-
131
- const lineIssue = assertDiffEdge.bind(null, xy(-5, -5));
132
-
133
- lineIssue(xy(-5, 2), xy(-5, 0), xy(-5, -5));
134
- //Top Right
135
- assertDiffEdge(xy(5, 5), xy(0, 5), xy(2, 5), xy(5, 5));
136
- assertDiffEdge(xy(5, 5), xy(5, 0), xy(5, 1), xy(5, 5));
137
-
138
- // //Bottom Right
139
- assertDiffEdge(xy(5, -5), xy(5, 0), xy(5, -0.1), xy(5, -5));
140
- assertDiffEdge(xy(5, -5), xy(0, -5), xy(1, -5), xy(5, -5));
141
-
142
- //Top Left
143
- assertDiffEdge(xy(-5, 5), xy(-5, 0), xy(-5, 0.1), xy(-5, 5));
144
- assertDiffEdge(xy(-5, 5), xy(0, 5), xy(-1, 5), xy(-5, 5));
145
-
146
- //Bottom Left
147
- assertDiffEdge(xy(-5, -5), xy(-5, 0), xy(-5, -0.1), xy(-5, -5));
148
- assertDiffEdge(xy(-5, -5), xy(0, -5), xy(-1, -5), xy(-5, -5));
149
- });
150
-
151
- describe('getOpposingSide', () => {
152
- const assertOpposingSide = (hyp, angle, expected) => {
153
- it(`${hyp}, ${angle} = ${expected}`, () => {
154
- const radians = toRadians(angle);
155
- const result = getOpposingSide(hyp, radians);
156
- expect(result).toBeCloseTo(expected);
157
- });
158
- };
159
-
160
- assertOpposingSide(1, 45, 0.707);
161
- assertOpposingSide(1.25, 45, 0.88);
162
- });
163
- });
@@ -1,229 +0,0 @@
1
- import * as utils from '../utils';
2
-
3
- const xy = utils.xy;
4
-
5
- const tick = (isMajor, v) => ({
6
- major: isMajor,
7
- value: v,
8
- x: v,
9
- });
10
-
11
- const major = tick.bind(null, true);
12
- const minor = tick.bind(null, false);
13
-
14
- describe('utils', () => {
15
- describe('getDelta', () => {
16
- const assertDelta = (from, to, delta) => {
17
- it(`returns a delta of: ${delta} for ${from} -> ${to}`, () => {
18
- const d = utils.getDelta(from, to);
19
- expect(d.x).toEqual(delta.x);
20
- expect(d.y).toEqual(delta.y);
21
- });
22
- };
23
- assertDelta(xy(0, 0), xy(0, 1), xy(0, 1));
24
- assertDelta(xy(0, 1), xy(0, 0), xy(0, -1));
25
- assertDelta(xy(1, 1), xy(3, 3), xy(2, 2));
26
- assertDelta(xy(-1, -1), xy(3, 3), xy(4, 4));
27
- assertDelta(xy(-1, -1), xy(-2, -5), xy(-1, -4));
28
- });
29
-
30
- describe('polygonToArea', () => {
31
- const assertPolygon = (points, area) => {
32
- it(`converts ${points} -> ${area}`, () => {
33
- const result = utils.polygonToArea(points);
34
- expect(result).toEqual(area);
35
- });
36
- };
37
- assertPolygon([xy(0, 0), xy(1, 1), xy(1, -1)], {
38
- left: 0,
39
- top: 1,
40
- bottom: -1,
41
- right: 1,
42
- });
43
- assertPolygon([xy(0, 0), xy(3, 0), xy(2, -1), xy(4, -3), xy(1, -4), xy(2, -2)], {
44
- left: 0,
45
- top: 0,
46
- bottom: -4,
47
- right: 4,
48
- });
49
- });
50
-
51
- describe('buildTickModel', () => {
52
- let scaleFn;
53
-
54
- beforeEach(() => {
55
- scaleFn = jest.fn(function (v) {
56
- return v;
57
- });
58
- });
59
-
60
- it('builds major only ticks', () => {
61
- let result = utils.buildTickModel({ min: 0, max: 2 }, { minor: 0 }, 1, scaleFn);
62
- expect(result).toEqual([major(0), major(1), major(2)]);
63
- });
64
-
65
- it('builds minor + major ticks', () => {
66
- let result = utils.buildTickModel({ min: 0, max: 2 }, { minor: 1 }, 0.5, scaleFn);
67
- expect(result).toEqual([major(0), minor(0.5), major(1), minor(1.5), major(2)]);
68
- });
69
- });
70
-
71
- describe('snapTo', () => {
72
- let assertSnapTo = (min, max, interval, value, expected) => {
73
- it(`snaps ${value} to ${expected} with domain ${min}<->${max} with interval: ${interval} `, () => {
74
- let result = utils.snapTo(min, max, interval, value);
75
- expect(result).toEqual(expected);
76
- });
77
- };
78
-
79
- describe('with 0, 10, 0.25', () => {
80
- let a = assertSnapTo.bind(null, 0, 10, 0.25);
81
- a(1, 1);
82
- a(1.2, 1.25);
83
- a(0.2, 0.25);
84
- a(5.2, 5.25);
85
- a(5.125, 5.25);
86
- a(5.124, 5);
87
- });
88
-
89
- describe('with 0, 10, 1', () => {
90
- let a = assertSnapTo.bind(null, 0, 10, 1);
91
- a(0, 0);
92
- a(10, 10);
93
- a(100, 10);
94
- a(1, 1);
95
- a(1.2, 1);
96
- a(0.2, 0);
97
- a(5.2, 5);
98
- a(5.001, 5);
99
- });
100
- });
101
-
102
- describe('getInterval', () => {
103
- let assertGetInterval = (min, max, ticks, expected) => {
104
- let paramsDescription = JSON.stringify(ticks);
105
- it(`converts: ${paramsDescription} to ${JSON.stringify(expected)}`, () => {
106
- let result = utils.getInterval({ min: min, max: max }, ticks);
107
- expect(result).toEqual(expected);
108
- });
109
- };
110
-
111
- describe('with bad params', () => {
112
- it('throws an error if min > max', () => {
113
- expect(() => {
114
- let result = utils.convertFrequencyToInterval(
115
- { min: 11, max: 10, tickFrequency: 1, betweenTickCount: 0 },
116
- { interval: 10, major: 10 },
117
- );
118
- }).toThrow(Error);
119
- });
120
-
121
- it('throws an error if min = max', () => {
122
- expect(() => {
123
- let result = utils.convertFrequencyToInterval(
124
- { min: 10, max: 10, tickFrequency: 1, betweenTickCount: 0 },
125
- { interval: 10, major: 10 },
126
- );
127
- }).toThrow(Error);
128
- });
129
- });
130
-
131
- describe('with domain 0 -> 1', () => {
132
- let a = assertGetInterval.bind(null, 0, 1);
133
- a({ major: 2, minor: 0 }, 1);
134
- a({ major: 2, minor: 1 }, 0.5);
135
- });
136
-
137
- describe('with domain 0 -> 10', () => {
138
- let a = assertGetInterval.bind(null, 0, 10);
139
-
140
- it('throws an error if the tick frequency is less than 2', () => {
141
- expect(() => {
142
- let result = utils.convertFrequencyToInterval(
143
- { min: 0, max: 10, tickFrequency: 1, betweenTickCount: 0 },
144
- { interval: 10, major: 10 },
145
- );
146
- }).toThrow(Error);
147
- });
148
-
149
- a({ major: 2, minor: 9 }, 1);
150
- a({ major: 2, minor: 0 }, 10);
151
- a({ major: 3, minor: 0 }, 5);
152
- a({ major: 3, minor: 1 }, 2.5);
153
- a({ major: 4, minor: 0 }, 3.3333);
154
- a({ major: 5, minor: 0 }, 2.5);
155
- a({ major: 6, minor: 0 }, 2);
156
- a({ major: 7, minor: 0 }, 1.6667);
157
- a({ major: 8, minor: 0 }, 1.4286);
158
- a({ major: 9, minor: 0 }, 1.25);
159
- a({ major: 10, minor: 0 }, 1.1111);
160
- a({ major: 11, minor: 0 }, 1);
161
- a({ major: 11, minor: 1 }, 0.5);
162
- a({ major: 11, minor: 2 }, 0.3333);
163
- });
164
-
165
- describe('with domain 0 -> 100', () => {
166
- let a = assertGetInterval.bind(null, 0, 100);
167
- a({ major: 11, minor: 1 }, 5);
168
- a({ major: 101, minor: 0 }, 1);
169
- });
170
-
171
- describe('with domain -5 - 5', () => {
172
- let a = assertGetInterval.bind(null, -5, 5);
173
- a({ major: 11, minor: 0 }, 1);
174
- });
175
-
176
- describe('with domain 0 - 5', () => {
177
- let a = assertGetInterval.bind(null, 0, 5);
178
- a({ major: 11, minor: 0 }, 0.5);
179
- a({ major: 11, minor: 2 }, 0.1667);
180
- a({ major: 11, minor: 1 }, 0.25);
181
- });
182
- });
183
-
184
- describe('findLongestWord', () => {
185
- it('should return 0 if label is undefined', () => {
186
- const label = undefined;
187
- const result = utils.findLongestWord(label);
188
-
189
- expect(result).toEqual(0);
190
- });
191
-
192
- it('should return 0 if label is null', () => {
193
- const label = null;
194
- const result = utils.findLongestWord(label);
195
-
196
- expect(result).toEqual(0);
197
- });
198
-
199
- it('should return 6 if the longest word from label has 6 letters', () => {
200
- const label = 'Number of months';
201
- const result = utils.findLongestWord(label);
202
-
203
- expect(result).toEqual(6);
204
- });
205
- });
206
-
207
- describe('amountToIncreaseWidth', () => {
208
- it('should return 0 if longestWord is undefined', () => {
209
- const longestWord = undefined;
210
- const result = utils.amountToIncreaseWidth(longestWord);
211
-
212
- expect(result).toEqual(0);
213
- });
214
-
215
- it('should return 0 if longestWord is null', () => {
216
- const longestWord = null;
217
- const result = utils.amountToIncreaseWidth(longestWord);
218
-
219
- expect(result).toEqual(0);
220
- });
221
-
222
- it('should return 150 if longestWord is 10', () => {
223
- const longestWord = 10;
224
- const result = utils.amountToIncreaseWidth(longestWord);
225
-
226
- expect(result).toEqual(200);
227
- });
228
- });
229
- });
package/src/draggable.jsx DELETED
@@ -1,11 +0,0 @@
1
- import Draggable, { DraggableCore } from 'react-draggable';
2
-
3
- export default class LocalDraggable extends Draggable {
4
- componentWillReceiveProps(next) {
5
- super.componentWillReceiveProps(next);
6
- //Remove the x/y state as these values have now been updated and will come through as props.
7
- this.setState({ x: 0, y: 0 });
8
- }
9
- }
10
-
11
- export { DraggableCore };