observablehq / plot

A concise API for exploratory data visualization implementing a layered grammar of graphics
https://observablehq.com/plot/
ISC License
4.16k stars 171 forks source link

Dot / circle with centroid radius value isn't responsive to accessor changes #2064

Closed akre54 closed 2 months ago

akre54 commented 2 months ago

Steps to reproduce:

Video:

https://github.com/observablehq/plot/assets/931368/0b7f4af0-e480-4243-9082-bebf425b4932

I would expect that the radius size of the bubbles double in response to this change, similar to the way that the legend updates. This also means that responsive values from notebook variables don't actually update the svg. I can confirm that this works as I'd expect using Plot.image and the width property. Is there something different with r?

mbostock commented 2 months ago

This is the intended behavior because when you double the values, it doubles the implicit domain, and so the effective size of the bubbles is the same. If you want to change the size of the bubbles, you need to either set the range or domain of the r scale.

akre54 commented 2 months ago

Thanks @mbostock. Appreciate the quick response. I'm not seeing where the documentation is for setting the range or domain on a Mark. The Scales documentation seems to imply that I can pass a domain property, but I'm not seeing how to use that with the example map.

Is this right?

r: {
  value: 'population',
  range: [0, 5000],
  domain: [0, 10000],
},

This seems to work as I'd intend (where negIconScale is a viewof Inputs.range)

Plot.image(
  negGeoJson,
  Plot.centroid({
    src: negative.src,
    width: d => d.properties.earlier * negIconScale,
  })
),

Is width just treated differently as not a channel?

mbostock commented 2 months ago

It’s not a mark option; it’s the r scale which is defined at the plot level. Edit the r: {range: …} line in the linked notebook.

akre54 commented 2 months ago

Oh got it - I just grabbed a random notebook and I missed that. Thanks