This message was deleted.
# help
s
This message was deleted.
m
What are you referring to with minimum / maximum? With specifying the y.domain array you can set the min and max for the domain. The domain is refering to the data space. I think you are right maximum is the maximum of the data and the minimum defaults to the minimum if negative otherwise 0. If you create your plot as a named cell, e.g. myPlot = { // insert Plot here }, then you can look up the domain with myPlot.scale("y").domain With specifying the y.range array you can set the min and max for the range. The range is refering to the screen space. If you create your plot as a named cell, e.g. myPlot = { // insert Plot here }, then you can look up the range with myPlot.scale("y").range
t
@Mihael Ankerst thx for the confirmations, I think one of the annoyance is that I need to set the domain during the plot initialization unless I misunderstood something, such that
Copy code
const barPlot = Plot.plot({
      x: { },
      y: {
        // precompute domain here, that's why I asked that original question
        domain: custom_domain,
      },
      marks: [
        Plot.barY(dataset, {}),
      ],
    });
unless I can do something magical like
Copy code
const barPlot = Plot.plot({}) // without setting domain here

const current_default_domain = barPlot.getDomain()
barPlot.updateDomain([ do some comparison and update according ])

//rendering the plot
I'm new to
observable plot
and
d3
, so I just have some random idea in my mind based on the doc and typescript hint most likely
m
Yes, that is correct how you describe it. you might use one cell getting the default domain
Copy code
// cell 1 
myYDomain = Plot.plot(// your Plot).scale("y").domain
and another cell to render with the Plot with the same options but initializing the y domain with an adjusted domain based on the default domain you obtain in cell 1
t
oh thx, I just try it out, another reason I asked the
update
thing is also because I was using
react
, it could be handy if I precompute the
plot
and then just do the partial update without rebuilding the entire graph.
m
Why so you need the default values for the domain? I find typically you either go with the default domain. Or, alternatively, you set the domain according to your needs, then you just set the domain without the need to know the defaults
t
it's just for users technically if they just interesting in things above certain min, and ignore the below, vise versa. And if they are being lazy to set the another min/max, sacrifice DX for UX strictly
@Mihael Ankerst just a little feedback for this approach, it seems like there is not easy way to update existing svg domain created by the plot(); so precompute is probably the way to go. or a pretty bad way that calls the plot twice, the first time is just for getting that default domain like.
Copy code
const draftMarks = Plot.marks(
      Plot.barY(dataset, {})
    );
    const defaultDomain = draftMarks.plot().scale("y")?.domain();
    
    const customDomain = [] // do something based on defaultDomain;

    const barPlot = Plot.plot({
      x: {},
      y: { domain: customDomain },
      marks: [draftMarks],
    });