components/Line: refactor out abs X / Y
This commit is contained in:
parent
f3498331ad
commit
0b65918240
@ -35,6 +35,9 @@ export default function Line(props: ILineProps): JSX.Element {
|
|||||||
const oy = dir(props.startPos.y - props.endPos.y);
|
const oy = dir(props.startPos.y - props.endPos.y);
|
||||||
const d = Number(`${ox}${oy}`) as Direction;
|
const d = Number(`${ox}${oy}`) as Direction;
|
||||||
|
|
||||||
|
const absX = Math.abs(props.startPos.x - props.endPos.x);
|
||||||
|
const absY = Math.abs(props.startPos.y - props.endPos.y);
|
||||||
|
|
||||||
switch (d) {
|
switch (d) {
|
||||||
case Direction.None:
|
case Direction.None:
|
||||||
break;
|
break;
|
||||||
@ -42,59 +45,55 @@ export default function Line(props: ILineProps): JSX.Element {
|
|||||||
x = pos(props.endPos.x) - margin + offset;
|
x = pos(props.endPos.x) - margin + offset;
|
||||||
y = pos(props.endPos.y) - margin + offset;
|
y = pos(props.endPos.y) - margin + offset;
|
||||||
w = 55;
|
w = 55;
|
||||||
h = pos(props.startPos.y - props.endPos.y +1) - margin - offset * 2;
|
h = pos(absY + 1) - margin - offset * 2;
|
||||||
t = '';
|
t = '';
|
||||||
break;
|
break;
|
||||||
case Direction.Down:
|
case Direction.Down:
|
||||||
x = pos(props.startPos.x) - margin + offset;
|
x = pos(props.startPos.x) - margin + offset;
|
||||||
y = pos(props.startPos.y) - margin + offset;
|
y = pos(props.startPos.y) - margin + offset;
|
||||||
w = 55;
|
w = 55;
|
||||||
h = pos(props.endPos.y - props.startPos.y +1) - margin - offset * 2;
|
h = pos(absY + 1) - margin - offset * 2;
|
||||||
t = '';
|
t = '';
|
||||||
break;
|
break;
|
||||||
case Direction.Left:
|
case Direction.Left:
|
||||||
x = pos(props.endPos.x) - margin + offset;
|
x = pos(props.endPos.x) - margin + offset;
|
||||||
y = pos(props.endPos.y) - margin + offset;
|
y = pos(props.endPos.y) - margin + offset;
|
||||||
w = pos(props.startPos.x - props.endPos.x +1) - margin - offset * 2;
|
w = pos(absX + 1) - margin - offset * 2;
|
||||||
h = 55;
|
h = 55;
|
||||||
t = '';
|
t = '';
|
||||||
break;
|
break;
|
||||||
case Direction.LeftUp:
|
case Direction.LeftUp:
|
||||||
x = pos(props.endPos.x-1) + margin;
|
x = pos(props.endPos.x-1) + margin;
|
||||||
y = pos(props.endPos.y) - margin + offset;
|
y = pos(props.endPos.y) - margin + offset;
|
||||||
w = props.startPos.x - props.endPos.x;
|
w = pos(absX) + (margin - offset * 2) + absX * (margin - offset * 2);
|
||||||
w = pos(w) + (margin - offset * 2) + w * (margin - offset * 2);
|
|
||||||
h = 55;
|
h = 55;
|
||||||
t = `translate(29,-14),rotate(45, ${x-offset}, ${y+offset})`
|
t = `translate(29,-14),rotate(45, ${x-offset}, ${y+offset})`
|
||||||
break;
|
break;
|
||||||
case Direction.LeftDown:
|
case Direction.LeftDown:
|
||||||
x = pos(props.endPos.x-1) + margin;
|
x = pos(props.endPos.x-1) + margin;
|
||||||
y = pos(props.endPos.y) - margin + offset;
|
y = pos(props.endPos.y) - margin + offset;
|
||||||
w = props.startPos.x - props.endPos.x;
|
w = pos(absX) + (margin - offset * 2) + absX * (margin - offset * 2);
|
||||||
w = pos(w) + (margin - offset * 2) + w * (margin - offset * 2);
|
|
||||||
h = 55;
|
h = 55;
|
||||||
t = `translate(-12,27),rotate(-45, ${x+offset}, ${y-offset})`
|
t = `translate(-12,27),rotate(-45, ${x+offset}, ${y-offset})`
|
||||||
break;
|
break;
|
||||||
case Direction.Right:
|
case Direction.Right:
|
||||||
x = pos(props.startPos.x) - margin + offset;
|
x = pos(props.startPos.x) - margin + offset;
|
||||||
y = pos(props.startPos.y) - margin + offset;
|
y = pos(props.startPos.y) - margin + offset;
|
||||||
w = pos(props.endPos.x - props.startPos.x +1) - margin - offset * 2;
|
w = pos(absX + 1) - margin - offset * 2;
|
||||||
h = 55;
|
h = 55;
|
||||||
t = '';
|
t = '';
|
||||||
break;
|
break;
|
||||||
case Direction.RightUp:
|
case Direction.RightUp:
|
||||||
x = pos(props.startPos.x) - margin + offset;
|
x = pos(props.startPos.x) - margin + offset;
|
||||||
y = pos(props.startPos.y) - margin + offset;
|
y = pos(props.startPos.y) - margin + offset;
|
||||||
w = props.endPos.x - props.startPos.x;
|
w = pos(absX) + (margin - offset * 2) + absX * (margin - offset * 2);
|
||||||
w = pos(w) + (margin - offset * 2) + w * (margin - offset * 2);
|
|
||||||
h = 55;
|
h = 55;
|
||||||
t = `translate(-9, 29),rotate(-45, ${x-offset}, ${y+offset})`
|
t = `translate(-9, 29),rotate(-45, ${x-offset}, ${y+offset})`
|
||||||
break;
|
break;
|
||||||
case Direction.RightDown:
|
case Direction.RightDown:
|
||||||
x = pos(props.startPos.x) - margin + offset;
|
x = pos(props.startPos.x) - margin + offset;
|
||||||
y = pos(props.startPos.y) - margin + offset;
|
y = pos(props.startPos.y) - margin + offset;
|
||||||
w = props.endPos.x - props.startPos.x;
|
w = pos(absX) + (margin - offset * 2) + absX * (margin - offset * 2);
|
||||||
w = pos(w) + (margin - offset * 2) + w * (margin - offset * 2);
|
|
||||||
h = 55;
|
h = 55;
|
||||||
t = `translate(27, -14),rotate(45, ${x-offset}, ${y+offset})`
|
t = `translate(27, -14),rotate(45, ${x-offset}, ${y+offset})`
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user