observablehq / feedback

Customer submitted bugs and feature requests
42 stars 3 forks source link

easy options for customizing graticules in Plot #540

Open aaronkyle opened 1 year ago

aaronkyle commented 1 year ago

Is your feature request related to a problem? Please describe. When trying to set graticules using Plot, reading through the documentation to learn how to do this is rather confusing: first one is routed here: https://github.com/observablehq/plot/blob/main/README.md#plotgraticuleoptions ... which includes a rather terse statement indicating that I can pass in options (without elaborating what options or how they are set). From there I am routed here: https://github.com/d3/d3-geo/blob/main/README.md#geoGraticule10, which elaborate more on options, but still bits of information are lacking (for example, #graticule.step([step]) ... doesn't clarify that steps are defined as grid pars [1,1] with the first pair being longitude and the next being latitude). ... It feels like it should be easier and more clear to set graticule options in Plot.

Describe the solution you'd like I'd to pass in like simple options for graticules, eg: {graticule: [step: [1,1], strokeWidth: 1, strokeOpacity 0.1] }. Also nice would be some control over setting graticule labels.

Describe alternatives you've considered Using D3

Additional context Thank you!

mbostock commented 1 year ago

The graticule mark supports the standard mark options, so you can say

Plot.graticule({strokeWidth: 1, strokeOpacity: 0.1})

However, it does not support changing the geometry of the graticule; it always uses d3.geoGraticule10 under the hood.

https://github.com/observablehq/plot/blob/28b1a4c0e202c590bbc4632d0400350b6e53e7b9/src/marks/geo.js#L95-L97

If you want a different graticule, you can use d3.geoGraticule directly in conjunction with Plot.geo. We also don’t currently provide any facility for labeled graticules (which is hard).

aaronkyle commented 1 year ago

Thank you! And apologies for my confusion and therefore poor example. In creating the notebook that prompted me to write this, I did manage to figure out how to gain control of graticule styling, as such:

 Plot.geo(d3.geoGraticule().step([1, 1])(), {
      stroke: "red",
      strokeOpacity: 0.3
    }),

I didn't realize that what I was availing of the standard mark options in Plot. Rather, I thought that I gained this control by 'escaping' into D3 after invoking d3.geoGraticule directly. Thank you for clarifying.

I guess what I was trying to express / request was that sense I had that introducing these adjustment required a few steps of tracing through the docs and trying to intuit how the controls work, and in the process discovering that d3.geoGraticule10 is effectively just d3.geoGraticule()(). So the 'feature request' I sought to raise is making it easier for people to directly introduce d3.geoGraticule options into Plot.

Thank you!