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

adopt the new classes for plot's big numbers #554

Merged
merged 26 commits into from
Jan 25, 2024
Merged

adopt the new classes for plot's big numbers #554

merged 26 commits into from
Jan 25, 2024

Conversation

Fil
Copy link
Contributor

@Fil Fil commented Jan 17, 2024

the new classes from #547 require less code overall to create big numbers; there are two things to fix, though:

  1. by default the trend is too close to the big number; not sure how to address this cleanly — I'm currently adding a margin-right on .big to fix this.
  2. The link (for open PRs) makes the number blue, and I want to make it black again (or white on dark background)

I've fixed these two issues in 1ab1eb0 but it's not really fancy.

related: #248

closes #582

@Fil Fil requested a review from mbostock January 17, 2024 00:26
@Fil Fil mentioned this pull request Jan 17, 2024
@Fil Fil mentioned this pull request Jan 22, 2024
@Fil Fil marked this pull request as ready for review January 22, 2024 06:58
<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>
Copy link
Member

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.

Copy link
Contributor Author

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).

Copy link
Member

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 Show resolved Hide resolved
examples/plot/docs/index.md Outdated Show resolved Hide resolved
Copy link
Member

@mbostock mbostock left a 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>
Copy link
Member

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/google-analytics/docs/index.md Outdated Show resolved Hide resolved
examples/google-analytics/docs/index.md Outdated Show resolved Hide resolved
examples/google-analytics/docs/index.md Outdated Show resolved Hide resolved
examples/google-analytics/docs/index.md Outdated Show resolved Hide resolved
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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 Show resolved Hide resolved
examples/plot/docs/index.md Outdated Show resolved Hide resolved
examples/plot/docs/index.md Outdated Show resolved Hide resolved
</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>
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 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>
Fil and others added 7 commits January 23, 2024 04:26
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
@Fil
Copy link
Contributor Author

Fil commented Jan 25, 2024

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.

Copy link
Member

@mbostock mbostock left a 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.

@Fil
Copy link
Contributor Author

Fil commented Jan 25, 2024

I have not seen a difference with or without small. But I'll add it back.

@Fil Fil enabled auto-merge (squash) January 25, 2024 17:35
@Fil Fil merged commit a1cbe3d into main Jan 25, 2024
2 checks passed
@Fil Fil deleted the fil/plot-big branch January 25, 2024 17:36
@mbostock
Copy link
Member

It’s because the card class already applies small. So not necessary now!

@Fil
Copy link
Contributor Author

Fil commented Jan 26, 2024

Note to myself: good to keep the small class in the trend helper, so that it can be used outside of a card.

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.

upgrade bigNumber to class=big in all examples
2 participants