Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

non-layered-tidy-tree-layout

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

non-layered-tidy-tree-layout - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

package.json
{
"name": "non-layered-tidy-tree-layout",
"version": "2.0.0",
"version": "2.0.1",
"description": "Draw non-layered tidy trees in linear time",

@@ -5,0 +5,0 @@ "main": "dist/non-layered-tidy-tree-layout.js",

@@ -117,2 +117,4 @@ # non-layered-tidy-tree-layout

### [2.0.1]
- Fixed bounding box calculation in `Layout.getSize` and `Layout.assignLayout` and `Layout.layout`
### [2.0.0]

@@ -119,0 +121,0 @@ - Added `Layout.layout`

@@ -32,2 +32,5 @@ import { layout, Tree } from './algorithm'

* Layout treeData.
* Return modified treeData and the bounding box encompassing all the nodes.
*
* See getSize() for more explanation.
*/

@@ -37,7 +40,5 @@ layout(treeData) {

layout(tree)
const { boundingBox, result } = this.assignLayout(tree, treeData)
const box = { left: this.bb.gap / 2, right: 0, top: 0, bottom: 0}
this.assignLayout(tree, treeData, box)
return { result: treeData, boundingBox: box }
return { result, boundingBox }
}

@@ -79,18 +80,22 @@

/**
* Return the width and height needed to draw the tree,
* without the bounding boxes.
*
* Remember after assignCoordinates, the leftest node in the tree
* already has its x set at BoundingBox.gap / 2. It is the client's
* responsibility to account for this when drawing.
* Return the bounding box that encompasses all the nodes.
* The result has a structure of
* { left: number, right: number, top: number, bottom: nubmer}.
* This is not the same bounding box concept as the `BoundingBox` class
* used to construct `Layout` class.
*/
getSize(treeData, box = null) {
const { x, y, width, height } = treeData
if (box === null) {
box = { right: 0, bottom: 0 }
box = { left: x, right: x + width, top: y, bottom: y + height }
}
box.right = Math.max(box.right, treeData.x + treeData.width)
box.bottom = Math.max(box.bottom, treeData.y + treeData.height)
box.left = Math.min(box.left, x)
box.right = Math.max(box.right, x + width)
box.top = Math.min(box.top, y)
box.bottom = Math.max(box.bottom, y + height)
for (const child of treeData.children) {
this.getSize(child, box)
if (treeData.children) {
for (const child of treeData.children) {
this.getSize(child, box)
}
}

@@ -104,3 +109,3 @@

*/
assignLayout(tree, treeData, box) {
assignLayout(tree, treeData, box = null) {
const { x, y } = this.bb.removeBoundingBox(tree.x, tree.y)

@@ -110,4 +115,10 @@ treeData.x = x

box.right = Math.max(box.right, x + treeData.width)
box.bottom = Math.max(box.bottom, y + treeData.height)
const { width, height } = treeData
if (box === null) {
box = { left: x, right: x + width, top: y, bottom: y + height }
}
box.left = Math.min(box.left, x)
box.right = Math.max(box.right, x + width)
box.top = Math.min(box.top, y)
box.bottom = Math.max(box.bottom, y + height)

@@ -117,2 +128,4 @@ for (let i = 0; i < tree.c.length; i++) {

}
return { result: treeData, boundingBox: box }
}

@@ -119,0 +132,0 @@ }

@@ -53,1 +53,49 @@ import { BoundingBox, Layout } from '../src/helpers'

})
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 })
)
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc