observablehq / observablehq/plot

Format the result of a built-in reducer

Open
#1,183 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
HTML
Stars
5.4k
Forks
244
PR merge metrics
No merged PRs in 30d

Description

When using a built-in reducer that returns a number such as sum or proportion, sometimes you want to apply a number formatter for better readability. You can do that by re-implementing the reducer in user code:

https://github.com/observablehq/plot/blob/c323b7850276ebc9a7afbcd5cccf1962db4c0f92/src/transforms/group.js#L388-L392

But it’d be nice if there were either a hook to wrap the built-in reducer (e.g., a format option as an output channel for the group and bin transform that applies to the text and title channels?) or if we exposed the internal implementations so that you can more easily wrap them.

Also, sometimes you don’t just want to format the output of a single reducer; you might want to run multiple reducers and combine them into the tooltip or text.

Previously #655.
Ref. https://talk.observablehq.com/t/observable-plot-formatting-group-transform-proportion-text/7409/2
Ref. https://talk.observablehq.com/t/getting-values-for-proportion-reducers-in-plot/6040/2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/transforms/group.js at lines 388–392, where the linked built-in reducer implementations are defined. Read the discussion in #655 and the two referenced Observable forum threads to understand the proposed API choices. Done means establishing a clear way to format reducer output and, if supported, combine multiple reducer results for text or tooltips.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
data-visualization
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.