-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
report(category): enable all categories to show audit groups #4278
Merged
paulirish
merged 12 commits into
GoogleChrome:master
from
kdzwinel:report-category-refactor
Feb 21, 2018
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
bc4e785
Split category-renderer into three files
kdzwinel 3e5d26f
Make a11y renderer work with audits w/o categories
kdzwinel 516e1ee
clean up
kdzwinel 6948947
Add 'X failed audits' header
kdzwinel 58211d7
Remove a11y category renderer
kdzwinel a468648
Make linter happy
kdzwinel ef0e923
Fix tests.
kdzwinel 82483eb
Make closure compiler happy
kdzwinel 9be3b4c
Extract _renderFailedAuditsSection and add header only for non-groupe…
kdzwinel 12c8c26
Add missing jsdoc
kdzwinel 9f25df8
Update lighthouse viewer
kdzwinel 7b93325
compile-devtools fixes
kdzwinel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
417 changes: 118 additions & 299 deletions
417
lighthouse-core/report/v2/renderer/category-renderer.js
Large diffs are not rendered by default.
Oops, something went wrong.
191 changes: 191 additions & 0 deletions
191
lighthouse-core/report/v2/renderer/performance-category-renderer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,191 @@ | ||
/** | ||
* @license Copyright 2018 Google Inc. All Rights Reserved. | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. | ||
*/ | ||
'use strict'; | ||
|
||
/* globals self, Util, CategoryRenderer */ | ||
|
||
class PerformanceCategoryRenderer extends CategoryRenderer { | ||
/** | ||
* @param {!ReportRenderer.AuditJSON} audit | ||
* @param {number} scale | ||
* @return {!Element} | ||
*/ | ||
_renderTimelineMetricAudit(audit, scale) { | ||
const tmpl = this.dom.cloneTemplate('#tmpl-lh-timeline-metric', this.templateContext); | ||
const element = this.dom.find('.lh-timeline-metric', tmpl); | ||
element.classList.add(`lh-timeline-metric--${Util.calculateRating(audit.score)}`); | ||
|
||
const titleEl = this.dom.find('.lh-timeline-metric__title', tmpl); | ||
titleEl.textContent = audit.result.description; | ||
|
||
const valueEl = this.dom.find('.lh-timeline-metric__value', tmpl); | ||
valueEl.textContent = audit.result.displayValue; | ||
|
||
const descriptionEl = this.dom.find('.lh-timeline-metric__description', tmpl); | ||
descriptionEl.appendChild(this.dom.convertMarkdownLinkSnippets(audit.result.helpText)); | ||
|
||
if (typeof audit.result.rawValue !== 'number') { | ||
const debugStrEl = this.dom.createChildOf(element, 'div', 'lh-debug'); | ||
debugStrEl.textContent = audit.result.debugString || 'Report error: no metric information'; | ||
return element; | ||
} | ||
|
||
const sparklineBarEl = this.dom.find('.lh-sparkline__bar', tmpl); | ||
sparklineBarEl.style.width = `${audit.result.rawValue / scale * 100}%`; | ||
|
||
return element; | ||
} | ||
|
||
/** | ||
* @param {!ReportRenderer.AuditJSON} audit | ||
* @param {number} scale | ||
* @return {!Element} | ||
*/ | ||
_renderPerfHintAudit(audit, scale) { | ||
const extendedInfo = /** @type {!PerformanceCategoryRenderer.PerfHintExtendedInfo} | ||
*/ (audit.result.extendedInfo); | ||
const tooltipAttrs = {title: audit.result.displayValue}; | ||
|
||
const element = this.dom.createElement('details', [ | ||
'lh-perf-hint', | ||
`lh-perf-hint--${Util.calculateRating(audit.score)}`, | ||
'lh-expandable-details', | ||
].join(' ')); | ||
|
||
const summary = this.dom.createChildOf(element, 'summary', 'lh-perf-hint__summary ' + | ||
'lh-expandable-details__summary'); | ||
const titleEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__title'); | ||
titleEl.textContent = audit.result.description; | ||
|
||
this.dom.createChildOf(summary, 'div', 'lh-toggle-arrow', {title: 'See resources'}); | ||
|
||
if (!extendedInfo || typeof audit.result.rawValue !== 'number') { | ||
const debugStrEl = this.dom.createChildOf(summary, 'div', 'lh-debug'); | ||
debugStrEl.textContent = audit.result.debugString || 'Report error: no extended information'; | ||
return element; | ||
} | ||
|
||
const sparklineContainerEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__sparkline', | ||
tooltipAttrs); | ||
const sparklineEl = this.dom.createChildOf(sparklineContainerEl, 'div', 'lh-sparkline'); | ||
const sparklineBarEl = this.dom.createChildOf(sparklineEl, 'div', 'lh-sparkline__bar'); | ||
sparklineBarEl.style.width = audit.result.rawValue / scale * 100 + '%'; | ||
|
||
const statsEl = this.dom.createChildOf(summary, 'div', 'lh-perf-hint__stats', tooltipAttrs); | ||
const statsMsEl = this.dom.createChildOf(statsEl, 'div', 'lh-perf-hint__primary-stat'); | ||
statsMsEl.textContent = Util.formatMilliseconds(audit.result.rawValue); | ||
|
||
if (extendedInfo.value.wastedKb) { | ||
const statsKbEl = this.dom.createChildOf(statsEl, 'div', 'lh-perf-hint__secondary-stat'); | ||
statsKbEl.textContent = Util.formatNumber(extendedInfo.value.wastedKb) + ' KB'; | ||
} | ||
|
||
const descriptionEl = this.dom.createChildOf(element, 'div', 'lh-perf-hint__description'); | ||
descriptionEl.appendChild(this.dom.convertMarkdownLinkSnippets(audit.result.helpText)); | ||
|
||
if (audit.result.debugString) { | ||
const debugStrEl = this.dom.createChildOf(summary, 'div', 'lh-debug'); | ||
debugStrEl.textContent = audit.result.debugString; | ||
} | ||
|
||
if (audit.result.details) { | ||
element.appendChild(this.detailsRenderer.render(audit.result.details)); | ||
} | ||
|
||
return element; | ||
} | ||
|
||
/** | ||
* @override | ||
*/ | ||
render(category, groups) { | ||
const element = this.dom.createElement('div', 'lh-category'); | ||
this.createPermalinkSpan(element, category.id); | ||
element.appendChild(this.renderCategoryScore(category)); | ||
|
||
const metricAudits = category.audits.filter(audit => audit.group === 'perf-metric'); | ||
const metricAuditsEl = this.renderAuditGroup(groups['perf-metric'], {expandable: false}); | ||
const timelineContainerEl = this.dom.createChildOf(metricAuditsEl, 'div', | ||
'lh-timeline-container'); | ||
const timelineEl = this.dom.createChildOf(timelineContainerEl, 'div', 'lh-timeline'); | ||
|
||
let perfTimelineScale = 0; | ||
metricAudits.forEach(audit => { | ||
if (typeof audit.result.rawValue === 'number' && audit.result.rawValue) { | ||
perfTimelineScale = Math.max(perfTimelineScale, audit.result.rawValue); | ||
} | ||
}); | ||
|
||
const thumbnailAudit = category.audits.find(audit => audit.id === 'screenshot-thumbnails'); | ||
const thumbnailResult = thumbnailAudit && thumbnailAudit.result; | ||
if (thumbnailResult && thumbnailResult.details) { | ||
const thumbnailDetails = /** @type {!DetailsRenderer.FilmstripDetails} */ | ||
(thumbnailResult.details); | ||
perfTimelineScale = Math.max(perfTimelineScale, thumbnailDetails.scale); | ||
const filmstripEl = this.detailsRenderer.render(thumbnailDetails); | ||
timelineEl.appendChild(filmstripEl); | ||
} | ||
|
||
metricAudits.forEach(item => { | ||
if (item.id === 'speed-index-metric' || item.id === 'estimated-input-latency') { | ||
return metricAuditsEl.appendChild(this.renderAudit(item)); | ||
} | ||
|
||
timelineEl.appendChild(this._renderTimelineMetricAudit(item, perfTimelineScale)); | ||
}); | ||
|
||
metricAuditsEl.open = true; | ||
element.appendChild(metricAuditsEl); | ||
|
||
const hintAudits = category.audits | ||
.filter(audit => audit.group === 'perf-hint' && audit.score < 100) | ||
.sort((auditA, auditB) => auditB.result.rawValue - auditA.result.rawValue); | ||
if (hintAudits.length) { | ||
const maxWaste = Math.max(...hintAudits.map(audit => audit.result.rawValue)); | ||
const scale = Math.ceil(maxWaste / 1000) * 1000; | ||
const hintAuditsEl = this.renderAuditGroup(groups['perf-hint'], {expandable: false}); | ||
hintAudits.forEach(item => hintAuditsEl.appendChild(this._renderPerfHintAudit(item, scale))); | ||
hintAuditsEl.open = true; | ||
element.appendChild(hintAuditsEl); | ||
} | ||
|
||
const infoAudits = category.audits | ||
.filter(audit => audit.group === 'perf-info' && audit.score < 100); | ||
if (infoAudits.length) { | ||
const infoAuditsEl = this.renderAuditGroup(groups['perf-info'], {expandable: false}); | ||
infoAudits.forEach(item => infoAuditsEl.appendChild(this.renderAudit(item))); | ||
infoAuditsEl.open = true; | ||
element.appendChild(infoAuditsEl); | ||
} | ||
|
||
const passedElements = category.audits | ||
.filter(audit => (audit.group === 'perf-hint' || audit.group === 'perf-info') && | ||
audit.score === 100) | ||
.map(audit => this.renderAudit(audit)); | ||
|
||
if (!passedElements.length) return element; | ||
|
||
const passedElem = this.renderPassedAuditsSection(passedElements); | ||
element.appendChild(passedElem); | ||
return element; | ||
} | ||
} | ||
|
||
if (typeof module !== 'undefined' && module.exports) { | ||
module.exports = PerformanceCategoryRenderer; | ||
} else { | ||
self.PerformanceCategoryRenderer = PerformanceCategoryRenderer; | ||
} | ||
|
||
/** | ||
* @typedef {{ | ||
* value: { | ||
* wastedMs: (number|undefined), | ||
* wastedKb: (number|undefined), | ||
* } | ||
* }} | ||
*/ | ||
PerformanceCategoryRenderer.PerfHintExtendedInfo; // eslint-disable-line no-unused-expressions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since this is a new file we need to update https://github.com/ChromeDevTools/devtools-frontend/blob/master/front_end/audits2/module.json#L20 . Because it's missing
yarn compile-devtools
is currently failing.[Edit] somehow it passes on travis, no idea what's going on