diff --git a/packages/vx-geo/src/graticule/Graticule.js b/packages/vx-geo/src/graticule/Graticule.js new file mode 100644 index 000000000..cb14c3e5b --- /dev/null +++ b/packages/vx-geo/src/graticule/Graticule.js @@ -0,0 +1,68 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { Group } from '@vx/group'; +import additionalProps from '../util/additionalProps'; +import { geoGraticule } from 'd3-geo'; + +export default function Graticule({ + graticule, + lines, + outline, + extent, + extentMajor, + extentMinor, + step, + stepMajor, + stepMinor, + precision, + ...restProps +}) { + const currGraticule = geoGraticule(); + + if (extent) currGraticule.extent(extent); + if (extentMajor) currGraticule.extentMajor(extentMajor); + if (extentMinor) currGraticule.extentMinor(extentMinor); + if (step) currGraticule.step(step); + if (stepMajor) currGraticule.stepMajor(stepMajor); + if (stepMinor) currGraticule.stepMinor(stepMinor); + if (precision) currGraticule.stepMinor(precision); + + return ( + + {graticule && + } + {lines && + currGraticule.lines().map((line, i) => + + + + )} + {outline && + } + + ); +} + +Graticule.propTypes = { + graticule: PropTypes.func, + lines: PropTypes.func, + outline: PropTypes.func +}; diff --git a/packages/vx-geo/src/projections/Graticule.js b/packages/vx-geo/src/projections/Graticule.js deleted file mode 100644 index e838a8d01..000000000 --- a/packages/vx-geo/src/projections/Graticule.js +++ /dev/null @@ -1 +0,0 @@ -// TODO: Add graticule component. diff --git a/packages/vx-geo/src/projections/Projection.js b/packages/vx-geo/src/projections/Projection.js index 7c959e56c..626a72442 100644 --- a/packages/vx-geo/src/projections/Projection.js +++ b/packages/vx-geo/src/projections/Projection.js @@ -3,6 +3,7 @@ import PropTypes from 'prop-types'; import classnames from 'classnames'; import { Group } from '@vx/group'; import additionalProps from '../util/additionalProps'; +import Graticule from '../graticule/Graticule'; import { geoOrthographic, geoAlbers, geoMercator, geoPath } from 'd3-geo'; // TODO: Implement all projections of d3-geo @@ -29,6 +30,9 @@ export default function Projection({ fitExtent, fitSize, centroid, + graticule, + graticuleLines, + graticuleOutline, className, ...restProps }) { @@ -47,14 +51,24 @@ export default function Projection({ const path = geoPath().projection(currProjection); return ( - + + {graticule && + !graticule.foreGround && + path(g)} {...graticule} />} + {graticuleLines && + !graticuleLines.foreGround && + path(g)} {...graticuleLines} />} + {graticuleOutline && + !graticuleOutline.foreGround && + path(g)} {...graticuleOutline} />} + {data.map((feature, i) => { let c; if (centroid) c = path.centroid(feature); return ( path(g)} {...graticule} />} + {graticuleLines && + graticuleLines.foreGround && + path(g)} {...graticuleLines} />} + {graticuleOutline && + graticuleOutline.foreGround && + path(g)} {...graticuleOutline} />} ); }