config redirect

This commit is contained in:
Nuno Coração
2023-01-29 22:30:24 +00:00
parent 17557c7d73
commit 5fb4bd8083
9905 changed files with 1258996 additions and 36355 deletions
+100
View File
@@ -0,0 +1,100 @@
import { BoundingBox, Layout } from '../src/helpers'
test('bounding box', () => {
const bb = new BoundingBox(10, 20)
expect(bb.addBoundingBox(100, 200)).toEqual(
expect.objectContaining({
width: 110,
height: 220
})
)
expect(bb.removeBoundingBox(10, 120)).toEqual(
expect.objectContaining({
x: 15,
y: 120
})
)
})
test('Layout class', () => {
const data = {
width: 10,
height: 10,
children: [
{
width: 10,
height: 10,
children: [{ width: 150, height: 10, children: [] }]
},
{ width: 10, height: 10, children: [] },
{ width: 10, height: 10, children: [] },
{ width: 10, height: 10, children: [] },
{ width: 10, height: 20, children: [] }
]
}
const bb = new BoundingBox(10, 10)
const layout = new Layout(bb)
const { boundingBox } = layout.layout(data)
expect(data).toEqual(expect.objectContaining({ x: 120, y: 0 }))
expect(data.children[0]).toEqual(expect.objectContaining({ x: 75, y: 20 }))
expect(data.children[1]).toEqual(expect.objectContaining({ x: 97.5, y: 20 }))
expect(data.children[2]).toEqual(expect.objectContaining({ x: 120, y: 20 }))
expect(data.children[3]).toEqual(expect.objectContaining({ x: 142.5, y: 20 }))
expect(data.children[4]).toEqual(expect.objectContaining({ x: 165, y: 20 }))
expect(data.children[0].children[0]).toEqual(
expect.objectContaining({ x: 5, y: 40 })
)
expect(boundingBox).toEqual(
expect.objectContaining({ left: 5, right: 175, top: 0, bottom: 50 })
)
})
test('Big root, small child', () => {
const t = {
id: 0,
width: 100,
height: 50,
children: [{ id: 1, width: 50, height: 50 }]
}
const l = new Layout(new BoundingBox(0, 0))
const { result, boundingBox } = l.layout(t)
expect(result).toEqual(expect.objectContaining({ x: -25, y: 0 }))
expect(result.children[0]).toEqual(expect.objectContaining({ x: 0, y: 50 }))
expect(boundingBox).toEqual(
expect.objectContaining({ left: -25, right: 75, top: 0, bottom: 100 })
)
})
describe('Layout.getSize', () => {
test('big root, small child', () => {
const t = {
id: 0,
width: 100,
height: 50,
children: [{ id: 1, width: 50, height: 50 }]
}
const l = new Layout(new BoundingBox(0, 0))
l.layout(t)
const bb = l.getSize(t)
expect(bb).toEqual(
expect.objectContaining({ left: -25, right: 75, top: 0, bottom: 100 })
)
})
test('small root, big child', () => {
const t = {
id: 0,
width: 50,
height: 50,
children: [{ id: 1, width: 100, height: 50 }]
}
const l = new Layout(new BoundingBox(20, 20))
l.layout(t)
const bb = l.getSize(t)
expect(bb).toEqual(
expect.objectContaining({ left: 10, right: 110, top: 0, bottom: 120 })
)
})
})
+25
View File
@@ -0,0 +1,25 @@
import { Tree, layout } from '../src/algorithm'
export default {
convert(treeNode) {
if (treeNode === null) return null
let children = []
for (let i = 0; i < treeNode.children.length; i++) {
children[i] = this.convert(treeNode.children[i])
}
return new Tree(treeNode.width, treeNode.height, treeNode.y, children)
},
convertBack(converted, root) {
root.x = converted.x
for (let i = 0; i < converted.c.length; i++) {
this.convertBack(converted.c[i], root.children[i])
}
},
runOnConverted(root) {
layout(root)
}
}
+17
View File
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Test module in &gt;script&lt; tag</title>
</head>
<body>
<script src="../dist/non-layered-tidy-tree-layout.js"></script>
<script>
console.log(nonLayeredTidyTreeLayout);
console.log(nonLayeredTidyTreeLayout.Tree);
console.log(nonLayeredTidyTreeLayout.layout);
</script>
</body>
</html>
+5
View File
@@ -0,0 +1,5 @@
test('nonLayeredTidyTreeLayout exists', () => {
const { layout, Tree } = require('../dist/non-layered-tidy-tree-layout')
expect(layout).toBeTruthy()
expect(Tree).toBeTruthy()
})
+63
View File
@@ -0,0 +1,63 @@
import { layout, Tree } from '../src/algorithm'
import TreeNode from './tree-node'
import Marshall from './marshall'
test('layout tree with one node', () => {
const tree = new Tree(10, 5, 0, [])
layout(tree)
expect(tree).toEqual(expect.objectContaining({ x: 0, y: 0 }))
})
test('layout tree with 2 nodes', () => {
const child = new TreeNode(20, 10)
const root = new TreeNode(10, 4)
root.addChild(child)
const tree = Marshall.convert(root)
layout(tree)
Marshall.convertBack(tree, root)
expect(root).toEqual(expect.objectContaining({ x: 5, y: 0 }))
expect(child).toEqual(expect.objectContaining({ x: 0, y: 4 }))
})
test('layout tree with 3 nodes', () => {
const c1 = new TreeNode(10, 30)
const c2 = new TreeNode(20, 10)
const root = new TreeNode(40, 10)
root.addChild(c1)
root.addChild(c2)
const tree = Marshall.convert(root)
layout(tree)
Marshall.convertBack(tree, root)
expect(root).toEqual(expect.objectContaining({ x: -5, y: 0 }))
expect(c1).toEqual(expect.objectContaining({ x: 0, y: 10 }))
expect(c2).toEqual(expect.objectContaining({ x: 10, y: 10 }))
})
test('reflection of the tree is the mirror image of the original tree', () => {
const n1 = new TreeNode(10, 10)
const n2 = new TreeNode(10, 10)
const n3 = new TreeNode(10, 10)
const n4 = new TreeNode(10, 10)
const n5 = new TreeNode(10, 10)
const n6 = new TreeNode(10, 20)
const n7 = new TreeNode(150, 10)
n1.addChild(n2)
n1.addChild(n3)
n1.addChild(n4)
n1.addChild(n5)
n1.addChild(n6)
n2.addChild(n7)
const tree = Marshall.convert(n1)
layout(tree)
Marshall.convertBack(tree, n1)
expect(n1).toEqual(expect.objectContaining({ x: 110, y: 0 }))
expect(n2).toEqual(expect.objectContaining({ x: 70, y: 10 }))
expect(n3).toEqual(expect.objectContaining({ x: 90, y: 10 }))
expect(n4).toEqual(expect.objectContaining({ x: 110, y: 10 }))
expect(n5).toEqual(expect.objectContaining({ x: 130, y: 10 }))
expect(n6).toEqual(expect.objectContaining({ x: 150, y: 10 }))
expect(n7).toEqual(expect.objectContaining({ x: 0, y: 20 }))
})
+24
View File
@@ -0,0 +1,24 @@
export default class TreeNode {
constructor(width, height) {
this.width = width
this.height = height
this.x = 0
this.y = 0
this.children = []
}
addChild(child) {
child.y = this.y + this.height
this.children.push(child)
}
randExpand(tree) {
tree.y += this.height
const i = Math.floor(Math.random() * (this.children.length + 1))
if (i === this.children.length) {
this.children.push(tree)
} else {
this.children[i].randExpand(tree)
}
}
}