observablehq / observablehq/plot
The scale’s transform should apply to the scale’s explicit domain, if any
Nobody has claimed this yet.
- 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.
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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