@@ -199,9 +199,9 @@ class TestableLineChart {
199199 <ng-container
200200 *ngFor="
201201 let datum of getCursorAwareTooltipData(
202- tooltipData ,
203- cursorLocationInDataCoord ,
204- cursorLocation
202+ tooltipDataForTesting ,
203+ cursorLocationInDataCoordForTesting ,
204+ cursorLocationForTesting
205205 )
206206 "
207207 >
@@ -233,12 +233,6 @@ class TestableLineChart {
233233 </td>
234234 </tr>
235235 </ng-container>
236- <tr class="legend" *ngIf="additionalItemsCount > 0">
237- <td colspan="100">
238- {{ additionalItemsCount }} additional
239- {{ additionalItemsCount === 1 ? 'item' : 'items' }}
240- </td>
241- </tr>
242236 </tbody>
243237 </table>
244238 </ng-template>
@@ -263,13 +257,10 @@ class TestableScalarCardLineChart {
263257 readonly valueFormatter = numberFormatter ;
264258 readonly stepFormatter = intlNumberFormatter ;
265259
266- readonly MAX_TOOLTIP_ITEMS = 5 ;
267- tooltipTotalCount = 0 ;
268-
269260 constructor ( public readonly changeDetectorRef : ChangeDetectorRef ) { }
270261
271262 getCursorAwareTooltipData (
272- tooltipData : TooltipDatum < ScalarCardSeriesMetadata , ScalarCardPoint > [ ] ,
263+ tooltipData : TooltipDatum < ScalarCardSeriesMetadata > [ ] ,
273264 cursorLocationInDataCoord : { x : number ; y : number } ,
274265 cursorLocation : { x : number ; y : number }
275266 ) {
@@ -302,31 +293,22 @@ class TestableScalarCardLineChart {
302293 scalarTooltipData [ minIndex ] . metadata . closest = true ;
303294 }
304295
305- let sortedData ;
306296 switch ( this . tooltipSort ) {
307297 case TooltipSort . ASCENDING :
308- sortedData = scalarTooltipData . sort (
309- ( a , b ) => a . dataPoint . y - b . dataPoint . y
310- ) ;
311- break ;
298+ return scalarTooltipData . sort ( ( a , b ) => a . dataPoint . y - b . dataPoint . y ) ;
312299 case TooltipSort . DESCENDING :
313- sortedData = scalarTooltipData . sort (
314- ( a , b ) => b . dataPoint . y - a . dataPoint . y
315- ) ;
316- break ;
300+ return scalarTooltipData . sort ( ( a , b ) => b . dataPoint . y - a . dataPoint . y ) ;
317301 case TooltipSort . NEAREST :
318- sortedData = scalarTooltipData . sort ( ( a , b ) => {
302+ return scalarTooltipData . sort ( ( a , b ) => {
319303 return a . metadata . distToCursorPixels - b . metadata . distToCursorPixels ;
320304 } ) ;
321- break ;
322305 case TooltipSort . NEAREST_Y :
323- sortedData = scalarTooltipData . sort ( ( a , b ) => {
306+ return scalarTooltipData . sort ( ( a , b ) => {
324307 return a . metadata . distToCursorY - b . metadata . distToCursorY ;
325308 } ) ;
326- break ;
327309 case TooltipSort . DEFAULT :
328310 case TooltipSort . ALPHABETICAL :
329- sortedData = scalarTooltipData . sort ( ( a , b ) => {
311+ return scalarTooltipData . sort ( ( a , b ) => {
330312 if ( a . metadata . displayName < b . metadata . displayName ) {
331313 return - 1 ;
332314 }
@@ -335,15 +317,7 @@ class TestableScalarCardLineChart {
335317 }
336318 return 0 ;
337319 } ) ;
338- break ;
339320 }
340-
341- this . tooltipTotalCount = sortedData . length ;
342- return sortedData . slice ( 0 , this . MAX_TOOLTIP_ITEMS ) ;
343- }
344-
345- get additionalItemsCount ( ) : number {
346- return Math . max ( 0 , this . tooltipTotalCount - this . MAX_TOOLTIP_ITEMS ) ;
347321 }
348322}
349323
@@ -487,9 +461,9 @@ describe('scalar card line chart', () => {
487461 store . overrideSelector ( selectors . getMetricsCardUserViewBox , null ) ;
488462
489463 dispatchedActions = [ ] ;
490- spyOn ( store , 'dispatch' ) . and . callFake ( ( ( action : Action ) => {
464+ spyOn ( store , 'dispatch' ) . and . callFake ( ( action : Action ) => {
491465 dispatchedActions . push ( action ) ;
492- } ) as any ) ;
466+ } ) ;
493467 } ) ;
494468
495469 afterEach ( ( ) => {
@@ -810,11 +784,6 @@ describe('scalar card line chart', () => {
810784 tooltipData : TooltipDatum [ ]
811785 ) {
812786 fixture . componentInstance . tooltipDataForTesting = tooltipData ;
813- const lineChart = fixture . debugElement . query ( Selector . LINE_CHART ) ;
814- if ( lineChart ) {
815- lineChart . componentInstance . tooltipDataForTesting = tooltipData ;
816- lineChart . componentInstance . changeDetectorRef . markForCheck ( ) ;
817- }
818787 fixture . componentInstance . changeDetectorRef . markForCheck ( ) ;
819788 }
820789
@@ -823,23 +792,11 @@ describe('scalar card line chart', () => {
823792 dataPoint ?: { x : number ; y : number } ,
824793 domPoint ?: Point
825794 ) {
826- const lineChart = fixture . debugElement . query ( Selector . LINE_CHART ) ;
827795 if ( dataPoint ) {
828796 fixture . componentInstance . dataPointForTesting = dataPoint ;
829- if ( lineChart ) {
830- lineChart . componentInstance . dataPointForTesting = dataPoint ;
831- lineChart . componentInstance . cursorLocationInDataCoordForTesting =
832- dataPoint ;
833- }
834797 }
835798 if ( domPoint ) {
836799 fixture . componentInstance . cursorLocationForTesting = domPoint ;
837- if ( lineChart ) {
838- lineChart . componentInstance . cursorLocationForTesting = domPoint ;
839- }
840- }
841- if ( lineChart ) {
842- lineChart . componentInstance . changeDetectorRef . markForCheck ( ) ;
843800 }
844801 fixture . componentInstance . changeDetectorRef . markForCheck ( ) ;
845802 }
@@ -1412,96 +1369,6 @@ describe('scalar card line chart', () => {
14121369 [ '' , 'world' , '-500' , '1,000' , anyString , anyString ] ,
14131370 ] ) ;
14141371 } ) ) ;
1415-
1416- describe ( 'tooltip item limiting and legend' , ( ) => {
1417- const colors = [
1418- '#00f' ,
1419- '#0f0' ,
1420- '#f00' ,
1421- '#ff0' ,
1422- '#0ff' ,
1423- '#f0f' ,
1424- '#fff' ,
1425- '#000' ,
1426- ] ;
1427-
1428- function buildTooltipData ( count : number ) {
1429- return Array . from ( { length : count } , ( _ , i ) =>
1430- buildTooltipDatum ( {
1431- id : `row${ i + 1 } ` ,
1432- type : SeriesType . ORIGINAL ,
1433- displayName : `Row ${ i + 1 } ` ,
1434- alias : null ,
1435- visible : true ,
1436- color : colors [ i % colors . length ] ,
1437- } )
1438- ) ;
1439- }
1440-
1441- function getLegendRow (
1442- fixture : ComponentFixture < TestableScalarCardLineChart >
1443- ) {
1444- return fixture . debugElement . query ( By . css ( 'table.tooltip tr.legend' ) ) ;
1445- }
1446-
1447- it ( 'displays all items when there are 5 or fewer' , fakeAsync ( ( ) => {
1448- store . overrideSelector ( selectors . getMetricsScalarSmoothing , 0 ) ;
1449- const fixture = createComponent ( ) ;
1450- setTooltipData ( fixture , buildTooltipData ( 5 ) ) ;
1451- fixture . detectChanges ( ) ;
1452-
1453- expect ( fixture . debugElement . queryAll ( Selector . TOOLTIP_ROW ) . length ) . toBe (
1454- 5
1455- ) ;
1456- expect ( getLegendRow ( fixture ) ) . toBeNull ( ) ;
1457- } ) ) ;
1458-
1459- it ( 'limits tooltip to 5 items when there are more than 5' , fakeAsync ( ( ) => {
1460- store . overrideSelector ( selectors . getMetricsScalarSmoothing , 0 ) ;
1461- const fixture = createComponent ( ) ;
1462- setTooltipData ( fixture , buildTooltipData ( 7 ) ) ;
1463- fixture . detectChanges ( ) ;
1464-
1465- expect ( fixture . debugElement . queryAll ( Selector . TOOLTIP_ROW ) . length ) . toBe (
1466- 5
1467- ) ;
1468- } ) ) ;
1469-
1470- it ( 'shows legend with singular text for 1 additional item' , fakeAsync ( ( ) => {
1471- store . overrideSelector ( selectors . getMetricsScalarSmoothing , 0 ) ;
1472- const fixture = createComponent ( ) ;
1473- setTooltipData ( fixture , buildTooltipData ( 6 ) ) ;
1474- fixture . detectChanges ( ) ;
1475-
1476- const legendRow = getLegendRow ( fixture ) ;
1477- expect ( legendRow ) . not . toBeNull ( ) ;
1478- expect ( legendRow . nativeElement . textContent . trim ( ) ) . toBe (
1479- '1 additional item'
1480- ) ;
1481- } ) ) ;
1482-
1483- it ( 'shows legend with plural text for multiple additional items' , fakeAsync ( ( ) => {
1484- store . overrideSelector ( selectors . getMetricsScalarSmoothing , 0 ) ;
1485- const fixture = createComponent ( ) ;
1486- setTooltipData ( fixture , buildTooltipData ( 8 ) ) ;
1487- fixture . detectChanges ( ) ;
1488-
1489- const legendRow = getLegendRow ( fixture ) ;
1490- expect ( legendRow ) . not . toBeNull ( ) ;
1491- expect ( legendRow . nativeElement . textContent . trim ( ) ) . toBe (
1492- '3 additional items'
1493- ) ;
1494- } ) ) ;
1495-
1496- it ( 'does not show legend when there are exactly 5 items' , fakeAsync ( ( ) => {
1497- store . overrideSelector ( selectors . getMetricsScalarSmoothing , 0 ) ;
1498- const fixture = createComponent ( ) ;
1499- setTooltipData ( fixture , buildTooltipData ( 5 ) ) ;
1500- fixture . detectChanges ( ) ;
1501-
1502- expect ( getLegendRow ( fixture ) ) . toBeNull ( ) ;
1503- } ) ) ;
1504- } ) ;
15051372 } ) ;
15061373
15071374 describe ( 'linked time feature integration' , ( ) => {
0 commit comments