@@ -294,6 +294,7 @@ class SingleRegion extends EventEmitter<RegionEvents> {
294
294
this . content = document . createElement ( 'div' )
295
295
const isMarker = this . start === this . end
296
296
this . content . style . padding = `0.2em ${ isMarker ? 0.2 : 0.4 } em`
297
+ this . content . style . display = 'inline-block'
297
298
this . content . textContent = content
298
299
} else {
299
300
this . content = content
@@ -428,17 +429,18 @@ class RegionsPlugin extends BasePlugin<RegionsPluginEvents, RegionsPluginOptions
428
429
// Check that the label doesn't overlap with other labels
429
430
// If it does, push it down until it doesn't
430
431
const div = region . content as HTMLElement
431
- const labelLeft = div . getBoundingClientRect ( ) . left
432
- const labelWidth = region . element . scrollWidth
432
+ const box = div . getBoundingClientRect ( )
433
433
434
434
const overlap = this . regions
435
- . filter ( ( reg ) => {
436
- if ( reg === region || ! reg . content ) return false
437
- const left = reg . content . getBoundingClientRect ( ) . left
438
- const width = reg . element . scrollWidth
439
- return labelLeft < left + width && left < labelLeft + labelWidth
435
+ . map ( ( reg ) => {
436
+ if ( reg === region || ! reg . content ) return 0
437
+
438
+ const otherBox = reg . content . getBoundingClientRect ( )
439
+ if ( box . left < otherBox . left + otherBox . width && otherBox . left < box . left + box . width ) {
440
+ return otherBox . height
441
+ }
442
+ return 0
440
443
} )
441
- . map ( ( reg ) => reg . content ?. getBoundingClientRect ( ) . height || 0 )
442
444
. reduce ( ( sum , val ) => sum + val , 0 )
443
445
444
446
div . style . marginTop = `${ overlap } px`
0 commit comments