This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from sarbull/main
Implement Align links and arrows accordingly to nodes positions
- Loading branch information
Showing
7 changed files
with
5,202 additions
and
744 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"env": { | ||
"test": { | ||
"plugins": ["@babel/plugin-transform-modules-commonjs"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import { | ||
relativeTo, | ||
getNodeAnchorPoint, | ||
getLinkCoordinates | ||
} from './happi-graph-helpers'; | ||
|
||
/* | ||
nodeB(0, 1) | ||
. | ||
. | ||
. | ||
nodeA(0, 0) | ||
*/ | ||
test('nodeB should be above nodeA', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: 0, y: -101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "TOP", "b": "BOTTOM"}); | ||
}); | ||
|
||
/* | ||
. nodeB(1, 1) | ||
. | ||
nodeA(0, 0) . | ||
*/ | ||
test('nodeB should be above nodeA and on the right', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: 101, y: -101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "RIGHT", "b": "LEFT"}); | ||
}); | ||
|
||
/* | ||
nodeA(0, 0) . . . nodeB(1, 0) | ||
*/ | ||
test('nodeB should be on the right of nodeA', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: 101, y: 0, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "RIGHT", "b": "LEFT"}); | ||
}); | ||
|
||
/* | ||
nodeA(0, 0) . | ||
. | ||
. nodeB(1, -1) | ||
*/ | ||
test('nodeB should be below nodeA on the right', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: 100, y: -101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "RIGHT", "b": "LEFT"}); | ||
}); | ||
|
||
/* | ||
nodeA(0, 0) | ||
. | ||
. | ||
. | ||
nodeB(0, -1) | ||
*/ | ||
test('nodeB should be below nodeA', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: 0, y: 101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "BOTTOM", "b": "TOP"}); | ||
}); | ||
|
||
/* | ||
. nodeA(0, 0) | ||
. | ||
nodeB(-1, -1) . | ||
*/ | ||
test('nodeB should be below nodeA on the left', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: -101, y: 101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "LEFT", "b": "RIGHT"}); | ||
}); | ||
|
||
/* | ||
nodeB(-1, 0) . . . nodeA(0, 0) | ||
*/ | ||
test('nodeB should be on left of nodeA', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: -101, y: 0, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "LEFT", "b": "RIGHT"}); | ||
}); | ||
|
||
/* | ||
nodeB(-1, 1) . | ||
. | ||
. nodeA(0, 0) | ||
*/ | ||
test('nodeB should be above nodeA on the left', () => { | ||
let nodeA = { x: 0, y: 0, width: 100, height: 100 }; | ||
let nodeB = { x: -101, y: -101, width: 100, height: 100 }; | ||
|
||
expect(relativeTo(nodeA, nodeB)).toMatchObject({"a": "LEFT", "b": "RIGHT"}); | ||
}); | ||
|
||
test('getNodeAnchorPoint', () => { | ||
let node = { | ||
width: 100, | ||
height: 100, | ||
properties: {}, | ||
x: 0, | ||
y: 0 | ||
}; | ||
|
||
expect(getNodeAnchorPoint(node, 'TOP')).toMatchObject({ x: 50, y: 0 }); | ||
expect(getNodeAnchorPoint(node, 'BOTTOM')).toMatchObject({ x: 50, y: 100 }); | ||
expect(getNodeAnchorPoint(node, 'LEFT')).toMatchObject({ x: 0, y: 50 }); | ||
expect(getNodeAnchorPoint(node, 'RIGHT')).toMatchObject({ x: 100, y: 50 }); | ||
expect(getNodeAnchorPoint({ ...node, properties: { a: 1 } }, 'RIGHT')).toMatchObject({ x: 100, y: 50 }); | ||
}); | ||
|
||
test('getLinkCoordinates', () => { | ||
let nodeA = { width: 100, height: 100, properties: { a: 1, b: 2 }, x: 0, y: 0 }; | ||
|
||
let nodeB = { width: 100, height: 100, properties: { a: 1 }, x: 0, y: 200 }; | ||
|
||
expect(getLinkCoordinates(nodeA, nodeB, 'HORIZONTAL')).toMatchObject({ | ||
from: {x: 50, y: 100}, | ||
to: {x: 50, y: 200} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.