Skip to content

Commit 7422df6

Browse files
authored
misc(treemap): vary colors within bundle, update fonts (#16403)
1 parent 5e345b3 commit 7422df6

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

treemap/app/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h1 class="treemap-placeholder__heading">Lighthouse Treemap</h1>
5050
<path fill="#FF3" d="M20.5 10h7v7h-7z"/>
5151
</svg>
5252

53-
<span class="lh-header--title lh-text-dim">Lighthouse Treemap</span>
53+
<span class="lh-header--title lh-text-bold">Lighthouse Treemap</span>
5454
</div>
5555

5656
<div class="lh-header__url">

treemap/app/src/main.js

+35-10
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ class TreemapViewer {
133133
this.toggleTable(window.innerWidth >= 600);
134134
this.initListeners();
135135
this.setSelector({type: 'group', value: 'scripts'});
136+
dom.find('.lh-header--url-bytes').textContent =
137+
TreemapUtil.i18n.formatBytesWithBestUnit(this.currentTreemapRoot.resourceBytes);
136138
this.render();
137139
}
138140

@@ -468,14 +470,28 @@ class TreemapViewer {
468470
this.treemap.render(this.el);
469471
dom.find('.webtreemap-node').classList.add('webtreemap-node--root');
470472

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+
471489
this.createTable();
472490
}
473491

474492
if (rootChanged || viewChanged) {
475493
this.updateColors();
476494
this.applyActiveViewModeClass();
477-
dom.find('.lh-header--url-bytes').textContent =
478-
TreemapUtil.i18n.formatBytesWithBestUnit(this.currentTreemapRoot.resourceBytes);
479495
}
480496

481497
this.previousRenderState = {
@@ -658,28 +674,34 @@ class TreemapViewer {
658674

659675
/**
660676
* @param {number} hue
677+
* @param {number|null} depth
661678
*/
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);
664685
}
665686

666687
updateColors() {
667-
TreemapUtil.walk(this.currentTreemapRoot, node => {
688+
TreemapUtil.walk(this.currentTreemapRoot, (node, path) => {
689+
if (!node.dom) return;
690+
668691
// Color a depth one node and all children the same color.
669692
const depthOneNode = this.nodeToDepthOneNodeMap.get(node);
670693
const hue = depthOneNode &&
671694
this.getHueForD1NodeName(depthOneNode ? depthOneNode.name : node.name);
672-
const depthOneNodeColor = hue !== undefined ? this.getColorFromHue(hue) : 'white';
673-
674-
if (!node.dom) return;
675695

676696
let backgroundColor;
677697
if (this.currentViewMode.highlights) {
678698
// 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
681700
.find(highlight => TreemapUtil.pathsAreEqual(path, highlight.path));
682701
if (highlight) {
702+
const depthOneNodeColor = hue !== undefined ?
703+
this.getColorFromHue(hue, null) :
704+
'white';
683705
backgroundColor = highlight.color || depthOneNodeColor;
684706
} else {
685707
backgroundColor = 'white';
@@ -688,6 +710,9 @@ class TreemapViewer {
688710
return;
689711
}
690712

713+
const depthOneNodeColor = hue !== undefined ?
714+
this.getColorFromHue(hue, path.length) :
715+
'white';
691716
node.dom.style.backgroundColor = depthOneNodeColor;
692717

693718
// Shade the element to communicate coverage.

treemap/app/styles/treemap.css

+17-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
--color-gray-900: #212121;
1212

1313
--control-background-color: #e7f1fe;
14-
--text-color-secondary: var(--color-gray-600);
14+
--text-color-secondary: #474747;
15+
1516
--text-color: var(--color-gray-900);
1617
--text-color-active: #2a67ce;
1718
--text-color-active-secondary: #4484f3c7;
@@ -42,6 +43,11 @@ body {
4243

4344
.lh-text-dim {
4445
color: var(--text-color-secondary);
46+
font-weight: 400;
47+
}
48+
49+
.lh-text-bold {
50+
font-weight: 500;
4551
}
4652

4753
.lh-main {
@@ -96,11 +102,12 @@ body {
96102
.lh-header__logotitle {
97103
display: flex;
98104
align-items: center;
105+
font-size: 16px;
99106
}
100107

101108
.lh-topbar__logo {
102-
width: 24px;
103-
height: 24px;
109+
width: 28px;
110+
height: 28px;
104111
user-select: none;
105112
flex: none;
106113
}
@@ -211,6 +218,10 @@ header {
211218
outline: 2px solid black;
212219
}
213220

221+
.lh-treemap--view-mode--all .webtreemap-node {
222+
border: none;
223+
}
224+
214225
.lh-treemap--view-mode--unused-bytes .webtreemap-node::before {
215226
position: absolute;
216227
top: 0;
@@ -233,6 +244,9 @@ header {
233244
text-align: center;
234245
word-break: break-word;
235246
}
247+
.webtreemap-caption span {
248+
margin: 0 2px;
249+
}
236250

237251
/* Copied from viewer.css */
238252

0 commit comments

Comments
 (0)