-
Notifications
You must be signed in to change notification settings - Fork 129
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
adopt the new classes for plot's big numbers #554
Conversation
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
<div class="card"> | ||
<h2>Rolling 28-day Active users</h2> | ||
<span class="big">${summary[summary.length-1].active28d.toLocaleString("en-US")}</span> | ||
<span class="small">${((v) => html`<span class="${v > 0 ? "green" : v < 0 ? "red" : ""}">${bigNumber(v)} ${v > 0 ? "↗︎" : v < 0 ? "↘︎" : ""}`)(getCompareValue(summary, 'active28d'))}</span> |
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.
I think this has too much complexity to be practical. We need to find a way to encapsulate this.
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.
I've put the logic in a function of (value, format).
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.
I don’t see the change here. It looks like you did this for the Plot example but not the Google Analytics one. 😓
Also, I don’t think this really solves the problem I raised because someone still has to find the trend
function you wrote — we need to think about how to incorporate a practical solution “in the box” (in the standard library or default CSS).
(And also I want inline expressions for attributes #32 or even better server-side rendering #234…)
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.
I found lots more to clean up. We should run Prettier on this stuff, I guess, if it’s too hard to maintain style manually.
I think the bigger issue is that I want some more encapsulation for the green +42% ↗︎. It feels to me like something people will often want, and the fiddly combination of setting the class dynamically and finding the Unicode arrows seems impractical (given that this use case is very much our bread and butter).
<div class="card"> | ||
<h2>Rolling 28-day Active users</h2> | ||
<span class="big">${summary[summary.length-1].active28d.toLocaleString("en-US")}</span> | ||
<span class="small">${((v) => html`<span class="${v > 0 ? "green" : v < 0 ? "red" : ""}">${bigNumber(v)} ${v > 0 ? "↗︎" : v < 0 ? "↘︎" : ""}`)(getCompareValue(summary, 'active28d'))}</span> |
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.
I don’t see the change here. It looks like you did this for the Plot example but not the Google Analytics one. 😓
Also, I don’t think this really solves the problem I raised because someone still has to find the trend
function you wrote — we need to think about how to incorporate a practical solution “in the box” (in the standard library or default CSS).
(And also I want inline expressions for attributes #32 or even better server-side rendering #234…)
examples/plot/docs/index.md
Outdated
@@ -21,6 +20,9 @@ const stars = FileAttachment("data/plot-github-stars.csv").csv({typed: true}); | |||
const lastMonth = d3.utcDay.offset(today, -28); | |||
const lastWeek = d3.utcDay.offset(today, -7); | |||
const x = {domain: [start, today]}; | |||
function trend(value, format) { |
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.
function trend(value, format) { | |
function trend(value, format) { |
This sort of function should have a default format, or better, allow the format to be optionally specified as a function (and promote to a function when a string). If I wanted it to be reusable, I’d probably also take an options object instead of format
, and then allow things like the positive/negative/zero class to be specified, as well as the positive/negative/zero suffix.
examples/plot/docs/index.md
Outdated
</div> | ||
<div class="card"> | ||
<h2>Opened issues, 28d</h2> | ||
<span class="big">${d3.format(",")(d3.sum(issues, (d) => !d.pull_request && d.open >= lastMonth))}</span> |
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.
I’m not a big fan of the d3.format(",")
repetition here. And I’ve been thinking that d3-format is mostly deprecated anyway in favor of number.toLocaleString.
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
Co-authored-by: Mike Bostock <mbostock@gmail.com>
- adopt toLocaleString
I've added a trend component (for now it is local to each example; should we adopt it as part of stdlib yet?), and simplified things a bit. |
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.
Is it missing the small
class on the trend now? Looks good otherwise.
I have not seen a difference with or without |
It’s because the |
Note to myself: good to keep the |
the new classes from #547 require less code overall to create big numbers; there are two things to fix, though:
I've fixed these two issues in 1ab1eb0 but it's not really fancy.
related: #248
closes #582