Skip to content

Commit

Permalink
fix: move scaleFactor and absolute position calculation to a more len…
Browse files Browse the repository at this point in the history
…ient check, calculating the values also for children not in child areas.

Fixes #189.
  • Loading branch information
NiklasRentzCAU committed Aug 5, 2024
1 parent 69ef274 commit 320ef47
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions packages/klighd-core/src/depth-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* http://rtsys.informatik.uni-kiel.de/kieler
*
* Copyright 2021-2023 by
* Copyright 2021-2024 by
* + Kiel University
* + Department of Computer Science
* + Real-Time and Embedded Systems Group
Expand Down Expand Up @@ -200,6 +200,23 @@ export class DepthMap {
}

const kRendering = this.findRendering(element)

const current = element.parent as KNode

// compute own absolute scale and absolute position based on parent position
const parentAbsoluteScale = (element.parent as any).properties.absoluteScale
const scaleFactor = (element.parent as any).properties['org.eclipse.elk.topdown.scaleFactor'] ?? 1
element.properties.absoluteScale = parentAbsoluteScale * scaleFactor

if (element instanceof KNode) {
element.properties.absoluteX =
(current.properties.absoluteX as number) +
element.bounds.x * (element.properties.absoluteScale as number)
element.properties.absoluteY =
(current.properties.absoluteY as number) +
element.bounds.y * (element.properties.absoluteScale as number)
}

if (
element instanceof KNode &&
kRendering &&
Expand All @@ -218,20 +235,6 @@ export class DepthMap {
entry.providingRegion.parent = entry.containingRegion
entry.containingRegion.children.push(entry.providingRegion)

const current = element.parent as KNode

// compute own absolute scale and absolute position based on parent position
const parentAbsoluteScale = (element.parent as any).properties.absoluteScale
const scaleFactor = (element.parent as any).properties['org.eclipse.elk.topdown.scaleFactor'] ?? 1
element.properties.absoluteScale = parentAbsoluteScale * scaleFactor

element.properties.absoluteX =
(current.properties.absoluteX as number) +
element.bounds.x * (element.properties.absoluteScale as number)
element.properties.absoluteY =
(current.properties.absoluteY as number) +
element.bounds.y * (element.properties.absoluteScale as number)

entry.providingRegion.absolutePosition = {
x: element.properties.absoluteX as number,
y: element.properties.absoluteY as number,
Expand Down

0 comments on commit 320ef47

Please sign in to comment.