@pie-lib/graphing 2.14.22-next.0 → 2.16.0-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 +16 -0
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/__tests__/graph-with-controls.test.js +215 -0
- package/lib/__tests__/graph.test.js +290 -0
- package/lib/__tests__/grid.test.js +40 -0
- package/lib/__tests__/labels.test.js +59 -0
- package/lib/__tests__/mark-label.test.js +154 -0
- package/lib/__tests__/toggle-bar.test.js +54 -0
- package/lib/__tests__/tool-menu.test.js +43 -0
- package/lib/__tests__/undo-redo.test.js +42 -0
- package/lib/__tests__/use-debounce.test.js +28 -0
- package/lib/__tests__/utils.js +72 -0
- package/lib/__tests__/utils.test.js +133 -0
- package/lib/axis/__tests__/arrow.test.js +68 -0
- package/lib/axis/__tests__/axes.test.js +214 -0
- package/lib/axis/arrow.js +1 -1
- package/lib/axis/axes.js +6 -6
- package/lib/axis/index.js +1 -1
- package/lib/bg.js +1 -1
- package/lib/container/actions.js +1 -1
- package/lib/container/index.js +2 -5
- package/lib/container/marks.js +1 -1
- package/lib/container/middleware.js +1 -1
- package/lib/container/reducer.js +1 -1
- package/lib/coordinates-label.js +6 -4
- package/lib/graph-with-controls.js +9 -16
- package/lib/graph.js +30 -13
- package/lib/grid-setup.js +1 -1
- package/lib/grid.js +7 -15
- package/lib/index.js +9 -1
- package/lib/key-legend.js +246 -0
- package/lib/label-svg-icon.js +56 -0
- package/lib/labels.js +3 -2
- package/lib/mark-label.js +168 -57
- package/lib/toggle-bar.js +4 -5
- package/lib/tool-menu.js +3 -23
- package/lib/tools/absolute/__tests__/component.test.js +74 -0
- package/lib/tools/absolute/component.js +35 -0
- package/lib/tools/absolute/index.js +63 -0
- package/lib/tools/circle/__tests__/bg-circle.test.js +46 -0
- package/lib/tools/circle/__tests__/component.test.js +259 -0
- package/lib/tools/circle/bg-circle.js +5 -4
- package/lib/tools/circle/component.js +35 -16
- package/lib/tools/circle/index.js +1 -1
- package/lib/tools/exponential/__tests__/component.test.js +73 -0
- package/lib/tools/exponential/component.js +34 -0
- package/lib/tools/exponential/index.js +71 -0
- package/lib/tools/index.js +27 -7
- package/lib/tools/line/__tests__/component.test.js +56 -0
- package/lib/tools/line/component.js +3 -2
- package/lib/tools/line/index.js +1 -1
- package/lib/tools/parabola/__tests__/component.test.js +73 -0
- package/lib/tools/parabola/component.js +7 -6
- package/lib/tools/parabola/index.js +1 -1
- package/lib/tools/point/__tests__/component.test.js +97 -0
- package/lib/tools/point/component.js +15 -10
- package/lib/tools/point/index.js +1 -1
- package/lib/tools/polygon/__tests__/component.test.js +255 -0
- package/lib/tools/polygon/__tests__/index.test.js +95 -0
- package/lib/tools/polygon/__tests__/line.test.js +43 -0
- package/lib/tools/polygon/__tests__/polygon.test.js +73 -0
- package/lib/tools/polygon/component.js +26 -13
- package/lib/tools/polygon/index.js +1 -1
- package/lib/tools/polygon/line.js +13 -7
- package/lib/tools/polygon/polygon.js +7 -4
- package/lib/tools/ray/__tests__/component.test.js +48 -0
- package/lib/tools/ray/component.js +3 -2
- package/lib/tools/ray/index.js +1 -1
- package/lib/tools/segment/__tests__/component.test.js +48 -0
- package/lib/tools/segment/component.js +3 -2
- package/lib/tools/segment/index.js +1 -1
- package/lib/tools/shared/__tests__/arrow-head.test.js +62 -0
- package/lib/tools/shared/arrow-head.js +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +36 -0
- package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
- package/lib/tools/shared/icons/MissingSVG.js +35 -0
- package/lib/tools/shared/line/__tests__/index.test.js +301 -0
- package/lib/tools/shared/line/__tests__/line-path.test.js +78 -0
- package/lib/tools/shared/line/__tests__/with-root-edge.test.js +122 -0
- package/lib/tools/shared/line/index.js +52 -20
- package/lib/tools/shared/line/line-path.js +14 -8
- package/lib/tools/shared/line/with-root-edge.js +20 -9
- package/lib/tools/shared/point/__tests__/arrow-point.test.js +137 -0
- package/lib/tools/shared/point/__tests__/base-point.test.js +134 -0
- package/lib/tools/shared/point/arrow-point.js +2 -2
- package/lib/tools/shared/point/arrow.js +2 -2
- package/lib/tools/shared/point/base-point.js +44 -8
- package/lib/tools/shared/point/index.js +5 -2
- package/lib/tools/shared/styles.js +17 -8
- package/lib/tools/shared/types.js +1 -1
- package/lib/tools/sine/__tests__/component.test.js +81 -0
- package/lib/tools/sine/component.js +14 -5
- package/lib/tools/sine/index.js +1 -1
- package/lib/tools/vector/__tests__/component.test.js +45 -0
- package/lib/tools/vector/component.js +3 -2
- package/lib/tools/vector/index.js +1 -1
- package/lib/undo-redo.js +1 -2
- package/lib/use-debounce.js +1 -1
- package/lib/utils.js +2 -2
- package/package.json +7 -7
- package/src/__tests__/__snapshots__/graph-with-controls.test.jsx.snap +237 -0
- package/src/__tests__/__snapshots__/graph.test.jsx.snap +211 -0
- package/src/__tests__/__snapshots__/grid.test.jsx.snap +54 -0
- package/src/__tests__/__snapshots__/labels.test.jsx.snap +30 -0
- package/src/__tests__/__snapshots__/mark-label.test.jsx.snap +45 -0
- package/src/__tests__/__snapshots__/toggle-bar.test.jsx.snap +7 -0
- package/src/__tests__/__snapshots__/tool-menu.test.jsx.snap +13 -0
- package/src/__tests__/__snapshots__/undo-redo.test.jsx.snap +14 -0
- package/src/__tests__/graph-with-controls.test.jsx +147 -0
- package/src/__tests__/graph.test.jsx +230 -0
- package/src/__tests__/grid.test.jsx +20 -0
- package/src/__tests__/labels.test.jsx +38 -0
- package/src/__tests__/mark-label.test.jsx +68 -0
- package/src/__tests__/toggle-bar.test.jsx +36 -0
- package/src/__tests__/tool-menu.test.jsx +29 -0
- package/src/__tests__/undo-redo.test.jsx +25 -0
- package/src/__tests__/use-debounce.test.js +21 -0
- package/src/__tests__/utils.js +38 -0
- package/src/__tests__/utils.test.js +151 -0
- package/src/axis/__tests__/__snapshots__/arrow.test.jsx.snap +33 -0
- package/src/axis/__tests__/__snapshots__/axes.test.jsx.snap +122 -0
- package/src/axis/__tests__/arrow.test.jsx +39 -0
- package/src/axis/__tests__/axes.test.jsx +220 -0
- package/src/axis/axes.jsx +5 -5
- package/src/container/index.jsx +2 -4
- package/src/coordinates-label.jsx +4 -3
- package/src/graph-with-controls.jsx +8 -10
- package/src/graph.jsx +22 -10
- package/src/grid-setup.jsx +9 -6
- package/src/grid.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +115 -0
- package/src/label-svg-icon.jsx +39 -0
- package/src/labels.jsx +2 -1
- package/src/mark-label.jsx +149 -52
- package/src/toggle-bar.jsx +1 -2
- package/src/tool-menu.jsx +3 -26
- package/src/tools/absolute/__tests__/component.test.jsx +54 -0
- package/src/tools/absolute/component.jsx +23 -0
- package/src/tools/absolute/index.js +31 -0
- package/src/tools/circle/__tests__/__snapshots__/bg-circle.test.jsx.snap +46 -0
- package/src/tools/circle/__tests__/__snapshots__/component.test.jsx.snap +293 -0
- package/src/tools/circle/__tests__/bg-circle.test.jsx +28 -0
- package/src/tools/circle/__tests__/component.test.jsx +228 -0
- package/src/tools/circle/bg-circle.jsx +5 -4
- package/src/tools/circle/component.jsx +22 -8
- package/src/tools/exponential/__tests__/component.test.jsx +54 -0
- package/src/tools/exponential/component.jsx +23 -0
- package/src/tools/exponential/index.js +39 -0
- package/src/tools/index.js +38 -5
- package/src/tools/line/__tests__/__snapshots__/component.test.jsx.snap +20 -0
- package/src/tools/line/__tests__/component.test.jsx +36 -0
- package/src/tools/line/component.jsx +2 -1
- package/src/tools/parabola/__tests__/component.test.jsx +49 -0
- package/src/tools/parabola/component.jsx +7 -6
- package/src/tools/point/__tests__/__snapshots__/component.test.jsx.snap +40 -0
- package/src/tools/point/__tests__/component.test.jsx +66 -0
- package/src/tools/point/component.jsx +12 -6
- package/src/tools/polygon/__tests__/__snapshots__/component.test.jsx.snap +415 -0
- package/src/tools/polygon/__tests__/__snapshots__/line.test.jsx.snap +45 -0
- package/src/tools/polygon/__tests__/__snapshots__/polygon.test.jsx.snap +52 -0
- package/src/tools/polygon/__tests__/component.test.jsx +226 -0
- package/src/tools/polygon/__tests__/index.test.js +65 -0
- package/src/tools/polygon/__tests__/line.test.jsx +25 -0
- package/src/tools/polygon/__tests__/polygon.test.jsx +44 -0
- package/src/tools/polygon/component.jsx +39 -11
- package/src/tools/polygon/line.jsx +15 -7
- package/src/tools/polygon/polygon.jsx +7 -3
- package/src/tools/ray/__tests__/__snapshots__/component.test.jsx.snap +23 -0
- package/src/tools/ray/__tests__/component.test.jsx +29 -0
- package/src/tools/ray/component.jsx +2 -1
- package/src/tools/segment/__tests__/__snapshots__/component.test.jsx.snap +14 -0
- package/src/tools/segment/__tests__/component.test.jsx +28 -0
- package/src/tools/segment/component.jsx +2 -1
- package/src/tools/shared/__tests__/__snapshots__/arrow-head.test.jsx.snap +27 -0
- package/src/tools/shared/__tests__/arrow-head.test.jsx +34 -0
- package/src/tools/shared/icons/CorrectSVG.jsx +22 -0
- package/src/tools/shared/icons/IncorrectSVG.jsx +20 -0
- package/src/tools/shared/icons/MissingSVG.jsx +21 -0
- package/src/tools/shared/line/__tests__/__snapshots__/index.test.jsx.snap +360 -0
- package/src/tools/shared/line/__tests__/__snapshots__/line-path.test.jsx.snap +58 -0
- package/src/tools/shared/line/__tests__/__snapshots__/with-root-edge.test.jsx.snap +63 -0
- package/src/tools/shared/line/__tests__/index.test.jsx +255 -0
- package/src/tools/shared/line/__tests__/line-path.test.jsx +53 -0
- package/src/tools/shared/line/__tests__/with-root-edge.test.jsx +73 -0
- package/src/tools/shared/line/index.jsx +39 -13
- package/src/tools/shared/line/line-path.jsx +18 -7
- package/src/tools/shared/line/with-root-edge.jsx +10 -3
- package/src/tools/shared/point/__tests__/__snapshots__/arrow-point.test.jsx.snap +56 -0
- package/src/tools/shared/point/__tests__/__snapshots__/base-point.test.jsx.snap +44 -0
- package/src/tools/shared/point/__tests__/arrow-point.test.jsx +87 -0
- package/src/tools/shared/point/__tests__/base-point.test.jsx +84 -0
- package/src/tools/shared/point/arrow-point.jsx +4 -1
- package/src/tools/shared/point/arrow.jsx +4 -1
- package/src/tools/shared/point/base-point.jsx +28 -3
- package/src/tools/shared/point/index.jsx +7 -2
- package/src/tools/shared/styles.js +8 -3
- package/src/tools/sine/__tests__/component.test.jsx +51 -0
- package/src/tools/sine/component.jsx +7 -7
- package/src/tools/vector/__tests__/__snapshots__/component.test.jsx.snap +12 -0
- package/src/tools/vector/__tests__/component.test.jsx +26 -0
- package/src/tools/vector/component.jsx +2 -1
- package/src/undo-redo.jsx +0 -1
- package/src/utils.js +1 -1
- package/legacy.png +0 -0
- package/lib/axis/arrow.js.map +0 -1
- package/lib/axis/axes.js.map +0 -1
- package/lib/axis/index.js.map +0 -1
- package/lib/bg.js.map +0 -1
- package/lib/container/actions.js.map +0 -1
- package/lib/container/index.js.map +0 -1
- package/lib/container/marks.js.map +0 -1
- package/lib/container/middleware.js.map +0 -1
- package/lib/container/reducer.js.map +0 -1
- package/lib/coordinates-label.js.map +0 -1
- package/lib/graph-with-controls.js.map +0 -1
- package/lib/graph.js.map +0 -1
- package/lib/grid-setup.js.map +0 -1
- package/lib/grid.js.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/labels.js.map +0 -1
- package/lib/mark-label.js.map +0 -1
- package/lib/toggle-bar.js.map +0 -1
- package/lib/tool-menu.js.map +0 -1
- package/lib/tools/circle/bg-circle.js.map +0 -1
- package/lib/tools/circle/component.js.map +0 -1
- package/lib/tools/circle/index.js.map +0 -1
- package/lib/tools/index.js.map +0 -1
- package/lib/tools/line/component.js.map +0 -1
- package/lib/tools/line/index.js.map +0 -1
- package/lib/tools/parabola/component.js.map +0 -1
- package/lib/tools/parabola/index.js.map +0 -1
- package/lib/tools/point/component.js.map +0 -1
- package/lib/tools/point/index.js.map +0 -1
- package/lib/tools/polygon/component.js.map +0 -1
- package/lib/tools/polygon/index.js.map +0 -1
- package/lib/tools/polygon/line.js.map +0 -1
- package/lib/tools/polygon/polygon.js.map +0 -1
- package/lib/tools/ray/component.js.map +0 -1
- package/lib/tools/ray/index.js.map +0 -1
- package/lib/tools/segment/component.js.map +0 -1
- package/lib/tools/segment/index.js.map +0 -1
- package/lib/tools/shared/arrow-head.js.map +0 -1
- package/lib/tools/shared/line/index.js.map +0 -1
- package/lib/tools/shared/line/line-path.js.map +0 -1
- package/lib/tools/shared/line/with-root-edge.js.map +0 -1
- package/lib/tools/shared/point/arrow-point.js.map +0 -1
- package/lib/tools/shared/point/arrow.js.map +0 -1
- package/lib/tools/shared/point/base-point.js.map +0 -1
- package/lib/tools/shared/point/index.js.map +0 -1
- package/lib/tools/shared/styles.js.map +0 -1
- package/lib/tools/shared/types.js.map +0 -1
- package/lib/tools/sine/component.js.map +0 -1
- package/lib/tools/sine/index.js.map +0 -1
- package/lib/tools/vector/component.js.map +0 -1
- package/lib/tools/vector/index.js.map +0 -1
- package/lib/undo-redo.js.map +0 -1
- package/lib/use-debounce.js.map +0 -1
- package/lib/utils.js.map +0 -1
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withRootEdge } from '../../shared/line/with-root-edge';
|
|
3
|
+
import { buildDataPoints, exponentialFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
4
|
+
import { utils } from '@pie-lib/plot';
|
|
5
|
+
|
|
6
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
7
|
+
|
|
8
|
+
const { xy } = utils;
|
|
9
|
+
|
|
10
|
+
jest.mock('@pie-lib/graphing-utils', () => ({
|
|
11
|
+
buildDataPoints: jest.fn().mockReturnValue([]),
|
|
12
|
+
exponentialFromTwoPoints: jest.fn(() => jest.fn()),
|
|
13
|
+
getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
jest.mock('../../shared/line/with-root-edge', () => ({
|
|
17
|
+
withRootEdge: jest.fn(),
|
|
18
|
+
rootEdgeComponent: jest.fn(),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
describe('Exponential', () => {
|
|
22
|
+
let fnBody;
|
|
23
|
+
let graphProps;
|
|
24
|
+
let root;
|
|
25
|
+
let edge;
|
|
26
|
+
let result;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
require('../component');
|
|
30
|
+
fnBody = withRootEdge.mock.calls[0][0];
|
|
31
|
+
graphProps = getGraphProps();
|
|
32
|
+
root = xy(1, 1);
|
|
33
|
+
edge = xy(2, 2);
|
|
34
|
+
|
|
35
|
+
result = fnBody({ graphProps, root, edge });
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('fnBody is not null', () => {
|
|
39
|
+
expect(fnBody).toBeDefined();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('calls buildDataPoints', () => {
|
|
43
|
+
const { domain, range } = graphProps;
|
|
44
|
+
expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('calls exponentialFromTwoPoints', () => {
|
|
48
|
+
expect(exponentialFromTwoPoints).toHaveBeenCalledWith(root, edge);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('returns dataPoints', () => {
|
|
52
|
+
expect(result).toEqual({ root, edge, dataPoints: [] });
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import { buildDataPoints, exponentialFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
3
|
+
import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
|
|
4
|
+
|
|
5
|
+
const log = debug('pie-lib:graphing:exponential');
|
|
6
|
+
|
|
7
|
+
const Exponential = withRootEdge((props) => {
|
|
8
|
+
const { root, edge, graphProps } = props;
|
|
9
|
+
const { domain, range } = graphProps;
|
|
10
|
+
|
|
11
|
+
const dataPoints =
|
|
12
|
+
edge && edge.x === root.x
|
|
13
|
+
? []
|
|
14
|
+
: buildDataPoints(domain, range, root, edge, exponentialFromTwoPoints(root, edge), true);
|
|
15
|
+
|
|
16
|
+
log('dataPoints:', dataPoints);
|
|
17
|
+
|
|
18
|
+
return { root: props.root, edge: props.edge, dataPoints };
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const Component = rootEdgeComponent(Exponential);
|
|
22
|
+
|
|
23
|
+
export default Component;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Exponential from './component';
|
|
2
|
+
import debug from 'debug';
|
|
3
|
+
import { equalPoints, sameAxes } from '../../utils';
|
|
4
|
+
|
|
5
|
+
const log = debug('pie-lib:graphing:exponential');
|
|
6
|
+
|
|
7
|
+
export const tool = () => ({
|
|
8
|
+
type: 'exponential',
|
|
9
|
+
Component: Exponential,
|
|
10
|
+
complete: (data, mark) => ({ ...mark, building: false, closed: true }),
|
|
11
|
+
addPoint: (point, mark) => {
|
|
12
|
+
log('add point to exponential model: ', point, 'mark: ', mark);
|
|
13
|
+
if (mark && (equalPoints(mark.root, point) || sameAxes(mark.root, point))) {
|
|
14
|
+
return mark;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (mark && mark.root.y * point.y < 0) {
|
|
18
|
+
return mark;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (point.y === 0) {
|
|
22
|
+
return mark;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (!mark) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'exponential',
|
|
28
|
+
root: point,
|
|
29
|
+
edge: undefined,
|
|
30
|
+
closed: false,
|
|
31
|
+
building: true,
|
|
32
|
+
};
|
|
33
|
+
} else if (mark && !mark.root) {
|
|
34
|
+
throw new Error('no root - should never happen');
|
|
35
|
+
} else {
|
|
36
|
+
return { ...mark, edge: point, closed: true, building: false };
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
});
|
package/src/tools/index.js
CHANGED
|
@@ -1,15 +1,48 @@
|
|
|
1
1
|
import { tool as point } from './point';
|
|
2
2
|
import { tool as circle } from './circle';
|
|
3
3
|
import { tool as polygon } from './polygon';
|
|
4
|
-
import { tool as sine } from './sine
|
|
5
|
-
import { tool as parabola } from './parabola
|
|
4
|
+
import { tool as sine } from './sine';
|
|
5
|
+
import { tool as parabola } from './parabola';
|
|
6
6
|
import { tool as line } from './line';
|
|
7
7
|
import { tool as segment } from './segment';
|
|
8
8
|
import { tool as ray } from './ray';
|
|
9
9
|
import { tool as vector } from './vector';
|
|
10
|
+
import { tool as absolute } from './absolute';
|
|
11
|
+
import { tool as exponential } from './exponential';
|
|
10
12
|
|
|
11
|
-
const allTools = [
|
|
13
|
+
const allTools = [
|
|
14
|
+
'circle',
|
|
15
|
+
'line',
|
|
16
|
+
'label',
|
|
17
|
+
'parabola',
|
|
18
|
+
'point',
|
|
19
|
+
'polygon',
|
|
20
|
+
'ray',
|
|
21
|
+
'segment',
|
|
22
|
+
'sine',
|
|
23
|
+
'vector',
|
|
24
|
+
'absolute',
|
|
25
|
+
'exponential',
|
|
26
|
+
];
|
|
12
27
|
|
|
13
|
-
|
|
28
|
+
// need this because now we should treat label as other tools PD-3736
|
|
29
|
+
const labelTool = {
|
|
30
|
+
type: 'label',
|
|
31
|
+
};
|
|
14
32
|
|
|
15
|
-
|
|
33
|
+
const toolsArr = [
|
|
34
|
+
circle(),
|
|
35
|
+
line(),
|
|
36
|
+
parabola(),
|
|
37
|
+
point(),
|
|
38
|
+
polygon(),
|
|
39
|
+
ray(),
|
|
40
|
+
segment(),
|
|
41
|
+
sine(),
|
|
42
|
+
vector(),
|
|
43
|
+
absolute(),
|
|
44
|
+
exponential(),
|
|
45
|
+
labelTool,
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
export { allTools, toolsArr, circle, line, point, parabola, polygon, ray, sine, vector, absolute, exponential };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`ArrowedLine snapshot renders 1`] = `
|
|
4
|
+
<g>
|
|
5
|
+
<defs>
|
|
6
|
+
<ArrowMarker
|
|
7
|
+
className=""
|
|
8
|
+
id="1-enabled"
|
|
9
|
+
size={5}
|
|
10
|
+
/>
|
|
11
|
+
</defs>
|
|
12
|
+
<line
|
|
13
|
+
className="className"
|
|
14
|
+
markerEnd="url(#1-enabled)"
|
|
15
|
+
markerId="1"
|
|
16
|
+
markerStart="url(#1-enabled)"
|
|
17
|
+
onChange={[MockFunction]}
|
|
18
|
+
/>
|
|
19
|
+
</g>
|
|
20
|
+
`;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { ArrowedLine } from '../component';
|
|
4
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
5
|
+
jest.mock('@pie-lib/plot/index', () => {
|
|
6
|
+
const a = jest.requireActual('@pie-lib/plot/index');
|
|
7
|
+
return {
|
|
8
|
+
types: a.types,
|
|
9
|
+
gridDraggable: a.gridDraggable,
|
|
10
|
+
utils: a.utils,
|
|
11
|
+
trig: {
|
|
12
|
+
edges: jest.fn(() => jest.fn().mockReturnValue([0, 0])),
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('ArrowedLine', () => {
|
|
18
|
+
let w;
|
|
19
|
+
let onChange = jest.fn();
|
|
20
|
+
const wrapper = (extras) => {
|
|
21
|
+
const defaults = {
|
|
22
|
+
classes: {},
|
|
23
|
+
className: 'className',
|
|
24
|
+
onChange,
|
|
25
|
+
markerId: '1',
|
|
26
|
+
graphProps: getGraphProps(),
|
|
27
|
+
};
|
|
28
|
+
const props = { ...defaults, ...extras };
|
|
29
|
+
return shallow(<ArrowedLine {...props} />);
|
|
30
|
+
};
|
|
31
|
+
describe('snapshot', () => {
|
|
32
|
+
it('renders', () => {
|
|
33
|
+
expect(wrapper()).toMatchSnapshot();
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -12,6 +12,7 @@ const lineStyles = (theme) => ({
|
|
|
12
12
|
enabledArrow: styles.arrow(theme),
|
|
13
13
|
disabledArrow: styles.disabledArrow(theme),
|
|
14
14
|
disabled: styles.disabled(theme),
|
|
15
|
+
disabledSecondary: styles.disabledSecondary(theme),
|
|
15
16
|
correct: styles.correct(theme, 'stroke'),
|
|
16
17
|
correctArrow: styles.correct(theme),
|
|
17
18
|
incorrect: styles.incorrect(theme, 'stroke'),
|
|
@@ -42,7 +43,7 @@ export const ArrowedLine = (props) => {
|
|
|
42
43
|
y1={scale.y(eFrom.y)}
|
|
43
44
|
x2={scale.x(eTo.x)}
|
|
44
45
|
y2={scale.y(eTo.y)}
|
|
45
|
-
className={classNames(classes.line, disabled && classes.
|
|
46
|
+
className={classNames(classes.line, disabled && classes.disabledSecondary, classes[correctness], className)}
|
|
46
47
|
markerEnd={`url(#${props.markerId || markerId}-${suffix})`}
|
|
47
48
|
markerStart={`url(#${props.markerId || markerId}-${suffix})`}
|
|
48
49
|
{...rest}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { withRootEdge } from '../../shared/line/with-root-edge';
|
|
3
|
+
import { buildDataPoints, parabolaFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
4
|
+
import { utils } from '@pie-lib/plot';
|
|
5
|
+
|
|
6
|
+
import { graphProps as getGraphProps } from '../../../__tests__/utils';
|
|
7
|
+
|
|
8
|
+
const { xy } = utils;
|
|
9
|
+
jest.mock('@pie-lib/graphing-utils', () => ({
|
|
10
|
+
buildDataPoints: jest.fn().mockReturnValue([]),
|
|
11
|
+
parabolaFromTwoPoints: jest.fn(() => jest.fn()),
|
|
12
|
+
getAmplitudeAndFreq: jest.fn().mockReturnValue({ freq: 4, amplitude: 1 }),
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
jest.mock('../../shared/line/with-root-edge', () => ({
|
|
16
|
+
withRootEdge: jest.fn(),
|
|
17
|
+
rootEdgeComponent: jest.fn(),
|
|
18
|
+
}));
|
|
19
|
+
describe('Parabola', () => {
|
|
20
|
+
let fnBody;
|
|
21
|
+
let graphProps;
|
|
22
|
+
let root;
|
|
23
|
+
let edge;
|
|
24
|
+
let result;
|
|
25
|
+
beforeEach(() => {
|
|
26
|
+
require('../component');
|
|
27
|
+
fnBody = withRootEdge.mock.calls[0][0];
|
|
28
|
+
graphProps = getGraphProps();
|
|
29
|
+
root = xy(0, 0);
|
|
30
|
+
edge = xy(1, 1);
|
|
31
|
+
|
|
32
|
+
result = fnBody({ graphProps, root, edge });
|
|
33
|
+
});
|
|
34
|
+
it('fnBody is not null', () => {
|
|
35
|
+
expect(fnBody).toBeDefined();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('calls buildDataPoints', () => {
|
|
39
|
+
const { domain, range } = graphProps;
|
|
40
|
+
expect(buildDataPoints).toHaveBeenCalledWith(domain, range, root, edge, expect.anything(), true);
|
|
41
|
+
});
|
|
42
|
+
it('calls parabolaFromTwoPoints', () => {
|
|
43
|
+
expect(parabolaFromTwoPoints).toHaveBeenCalledWith(root, edge);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('returns dataPoints', () => {
|
|
47
|
+
expect(result).toEqual({ root, edge, dataPoints: [] });
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -2,21 +2,22 @@ import debug from 'debug';
|
|
|
2
2
|
import { buildDataPoints, parabolaFromTwoPoints } from '@pie-lib/graphing-utils';
|
|
3
3
|
import { withRootEdge, rootEdgeComponent } from '../shared/line/with-root-edge';
|
|
4
4
|
|
|
5
|
-
const log = debug('pie-lib:graphing:
|
|
5
|
+
const log = debug('pie-lib:graphing:parabola');
|
|
6
6
|
|
|
7
7
|
const Parabola = withRootEdge((props) => {
|
|
8
|
-
const {
|
|
9
|
-
|
|
10
|
-
const { root, edge } = props;
|
|
11
|
-
const interval = 1;
|
|
8
|
+
const { root, edge, graphProps } = props;
|
|
9
|
+
const { domain, range } = graphProps;
|
|
12
10
|
|
|
13
11
|
const dataPoints =
|
|
14
12
|
edge && edge.x === root.x
|
|
15
13
|
? []
|
|
16
|
-
: buildDataPoints(domain
|
|
14
|
+
: buildDataPoints(domain, range, root, edge, parabolaFromTwoPoints(root, edge), true);
|
|
15
|
+
|
|
17
16
|
log('dataPoints:', dataPoints);
|
|
17
|
+
|
|
18
18
|
return { root: props.root, edge: props.edge, dataPoints };
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
const Component = rootEdgeComponent(Parabola);
|
|
22
|
+
|
|
22
23
|
export default Component;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Component snapshot renders 1`] = `
|
|
4
|
+
<Fragment>
|
|
5
|
+
<WithStyles(GridDraggable)
|
|
6
|
+
graphProps={
|
|
7
|
+
Object {
|
|
8
|
+
"domain": Object {
|
|
9
|
+
"max": 1,
|
|
10
|
+
"min": 0,
|
|
11
|
+
"step": 1,
|
|
12
|
+
},
|
|
13
|
+
"range": Object {
|
|
14
|
+
"max": 1,
|
|
15
|
+
"min": 0,
|
|
16
|
+
"step": 1,
|
|
17
|
+
},
|
|
18
|
+
"scale": Object {
|
|
19
|
+
"x": [MockFunction],
|
|
20
|
+
"y": [MockFunction],
|
|
21
|
+
},
|
|
22
|
+
"size": Object {
|
|
23
|
+
"height": 400,
|
|
24
|
+
"width": 400,
|
|
25
|
+
},
|
|
26
|
+
"snap": Object {
|
|
27
|
+
"x": [MockFunction],
|
|
28
|
+
"y": [MockFunction],
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
onClick={[Function]}
|
|
33
|
+
onDrag={[Function]}
|
|
34
|
+
onDragStart={[Function]}
|
|
35
|
+
onDragStop={[Function]}
|
|
36
|
+
onTouchEnd={[Function]}
|
|
37
|
+
onTouchStart={[Function]}
|
|
38
|
+
/>
|
|
39
|
+
</Fragment>
|
|
40
|
+
`;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { graphProps, xy } from '../../../__tests__/utils';
|
|
4
|
+
|
|
5
|
+
import Component from '../component';
|
|
6
|
+
|
|
7
|
+
describe('Component', () => {
|
|
8
|
+
let w;
|
|
9
|
+
let onChange = jest.fn();
|
|
10
|
+
const wrapper = (extras, opts) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
classes: {},
|
|
13
|
+
className: 'className',
|
|
14
|
+
onChange,
|
|
15
|
+
graphProps: graphProps(),
|
|
16
|
+
};
|
|
17
|
+
const props = { ...defaults, ...extras };
|
|
18
|
+
return shallow(<Component {...props} />, opts);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
describe('snapshot', () => {
|
|
22
|
+
it('renders', () => {
|
|
23
|
+
w = wrapper();
|
|
24
|
+
expect(w).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
describe('logic', () => {
|
|
29
|
+
describe('move', () => {
|
|
30
|
+
it('calls onChange', () => {
|
|
31
|
+
const w = wrapper({ mark: { ...xy(0, 0) } });
|
|
32
|
+
w.instance().move({ x: 1, y: 1 });
|
|
33
|
+
expect(w.state('mark')).toMatchObject({ ...xy(1, 1) });
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe('labelChange', () => {
|
|
38
|
+
it('callsOnChange with label removed', () => {
|
|
39
|
+
const mark = { label: 'foo' };
|
|
40
|
+
const update = {};
|
|
41
|
+
const w = wrapper({ mark });
|
|
42
|
+
w.instance().labelChange(undefined);
|
|
43
|
+
expect(onChange).toHaveBeenCalledWith(mark, update);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
describe('clickPoint', () => {
|
|
48
|
+
let mark;
|
|
49
|
+
let w;
|
|
50
|
+
beforeEach(() => {
|
|
51
|
+
mark = { label: 'foo' };
|
|
52
|
+
w = wrapper({ mark, labelModeEnabled: true }, { disableLifecycleMethods: true });
|
|
53
|
+
w.instance().input = {
|
|
54
|
+
focus: jest.fn(),
|
|
55
|
+
};
|
|
56
|
+
w.instance().clickPoint();
|
|
57
|
+
});
|
|
58
|
+
it('calls onChange if labelModeEnabeld', () => {
|
|
59
|
+
expect(onChange).toHaveBeenCalledWith(mark, { label: '', ...mark });
|
|
60
|
+
});
|
|
61
|
+
it('calls input.focus', () => {
|
|
62
|
+
expect(w.instance().input.focus).toHaveBeenCalled();
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
});
|
|
@@ -60,13 +60,19 @@ export class Point extends React.Component {
|
|
|
60
60
|
clickPoint = () => {
|
|
61
61
|
const { labelModeEnabled, onChange, onClick, mark } = this.props;
|
|
62
62
|
|
|
63
|
-
if (labelModeEnabled) {
|
|
64
|
-
onChange(mark, { label: '', ...mark });
|
|
65
|
-
if (this.input) {
|
|
66
|
-
this.input.focus();
|
|
67
|
-
}
|
|
68
|
-
} else {
|
|
63
|
+
if (!labelModeEnabled) {
|
|
69
64
|
onClick(mark);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (mark.disabled) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onChange(mark, { label: '', ...mark });
|
|
73
|
+
|
|
74
|
+
if (this.input) {
|
|
75
|
+
this.input.focus();
|
|
70
76
|
}
|
|
71
77
|
};
|
|
72
78
|
|