Expose Fit Internals
curran opened this issue · comments
Faced with the task of adding fit
methods to geo-albers-usa-territories , I'm a bit stuck.
Ideally I could follow the pattern found in albersUsa.js, namely
import {fitExtent, fitSize, fitWidth, fitHeight} from "./fit.js";
However, since the projection is not inside this repository, and those internals from fit.js
are not exported from the top level of this package, I see no way to access them. Am I missing an approach that would work?
FWIW I did try
import { fitExtent, fitSize, fitWidth, fitHeight } from 'd3-geo/src/fit.js';
But that feels janky, and caused some headaches with Rollup (here's what I tried, for reference).
I propose to export these methods from the d3-geo
package, for use by projections defined outside this project.
Thoughts?
That might look something like adding the following to index.js:
(long names as this is probably a rare use case, and because these will end up on d3
itself)
export {
fitExtent as geoProjectionFitExtent,
fitSize as geoProjectionFitSize,
fitWidth as geoProjectionFitWidth,
fitHeight as geoProjectionFitHeight
} from "./projection/fit.js";
Then in the externally defined projection I could say:
import {
geoProjectionFitExtent as fitExtent,
geoProjectionFitSize as fitSize,
geoProjectionFitWidth as fitWidth,
geoProjectionFitHeight as fitHeight
} from 'd3-geo';
An alternative approach would be to finally offer a composite projections construct, that would deal with all the peculiarities (clipping, inverse, etc).
Interesting idea! Were there already discussions along the lines of a composite projections construct?
More sleuthing reveals another approach, though not sure if this is applicable https://github.com/d3/d3-geo-projection/blob/master/src/gilbert.js#L37
Maybe I could just say
property("fitExtent");
property("fitHeight");
property("fitSize");
property("fitWidth");
Considering submitting a PR with the change to expose these.
It looks like @HarryStevens has an alternative here https://observablehq.com/@washpostgraphics/geo-albers-usa-pr
It looks like @HarryStevens has an alternative here https://observablehq.com/@washpostgraphics/geo-albers-usa-pr
Yep, I just kept copy-pasting code from d3-geo until it stopped throwing errors.
apologies slightly off topic, but any chance of publishing https://observablehq.com/@washpostgraphics/geo-albers-usa-pr to npm for easier use off of observable?