Skip to content

Format tip pair as a single value when the two values are equal? #2135

Open

Description

@Fil

By default when formatting pairs (y1, y2), we display ${format(a)}—${format(b)}. It does not feel terribly useful to repeat the value when a and b end up being formatted identically.

If for example you're showing a tip on an interval that is [3.1—3.2] with an integer format, showing "3" (read as "somewhere around 3 something") is as informative and slightly better than "3—3" ("between 3 something and 3 something").

This does not happen often, since hopefully the format discriminates between values, but when it happens we would be as happy with showing ${format(a)} alone.

I tried to think of a case where on the opposite, one might want to show a repetition; for example on a calendar where you want to show an interval that goes "from Sunday to Sunday", as "Sun—Sun". In that case, you would have to create a specific channel since the automatic tip format would now show "Sun" only.

This enhancement would incidentally help with the waffle tips (#2132), but is not necessary for them, and should be discussed on its own merits.

(Note: does not apply when the value is the difference — i.e. hint: {length: true}).

Activity

  1. self-assigned this
    on Aug 15, 2024
  2. changed the title [-]Format tip pair as a single value when the two values are equal[/-] [+]Format tip pair as a single value when the two values are equal?[/+] on Aug 15, 2024
  3. Fil commented on Aug 22, 2024

    @Fil
    ContributorAuthor

    A case found in the wild: the binning of integers between 0 and 7, that results (by default) in small bins such as [4 — 4.5]. If the format was showing only the integer part (as suggested in #1268), this PR would automagically solve this case.
    integer tip

    (However in this case, we'd also want the bin labels to be "4" and not "4 inclusive to 5 exclusive".)

  4. mwaibel-go commented on Jan 28, 2026

    @mwaibel-go

    A first step that would allow API consumers to solve this would be to pass the bin boundaries to a custom formatter function instead of each boundary individually.

    To be clear, I’m talking about this API:

    Plot.binX(
      { y: 'count' },
      { x: 'startTimestamp',
        thresholds: 'day',
        tip: {
          format: {
            x: (date) => getGermanDate(date)
          }
        }
      },
    )

    Since I’m binning by days, the tip will look like “01.01.2026–01.01.2026”. This could be avoided if I could instead provide the formatter as

    format: {
      x: ([date1, date2]) => {
        const formattedDate1 = getGermanDate(date1)
        const formattedDate2 = getGermanDate(date2)
        return formattedDate1 !== formattedDate2 ? `${formattedDate1}–${formattedDate2}`: formattedDate1
      }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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