@@ -133,6 +133,8 @@ class TreemapViewer {
133
133
this . toggleTable ( window . innerWidth >= 600 ) ;
134
134
this . initListeners ( ) ;
135
135
this . setSelector ( { type : 'group' , value : 'scripts' } ) ;
136
+ dom . find ( '.lh-header--url-bytes' ) . textContent =
137
+ TreemapUtil . i18n . formatBytesWithBestUnit ( this . currentTreemapRoot . resourceBytes ) ;
136
138
this . render ( ) ;
137
139
}
138
140
@@ -468,14 +470,28 @@ class TreemapViewer {
468
470
this . treemap . render ( this . el ) ;
469
471
dom . find ( '.webtreemap-node' ) . classList . add ( 'webtreemap-node--root' ) ;
470
472
473
+ // For the "All" selector, delete the root node caption since it duplicates the
474
+ // information in the header.
475
+ if ( this . selector . type === 'group' ) {
476
+ dom . find ( '.webtreemap-caption' , this . el ) . remove ( ) ;
477
+ }
478
+
479
+ // Format the captions.
480
+ // The webtreemap `caption` option can only return strings, but we need to
481
+ // style portions of the caption differently.
482
+ for ( const el of dom . findAll ( '.webtreemap-caption' , this . el ) ) {
483
+ const parts = ( el . textContent || '' ) . split ( ' · ' , 2 ) ;
484
+ el . textContent = '' ;
485
+ dom . createChildOf ( el , 'span' , 'lh-text-bold' ) . textContent = parts [ 0 ] ;
486
+ dom . createChildOf ( el , 'span' , 'lh-text-dim' ) . textContent = parts [ 1 ] ;
487
+ }
488
+
471
489
this . createTable ( ) ;
472
490
}
473
491
474
492
if ( rootChanged || viewChanged ) {
475
493
this . updateColors ( ) ;
476
494
this . applyActiveViewModeClass ( ) ;
477
- dom . find ( '.lh-header--url-bytes' ) . textContent =
478
- TreemapUtil . i18n . formatBytesWithBestUnit ( this . currentTreemapRoot . resourceBytes ) ;
479
495
}
480
496
481
497
this . previousRenderState = {
@@ -658,28 +674,34 @@ class TreemapViewer {
658
674
659
675
/**
660
676
* @param {number } hue
677
+ * @param {number|null } depth
661
678
*/
662
- getColorFromHue ( hue ) {
663
- return TreemapUtil . hsl ( hue , 60 , 90 ) ;
679
+ getColorFromHue ( hue , depth = null ) {
680
+ if ( depth === null ) {
681
+ return TreemapUtil . hsl ( hue , 60 , 90 ) ;
682
+ }
683
+
684
+ return TreemapUtil . hsl ( hue , 20 + depth * 5 , 90 - depth * 5 ) ;
664
685
}
665
686
666
687
updateColors ( ) {
667
- TreemapUtil . walk ( this . currentTreemapRoot , node => {
688
+ TreemapUtil . walk ( this . currentTreemapRoot , ( node , path ) => {
689
+ if ( ! node . dom ) return ;
690
+
668
691
// Color a depth one node and all children the same color.
669
692
const depthOneNode = this . nodeToDepthOneNodeMap . get ( node ) ;
670
693
const hue = depthOneNode &&
671
694
this . getHueForD1NodeName ( depthOneNode ? depthOneNode . name : node . name ) ;
672
- const depthOneNodeColor = hue !== undefined ? this . getColorFromHue ( hue ) : 'white' ;
673
-
674
- if ( ! node . dom ) return ;
675
695
676
696
let backgroundColor ;
677
697
if ( this . currentViewMode . highlights ) {
678
698
// A view can set nodes to highlight. If so, don't color anything else.
679
- const path = this . nodeToPathMap . get ( node ) ;
680
- const highlight = path && this . currentViewMode . highlights
699
+ const highlight = this . currentViewMode . highlights
681
700
. find ( highlight => TreemapUtil . pathsAreEqual ( path , highlight . path ) ) ;
682
701
if ( highlight ) {
702
+ const depthOneNodeColor = hue !== undefined ?
703
+ this . getColorFromHue ( hue , null ) :
704
+ 'white' ;
683
705
backgroundColor = highlight . color || depthOneNodeColor ;
684
706
} else {
685
707
backgroundColor = 'white' ;
@@ -688,6 +710,9 @@ class TreemapViewer {
688
710
return ;
689
711
}
690
712
713
+ const depthOneNodeColor = hue !== undefined ?
714
+ this . getColorFromHue ( hue , path . length ) :
715
+ 'white' ;
691
716
node . dom . style . backgroundColor = depthOneNodeColor ;
692
717
693
718
// Shade the element to communicate coverage.
0 commit comments