Skip to content
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

Add Util.renderPerformanceCategoryForPSI() #5803

Closed
paulirish opened this issue Aug 7, 2018 · 0 comments · Fixed by #5804
Closed

Add Util.renderPerformanceCategoryForPSI() #5803

paulirish opened this issue Aug 7, 2018 · 0 comments · Fixed by #5804
Assignees

Comments

@paulirish
Copy link
Member

Expose a single API for PSI to use.

something like:

/** @typedef {import('./dom.js')} DOM */
/** @typedef {import('./psi-renderer.js')} PSIReportRenderer */

/**
 * @param {string} LHresponseJsonString
 * @return {Element}
 */
function renderPerformanceCategoryForPSI(lighthouseResponse) {
  var lighthouseJson = JSON.parse(lighthouseResponse);
  const dom = new DOM(document);

  const reportLHR = JSON.parse(JSON.stringify(lighthouseJson));
  reportLHR.reportCategories = Object.values(reportLHR.categories);
  ReportRenderer.smooshAuditResultsIntoCategories(reportLHR.audits, reportLHR.reportCategories);
  const perfCategory = reportLHR.reportCategories.find(cat => cat.id === 'performance');
  const perfRenderer = new PerformanceCategoryRenderer(dom, new DetailsRenderer(dom));
  const perfEl = perfRenderer.render(perfCategory, reportLHR.categoryGroups);

  const scoreGaugeEl = dom.find('.lh-score__gauge', perfEl);
  const scoreGaugeWrapper = dom.find('.lh-gauge__wrapper', scoreGaugeEl);
  scoreGaugeWrapper.classList.add('lh-gauge__wrapper--huge');
  scoreGaugeWrapper.removeAttribute('href');
  dom.find('.lh-category-header', perfEl).remove();
  dom.find('.lh-permalink', perfEl).remove();

  const datauri = PerformanceCategoryRenderer.getLastScreenshot(perfCategory);

  return [scoreGaugeEl, perfEl, datauri];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant