Skip to content

Commit

Permalink
Fix: regions overlap delay
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh committed May 11, 2024
1 parent 841a489 commit 7fb7c61
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions src/plugins/regions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,24 +467,26 @@ class RegionsPlugin extends BasePlugin<RegionsPluginEvents, RegionsPluginOptions
private avoidOverlapping(region: Region) {
if (!region.content) return

// Check that the label doesn't overlap with other labels
// If it does, push it down until it doesn't
const div = region.content as HTMLElement
const box = div.getBoundingClientRect()

const overlap = this.regions
.map((reg) => {
if (reg === region || !reg.content) return 0

const otherBox = reg.content.getBoundingClientRect()
if (box.left < otherBox.left + otherBox.width && otherBox.left < box.left + box.width) {
return otherBox.height
}
return 0
})
.reduce((sum, val) => sum + val, 0)
setTimeout(() => {
// Check that the label doesn't overlap with other labels
// If it does, push it down until it doesn't
const div = region.content as HTMLElement
const box = div.getBoundingClientRect()

const overlap = this.regions
.map((reg) => {
if (reg === region || !reg.content) return 0

const otherBox = reg.content.getBoundingClientRect()
if (box.left < otherBox.left + otherBox.width && otherBox.left < box.left + box.width) {
return otherBox.height
}
return 0
})
.reduce((sum, val) => sum + val, 0)

div.style.marginTop = `${overlap}px`
div.style.marginTop = `${overlap}px`
}, 10)
}

private adjustScroll(region: Region) {
Expand Down

0 comments on commit 7fb7c61

Please sign in to comment.