@pie-lib/graphing 2.14.21 → 2.14.22-next.1618
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.json +1 -1017
- package/CHANGELOG.md +159 -24
- package/NEXT.CHANGELOG.json +1 -0
- package/lib/axis/axes.js +5 -5
- package/lib/axis/axes.js.map +1 -1
- package/lib/container/index.js +1 -4
- package/lib/container/index.js.map +1 -1
- package/lib/coordinates-label.js +5 -3
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +8 -15
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +29 -12
- package/lib/graph.js.map +1 -1
- package/lib/grid.js +6 -14
- package/lib/grid.js.map +1 -1
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -1
- package/lib/key-legend.js +246 -0
- package/lib/key-legend.js.map +1 -0
- package/lib/label-svg-icon.js +56 -0
- package/lib/label-svg-icon.js.map +1 -0
- package/lib/labels.js +2 -1
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +167 -56
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +3 -4
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +2 -22
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/absolute/component.js +35 -0
- package/lib/tools/absolute/component.js.map +1 -0
- package/lib/tools/absolute/index.js +63 -0
- package/lib/tools/absolute/index.js.map +1 -0
- package/lib/tools/circle/bg-circle.js +4 -3
- package/lib/tools/circle/bg-circle.js.map +1 -1
- package/lib/tools/circle/component.js +34 -15
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/exponential/component.js +34 -0
- package/lib/tools/exponential/component.js.map +1 -0
- package/lib/tools/exponential/index.js +71 -0
- package/lib/tools/exponential/index.js.map +1 -0
- package/lib/tools/index.js +26 -6
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +2 -1
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/parabola/component.js +6 -5
- package/lib/tools/parabola/component.js.map +1 -1
- package/lib/tools/point/component.js +14 -9
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/polygon/component.js +25 -12
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/line.js +12 -6
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +6 -3
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/ray/component.js +2 -1
- package/lib/tools/ray/component.js.map +1 -1
- package/lib/tools/segment/component.js +2 -1
- package/lib/tools/segment/component.js.map +1 -1
- package/lib/tools/shared/icons/CorrectSVG.js +36 -0
- package/lib/tools/shared/icons/CorrectSVG.js.map +1 -0
- package/lib/tools/shared/icons/IncorrectSVG.js +36 -0
- package/lib/tools/shared/icons/IncorrectSVG.js.map +1 -0
- package/lib/tools/shared/icons/MissingSVG.js +35 -0
- package/lib/tools/shared/icons/MissingSVG.js.map +1 -0
- package/lib/tools/shared/line/index.js +51 -19
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +13 -7
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +19 -8
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +1 -1
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +1 -1
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +43 -7
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +4 -1
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +16 -7
- package/lib/tools/shared/styles.js.map +1 -1
- package/lib/tools/sine/component.js +13 -4
- package/lib/tools/sine/component.js.map +1 -1
- package/lib/tools/vector/component.js +2 -1
- package/lib/tools/vector/component.js.map +1 -1
- package/lib/undo-redo.js +0 -1
- package/lib/undo-redo.js.map +1 -1
- package/lib/utils.js +1 -1
- package/lib/utils.js.map +1 -1
- package/package.json +12 -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.jsx +8 -10
- package/src/index.js +2 -2
- package/src/key-legend.jsx +145 -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
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import * as utils from '../utils';
|
|
2
|
+
|
|
3
|
+
const xy = (x, y) => ({ x, y });
|
|
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('polygonToArea', () => {
|
|
16
|
+
const assertPolygon = (points, area) => {
|
|
17
|
+
it(`converts ${points} -> ${area}`, () => {
|
|
18
|
+
const result = utils.polygonToArea(points);
|
|
19
|
+
expect(result).toEqual(area);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
assertPolygon([xy(0, 0), xy(1, 1), xy(1, -1)], {
|
|
23
|
+
left: 0,
|
|
24
|
+
top: 1,
|
|
25
|
+
bottom: -1,
|
|
26
|
+
right: 1,
|
|
27
|
+
});
|
|
28
|
+
assertPolygon([xy(0, 0), xy(3, 0), xy(2, -1), xy(4, -3), xy(1, -4), xy(2, -2)], {
|
|
29
|
+
left: 0,
|
|
30
|
+
top: 0,
|
|
31
|
+
bottom: -4,
|
|
32
|
+
right: 4,
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('lineToArea', () => {
|
|
37
|
+
const assertLine = (from, to, expected) => {
|
|
38
|
+
it(`${from},${to} => ${expected}`, () => {
|
|
39
|
+
const result = utils.lineToArea(from, to);
|
|
40
|
+
expect(result).toEqual(expected);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
assertLine(xy(1, 1), xy(2, 2), { left: 1, top: 2, bottom: 1, right: 2 });
|
|
45
|
+
assertLine(xy(-1, 4), xy(4, -3), {
|
|
46
|
+
left: -1,
|
|
47
|
+
top: 4,
|
|
48
|
+
bottom: -3,
|
|
49
|
+
right: 4,
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('getTickValues', () => {
|
|
54
|
+
const assertGetTickValues = (props, expected) => {
|
|
55
|
+
it(` => ${expected}`, () => {
|
|
56
|
+
const result = utils.getTickValues(props);
|
|
57
|
+
expect(result).toEqual(expected);
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
assertGetTickValues({ min: 0, max: 10, step: 1 }, [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
|
|
62
|
+
assertGetTickValues({ min: 0, max: 3, step: 0.5 }, [0, 0.5, 1, 1.5, 2, 2.5, 3]);
|
|
63
|
+
assertGetTickValues({ min: -0.2, max: 2, step: 0.6 }, [0, 0.6, 1.2, 1.8]);
|
|
64
|
+
assertGetTickValues({ min: -3.4, max: 6.2, step: 1.2 }, [0, -1.2, -2.4, 1.2, 2.4, 3.6, 4.8, 6]);
|
|
65
|
+
|
|
66
|
+
assertGetTickValues({ min: 0.6, max: 4.8, step: 0.3 }, [
|
|
67
|
+
0.6,
|
|
68
|
+
0.9,
|
|
69
|
+
1.2,
|
|
70
|
+
1.5,
|
|
71
|
+
1.8,
|
|
72
|
+
2.1,
|
|
73
|
+
2.4,
|
|
74
|
+
2.7,
|
|
75
|
+
3.0,
|
|
76
|
+
3.3,
|
|
77
|
+
3.6,
|
|
78
|
+
3.9,
|
|
79
|
+
4.2,
|
|
80
|
+
4.5,
|
|
81
|
+
4.8,
|
|
82
|
+
]);
|
|
83
|
+
assertGetTickValues({ min: 0.5, max: 4.9, step: 0.3 }, [
|
|
84
|
+
0.6,
|
|
85
|
+
0.9,
|
|
86
|
+
1.2,
|
|
87
|
+
1.5,
|
|
88
|
+
1.8,
|
|
89
|
+
2.1,
|
|
90
|
+
2.4,
|
|
91
|
+
2.7,
|
|
92
|
+
3.0,
|
|
93
|
+
3.3,
|
|
94
|
+
3.6,
|
|
95
|
+
3.9,
|
|
96
|
+
4.2,
|
|
97
|
+
4.5,
|
|
98
|
+
4.8,
|
|
99
|
+
]);
|
|
100
|
+
assertGetTickValues({ min: 0, max: 3, step: 0.125 }, [
|
|
101
|
+
0,
|
|
102
|
+
0.125,
|
|
103
|
+
0.25,
|
|
104
|
+
0.375,
|
|
105
|
+
0.5,
|
|
106
|
+
0.625,
|
|
107
|
+
0.75,
|
|
108
|
+
0.875,
|
|
109
|
+
1,
|
|
110
|
+
1.125,
|
|
111
|
+
1.25,
|
|
112
|
+
1.375,
|
|
113
|
+
1.5,
|
|
114
|
+
1.625,
|
|
115
|
+
1.75,
|
|
116
|
+
1.875,
|
|
117
|
+
2,
|
|
118
|
+
2.125,
|
|
119
|
+
2.25,
|
|
120
|
+
2.375,
|
|
121
|
+
2.5,
|
|
122
|
+
2.625,
|
|
123
|
+
2.75,
|
|
124
|
+
2.875,
|
|
125
|
+
3,
|
|
126
|
+
]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe('countWords', () => {
|
|
130
|
+
it('should return 1 if label is undefined', () => {
|
|
131
|
+
const label = undefined;
|
|
132
|
+
const result = utils.countWords(label);
|
|
133
|
+
|
|
134
|
+
expect(result).toEqual(1);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it('should return 1 if label is null', () => {
|
|
138
|
+
const label = null;
|
|
139
|
+
const result = utils.countWords(label);
|
|
140
|
+
|
|
141
|
+
expect(result).toEqual(1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('should return 3 if label has 3 words', () => {
|
|
145
|
+
const label = 'Number of months';
|
|
146
|
+
const result = utils.countWords(label);
|
|
147
|
+
|
|
148
|
+
expect(result).toEqual(3);
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`Arrow snapshot down 1`] = `
|
|
4
|
+
<path
|
|
5
|
+
className="className"
|
|
6
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
7
|
+
transform="translate(0, 15) rotate(270)"
|
|
8
|
+
/>
|
|
9
|
+
`;
|
|
10
|
+
|
|
11
|
+
exports[`Arrow snapshot left 1`] = `
|
|
12
|
+
<path
|
|
13
|
+
className="className"
|
|
14
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
15
|
+
transform="translate(-15, 0) rotate(0)"
|
|
16
|
+
/>
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
exports[`Arrow snapshot right 1`] = `
|
|
20
|
+
<path
|
|
21
|
+
className="className"
|
|
22
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
23
|
+
transform="translate(15, 0) rotate(180)"
|
|
24
|
+
/>
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
exports[`Arrow snapshot up 1`] = `
|
|
28
|
+
<path
|
|
29
|
+
className="className"
|
|
30
|
+
d="m 0,0 8,-5 0,10 -8,-5"
|
|
31
|
+
transform="translate(0, -15) rotate(90)"
|
|
32
|
+
/>
|
|
33
|
+
`;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`RawXAxis snapshot renders 1`] = `
|
|
4
|
+
<Fragment>
|
|
5
|
+
<F
|
|
6
|
+
left={0}
|
|
7
|
+
scale={[MockFunction]}
|
|
8
|
+
tickFormat={[Function]}
|
|
9
|
+
tickLabelProps={[Function]}
|
|
10
|
+
top={0}
|
|
11
|
+
/>
|
|
12
|
+
<WithStyles(Arrow)
|
|
13
|
+
direction="left"
|
|
14
|
+
scale={
|
|
15
|
+
Object {
|
|
16
|
+
"x": [MockFunction],
|
|
17
|
+
"y": [MockFunction] {
|
|
18
|
+
"calls": Array [
|
|
19
|
+
Array [
|
|
20
|
+
0,
|
|
21
|
+
],
|
|
22
|
+
],
|
|
23
|
+
"results": Array [
|
|
24
|
+
Object {
|
|
25
|
+
"type": "return",
|
|
26
|
+
"value": 0,
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
x={0}
|
|
33
|
+
y={0}
|
|
34
|
+
/>
|
|
35
|
+
<WithStyles(Arrow)
|
|
36
|
+
direction="right"
|
|
37
|
+
scale={
|
|
38
|
+
Object {
|
|
39
|
+
"x": [MockFunction],
|
|
40
|
+
"y": [MockFunction] {
|
|
41
|
+
"calls": Array [
|
|
42
|
+
Array [
|
|
43
|
+
0,
|
|
44
|
+
],
|
|
45
|
+
],
|
|
46
|
+
"results": Array [
|
|
47
|
+
Object {
|
|
48
|
+
"type": "return",
|
|
49
|
+
"value": 0,
|
|
50
|
+
},
|
|
51
|
+
],
|
|
52
|
+
},
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
x={1}
|
|
56
|
+
y={0}
|
|
57
|
+
/>
|
|
58
|
+
</Fragment>
|
|
59
|
+
`;
|
|
60
|
+
|
|
61
|
+
exports[`RawYAxis snapshot renders 1`] = `
|
|
62
|
+
<Fragment>
|
|
63
|
+
<F
|
|
64
|
+
height={400}
|
|
65
|
+
hideZero={true}
|
|
66
|
+
left={0}
|
|
67
|
+
orientation="left"
|
|
68
|
+
scale={[MockFunction]}
|
|
69
|
+
tickFormat={[Function]}
|
|
70
|
+
tickLabelProps={[Function]}
|
|
71
|
+
tickLength={10}
|
|
72
|
+
tickTextAnchor="bottom"
|
|
73
|
+
top={0}
|
|
74
|
+
/>
|
|
75
|
+
<WithStyles(Arrow)
|
|
76
|
+
direction="down"
|
|
77
|
+
scale={
|
|
78
|
+
Object {
|
|
79
|
+
"x": [MockFunction] {
|
|
80
|
+
"calls": Array [
|
|
81
|
+
Array [
|
|
82
|
+
0,
|
|
83
|
+
],
|
|
84
|
+
],
|
|
85
|
+
"results": Array [
|
|
86
|
+
Object {
|
|
87
|
+
"type": "return",
|
|
88
|
+
"value": 0,
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
"y": [MockFunction],
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
x={0}
|
|
96
|
+
y={0}
|
|
97
|
+
/>
|
|
98
|
+
<WithStyles(Arrow)
|
|
99
|
+
direction="up"
|
|
100
|
+
scale={
|
|
101
|
+
Object {
|
|
102
|
+
"x": [MockFunction] {
|
|
103
|
+
"calls": Array [
|
|
104
|
+
Array [
|
|
105
|
+
0,
|
|
106
|
+
],
|
|
107
|
+
],
|
|
108
|
+
"results": Array [
|
|
109
|
+
Object {
|
|
110
|
+
"type": "return",
|
|
111
|
+
"value": 0,
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
},
|
|
115
|
+
"y": [MockFunction],
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
x={0}
|
|
119
|
+
y={1}
|
|
120
|
+
/>
|
|
121
|
+
</Fragment>
|
|
122
|
+
`;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Arrow } from '../arrow';
|
|
4
|
+
|
|
5
|
+
describe('Arrow', () => {
|
|
6
|
+
let w;
|
|
7
|
+
let onChange = jest.fn();
|
|
8
|
+
const wrapper = (extras) => {
|
|
9
|
+
const defaults = {
|
|
10
|
+
classes: {},
|
|
11
|
+
className: 'className',
|
|
12
|
+
onChange,
|
|
13
|
+
scale: {
|
|
14
|
+
x: jest.fn((n) => n),
|
|
15
|
+
y: jest.fn((n) => n),
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
const props = { ...defaults, ...extras };
|
|
19
|
+
return shallow(<Arrow {...props} />);
|
|
20
|
+
};
|
|
21
|
+
describe('snapshot', () => {
|
|
22
|
+
it('up', () => {
|
|
23
|
+
w = wrapper({ direction: 'up' });
|
|
24
|
+
expect(w).toMatchSnapshot();
|
|
25
|
+
});
|
|
26
|
+
it('down', () => {
|
|
27
|
+
w = wrapper({ direction: 'down' });
|
|
28
|
+
expect(w).toMatchSnapshot();
|
|
29
|
+
});
|
|
30
|
+
it('left', () => {
|
|
31
|
+
w = wrapper({ direction: 'left' });
|
|
32
|
+
expect(w).toMatchSnapshot();
|
|
33
|
+
});
|
|
34
|
+
it('right', () => {
|
|
35
|
+
w = wrapper({ direction: 'right' });
|
|
36
|
+
expect(w).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { shallow } from 'enzyme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { graphProps } from '../../__tests__/utils';
|
|
4
|
+
|
|
5
|
+
import Axes, { RawXAxis, RawYAxis, firstNegativeValue, sharedValues } from '../axes';
|
|
6
|
+
|
|
7
|
+
describe('RawXAxis', () => {
|
|
8
|
+
let w;
|
|
9
|
+
let onChange = jest.fn();
|
|
10
|
+
const wrapper = (extras) => {
|
|
11
|
+
const defaults = {
|
|
12
|
+
classes: {},
|
|
13
|
+
className: 'className',
|
|
14
|
+
onChange,
|
|
15
|
+
graphProps: graphProps(),
|
|
16
|
+
includeArrows: {
|
|
17
|
+
left: true,
|
|
18
|
+
right: true,
|
|
19
|
+
up: true,
|
|
20
|
+
down: true,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
const props = { ...defaults, ...extras };
|
|
24
|
+
return shallow(<RawXAxis {...props} />);
|
|
25
|
+
};
|
|
26
|
+
describe('snapshot', () => {
|
|
27
|
+
it('renders', () => {
|
|
28
|
+
w = wrapper();
|
|
29
|
+
expect(w).toMatchSnapshot();
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe('RawYAxis', () => {
|
|
35
|
+
let w;
|
|
36
|
+
let onChange = jest.fn();
|
|
37
|
+
const wrapper = (extras) => {
|
|
38
|
+
const defaults = {
|
|
39
|
+
classes: {},
|
|
40
|
+
className: 'className',
|
|
41
|
+
onChange,
|
|
42
|
+
graphProps: graphProps(),
|
|
43
|
+
includeArrows: {
|
|
44
|
+
left: true,
|
|
45
|
+
right: true,
|
|
46
|
+
up: true,
|
|
47
|
+
down: true,
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
const props = { ...defaults, ...extras };
|
|
51
|
+
return shallow(<RawYAxis {...props} />);
|
|
52
|
+
};
|
|
53
|
+
describe('snapshot', () => {
|
|
54
|
+
it('renders', () => {
|
|
55
|
+
w = wrapper();
|
|
56
|
+
expect(w).toMatchSnapshot();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const customScaleMock = (distance) => {
|
|
62
|
+
const fn = jest.fn((n) => n * distance);
|
|
63
|
+
fn.invert = jest.fn((n) => n * distance);
|
|
64
|
+
return fn;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
describe.only('Axes', () => {
|
|
68
|
+
let w;
|
|
69
|
+
let onChange = jest.fn();
|
|
70
|
+
|
|
71
|
+
const customGraphProps = {
|
|
72
|
+
...graphProps(),
|
|
73
|
+
domain: {
|
|
74
|
+
min: -2,
|
|
75
|
+
max: 2,
|
|
76
|
+
labelStep: 1,
|
|
77
|
+
step: 1,
|
|
78
|
+
},
|
|
79
|
+
range: {
|
|
80
|
+
min: -2,
|
|
81
|
+
max: 2,
|
|
82
|
+
step: 1,
|
|
83
|
+
labelStep: 1,
|
|
84
|
+
},
|
|
85
|
+
scale: {
|
|
86
|
+
x: customScaleMock(200),
|
|
87
|
+
y: customScaleMock(150),
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const wrapper = (extras) => {
|
|
92
|
+
const defaults = {
|
|
93
|
+
classes: {},
|
|
94
|
+
className: 'className',
|
|
95
|
+
onChange,
|
|
96
|
+
graphProps: customGraphProps,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const props = { ...defaults, ...extras };
|
|
100
|
+
return shallow(<Axes {...props} />);
|
|
101
|
+
};
|
|
102
|
+
describe('xValues', () => {
|
|
103
|
+
it('renders', () => {
|
|
104
|
+
w = wrapper();
|
|
105
|
+
const result = w.instance().xValues();
|
|
106
|
+
expect(result).toEqual({
|
|
107
|
+
columnTicksValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
|
|
108
|
+
distanceFromOriginToFirstNegativeX: 150,
|
|
109
|
+
firstNegativeX: -1,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
describe('yValues', () => {
|
|
114
|
+
it('renders', () => {
|
|
115
|
+
w = wrapper();
|
|
116
|
+
const result = w.instance().yValues();
|
|
117
|
+
expect(result).toEqual({
|
|
118
|
+
rowTickValues: expect.arrayContaining([-2, -1, 0, 1, 2]),
|
|
119
|
+
distanceFromOriginToFirstNegativeY: 200,
|
|
120
|
+
firstNegativeY: -1,
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe('firstNegativeValue should return undefiend for undefined interval', () => {
|
|
127
|
+
const interval = undefined;
|
|
128
|
+
const result = firstNegativeValue(interval);
|
|
129
|
+
expect(result).toEqual(undefined);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
describe('firstNegativeValue should return undefiend for empty interval', () => {
|
|
133
|
+
const interval = [];
|
|
134
|
+
const result = firstNegativeValue(interval);
|
|
135
|
+
expect(result).toEqual(undefined);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe('firstNegativeValue should return undefined if there is no negative in interval array', () => {
|
|
139
|
+
const interval = [1, 5, 7, 4, 5];
|
|
140
|
+
const result = firstNegativeValue(interval);
|
|
141
|
+
expect(result).toEqual(undefined);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
describe('firstNegativeValue should return first negative number from interval', () => {
|
|
145
|
+
const interval = [1, 5, 7, -2, 4, 5, -1];
|
|
146
|
+
const result = firstNegativeValue(interval);
|
|
147
|
+
expect(result).toEqual(-2);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
describe('skipValue should be empty array if firstNegativeValue for one of the axes is undefined', () => {
|
|
151
|
+
// x
|
|
152
|
+
const intervalX = [1, 2, 3, 4, 5, 6];
|
|
153
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
154
|
+
const distanceFromOriginToFirstNegativeX = -22;
|
|
155
|
+
|
|
156
|
+
// y
|
|
157
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
158
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
159
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
160
|
+
|
|
161
|
+
const deltaAllowance = 5;
|
|
162
|
+
|
|
163
|
+
const result = sharedValues(
|
|
164
|
+
firstNegativeX,
|
|
165
|
+
firstNegativeY,
|
|
166
|
+
distanceFromOriginToFirstNegativeX,
|
|
167
|
+
distanceFromOriginToFirstNegativeY,
|
|
168
|
+
deltaAllowance,
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
expect(result).toEqual([]);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe('skipValue should be empty array if firstNegativeX and firstNegativeY are equal but they do not overlap', () => {
|
|
175
|
+
// x
|
|
176
|
+
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
177
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
178
|
+
const distanceFromOriginToFirstNegativeX = -7;
|
|
179
|
+
|
|
180
|
+
// y
|
|
181
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
182
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
183
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
184
|
+
|
|
185
|
+
const deltaAllowance = 5;
|
|
186
|
+
|
|
187
|
+
const result = sharedValues(
|
|
188
|
+
firstNegativeX,
|
|
189
|
+
firstNegativeY,
|
|
190
|
+
distanceFromOriginToFirstNegativeX,
|
|
191
|
+
distanceFromOriginToFirstNegativeY,
|
|
192
|
+
deltaAllowance,
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
expect(result).toEqual([]);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe('skipValue should be -1 if firstNegativeX and firstNegativeY are equal and they overlap', () => {
|
|
199
|
+
// x
|
|
200
|
+
const intervalX = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
201
|
+
const firstNegativeX = firstNegativeValue(intervalX);
|
|
202
|
+
const distanceFromOriginToFirstNegativeX = -20;
|
|
203
|
+
|
|
204
|
+
// y
|
|
205
|
+
const intervalY = [-1, -2, 1, 2, 3, 4, 5, 6];
|
|
206
|
+
const firstNegativeY = firstNegativeValue(intervalY);
|
|
207
|
+
const distanceFromOriginToFirstNegativeY = -22;
|
|
208
|
+
|
|
209
|
+
const deltaAllowance = 5;
|
|
210
|
+
|
|
211
|
+
const result = sharedValues(
|
|
212
|
+
firstNegativeX,
|
|
213
|
+
firstNegativeY,
|
|
214
|
+
distanceFromOriginToFirstNegativeX,
|
|
215
|
+
distanceFromOriginToFirstNegativeY,
|
|
216
|
+
deltaAllowance,
|
|
217
|
+
);
|
|
218
|
+
|
|
219
|
+
expect(result).toEqual([-1]);
|
|
220
|
+
});
|
package/src/axis/axes.jsx
CHANGED
|
@@ -23,16 +23,16 @@ const AxisDefaultProps = {
|
|
|
23
23
|
|
|
24
24
|
const axisStyles = (theme) => ({
|
|
25
25
|
line: {
|
|
26
|
-
stroke: color.
|
|
27
|
-
strokeWidth:
|
|
26
|
+
stroke: color.defaults.PRIMARY,
|
|
27
|
+
strokeWidth: 3,
|
|
28
28
|
},
|
|
29
29
|
arrow: {
|
|
30
|
-
fill: color.
|
|
30
|
+
fill: color.defaults.PRIMARY,
|
|
31
31
|
},
|
|
32
32
|
tick: {
|
|
33
|
-
fill: color.
|
|
33
|
+
fill: color.defaults.PRIMARY,
|
|
34
34
|
'& > line': {
|
|
35
|
-
stroke: color.
|
|
35
|
+
stroke: color.defaults.PRIMARY,
|
|
36
36
|
},
|
|
37
37
|
},
|
|
38
38
|
labelFontSize: {
|
package/src/container/index.jsx
CHANGED
|
@@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
|
|
|
8
8
|
import isEqual from 'lodash/isEqual';
|
|
9
9
|
import { ActionCreators } from 'redux-undo';
|
|
10
10
|
import GraphWithControls from '../graph-with-controls';
|
|
11
|
-
import { lastActionMiddleware
|
|
11
|
+
import { lastActionMiddleware } from './middleware';
|
|
12
12
|
|
|
13
13
|
const mapStateToProps = (s) => ({
|
|
14
14
|
marks: s.marks.present,
|
|
@@ -58,11 +58,9 @@ class Root extends React.Component {
|
|
|
58
58
|
onStoreChange = () => {
|
|
59
59
|
const { marks, onChangeMarks } = this.props;
|
|
60
60
|
const storeState = this.store.getState();
|
|
61
|
-
const lastAction = getLastAction();
|
|
62
|
-
const isUndoOperation = lastAction.type.includes('UNDO') || lastAction.type.includes('REDO');
|
|
63
61
|
|
|
64
62
|
if (!isEqual(storeState.marks.present, marks)) {
|
|
65
|
-
onChangeMarks(storeState.marks.present
|
|
63
|
+
onChangeMarks(storeState.marks.present);
|
|
66
64
|
}
|
|
67
65
|
};
|
|
68
66
|
|
|
@@ -12,7 +12,7 @@ const styles = (theme) => ({
|
|
|
12
12
|
fontSize: theme.typography.fontSize,
|
|
13
13
|
borderRadius: '8px',
|
|
14
14
|
background: theme.palette.common.white,
|
|
15
|
-
color: color.
|
|
15
|
+
color: color.defaults.PRIMARY_DARK,
|
|
16
16
|
},
|
|
17
17
|
inputLabel: {
|
|
18
18
|
padding: 0,
|
|
@@ -20,8 +20,9 @@ const styles = (theme) => ({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
export const getLabelPosition = (graphProps, x, y, labelLength) => {
|
|
23
|
-
const { scale, domain } = graphProps;
|
|
24
|
-
|
|
23
|
+
const { scale, domain, range } = graphProps;
|
|
24
|
+
// treat corner cases for maximum and minimum
|
|
25
|
+
const topShift = y === range.min ? 16 : y === range.max ? 0 : 8;
|
|
25
26
|
const leftShift = 10;
|
|
26
27
|
const rightEdge = scale.x(x) + labelLength + leftShift;
|
|
27
28
|
|
|
@@ -89,9 +89,8 @@ export class GraphWithControls extends React.Component {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
changeCurrentTool = (tool, tools) =>
|
|
93
|
-
|
|
94
|
-
toggleLabelMode = () => this.setState((state) => ({ labelModeEnabled: !state.labelModeEnabled }));
|
|
92
|
+
changeCurrentTool = (tool, tools) =>
|
|
93
|
+
this.setState({ currentTool: tools.find((t) => t.type === tool), labelModeEnabled: tool === 'label' });
|
|
95
94
|
|
|
96
95
|
render() {
|
|
97
96
|
let { currentTool, labelModeEnabled } = this.state;
|
|
@@ -123,7 +122,9 @@ export class GraphWithControls extends React.Component {
|
|
|
123
122
|
showTitle,
|
|
124
123
|
title,
|
|
125
124
|
titlePlaceholder,
|
|
126
|
-
language
|
|
125
|
+
language,
|
|
126
|
+
removeIncompleteTool,
|
|
127
|
+
limitLabeling,
|
|
127
128
|
} = this.props;
|
|
128
129
|
let { backgroundMarks, marks, toolbarTools } = this.props;
|
|
129
130
|
|
|
@@ -151,13 +152,12 @@ export class GraphWithControls extends React.Component {
|
|
|
151
152
|
draggableTools={draggableTools}
|
|
152
153
|
labelModeEnabled={labelModeEnabled}
|
|
153
154
|
onChange={(tool) => this.changeCurrentTool(tool, tools)}
|
|
154
|
-
onToggleLabelMode={this.toggleLabelMode}
|
|
155
155
|
toolbarTools={toolbarTools}
|
|
156
156
|
onChangeTools={onChangeTools}
|
|
157
157
|
language={language}
|
|
158
158
|
/>
|
|
159
159
|
|
|
160
|
-
{!disabled && <UndoRedo onUndo={onUndo} onRedo={onRedo} onReset={onReset} language={language}/>}
|
|
160
|
+
{!disabled && <UndoRedo onUndo={onUndo} onRedo={onRedo} onReset={onReset} language={language} />}
|
|
161
161
|
</React.Fragment>
|
|
162
162
|
);
|
|
163
163
|
|
|
@@ -198,6 +198,8 @@ export class GraphWithControls extends React.Component {
|
|
|
198
198
|
title={title}
|
|
199
199
|
titlePlaceholder={titlePlaceholder}
|
|
200
200
|
tools={tools}
|
|
201
|
+
removeIncompleteTool={removeIncompleteTool}
|
|
202
|
+
limitLabeling={limitLabeling}
|
|
201
203
|
/>
|
|
202
204
|
</div>
|
|
203
205
|
);
|
|
@@ -216,10 +218,6 @@ const styles = (theme) => ({
|
|
|
216
218
|
padding: theme.spacing.unit,
|
|
217
219
|
color: color.text(),
|
|
218
220
|
backgroundColor: color.primaryLight(),
|
|
219
|
-
borderTop: `solid 1px ${color.primaryDark()}`,
|
|
220
|
-
borderBottom: `solid 0px ${color.primaryDark()}`,
|
|
221
|
-
borderLeft: `solid 1px ${color.primaryDark()}`,
|
|
222
|
-
borderRight: `solid 1px ${color.primaryDark()}`,
|
|
223
221
|
'& button': {
|
|
224
222
|
fontSize: theme.typography.fontSize,
|
|
225
223
|
},
|