diff --git a/src/plugins/regions.ts b/src/plugins/regions.ts index ff95b3fe6..3b6b849bb 100644 --- a/src/plugins/regions.ts +++ b/src/plugins/regions.ts @@ -467,24 +467,26 @@ class RegionsPlugin extends BasePlugin { - 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) {