@pie-lib/graphing 2.4.9 → 2.4.12
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 +33 -0
- package/lib/axis/arrow.js +17 -13
- package/lib/axis/arrow.js.map +1 -1
- package/lib/axis/axes.js +57 -51
- package/lib/axis/axes.js.map +1 -1
- package/lib/axis/index.js +5 -1
- package/lib/axis/index.js.map +1 -1
- package/lib/bg.js +16 -14
- package/lib/bg.js.map +1 -1
- package/lib/container/index.js +21 -15
- package/lib/container/index.js.map +1 -1
- package/lib/coordinates-label.js +4 -4
- package/lib/coordinates-label.js.map +1 -1
- package/lib/graph-with-controls.js +29 -25
- package/lib/graph-with-controls.js.map +1 -1
- package/lib/graph.js +56 -42
- package/lib/graph.js.map +1 -1
- package/lib/grid.js +20 -14
- package/lib/grid.js.map +1 -1
- package/lib/index.js +5 -1
- package/lib/index.js.map +1 -1
- package/lib/labels.js +28 -24
- package/lib/labels.js.map +1 -1
- package/lib/mark-label.js +16 -8
- package/lib/mark-label.js.map +1 -1
- package/lib/toggle-bar.js +18 -16
- package/lib/toggle-bar.js.map +1 -1
- package/lib/tool-menu.js +22 -16
- package/lib/tool-menu.js.map +1 -1
- package/lib/tools/circle/bg-circle.js +26 -18
- package/lib/tools/circle/bg-circle.js.map +1 -1
- package/lib/tools/circle/component.js +30 -28
- package/lib/tools/circle/component.js.map +1 -1
- package/lib/tools/circle/index.js +4 -4
- package/lib/tools/circle/index.js.map +1 -1
- package/lib/tools/index.js +16 -15
- package/lib/tools/index.js.map +1 -1
- package/lib/tools/line/component.js +12 -6
- package/lib/tools/line/component.js.map +1 -1
- package/lib/tools/parabola/component.js.map +1 -1
- package/lib/tools/parabola/index.js +4 -4
- package/lib/tools/parabola/index.js.map +1 -1
- package/lib/tools/point/component.js +21 -17
- package/lib/tools/point/component.js.map +1 -1
- package/lib/tools/point/index.js +2 -2
- package/lib/tools/polygon/component.js +55 -47
- package/lib/tools/polygon/component.js.map +1 -1
- package/lib/tools/polygon/index.js +12 -8
- package/lib/tools/polygon/index.js.map +1 -1
- package/lib/tools/polygon/line.js +26 -18
- package/lib/tools/polygon/line.js.map +1 -1
- package/lib/tools/polygon/polygon.js +26 -18
- package/lib/tools/polygon/polygon.js.map +1 -1
- package/lib/tools/ray/component.js +12 -6
- package/lib/tools/ray/component.js.map +1 -1
- package/lib/tools/segment/component.js +4 -2
- package/lib/tools/segment/component.js.map +1 -1
- package/lib/tools/shared/arrow-head.js +4 -4
- package/lib/tools/shared/arrow-head.js.map +1 -1
- package/lib/tools/shared/line/index.js +46 -44
- package/lib/tools/shared/line/index.js.map +1 -1
- package/lib/tools/shared/line/line-path.js +28 -20
- package/lib/tools/shared/line/line-path.js.map +1 -1
- package/lib/tools/shared/line/with-root-edge.js +8 -6
- package/lib/tools/shared/line/with-root-edge.js.map +1 -1
- package/lib/tools/shared/point/arrow-point.js +21 -15
- package/lib/tools/shared/point/arrow-point.js.map +1 -1
- package/lib/tools/shared/point/arrow.js +22 -50
- package/lib/tools/shared/point/arrow.js.map +1 -1
- package/lib/tools/shared/point/base-point.js +22 -16
- package/lib/tools/shared/point/base-point.js.map +1 -1
- package/lib/tools/shared/point/index.js +8 -4
- package/lib/tools/shared/point/index.js.map +1 -1
- package/lib/tools/shared/styles.js +1 -1
- package/lib/tools/shared/types.js +1 -1
- package/lib/tools/sine/component.js.map +1 -1
- package/lib/tools/sine/index.js +4 -4
- package/lib/tools/sine/index.js.map +1 -1
- package/lib/tools/vector/component.js +21 -8
- package/lib/tools/vector/component.js.map +1 -1
- package/lib/undo-redo.js +20 -16
- package/lib/undo-redo.js.map +1 -1
- package/lib/use-debounce.js +7 -3
- package/lib/use-debounce.js.map +1 -1
- package/lib/utils.js +70 -5
- package/lib/utils.js.map +1 -1
- package/package.json +4 -4
- package/src/axis/axes.jsx +1 -1
- package/src/graph.jsx +13 -6
- package/src/tools/shared/point/arrow.jsx +1 -30
- package/src/tools/vector/component.jsx +20 -6
- package/src/utils.js +62 -4
|
@@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
|
|
|
5
5
|
import { types } from '@pie-lib/plot';
|
|
6
6
|
import classNames from 'classnames';
|
|
7
7
|
import { withStyles } from '@material-ui/core/styles';
|
|
8
|
+
import { getDistanceBetweenTwoPoints } from '../../utils';
|
|
8
9
|
|
|
9
10
|
const lineStyles = theme => ({
|
|
10
11
|
line: styles.line(theme),
|
|
@@ -14,8 +15,20 @@ const lineStyles = theme => ({
|
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
export const Line = props => {
|
|
17
|
-
const {
|
|
18
|
-
|
|
18
|
+
const {
|
|
19
|
+
className,
|
|
20
|
+
classes,
|
|
21
|
+
disabled,
|
|
22
|
+
correctness,
|
|
23
|
+
graphProps: { scale },
|
|
24
|
+
from,
|
|
25
|
+
to,
|
|
26
|
+
...rest
|
|
27
|
+
} = props;
|
|
28
|
+
const startPoint = { x: scale.x(from.x), y: scale.y(from.y) };
|
|
29
|
+
const endPoint = { x: scale.x(to.x), y: scale.y(to.y) };
|
|
30
|
+
const length = getDistanceBetweenTwoPoints(startPoint, endPoint);
|
|
31
|
+
|
|
19
32
|
return (
|
|
20
33
|
<line
|
|
21
34
|
className={classNames(
|
|
@@ -24,10 +37,11 @@ export const Line = props => {
|
|
|
24
37
|
classes[correctness],
|
|
25
38
|
className
|
|
26
39
|
)}
|
|
27
|
-
x1={
|
|
28
|
-
y1={
|
|
29
|
-
x2={
|
|
30
|
-
y2={
|
|
40
|
+
x1={startPoint.x}
|
|
41
|
+
y1={startPoint.y}
|
|
42
|
+
x2={endPoint.x}
|
|
43
|
+
y2={endPoint.y}
|
|
44
|
+
strokeDasharray={length - 7}
|
|
31
45
|
{...rest}
|
|
32
46
|
/>
|
|
33
47
|
);
|
package/src/utils.js
CHANGED
|
@@ -21,14 +21,14 @@ export const getTickValues = prop => {
|
|
|
21
21
|
|
|
22
22
|
while (tickVal >= prop.min && tickValues.indexOf(tickVal) < 0) {
|
|
23
23
|
tickValues.push(tickVal);
|
|
24
|
-
tickVal = Math.round((tickVal - prop.step) *
|
|
24
|
+
tickVal = Math.round((tickVal - prop.step) * 10000) / 10000;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
tickVal = Math.round(prop.step *
|
|
27
|
+
tickVal = Math.round(prop.step * 10000) / 10000;
|
|
28
28
|
|
|
29
29
|
while (tickVal <= prop.max && tickValues.indexOf(tickVal) < 0) {
|
|
30
30
|
tickValues.push(tickVal);
|
|
31
|
-
tickVal = Math.round((tickVal + prop.step) *
|
|
31
|
+
tickVal = Math.round((tickVal + prop.step) * 10000) / 10000;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
// return only ticks that are inside the min-max interval
|
|
@@ -114,7 +114,7 @@ export const getMiddleOfTwoPoints = (a, b) => ({
|
|
|
114
114
|
y: (a.y + b.y) / 2
|
|
115
115
|
});
|
|
116
116
|
|
|
117
|
-
export const roundNumber = number => parseFloat(number.toFixed(
|
|
117
|
+
export const roundNumber = number => parseFloat(number.toFixed(4));
|
|
118
118
|
|
|
119
119
|
export const sameAxes = (p1, p2) =>
|
|
120
120
|
p1 && p2 && (roundNumber(p1.x) === roundNumber(p2.x) || roundNumber(p1.y) === roundNumber(p2.y));
|
|
@@ -175,3 +175,61 @@ export const getAdjustedGraphLimits = graphProps => {
|
|
|
175
175
|
}
|
|
176
176
|
};
|
|
177
177
|
};
|
|
178
|
+
|
|
179
|
+
export const getDistanceBetweenTwoPoints = (a, b) =>
|
|
180
|
+
Math.sqrt((b.x - a.x) * (b.x - a.x) + (b.y - a.y) * (b.y - a.y));
|
|
181
|
+
|
|
182
|
+
const sortPoints = array => (array || []).sort((a, b) => a.x - b.x || a.y - b.y);
|
|
183
|
+
|
|
184
|
+
// check colliniarity of 3 points (source: https://www.geeksforgeeks.org/program-check-three-points-collinear/)
|
|
185
|
+
const checkCollinearity = (a, b, c) => (a.x - b.x) * (c.y - b.y) === (c.x - b.x) * (a.y - b.y);
|
|
186
|
+
|
|
187
|
+
// 2 lines are overlapping if all 4 points are collinear
|
|
188
|
+
const isSameLine = (markA, markB) =>
|
|
189
|
+
checkCollinearity(markA.from, markB.from, markB.to) &&
|
|
190
|
+
checkCollinearity(markA.to, markB.from, markB.to);
|
|
191
|
+
|
|
192
|
+
const isSameCircle = (markA, markB) =>
|
|
193
|
+
equalPoints(markA.root, markB.root) &&
|
|
194
|
+
getDistanceBetweenTwoPoints(markB.root, markB.edge) ===
|
|
195
|
+
getDistanceBetweenTwoPoints(markA.root, markA.edge);
|
|
196
|
+
|
|
197
|
+
export const isDuplicatedMark = (mark, marks, oldMark) => {
|
|
198
|
+
const { type, building } = mark;
|
|
199
|
+
|
|
200
|
+
if (building) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
const filteredMarks = (marks || []).filter(m => m.type === type && !m.building);
|
|
205
|
+
const index = filteredMarks.findIndex(m => isEqual(m, oldMark));
|
|
206
|
+
|
|
207
|
+
if (index !== -1) {
|
|
208
|
+
filteredMarks.splice(index, 1);
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
const duplicated = filteredMarks.find(m => {
|
|
212
|
+
if (type === 'circle' || type === 'parabola' || type === 'sine') {
|
|
213
|
+
const { root, edge } = mark;
|
|
214
|
+
|
|
215
|
+
return (
|
|
216
|
+
(equalPoints(root, m.root) && equalPoints(edge, m.edge)) ||
|
|
217
|
+
(type === 'circle' && isSameCircle(m, mark))
|
|
218
|
+
);
|
|
219
|
+
} else if (type === 'line' || type === 'ray' || type === 'segment' || type === 'vector') {
|
|
220
|
+
const { from, to } = mark;
|
|
221
|
+
|
|
222
|
+
return (
|
|
223
|
+
(equalPoints(from, m.from) && equalPoints(to, m.to)) ||
|
|
224
|
+
(equalPoints(from, m.to) && equalPoints(to, m.from)) ||
|
|
225
|
+
(type === 'line' && isSameLine(m, mark))
|
|
226
|
+
);
|
|
227
|
+
} else if (type === 'polygon') {
|
|
228
|
+
return isEqual(sortPoints(cloneDeep(mark.points)), sortPoints(cloneDeep(m.points)));
|
|
229
|
+
} else if (type === 'point') {
|
|
230
|
+
return equalPoints(m, mark);
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
return !!duplicated;
|
|
235
|
+
};
|