All files / app/codeCharta/util/algorithm/streetLayout/strip verticalStrip.ts

96.77% Statements 30/31
62.5% Branches 5/8
100% Functions 4/4
96.77% Lines 30/31

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 6315x 15x 15x     15x 15x 15x     15x   1x                     1x   1x     1x 1x 1x 1x 1x   1x 1x 1x 1x 1x           1x   1x       2x 2x 2x 2x 2x   2x 2x   2x      
import Strip from "./strip"
import Rectangle from "../rectangle"
import { Vector2 } from "three"
import { CodeMapNode } from "../../../../codeCharta.model"
 
export enum VerticalOrder {
    topToBottom,
    bottomToTop
}
 
export default class VerticalStrip extends Strip {
    constructor(nodes: CodeMapNode[]) {
        super(nodes)
    }
 
    layout(
        rect: Rectangle,
        rootSize: number,
        metricName: string,
        currentTreemapDepth: number,
        margin: number,
        order: VerticalOrder = VerticalOrder.topToBottom
    ): CodeMapNode[] {
        let offsetY = rect.topLeft.y
 
        Iif (order !== VerticalOrder.topToBottom) {
            this.nodes.reverse()
        }
        const nodes = this.nodes
        const rootArea = rect.area()
        const height = rect.height
        const width = this.totalScaledSize(nodes, metricName, rootSize, rootArea) / height
        const stripNodes: CodeMapNode[] = []
 
        for (const node of nodes) {
            const nodeSize = this.scaledSize(node, rootSize, rootArea, metricName)
            const nodeHeight = width > 0 ? nodeSize / width : 0
            const newRect = new Rectangle(new Vector2(rect.topLeft.x, offsetY), width, nodeHeight)
            stripNodes.push({
                ...node,
                value: node.type === "File" ? rootSize : 0,
                rect: this.applyNodeMargin(newRect, margin),
                zOffset: currentTreemapDepth
            })
            offsetY += nodeHeight
        }
        return stripNodes
    }
 
    worstAspectRatio(nodes: CodeMapNode[], rect: Rectangle, rootSize: number, metricName: string): number {
        const height = rect.height
        const rootArea = rect.area()
        const totalSize = this.totalScaledSize(nodes, metricName, rootSize, rootArea)
        const stripMin = this.min(nodes, metricName, rootSize, rootArea)
        const stripMax = this.max(nodes, metricName, rootSize, rootArea)
 
        const heightSquared = height ** 2
        const totalSizeSquared = totalSize ** 2
 
        return Math.max((heightSquared * stripMax) / totalSizeSquared, totalSizeSquared / (heightSquared * stripMin))
    }
}