Skip to content

quantize transform #1497

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
wants to merge 5 commits into from
Closed

quantize transform #1497

wants to merge 5 commits into from

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Apr 27, 2023

For converting quantitative or temporal data into ordinal data.

image

Plot.plot({
  x: {tickFormat: "%Y"},
  marks: [
    Plot.barY(olympians, Plot.groupX({y: "count"}, Plot.quantizeX(d3.utcYear.every(5), {x: "date_of_birth"})))
  ]
})

The previous implementation of ordinal intervals #513 #849 uses a scale transform. This is fine if there’s no mark transform involved, but since the mark transforms run before the scale transform (i.e., the scale transform applies to the output of the mark transform rather than the input), it doesn’t help much in the case above, when grouping. I originally considered adding an interval option to the group transform, but that starts to get confusing with the existing interval mark option (which applies to the opposite dimension in the case of barY!), so I thought it better to have an explicit transform.

Regarding the implementation, I like the reuse of Plot.map, but I don’t like the plumbing required to propagate the knowledge that a channel has an associated interval. I added the plumbing to the group transform for x and y, but I didn’t add it anywhere else, so there’s probably some cases where this isn’t going to work. This plumbing is needed to ensure that the (ordinal) scale produces a tick for every interval value in the domain, and to suppress the warning that would otherwise occur when using quantitative or temporal data with an ordinal scale.

Another confusing aspect is that there’s already the interval mark option, but that does something else, which is converting a singular value into an extent [start, stop]. Like, in the case of barY, now I wonder if the interval option should instead apply to the x channel to quantize values, instead of applying to the y channel like it does now. I don’t want to make a backwards-incompatible change, though. Maybe this suggests that we should call this the “quantize” transform instead of the “interval” transform? Update: Yes, we’ll use the name “quantize” instead.

TODO

  • Rename to “quantize” transform?
  • Add a generic Plot.interval Plot.quantize transform for any channel (akin to Plot.map)?
  • Adopt named skip intervals from skip intervals #1506.
  • Do other channels need the interval hint propagated?
  • Do other transforms need to propagate the interval hint?
  • Create a documentation page for the quantize transform
  • Create a documentation page for intervals (documenting named intervals etc.)

@mbostock mbostock requested a review from Fil April 27, 2023 18:20
@mbostock mbostock force-pushed the mbostock/interval-transform branch 2 times, most recently from f44244d to 609e3b2 Compare April 28, 2023 19:50
@mbostock mbostock changed the title interval transform quantize transform Apr 28, 2023
@Fil Fil mentioned this pull request Apr 28, 2023
@mbostock mbostock force-pushed the mbostock/interval-transform branch from 2662e3c to 0924d7c Compare April 28, 2023 22:15
@mbostock
Copy link
Member Author

I want to try a different take on this using the existing interval scale option. If I can make that available to the group transform, then I can make this work:

Plot.plot({
  x: {
    tickFormat: "%Y",
    interval: "5 years"
  },
  marks: [
    Plot.barY(olympians, Plot.groupX({y: "count"}, {x: "date_of_birth"}))
  ]
})

(And in theory we could infer the appropriate tickFormat, too.)

@mbostock
Copy link
Member Author

Closing in favor of #1511.

@mbostock mbostock closed this Apr 30, 2023
@mbostock mbostock deleted the mbostock/interval-transform branch April 30, 2023 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant