Skip to content

Commit

Permalink
Use scoreMode
Browse files Browse the repository at this point in the history
  • Loading branch information
ebidel committed Apr 5, 2017
1 parent e82eabc commit 1d04b26
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions lighthouse-core/report/v2/report-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ const RATINGS = {
/**
* Convert a score to a rating label.
* @param {!number} score
* @param {!string} precision One of 'binary', 'numeric', 'grade'.
* @param {!string} scoringMode One of Audit.SCORING_MODES.
* @return {!string}
*/
function calculateRating(score, precision) {
if (precision === 'numeric') {
function calculateRating(score, scoringMode) {
if (scoringMode === 'numeric') {
let rating = RATINGS.FAIL.label;
if (score >= RATINGS.PASS.minScore) {
rating = RATINGS.PASS.label;
} else if (score >= RATINGS.AVERAGE.minScore) {
rating = RATINGS.AVERAGE.label;
}
return rating;
} else if (precision === 'grade') {
// Not implemented yet.
}

// Treat as binary by default.
Expand Down Expand Up @@ -153,19 +151,19 @@ class ReportRenderer {

/**
* @param {!Element} tmpl Parent node to populate with values.
* @param {!{value: string, precision: string}} score
* @param {!{value: string, scoringMode: string}} score
* @param {!string} title
* @param {!string} description
* @return {!Element}
*/
_populateScore(tmpl, score, title, description) {
const rating = calculateRating(score.value, score.precision);
const rating = calculateRating(score.value, score.scoringMode);

// Fill in the blanks.
const value = tmpl.querySelector('.lighthouse-score__value');
DOM.setText(value, formatNumber(score.value));
DOM.addClass(value, `lighthouse-score__value--${rating}`,
`lighthouse-score__value--${score.precision}`);
`lighthouse-score__value--${score.scoringMode}`);

DOM.setText(tmpl.querySelector('.lighthouse-score__title'), title);
DOM.setText(tmpl.querySelector('.lighthouse-score__description'), description);
Expand All @@ -174,7 +172,7 @@ class ReportRenderer {
}

/**
* @param {!{value: string, precision: string}} score
* @param {!{value: string, scoringMode: string}} score
* @param {!string} title
* @param {!string} description
* @return {!Element}
Expand All @@ -185,7 +183,7 @@ class ReportRenderer {
}

/**
* @param {!{value: string, precision: string}} score
* @param {!{value: string, scoringMode: string}} score
* @param {!string} title
* @param {!string} description
* @return {!Element}
Expand Down Expand Up @@ -282,8 +280,7 @@ class ReportRenderer {
*/
_renderCategory(category) {
const element = this._dom.createElement('div', 'lighthouse-category');
// TODO: use precision when it's on category.score.
const score = {value: Math.round(category.score), precision: 'numeric'};
const score = {value: Math.round(category.score), scoringMode: 'numeric'};
element.appendChild(
this._renderAuditScore(score, category.name, category.description, category));
for (const audit of category.audits) {
Expand All @@ -306,9 +303,7 @@ class ReportRenderer {
title += ` (target: ${audit.result.optimalValue})`;
}

// TODO: use precision when it's on audit.score.
const score = {value: audit.score, precision: 'numeric'};

const score = {value: audit.score, scoringMode: audit.result.scoringMode};
element.appendChild(this._renderAuditScore(score, title, audit.result.helpText, audit));

// Append audit details to to header section so the entire audit is within one <details>.
Expand All @@ -326,6 +321,7 @@ class ReportRenderer {

// Exports
self.ReportRenderer = ReportRenderer;
self.DOM = DOM;
})(self);

/** @typedef {{type: string, text: string|undefined, header: DetailsJSON|undefined, items: Array<DetailsJSON>|undefined}} */
Expand Down

0 comments on commit 1d04b26

Please sign in to comment.