@@ -67,6 +67,7 @@ import {
67
67
import {
68
68
DataSeries ,
69
69
DataSeriesMetadataMap ,
70
+ Point ,
70
71
RendererType ,
71
72
ScaleType ,
72
73
TooltipDatum ,
@@ -115,7 +116,8 @@ import {VisLinkedTimeSelectionWarningModule} from './vis_linked_time_selection_w
115
116
[ngTemplateOutlet]="tooltipTemplate"
116
117
[ngTemplateOutletContext]="{
117
118
data: tooltipDataForTesting,
118
- cursorLocationInDataCoord: cursorLocForTesting
119
+ cursorLocationInDataCoord: cursorLocationInDataCoordForTesting,
120
+ cursorLocation: cursorLocationForTesting
119
121
}"
120
122
></ng-container>
121
123
<ng-container
@@ -165,10 +167,14 @@ class TestableLineChart {
165
167
@Output ( )
166
168
onViewBoxOverridden = new EventEmitter < boolean > ( ) ;
167
169
168
- // This input does not exist on real line-chart and is devised to make tooltipTemplate
170
+ // These inputs do not exist on the real line-chart and is devised to make tooltipTemplate
169
171
// testable without using the real implementation.
170
172
@Input ( ) tooltipDataForTesting : TooltipDatum [ ] = [ ] ;
171
- @Input ( ) cursorLocForTesting : { x : number ; y : number } = { x : 0 , y : 0 } ;
173
+ @Input ( ) cursorLocationInDataCoordForTesting : { x : number ; y : number } = {
174
+ x : 0 ,
175
+ y : 0 ,
176
+ } ;
177
+ @Input ( ) cursorLocationForTesting : { x : number ; y : number } = { x : 0 , y : 0 } ;
172
178
173
179
private isViewBoxOverridden = new ReplaySubject < boolean > ( 1 ) ;
174
180
@@ -1142,7 +1148,8 @@ describe('scalar card', () => {
1142
1148
describe ( 'tooltip' , ( ) => {
1143
1149
function buildTooltipDatum (
1144
1150
metadata ?: ScalarCardSeriesMetadata ,
1145
- point : Partial < ScalarCardPoint > = { }
1151
+ point : Partial < ScalarCardPoint > = { } ,
1152
+ pixelLocation : Point = { x : 0 , y : 0 }
1146
1153
) : TooltipDatum < ScalarCardSeriesMetadata , ScalarCardPoint > {
1147
1154
return {
1148
1155
id : metadata ?. id ?? 'a' ,
@@ -1165,6 +1172,7 @@ describe('scalar card', () => {
1165
1172
relativeTimeInMs : 0 ,
1166
1173
...point ,
1167
1174
} ,
1175
+ pixelLocation,
1168
1176
} ;
1169
1177
}
1170
1178
@@ -1180,11 +1188,19 @@ describe('scalar card', () => {
1180
1188
1181
1189
function setCursorLocation (
1182
1190
fixture : ComponentFixture < ScalarCardContainer > ,
1183
- cursorLocInDataCoord ?: { x : number ; y : number }
1191
+ cursorLocInDataCoord ?: { x : number ; y : number } ,
1192
+ cursorLocationInPixels ?: Point
1184
1193
) {
1185
1194
const lineChart = fixture . debugElement . query ( Selector . LINE_CHART ) ;
1186
1195
1187
- lineChart . componentInstance . cursorLocForTesting = cursorLocInDataCoord ;
1196
+ if ( cursorLocInDataCoord ) {
1197
+ lineChart . componentInstance . cursorLocationInDataCoordForTesting =
1198
+ cursorLocInDataCoord ;
1199
+ }
1200
+ if ( cursorLocationInPixels ) {
1201
+ lineChart . componentInstance . cursorLocationForTesting =
1202
+ cursorLocationInPixels ;
1203
+ }
1188
1204
lineChart . componentInstance . changeDetectorRef . markForCheck ( ) ;
1189
1205
}
1190
1206
@@ -1616,6 +1632,10 @@ describe('scalar card', () => {
1616
1632
y : 1000 ,
1617
1633
value : 1000 ,
1618
1634
wallTime : new Date ( '2020-01-01' ) . getTime ( ) ,
1635
+ } ,
1636
+ {
1637
+ x : 0 ,
1638
+ y : 100 ,
1619
1639
}
1620
1640
) ,
1621
1641
buildTooltipDatum (
@@ -1634,6 +1654,10 @@ describe('scalar card', () => {
1634
1654
y : - 500 ,
1635
1655
value : - 500 ,
1636
1656
wallTime : new Date ( '2020-12-31' ) . getTime ( ) ,
1657
+ } ,
1658
+ {
1659
+ x : 50 ,
1660
+ y : 0 ,
1637
1661
}
1638
1662
) ,
1639
1663
buildTooltipDatum (
@@ -1652,26 +1676,30 @@ describe('scalar card', () => {
1652
1676
y : 3 ,
1653
1677
value : 3 ,
1654
1678
wallTime : new Date ( '2021-01-01' ) . getTime ( ) ,
1679
+ } ,
1680
+ {
1681
+ x : 1000 ,
1682
+ y : 30 ,
1655
1683
}
1656
1684
) ,
1657
1685
] ) ;
1658
- setCursorLocation ( fixture , { x : 500 , y : - 100 } ) ;
1686
+ setCursorLocation ( fixture , { x : 500 , y : - 100 } , { x : 50 , y : 0 } ) ;
1659
1687
fixture . detectChanges ( ) ;
1660
1688
assertTooltipRows ( fixture , [
1661
1689
[ '' , 'Row 2' , '-500' , '1,000' , anyString , anyString ] ,
1662
1690
[ '' , 'Row 1' , '1000' , '0' , anyString , anyString ] ,
1663
1691
[ '' , 'Row 3' , '3' , '10,000' , anyString , anyString ] ,
1664
1692
] ) ;
1665
1693
1666
- setCursorLocation ( fixture , { x : 500 , y : 600 } ) ;
1694
+ setCursorLocation ( fixture , { x : 500 , y : 600 } , { x : 50 , y : 80 } ) ;
1667
1695
fixture . detectChanges ( ) ;
1668
1696
assertTooltipRows ( fixture , [
1669
1697
[ '' , 'Row 1' , '1000' , '0' , anyString , anyString ] ,
1670
1698
[ '' , 'Row 2' , '-500' , '1,000' , anyString , anyString ] ,
1671
1699
[ '' , 'Row 3' , '3' , '10,000' , anyString , anyString ] ,
1672
1700
] ) ;
1673
1701
1674
- setCursorLocation ( fixture , { x : 10000 , y : - 100 } ) ;
1702
+ setCursorLocation ( fixture , { x : 10000 , y : - 100 } , { x : 1000 , y : 20 } ) ;
1675
1703
fixture . detectChanges ( ) ;
1676
1704
assertTooltipRows ( fixture , [
1677
1705
[ '' , 'Row 3' , '3' , '10,000' , anyString , anyString ] ,
@@ -1680,7 +1708,7 @@ describe('scalar card', () => {
1680
1708
] ) ;
1681
1709
1682
1710
// Right between row 1 and row 2. When tied, original order is used.
1683
- setCursorLocation ( fixture , { x : 500 , y : 250 } ) ;
1711
+ setCursorLocation ( fixture , { x : 500 , y : 250 } , { x : 25 , y : 50 } ) ;
1684
1712
fixture . detectChanges ( ) ;
1685
1713
assertTooltipRows ( fixture , [
1686
1714
[ '' , 'Row 1' , '1000' , '0' , anyString , anyString ] ,
0 commit comments