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

A multi-line time format by default #1285

Closed
Tracked by #1711
mbostock opened this issue Feb 17, 2023 · 2 comments · Fixed by #1718
Closed
Tracked by #1711

A multi-line time format by default #1285

mbostock opened this issue Feb 17, 2023 · 2 comments · Fixed by #1718
Labels
enhancement New feature or request

Comments

@mbostock
Copy link
Member

mbostock commented Feb 17, 2023

Now that we support multi-line ticks, it’d be nice if time scales used them by default. For example, rather than this (ref. https://observablehq.com/@hrbrmstr/cdc-avian-flu-outbreak-tracker):

untitled (8)

Plot.plot({
  x: {
    label: null
  },
  y: {
    label: "↑ Cumulative culls (millions)",
    transform: d => d / 1e6
  },
  marks: [
    Plot.ruleY([0]),
    Plot.lineY(aflu, Plot.mapY("cumsum", {reverse: true, x: "outbreak_date", y: "flock_size"}))
  ]
})

You might get this:

untitled (9)

Plot.plot({
  x: {
    label: null,
    tickFormat: (
        (formatYear, formatMonth) => (x) =>
          d3.utcMonth.count(d3.utcYear(x), x) < 1
            ? `${formatMonth(x)}\n${formatYear(x)}`
            : formatMonth(x)
      )(d3.utcFormat("%Y"), d3.utcFormat("%b"))
  },
  y: {
    label: "↑ Cumulative culls (millions)",
    transform: d => d / 1e6
  },
  marks: [
    Plot.ruleY([0]),
    Plot.lineY(aflu, Plot.mapY("cumsum", {reverse: true, x: "outbreak_date", y: "flock_size"}))
  ]
})

I think this means rolling our own time format, rather than relying on d3-scale’s default.

Ref. https://blog.datawrapper.de/new-axis-ticks/

@mbostock mbostock added the enhancement New feature or request label Feb 17, 2023
@mbostock
Copy link
Member Author

Another useful thing we could do is add a title (tooltip) that gives you the full date and time on hover. This way even if the axis tick is ambiguous (e.g., only showing milliseconds), you can hover to see the complete time.

@mbostock
Copy link
Member Author

Prototype: https://observablehq.com/d/b10d9ab04d996d26

nachocab added a commit to nachocab/plot that referenced this issue Jun 26, 2023
Probably not needed now that observablehq#1285 was closed by observablehq#1718
Fil pushed a commit that referenced this issue Jun 26, 2023
Probably not needed now that #1285 was closed by #1718
Fil pushed a commit that referenced this issue Aug 21, 2023
Probably not needed now that #1285 was closed by #1718
chaichontat pushed a commit to chaichontat/plot that referenced this issue Jan 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant