Skip to content

A multi-line time format by default #1285

Closed
@mbostock

Description

@mbostock

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/

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions