Skip to content

Commit

Permalink
new(geo, vendor): add d3-geo@3 to visx-vendor, support `geoPath.d…
Browse files Browse the repository at this point in the history
…igits(n)` (#1767)

* Update `d3-geo`, add it to `visx-vendor`, support `Projection#digits`

* Link to issue

* Reduce diff

* tsconfigs

* Update packages/visx-geo/src/projections/Projection.tsx

Co-authored-by: Chris Williams <[email protected]>

* Reduce diff

* Update `@types/d3-geo` to `3.1.0`

* Dedupe `d3-array`

---------

Co-authored-by: Chris Williams <[email protected]>
  • Loading branch information
kachkaev and williaster authored Nov 13, 2023
1 parent 6a14177 commit 1ee0374
Show file tree
Hide file tree
Showing 15 changed files with 71 additions and 23 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ module.exports = {
verbose: false,
testPathIgnorePatterns: ['<rootDir>/packages/visx-demo'],
transformIgnorePatterns: [
'node_modules/(?!(d3-(array|color|format|interpolate|scale|time|time-format)|delaunator|internmap|robust-predicates)/)',
'node_modules/(?!(d3-(array|color|format|geo|interpolate|scale|time|time-format)|delaunator|internmap|robust-predicates)/)',
],
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
"ts-node": "9.1.1",
"typescript": "^3.8.3"
},
"packageManager": "[email protected]",
"workspaces": {
"packages": ["./packages/*"],
"nohoist": ["**/@visx/vendor/**"]
Expand Down
1 change: 0 additions & 1 deletion packages/visx-demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@
"babel-loader": "^8.2.2",
"classnames": "^2.3.1",
"d3-collection": "^1.0.4",
"d3-geo": "^1.11.3",
"d3-hierarchy": "^1.1.4",
"d3-scale-chromatic": "^1.3.3",
"d3-shape": "^1.0.6",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { geoCentroid } from 'd3-geo';
import { AlbersUsa } from '@visx/geo';
import { geoCentroid } from '@visx/vendor/d3-geo';
import * as topojson from 'topojson-client';
import topology from './usa-topo.json';
import stateAbbrs from './us-abbr.json';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@types/react-dom": "^18",
"@visx/geo": "latest",
"@visx/responsive": "latest",
"d3-geo": "^3.0.1",
"@visx/vendor": "latest",
"react": "^18",
"react-dom": "^18",
"react-scripts-ts": "3.1.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/visx-demo/src/sandboxes/visx-geo-custom/Example.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import * as topojson from 'topojson-client';
import { scaleQuantize } from '@visx/scale';
import { CustomProjection, Graticule } from '@visx/geo';
import { Projection } from '@visx/geo/lib/types';
import { Zoom } from '@visx/zoom';
import {
geoConicConformal,
geoTransverseMercator,
geoNaturalEarth1,
geoConicEquidistant,
geoOrthographic,
geoStereographic,
} from 'd3-geo';
} from '@visx/vendor/d3-geo';
import { Zoom } from '@visx/zoom';
import topology from './world-topo.json';

export type GeoCustomProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"@visx/geo": "latest",
"@visx/responsive": "latest",
"@visx/scale": "latest",
"@visx/vendor": "latest",
"@visx/zoom": "latest",
"d3-geo": "^1.11.9",
"react": "^18",
"react-dom": "^18",
"react-scripts-ts": "3.1.0",
Expand Down
3 changes: 1 addition & 2 deletions packages/visx-geo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
},
"homepage": "https://github.com/airbnb/visx#readme",
"dependencies": {
"@types/d3-geo": "^1.11.1",
"@types/geojson": "*",
"@types/react": "*",
"@visx/group": "3.3.0",
"@visx/vendor": "3.3.0",
"classnames": "^2.3.1",
"d3-geo": "^1.11.3",
"prop-types": "^15.5.10"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/visx-geo/src/graticule/Graticule.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { Group } from '@visx/group';
import { geoGraticule, GeoGraticuleGenerator } from 'd3-geo';
import { geoGraticule, GeoGraticuleGenerator } from '@visx/vendor/d3-geo';
// eslint-disable-next-line import/no-unresolved
import { LineString, MultiLineString, Polygon } from 'geojson';

Expand Down
8 changes: 6 additions & 2 deletions packages/visx-geo/src/projections/Projection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
GeoPath,
GeoProjection,
ExtendedFeature,
} from 'd3-geo';
} from '@visx/vendor/d3-geo';
// this is just for types
// eslint-disable-next-line import/no-unresolved
import { LineString, Polygon, MultiLineString } from 'geojson';
Expand Down Expand Up @@ -93,6 +93,8 @@ export type ProjectionProps<Datum extends GeoPermissibleObjects = GeoPermissible
graticuleLines?: Omit<GraticuleProps, 'lines'> & { foreground: boolean };
/** If specified, renders a Graticule outline with the specified props. Specify `graticuleOutline.foreground = true` to be rendered on top of features. */
graticuleOutline?: Omit<GraticuleProps, 'outline'> & { foreground: boolean };
/** Limits the digits for coordinates generated in SVG path strings to the specified number of digits. */
digits?: number;
/** Sets the radius used to display Point and MultiPoint geometries to the specified number. */
pointRadius?: number;
};
Expand Down Expand Up @@ -128,6 +130,7 @@ export default function Projection<Datum extends GeoPermissibleObjects>({
graticuleOutline,
className,
innerRef,
digits,
pointRadius,
children,
...restProps
Expand All @@ -149,7 +152,8 @@ export default function Projection<Datum extends GeoPermissibleObjects>({

const path = geoPath().projection(currProjection);

if (pointRadius) path.pointRadius(pointRadius);
if (digits !== undefined) path.digits(digits);
if (pointRadius !== undefined) path.pointRadius(pointRadius);

const features: ParsedFeature<Datum>[] = data.map((feature, i) => ({
feature,
Expand Down
5 changes: 4 additions & 1 deletion packages/visx-geo/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { GeoProjection, GeoPermissibleObjects as GeoPermissibleObjectType } from 'd3-geo';
import {
GeoProjection,
GeoPermissibleObjects as GeoPermissibleObjectType,
} from '@visx/vendor/d3-geo';

export type GeoPermissibleObjects = GeoPermissibleObjectType;

Expand Down
3 changes: 3 additions & 0 deletions packages/visx-geo/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
"references": [
{
"path": "../visx-group"
},
{
"path": "../visx-vendor"
}
]
}
2 changes: 2 additions & 0 deletions packages/visx-vendor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"@types/d3-color": "3.1.0",
"@types/d3-delaunay": "6.0.1",
"@types/d3-format": "3.0.1",
"@types/d3-geo": "3.1.0",
"@types/d3-interpolate": "3.0.1",
"@types/d3-scale": "4.0.2",
"@types/d3-time": "3.0.0",
Expand All @@ -25,6 +26,7 @@
"d3-color": "3.1.0",
"d3-delaunay": "6.0.2",
"d3-format": "3.1.0",
"d3-geo": "3.1.0",
"d3-interpolate": "3.0.1",
"d3-scale": "4.0.2",
"d3-time": "3.1.0",
Expand Down
37 changes: 37 additions & 0 deletions packages/visx-vendor/test/d3-geo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/* This test verifies that these modules and types are exported correctly */
import {
// @ts-expect-error Make sure invalid imports fail:
INVALID_TYPE,
ExtendedFeature,
ExtendedFeatureCollection,
ExtendedGeometryCollection,
GeoCircleGenerator,
GeoConicProjection,
GeoContext,
GeoGeometryObjects,
GeoGraticuleGenerator,
GeoIdentityTransform,
GeoPath,
GeoPermissibleObjects,
GeoProjection,
GeoRawProjection,
GeoRotation,
GeoSphere,
GeoStreamWrapper,
GeoStream,
GeoTransformPrototype,
geoAlbers,
geoAlbersUsa,
geoArea,
geoAzimuthalEqualArea,
geoAzimuthalEqualAreaRaw,
geoAzimuthalEquidistant,
geoAzimuthalEquidistantRaw,
geoBounds,
} from '@visx/vendor/d3-geo';

describe('d3-geo', () => {
it('exports valid functions', () => {
expect(geoBounds).toBeInstanceOf(Function);
});
});
20 changes: 10 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2693,10 +2693,10 @@
resolved "https://registry.yarnpkg.com/@types/d3-format/-/d3-format-3.0.1.tgz#194f1317a499edd7e58766f96735bdc0216bb89d"
integrity sha512-5KY70ifCCzorkLuIkDe0Z9YTf9RR2CjBX1iaJG+rgM/cPP+sO+q9YdQ9WdhQcgPj1EQiJ2/0+yUkkziTG6Lubg==

"@types/d3-geo@^1.11.1":
version "1.11.1"
resolved "https://registry.yarnpkg.com/@types/d3-geo/-/d3-geo-1.11.1.tgz#e96ec91f16221d87507fec66b2cc889f52d2493e"
integrity sha512-Ox8WWOG3igDRoep/dNsGbOiSJYdUG3ew/6z0ETvHyAtXZVBjOE0S96zSSmzgl0gqQ3RdZjn2eeJOj9oRcMZPkQ==
"@types/d3-geo@3.1.0":
version "3.1.0"
resolved "https://registry.yarnpkg.com/@types/d3-geo/-/d3-geo-3.1.0.tgz#b9e56a079449174f0a2c8684a9a4df3f60522440"
integrity sha512-856sckF0oP/diXtS4jNsiQw/UuK5fQG8l/a9VVLeSouf1/PPbBE1i1W852zVwKwYCBkFJJB7nCFTbk6UMEXBOQ==
dependencies:
"@types/geojson" "*"

Expand Down Expand Up @@ -5054,7 +5054,7 @@ d3-array@1:
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-1.2.4.tgz#635ce4d5eea759f6f605863dbcfc30edc737f71f"
integrity sha512-KHW6M86R+FUPYGb3R5XiYjXPq7VzwxZ22buHhAEVG5ztoEcZZMLov530mmccaqA1GghZArjQV46fuc8kUqhhHw==

"d3-array@2 - 3", "[email protected] - 3", [email protected]:
"d3-array@2 - 3", "[email protected] - 3", "[email protected] - 3", [email protected]:
version "3.2.1"
resolved "https://registry.yarnpkg.com/d3-array/-/d3-array-3.2.1.tgz#39331ea706f5709417d31bbb6ec152e0328b39b3"
integrity sha512-gUY/qeHq/yNqqoCKNq4vtpFLdoCdvyNpWoC/KNjhGbhDuQpAM9sIQQKkXSNpXa9h5KySs/gzm7R88WkUutgwWQ==
Expand Down Expand Up @@ -5108,12 +5108,12 @@ d3-dispatch@^1.0.3:
resolved "https://registry.yarnpkg.com/d3-format/-/d3-format-3.1.0.tgz#9260e23a28ea5cb109e93b21a06e24e2ebd55641"
integrity sha512-YyUI6AEuY/Wpt8KWLgZHsIU86atmikuoOmCfommt0LYHiQSPjvX2AcFc38PX0CBpr2RCyZhjex+NS/LPOv6YqA==

d3-geo@^1.11.3:
version "1.12.1"
resolved "https://registry.yarnpkg.com/d3-geo/-/d3-geo-1.12.1.tgz#7fc2ab7414b72e59fbcbd603e80d9adc029b035f"
integrity sha512-XG4d1c/UJSEX9NfU02KwBL6BYPj8YKHxgBEw5om2ZnTRSbIcego6dhHwcxuSR3clxh0EpE38os1DVPOmnYtTPg==
d3-geo@3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/d3-geo/-/d3-geo-3.1.0.tgz#74fd54e1f4cebd5185ac2039217a98d39b0a4c0e"
integrity sha512-JEo5HxXDdDYXCaWdwLRt79y7giK8SbhZJbFWXqbRTolCHFI5jRqteLzCsq51NKbUoX0PjBVSohxrx+NoOUujYA==
dependencies:
d3-array "1"
d3-array "2.5.0 - 3"

d3-hierarchy@^1.1.4, d3-hierarchy@^1.1.8:
version "1.1.9"
Expand Down

0 comments on commit 1ee0374

Please sign in to comment.