Skip to content

Commit

Permalink
Refactor some constants
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanenkoVladimir committed Oct 21, 2022
1 parent e1765ad commit a99edd1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe("FloorLabelHelper", () => {
})

describe("isLabelNode", () => {
function createNode(isLeaf: boolean, mapNodeDepth?: number, length?: number): Node {
function createNode(isLeaf: boolean, mapNodeDepth?: number, width?: number): Node {
return {
attributes: undefined,
color: "",
Expand All @@ -48,15 +48,15 @@ describe("FloorLabelHelper", () => {
id: 0,
incomingEdgePoint: undefined,
isLeaf,
length,
length: 0,
link: "",
mapNodeDepth,
markingColor: undefined,
name: "",
outgoingEdgePoint: undefined,
path: "",
visible: false,
width: 0,
width,
x0: 0,
y0: 0,
z0: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import { Node } from "../../../../codeCharta.model"

const FOLDER_LABEL_TOO_SMALL_PARENT = 0.09

const FOLDER_LABEL_TOO_SMALL_ROOT = 0.009

export class FloorLabelHelper {
static getMapResolutionScaling(mapWidth: number) {
const { width: displayWidth } = <HTMLCanvasElement>document.getElementById("codeMapScene")
Expand All @@ -20,8 +24,8 @@ export class FloorLabelHelper {
return (
!node.isLeaf &&
node.mapNodeDepth < 3 &&
(parentNode === undefined || node.length / parentNode.length > 0.09) &&
(rootNode === undefined || node.length / rootNode.length > 0.009)
(parentNode === undefined || node.width / parentNode.width > FOLDER_LABEL_TOO_SMALL_PARENT) &&
(rootNode === undefined || node.width / rootNode.width > FOLDER_LABEL_TOO_SMALL_ROOT)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ function calculateFolderLabelPadding(
return padding_root + padding_folder * amountOfFoldersDepthOne + padding_folder * amountOfFolderDepthTwo
}

const HUGE_MAP = 15_000
const BIG_MAP = 10_000

const HUGE_MAP_FACTOR = 0.35

const BIG_MAP_FACTOR = 0.5

export function calculateTotalNodeArea(
buildingAreasIncludingPadding: number[],
hierarchyNode: HierarchyNode<CodeMapNode>,
Expand Down Expand Up @@ -197,8 +204,8 @@ export function calculateTotalNodeArea(
* Step 12:
*/

if (rootSide > 10_000) {
factor = rootSide > 15_000 ? 0.35 : 0.5
if (rootSide > BIG_MAP) {
factor = rootSide > HUGE_MAP ? HUGE_MAP_FACTOR : BIG_MAP_FACTOR

This comment has been minimized.

Copy link
@BridgeAR

BridgeAR Oct 21, 2022

Member

What about just calculating a maximum with an exact factor?

This comment has been minimized.

Copy link
@RomanenkoVladimir

RomanenkoVladimir Oct 24, 2022

Author Member

You mean scaling the factor down: something like factor = MaxMapSize/CurrentMapSize?

rootSide = Math.max(rootWidthWithDefaultPadding * factor, Math.sqrt(totalNodeArea + shiftedFolderLabelPadding ** 2) * factor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ export function getBuildingAreasWithProportionalPadding(
})
}

const HUGE_MAP = 70_000

const FOLDER_LABEL_TOO_SMALL_PARENT = 0.09

const FOLDER_LABEL_TOO_SMALL_ROUTE = 0.009

function getSquarifiedTreeMap(map: CodeMapNode, state: State): SquarifiedTreeMap {
map.children = map.children.filter(child => child.attributes[state.dynamicSettings.areaMetric] !== 0)

Expand Down Expand Up @@ -212,7 +218,7 @@ function getSquarifiedTreeMap(map: CodeMapNode, state: State): SquarifiedTreeMap
let paddingDepthZero = PADDING_APPROX_FOR_DEPTH_ZERO
let paddingDepthOne = PADDING_APPROX_FOR_DEPTH_ONE

if (rootSize > 70_000) {
if (rootSize > HUGE_MAP) {
paddingDepthOne = PADDING_APPROX_FOR_DEPTH_ONE_BIG
paddingDepthZero = PADDING_APPROX_FOR_DEPTH_ZERO_BIG
}
Expand All @@ -221,7 +227,12 @@ function getSquarifiedTreeMap(map: CodeMapNode, state: State): SquarifiedTreeMap
// Add a big padding for the first folder level (the font is bigger than in deeper levels)
return Math.max(rootSize * paddingDepthZero, DEFAULT_PADDING_FLOOR_LABEL_FROM_LEVEL_1)
}
if (node.depth > 0 && node.depth < 3 && node.value / node.parent.value > 0.09 && node.value / rootNode.value > 0.009) {
if (
node.depth > 0 &&
node.depth < 3 &&
node.value / node.parent.value > FOLDER_LABEL_TOO_SMALL_PARENT &&
node.value / rootNode.value > FOLDER_LABEL_TOO_SMALL_ROUTE
) {
return Math.max(rootSize * paddingDepthOne, DEFAULT_PADDING_FLOOR_LABEL_FROM_LEVEL_2)
}
}
Expand Down

0 comments on commit a99edd1

Please sign in to comment.