Skip to content
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

[geoPath]: pointRadius() Accessor pattern #67

Closed
tomwanzek opened this issue Nov 3, 2016 · 2 comments
Closed

[geoPath]: pointRadius() Accessor pattern #67

tomwanzek opened this issue Nov 3, 2016 · 2 comments

Comments

@tomwanzek
Copy link
Contributor

This is more of a question. I noticed that the geo path pointRadius() getter returns:

  1. either an accessor function, or
  2. a constant numeric value (i.p. the 4.5 default)

If I recall correctly, in a fair share of the other D3 modules, similar accessors will always return an accessor function, even if it just wraps a constant return value.

Understanding that changing this would be breaking, I simply wondered, if there is a rationale for it, which is specific to the d3-geo applications?

@mbostock
Copy link
Member

mbostock commented Nov 3, 2016

See d3/d3-shape#23, and earlier, d3/d3#1145.

In the past, I tried to preserve the type as it was set, mostly to facilitate debugging. So, if the value was set as a constant, it would be returned as a constant. In 4.0, I think I generally standardized on always promoting constants to functions. The path.pointRadius is treated a little specially because it can be optimized to set contextStream.pointRadius once if the radius is a constant, rather than always boxing it with a function. That avoids initializing the circle string (see path/string.js) for rendering each feature, but a better optimization would be to initialize the circle string lazily.

I’d probably be okay with changing the behavior without a major release, as the documentation does say that it returns the “current radius accessor” and not the “current radius”, and so this should probably be considered a bug. But yes, there’s a chance this could break something, and it doesn’t seem hugely important either way. 😁

@tomwanzek
Copy link
Contributor Author

Thanks, like I said, I thought you might have had a reason. So I leave it up to you to find the best fit for this particular accessor (rather than just blindly following a pattern.) I have just pushed updated d3-geo definitions (1.3.1) to DefinitelyTyped. So once they are merged/published everything is in synch with D3 proper.

The definitions in this latest version return a union-type of either number or "accessor function signature". If the module changes we can change that as well.

I am considering a follow-up commit/PR anyway, because I might want to break-out the composite projection interface from the more complete projection interface (i.e. the unsupported methods).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants