Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

[enhancement] Expose Mark's data properties like domain #1028

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dgrcode opened this issue Aug 20, 2022 · 0 comments
Closed

[enhancement] Expose Mark's data properties like domain #1028

dgrcode opened this issue Aug 20, 2022 · 0 comments

Comments

@dgrcode
Copy link

dgrcode commented Aug 20, 2022

Feature Request

I'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.

Why

I'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 ¯\_(ツ)_/¯

Current Workaround

The current solution I've found is to use d3.extent, but that's about extra 12.6 kb (gzipped) that I imagine is already bundled with plot.

Additional workarounds that I've tried:

  • Create another plot as "draft" and get the data I need from there. I went a different way because I feel it's too much to create a brand new plot just for this. The code looked more or less like the following:
    const draftChart = Plot.marks(Plot.line(values)).plot()
    const yExtent = draftChart.scale('y').domain
    // the rest of the code would look just as the code using d3.extent
  • Try to mutate chart.scale('y').domain after plot creation. This didn't change anything. The object property was updated, but I imagine the plot itself was created before the mutation, so it didn't have any effect. Maybe a plot.update() method would be handy here, which could be related to updating in place? #1022.
@observablehq observablehq locked and limited conversation to collaborators Aug 22, 2022
@Fil Fil converted this issue into discussion #1030 Aug 22, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant