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

report: add PWA category badge gauge #6526

Merged
merged 5 commits into from
Nov 17, 2018
Merged

report: add PWA category badge gauge #6526

merged 5 commits into from
Nov 17, 2018

Conversation

brendankenny
Copy link
Member

@brendankenny brendankenny commented Nov 12, 2018

Part of #6395

A bit hacked together, but it works. Work in earlier PRs keeps the hackiness fairly well contained, though, and it should be easy to revise what's in this initial draft.

Currently

  • needs tests
  • the svg needs optimizing (a naive optimization eliminated the gradients, so skipped for now)
  • there should be a cleaner way to reveal score badges or portions of the score badges
  • (maybe eventually) needs a rethink of css classes (e.g. should the "gauge" be anything in that spot, or just the gauge-like gauge. If so, what should that spot be called)

screen shot 2018-11-11 at 19 24 20

screen shot 2018-11-11 at 20 29 50

margin: 0 4px;
}

.lh-scores-header .lh-gauge--pwa__wrapper {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it would be nice if this could be .lh-gauge__wrapper:last-of-type, but it doesn't work on classes. Open to other ways to do this that don't rely on the pwa wrapper being where it is

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we really care if it's an .lh-gauge?
couldn't we just do .lh-scores-header > :last-child ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couldn't we just do .lh-scores-header > :last-child ?

we can't because when you don't run the PWA category you don't want a vertical line before the next last-child in line once the PWA gauge is gone :)

Maybe we should make an explicit divider line class, but this seems fine for now (if/when we ever get another special score gauge we can reevaluate)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course :) forgot about running without pwa.

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

flushing the two comments I had before I had to run out the door, will be back later but screenshots look nice! :D

*/
renderScoreGauge(category) {
// Defer to parent-gauge style if category error.
if (category.score === null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't decide if I like the explicit documentation that score === null when it fails or would prefer to play it safe with Number.isFinite, any insight you used to share with me?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any insight you used to share with me?

I used it just because that's what categoryRenderer.renderScoreGauge uses :)

Looking more into it now, null is what ReportScoring.arithmeticMean returns in case of error, and combined with the fact that we haven't seen any issues with it for plain old categoryRenderer...seems fine?


const passingGroupIds = this._getPassingGroupIds(category.auditRefs);
let className = 'lh-badged-na';
if (passingGroupIds.has('pwa-fast-reliable')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😆

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify the laughing was on this whole nesting business we need to do, not just this line :)

FWIW, I'd probably find something like

const isReliable = passingGroupIds.has()
const isInstallable = ...
const isOptimized = ...

if (isReliable && isInstallable && isOptimized) className = 'lh-badged-all'
else if (isReliable && isInstallable) className = 'lh-badged-reliable-installable'
...

a bit easier to read, but no biggie

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, that is significantly easier to read. I was very tired when I wrote all that is my only excuse :)

While you were writing this I was just working on a more css-centric version. What do you think of this instead?

The looooong class names are the only downside. Maybe we can short circuit the BEMness to pick short names

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

didn't realize most of the lines were SVG and I was mostly done already sorry! :)


const passingGroupIds = this._getPassingGroupIds(category.auditRefs);
let className = 'lh-badged-na';
if (passingGroupIds.has('pwa-fast-reliable')) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to clarify the laughing was on this whole nesting business we need to do, not just this line :)

FWIW, I'd probably find something like

const isReliable = passingGroupIds.has()
const isInstallable = ...
const isOptimized = ...

if (isReliable && isInstallable && isOptimized) className = 'lh-badged-all'
else if (isReliable && isInstallable) className = 'lh-badged-reliable-installable'
...

a bit easier to read, but no biggie

<template id="tmpl-lh-gauge--pwa">
<style>
.lh-gauge--pwa {
width: calc(3 * var(--header-font-size));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there significance to this 3 or just feels about right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there significance to this 3 or just feels about right?

I copied this over from .lh-gauge since lh-gauge (and its modifiers) had a bunch of svg-score-gauge-specific properties. Basically it just means 60px :)

This is one of the properties that make it seem we need a more general "this is a round-ish thing representing the overall category score" name that includes both the gauge we've had and the badge container (though we could just stick with lh-gauge and move the current gauge stuff down inside).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lh-gauge defines --circle-size: calc(3 * var(--header-font-size)); in its wrapper.

seems good to either do that here too or to move the circle-size into the .lh-vars block.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems good to either do that here too or to move the circle-size into the .lh-vars block.

after discussion, moved into .lh-vars block. It makes sense that the gauges should stay the same size and it turns out we were using the same number in a few other places that could benefit from a single definition

display: none;
}

.lh-badged-na .lh-gauge--pwa--na {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are all just lining up the lh-badged-* with lh-gauge--pwa--* right? since the intention is all identical and we would ideally replace something simpler maybe it does make sense to combine them?

@hwikyounglee
Copy link

💖

Thanks @brendankenny!

I think we can use a few more pixels above the sub group title (to make the total pixel 24px).

image

💖

Copy link
Member

@paulirish paulirish left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm % diff handling of the circle-size custom prop

const categoryGauge = renderer.renderScoreGauge(category);

// Group gauges that aren't default at the end of the header
if (renderer.renderScoreGauge === categoryRenderer.renderScoreGauge) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm! how does equality on a function work? seems fine though i'm curious.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how does equality on a function work?

it's (shared) on the root prototype, so if a renderer descends from CategoryRenderer but doesn't override renderScoreGauge it'll just be the same function object.

I was originally going to do something more complicated with verifying which prototype the function that will be called was defined on, but it doesn't buy anything extra, and considering this is the only special gauge for now, anything much more complicated than a specialized check directly for the pwa renderer would be compounding the silliness.

<template id="tmpl-lh-gauge--pwa">
<style>
.lh-gauge--pwa {
width: calc(3 * var(--header-font-size));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lh-gauge defines --circle-size: calc(3 * var(--header-font-size)); in its wrapper.

seems good to either do that here too or to move the circle-size into the .lh-vars block.

const tmpl = this.dom.cloneTemplate('#tmpl-lh-gauge--pwa', this.templateContext);
const wrapper = /** @type {HTMLAnchorElement} */ (this.dom.find('.lh-gauge--pwa__wrapper',
tmpl));
wrapper.href = `#${category.id}`;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should also clarify the state in a tooltip.

We could do with a full lh-tooltip and bulleted list, but here's a minimal [title] example:
image

Regardless, I don't think it should hold up this PR. (which is indeed v clean)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, it feels like it should have a tooltip. I'll add it to the list

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative idea:
Fast and reliable: 3/3, Installable: 3/3, PWA Optimized: 4/6

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 this pull request may close these issues.

5 participants