1
1
import { ElementRef , Injector } from '@angular/core' ;
2
- import {
3
- PopoverBackdrop ,
4
- PopoverPositionType ,
5
- PopoverRef ,
6
- PopoverRelativePositionLocation ,
7
- PopoverService
8
- } from '@hypertrace/components' ;
2
+ import { PopoverBackdrop , PopoverPositionType , PopoverRef , PopoverService } from '@hypertrace/components' ;
9
3
import { BehaviorSubject , merge , Observable , ReplaySubject , Subject } from 'rxjs' ;
10
4
import { switchMap } from 'rxjs/operators' ;
11
5
import { TopologyEdge , TopologyNode , TopologyTooltip , TopologyTooltipOptions } from '../../topology' ;
@@ -26,12 +20,12 @@ export class TopologyTooltipPopover implements TopologyTooltip {
26
20
private readonly injector : Injector ,
27
21
private readonly popoverService : PopoverService
28
22
) {
29
- this . popoverSubject = new BehaviorSubject ( this . buildPopover ( false ) ) ;
23
+ this . popoverSubject = new BehaviorSubject ( this . buildPopover ( false , this . container ) ) ;
30
24
this . hidden$ = this . popoverSubject . pipe ( switchMap ( popover => merge ( popover . hidden$ , popover . closed$ ) ) ) ;
31
25
}
32
26
33
- public showWithNodeData ( node : TopologyNode , options : TopologyTooltipOptions = { } ) : void {
34
- this . rebuildPopoverIfNeeded ( options ) ;
27
+ public showWithNodeData ( node : TopologyNode , origin : ElementRef , options : TopologyTooltipOptions = { } ) : void {
28
+ this . rebuildPopoverIfNeeded ( origin , options ) ;
35
29
this . dataSubject . next ( {
36
30
type : 'node' ,
37
31
node : node ,
@@ -40,8 +34,8 @@ export class TopologyTooltipPopover implements TopologyTooltip {
40
34
this . popover . show ( ) ;
41
35
}
42
36
43
- public showWithEdgeData ( edge : TopologyEdge , options : TopologyTooltipOptions = { } ) : void {
44
- this . rebuildPopoverIfNeeded ( options ) ;
37
+ public showWithEdgeData ( edge : TopologyEdge , origin : ElementRef , options : TopologyTooltipOptions = { } ) : void {
38
+ this . rebuildPopoverIfNeeded ( origin , options ) ;
45
39
this . dataSubject . next ( {
46
40
type : 'edge' ,
47
41
edge : edge ,
@@ -60,17 +54,17 @@ export class TopologyTooltipPopover implements TopologyTooltip {
60
54
this . popoverSubject . complete ( ) ;
61
55
}
62
56
63
- private rebuildPopoverIfNeeded ( options : TopologyTooltipOptions ) : void {
57
+ private rebuildPopoverIfNeeded ( origin : ElementRef , options : TopologyTooltipOptions ) : void {
64
58
const modal = ! ! options . modal ;
65
59
if ( modal === this . popover . hasBackdrop ( ) ) {
66
60
return ;
67
61
}
68
62
69
63
this . popover . close ( ) ; // Close existing popover
70
- this . popoverSubject . next ( this . buildPopover ( modal ) ) ;
64
+ this . popoverSubject . next ( this . buildPopover ( ! ! options . modal , origin ) ) ;
71
65
}
72
66
73
- private buildPopover ( modal : boolean ) : PopoverRef {
67
+ private buildPopover ( modal : boolean , origin : ElementRef ) : PopoverRef {
74
68
const popover = this . popoverService . drawPopover ( {
75
69
componentOrTemplate : this . tooltipDefinition . class ,
76
70
position : {
@@ -86,9 +80,10 @@ export class TopologyTooltipPopover implements TopologyTooltip {
86
80
}
87
81
88
82
popover . updatePositionStrategy ( {
89
- type : PopoverPositionType . Relative ,
90
- locationPreferences : [ PopoverRelativePositionLocation . InsideTopLeft ] ,
91
- origin : this . container
83
+ type : PopoverPositionType . FollowMouse ,
84
+ boundingElement : modal ? origin . nativeElement : this . container . nativeElement ,
85
+ offsetX : 50 ,
86
+ offsetY : 30
92
87
} ) ;
93
88
94
89
return popover ;
0 commit comments