observablehq / observablehq/plot

The scale’s transform should apply to the scale’s explicit domain, if any

Open
#1,565 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

In this example, it’s confusing that the domain is specified in the transformed space [-100, 100] instead of the pre-transformed space [0, 2]; everything else, including the ruleY is specified in the pre-transformed space. So, you want the domain to be specified in the same space so that you can add and remove the transform without needing to change anything else in the plot.

Screenshot 2023-05-16 at 11 41 46 AM
Plot.plot({
  y: {
    domain: [-100, 100],
    label: "↑ Close (%)",
    transform: (y) => (y - 1) * 100,
    tickFormat: "+d"
  },
  color: {
    legend: true
  },
  marks: [
    Plot.ruleX([frcb[i].Date]),
    Plot.ruleY([1]),
    Plot.lineY(stocks, Plot.normalizeY((Y) => Y[i], {x: "Date", y: "Close", stroke: "Symbol", tip: true})),
  ]
})

I think the reason we don’t do this now somewhat inadvertent: when the domain is not specified explicitly, it is derived from the channels, which already have the transform applied. So, we don’t want to apply the transform to the domain if the domain was derived from already-transformed channels; we only want to apply it when the domain was specified explicitly.

I don’t see an obvious way of making this change backwards compatible, since it changes the meaning of the domain option when the transform option is present. (We could introduce another option to control whether the transform applies to the domain, but it’ll still be confusing unless we change the default behavior.) So maybe this isn’t fixable, but I figure I would at least write this down in case others run into the same confusion.

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 the y-scale configuration in the example and trace how an explicit domain differs from a domain derived from transformed channels. The desired behavior is for an explicit domain such as [0, 2] to receive the scale transform while derived domains retain their current behavior; assess the backward-compatibility concern before defining the change.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.