From 4368d0d42dca8bd3310298e4f0a51c33375c2d5a Mon Sep 17 00:00:00 2001 From: Eric Bidelman Date: Tue, 4 Apr 2017 12:48:30 -0700 Subject: [PATCH 01/10] Report v2: check/x boolean audits, expand details failing audits, optimal val --- lighthouse-core/report/v2/report-renderer.js | 57 +++++++-- lighthouse-core/report/v2/report-styles.css | 120 +++++++++++++++++-- 2 files changed, 155 insertions(+), 22 deletions(-) diff --git a/lighthouse-core/report/v2/report-renderer.js b/lighthouse-core/report/v2/report-renderer.js index dbc3d6e525ce..7b648c3d4605 100644 --- a/lighthouse-core/report/v2/report-renderer.js +++ b/lighthouse-core/report/v2/report-renderer.js @@ -31,6 +31,10 @@ const RATINGS = { * @return {string} */ function calculateRating(value) { + if (typeof value === 'boolean') { + return value ? RATINGS.GOOD.label : RATINGS.POOR.label; + } + let rating = RATINGS.POOR.label; if (value >= RATINGS.GOOD.minScore) { rating = RATINGS.GOOD.label; @@ -98,19 +102,42 @@ window.ReportRenderer = class ReportRenderer { * @param {string} description * @return {!Element} */ - _renderScore(score, title, description) { - const element = this._createElement('div', 'lighthouse-score'); + _renderScore(score, title, description, auditOrCategory) { + const isAudit = 'result' in auditOrCategory; + const tagName = isAudit ? 'details' : 'div'; + + // Score template. Audits get a details dropdown. Categories don't. + const tmpContainer = this._createElement('div'); + tmpContainer.innerHTML = `
+
+ <${tagName} class="lighthouse-score__header"> + + +
+
+
+ +
`; - const value = element.appendChild(this._createElement('div', 'lighthouse-score__value')); + // Fill in the blanks. + const value = tmpContainer.querySelector('.lighthouse-score__value'); value.textContent = formatNumber(score); value.classList.add(`lighthouse-score__value--${calculateRating(score)}`); - const column = element.appendChild(this._createElement('div', 'lighthouse-score__text')); - column.appendChild(this._createElement('div', 'lighthouse-score__title')).textContent = title; - column.appendChild( - this._createElement('div', 'lighthouse-score__description')).textContent = description; + if (typeof score === 'boolean') { + value.classList.add('lighthouse-score__value--boolean'); + } - return element; + tmpContainer.querySelector('.lighthouse-score__title').textContent = title; + tmpContainer.querySelector('.lighthouse-score__description').textContent = description; + + const header = tmpContainer.querySelector('.lighthouse-score__header'); + header.open = score < 1; + if (isAudit && auditOrCategory.result.details) { + header.appendChild(this._renderDetails(auditOrCategory.result.details)); + } + + return tmpContainer.firstChild; } /** @@ -200,7 +227,8 @@ window.ReportRenderer = class ReportRenderer { */ _renderCategory(category) { const element = this._createElement('div', 'lighthouse-category'); - element.appendChild(this._renderScore(category.score, category.name, category.description)); + element.appendChild( + this._renderScore(category.score, category.name, category.description, category)); for (const audit of category.audits) { element.appendChild(this._renderAudit(audit)); } @@ -215,12 +243,15 @@ window.ReportRenderer = class ReportRenderer { const element = this._createElement('div', 'lighthouse-audit'); let title = audit.result.description; if (audit.result.displayValue) { - title += ': ' + audit.result.displayValue; + title += `: ${audit.result.displayValue}`; } - element.appendChild(this._renderScore(audit.score, title, audit.result.helpText)); - if (audit.result.details) { - element.appendChild(this._renderDetails(audit.result.details)); + if (audit.result.optimalValue) { + title += ` (target: ${audit.result.optimalValue})`; } + + element.appendChild( + this._renderScore(audit.result.score, title, audit.result.helpText, audit)); + return element; } }; diff --git a/lighthouse-core/report/v2/report-styles.css b/lighthouse-core/report/v2/report-styles.css index 8e601e34f7a7..8b3ff377fa22 100644 --- a/lighthouse-core/report/v2/report-styles.css +++ b/lighthouse-core/report/v2/report-styles.css @@ -17,6 +17,7 @@ :root { --text-font-family: '.SFNSDisplay-Regular', 'Helvetica Neue', 'Lucida Grande', sans-serif; --body-font-size: 13px; + --default-padding: 16px; --secondary-text-color: #565656; /*--accent-color: #3879d9;*/ @@ -27,8 +28,11 @@ --report-border-color: #ebebeb; - --lh-score-width: 50px; - --lh-score-margin: 20px; + --lh-score-highlight-bg: #fafafa; + --lh-score-icon-background-size: 17px; + --lh-score-margin: var(--default-padding); + --lh-audit-score-width: 35px; + --lh-category-score-width: 50px; } * { @@ -42,8 +46,9 @@ body { line-height: var(--body-line-height); } -.--hidden { - display: none !important; +/* List */ +.lighthouse-list { + font-size: smaller; } .lighthouse-list__header { @@ -70,26 +75,70 @@ body { flex: none; padding: 5px; margin-right: var(--lh-score-margin); - width: var(--lh-score-width); + width: var(--lh-audit-score-width); display: flex; justify-content: center; + align-items: center; background: var(--warning-color); color: #fff; border-radius: 2px; + position: relative; +} + +.lighthouse-score__value::after { + content: ''; + position: absolute; + left: 0; + right: 0; + top: 0; + bottom: 0; + background-color: #000; + border-radius: inherit; +} + +.lighthouse-score__value--boolean { + text-indent: -500px; +} + +/* No icon for audits with number scores. */ +.lighthouse-score__value:not(.lighthouse-score__value--boolean)::after { + content: none; } .lighthouse-score__value--good { background: var(--good-color); } +.lighthouse-score__value--good::after { + background: url('data:image/svg+xml;utf8,good') no-repeat 50% 50%; + background-size: var(--lh-score-icon-background-size); +} + .lighthouse-score__value--average { background: var(--average-color); } +.lighthouse-score__value--average::after { + background: none; + content: '!'; + background-color: var(--average-color); + color: #fff; + display: flex; + justify-content: center; + align-items: center; + font-weight: 500; + font-size: 15px; +} + .lighthouse-score__value--poor { background: var(--poor-color); } +.lighthouse-score__value--poor::after { + background: url('data:image/svg+xml;utf8,poor') no-repeat 50% 50%; + background-size: var(--lh-score-icon-background-size); +} + .lighthouse-score__title { margin-bottom: 10px; } @@ -97,12 +146,53 @@ body { .lighthouse-score__description { font-size: smaller; color: var(--secondary-text-color); + margin: var(--default-padding) 0; +} + +.lighthouse-score__header { + flex: 1; + margin-top: 2px; } +.lighthouse-score__header[open] .lighthouse-score__arrow { + transform: rotateZ(90deg); +} + +.lighthouse-score__arrow { + background: url('data:image/svg+xml;utf8,') no-repeat 50% 50%; + background-size: contain; + background-color: transparent; + width: 24px; + height: 24px; + flex: none; + margin: 0 8px 0 8px; + transition: transform 150ms ease-in-out; +} + +.lighthouse-score__snippet { + display: flex; + align-items: center; + justify-content: space-between; + cursor: pointer; + /*outline: none;*/ +} + +.lighthouse-score__snippet::-moz-list-bullet { + display: none; +} + +.lighthouse-score__snippet::-webkit-details-marker { + display: none; +} + +/*.lighthouse-score__snippet:focus .lighthouse-score__title { + outline: rgb(59, 153, 252) auto 5px; +}*/ + /* Audit */ .lighthouse-audit { - margin-top: 20px; + margin-top: var(--default-padding); } .lighthouse-audit > .lighthouse-score { @@ -121,7 +211,7 @@ body { } .lighthouse-report { - padding: 16px; + padding: var(--default-padding); } .lighthouse-category { @@ -134,14 +224,26 @@ body { padding-top: 0; } -.lighthouse-category > *:not(.lighthouse-score) { - margin-left: calc(var(--lh-score-width) + var(--lh-score-margin)); +.lighthouse-category > .lighthouse-audit { + margin-left: calc(var(--lh-category-score-width) + var(--lh-score-margin)); } .lighthouse-category > .lighthouse-score { font-size: 20px; } +.lighthouse-category > .lighthouse-score .lighthouse-score__value { + width: var(--lh-category-score-width); +} + +/* hide drop down arrow for categories and use correct pointer */ +.lighthouse-category > .lighthouse-score .lighthouse-score__arrow { + display: none; +} +.lighthouse-category > .lighthouse-score .lighthouse-score__snippet { + cursor: initial; +} + .lighthouse-category > .lighthouse-score .lighthouse-score__title { font-size: 24px; font-weight: 400; From e82eabc39c4460a18fef5eb191d5f0bda39ac2e9 Mon Sep 17 00:00:00 2001 From: Eric Bidelman Date: Tue, 4 Apr 2017 23:10:14 -0700 Subject: [PATCH 02/10] Generate DOM from `