-
Feature RequestI'd like to be able to get properties from my data before the plot is created, so I can use them during plot creation. For simplicity, let's say I want to increase my Y domain so it has 10 extra units on each side. I'm thinking it would look something like the following: const lineMark = Plot.line(values)
const [yDomMin, yDomMax] = lineMark.scale('y').domain
const chart = Plot.plot({
y: {
domain: [yDomMin - 10, yDomMax + 10] // for example
},
marks: [lineMark]
}) Right now I'd have to do some math, that I imagine will be redone during plot creation. WhyI'll describe the use case in particular that has triggered this request, since I might be missing something that could allow me to do it with the current state of the library. I want to be able to find the distance between my domain in y, and add an extra 10% of domain on each side. Sort of like padding the domain. The reason is that I feel the line is the beginning of the data when the line starts exactly on the bottom-left corner. Adding the padding makes me feel I can scroll sideways to see previous data. Not sure if it makes sense, but that's the way I see it ¯\_(ツ)_/¯ EDIT: Adding an example of what I mean by "padding the domain" in a chart Note how the line is separated vertically from the edges of the chart by adding more empty chart –vs adding empty space–. Current WorkaroundThe current solution I've found is to use Additional workarounds that I've tried:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I wonder if inset could be the right answer for this use case? It's in pixels, so if the chart is 400 pixels high and you want something like a 10% padding on top and bottom, try:
You could also try to add the nice: true option to the y scale, independently or in combination with the preceding setting; it might also help avoid this “bottom-left corner” issue. chart.scale('y') exposes a copy of the computed scale, so you can create a new chart with a consistent scale—it's not meant for updating a chart. |
Beta Was this translation helpful? Give feedback.
-
I don’t think the proposed API would work well because it only considers a single mark (the line mark); in practice most Plots include multiple marks as well as scale options which collectively affect the definition of the y-scale domain. Therefore it would be almost intractable to pull out a single mark (or a subset of the plot), extract the y-scale definition, and then construct a new plot with an almost-the-same-but-not-quite definition of the y-scale. Like @Fil said, the inset and nice scale options are both attractive here. The issue with the inset option is that it is in screen space (i.e., range) rather than data space (i.e., domain). I could imagine another scale option that is for padding the domain in data space, although that would only be possible for quantitative scales (since you can’t add or subtract ordinal or categorical values). I could also see it being nice to have a fractional inset, where rather than specifying the inset in pixels, you specify it as some proportion of the available range (e.g., the inner width or height of the plot). |
Beta Was this translation helpful? Give feedback.
I don’t think the proposed API would work well because it only considers a single mark (the line mark); in practice most Plots include multiple marks as well as scale options which collectively affect the definition of the y-scale domain. Therefore it would be almost intractable to pull out a single mark (or a subset of the plot), extract the y-scale definition, and then construct a new plot with an almost-the-same-but-not-quite definition of the y-scale.
Like @Fil said, the inset and nice scale options are both attractive here. The issue with the inset option is that it is in screen space (i.e., range) rather than data space (i.e., domain). I could imagine another scale option that is fo…