From 48678eae9f37851227f0e06e213c950c6a939424 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 30 Nov 2022 18:50:24 -0800 Subject: [PATCH 1/2] default geo clip --- README.md | 4 +- src/marks/geo.js | 8 +-- src/marks/hexgrid.js | 2 +- test/output/armadillo.svg | 5 +- test/output/bertin1953Facets.svg | 20 +++++-- test/output/graticule.svg | 10 +++- test/output/nullProjection.svg | 5 +- test/output/usCountyChoropleth.html | 10 +++- test/output/usStateCapitals.svg | 10 +++- test/output/usStateCapitalsVoronoi.svg | 14 +++-- test/output/walmarts.html | 5 +- test/output/walmartsDecades.svg | 75 ++++++++++++++++++++------ test/output/walmartsDensity.svg | 5 +- 13 files changed, 133 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index c581ea0dcb..16f46838d8 100644 --- a/README.md +++ b/README.md @@ -1257,7 +1257,7 @@ Equivalent to [Plot.dot](#plotdotdata-options) except that the **symbol** option Plot.geo(counties, {fill: d => d.properties.rate}) ``` -Returns a new geo mark with the given *data* and *options*. If *data* is a GeoJSON feature collection, then the mark’s data is *data*.features; if *data* is a GeoJSON geometry collection, then the mark’s data is *data*.geometries; if *data* is some other GeoJSON object, then the mark’s data is the single-element array [*data*]. If the **geometry** option is not specified, *data* is assumed to be a GeoJSON object or an iterable of GeoJSON objects. +Returns a new geo mark with the given *data* and *options*. If *data* is a GeoJSON feature collection, then the mark’s data is *data*.features; if *data* is a GeoJSON geometry collection, then the mark’s data is *data*.geometries; if *data* is some other GeoJSON object, then the mark’s data is the single-element array [*data*]. If the **geometry** option is not specified, *data* is assumed to be a GeoJSON object or an iterable of GeoJSON objects. The **clip** option defaults to *frame*, clipping the mark to the frame’s dimensions. In addition to the [standard mark options](#marks), the **r** option controls the size of Point and MultiPoint geometries. It can be specified as either a channel or constant. When **r** is specified as a number, it is interpreted as a constant radius in pixels; otherwise it is interpreted as a channel and the effective radius is controlled by the *r* scale. (As with [dots](#dot), the *r* scale defaults to a *sqrt* scale such that the visual area of a point is proportional to its associated value.) If the **r** option is not specified it defaults to 3 pixels. Geometries with a nonpositive radius are not drawn. If **r** is a channel, geometries will be sorted by descending radius by default. @@ -1289,7 +1289,7 @@ Plot.hexgrid() -The **binWidth** option specifies the distance between the centers of neighboring hexagons, in pixels (defaults to 20). The **clip** option defaults to true, clipping the mark to the frame’s dimensions. +The **binWidth** option specifies the distance between the centers of neighboring hexagons, in pixels (defaults to 20). The **clip** option defaults to *frame*, clipping the mark to the frame’s dimensions. diff --git a/src/marks/geo.js b/src/marks/geo.js index 06e333fefe..85c080e589 100644 --- a/src/marks/geo.js +++ b/src/marks/geo.js @@ -17,15 +17,15 @@ const defaults = { }; export class Geo extends Mark { - constructor(data, options = {}) { - const [vr, cr] = maybeNumberChannel(options.r, 3); + constructor(data, {clip = "frame", r, geometry, ...options} = {}) { + const [vr, cr] = maybeNumberChannel(r, 3); super( data, { - geometry: {value: options.geometry}, + geometry: {value: geometry}, r: {value: vr, scale: "r", filter: positive, optional: true} }, - withDefaultSort(options), + withDefaultSort({clip, ...options}), defaults ); this.r = cr; diff --git a/src/marks/hexgrid.js b/src/marks/hexgrid.js index 13ffb35813..9c4f122d18 100644 --- a/src/marks/hexgrid.js +++ b/src/marks/hexgrid.js @@ -18,7 +18,7 @@ export function hexgrid(options) { } export class Hexgrid extends Mark { - constructor({binWidth = 20, clip = true, ...options} = {}) { + constructor({binWidth = 20, clip = "frame", ...options} = {}) { super(undefined, undefined, {clip, ...options}, defaults); this.binWidth = number(binWidth); } diff --git a/test/output/armadillo.svg b/test/output/armadillo.svg index 5679253c94..a5fe90f065 100644 --- a/test/output/armadillo.svg +++ b/test/output/armadillo.svg @@ -25,7 +25,10 @@ - + + + + \ No newline at end of file diff --git a/test/output/bertin1953Facets.svg b/test/output/bertin1953Facets.svg index c0bb3e9cea..2597b29de8 100644 --- a/test/output/bertin1953Facets.svg +++ b/test/output/bertin1953Facets.svg @@ -23,19 +23,31 @@ - + + + + - + + + + - + + + + - + + + + diff --git a/test/output/graticule.svg b/test/output/graticule.svg index f7dee14ee7..00d23ceb54 100644 --- a/test/output/graticule.svg +++ b/test/output/graticule.svg @@ -13,10 +13,16 @@ white-space: pre; } - + + + + - + + + + \ No newline at end of file diff --git a/test/output/nullProjection.svg b/test/output/nullProjection.svg index d11171d822..abb971ce22 100644 --- a/test/output/nullProjection.svg +++ b/test/output/nullProjection.svg @@ -13,7 +13,10 @@ white-space: pre; } - + + + + \ No newline at end of file diff --git a/test/output/usCountyChoropleth.html b/test/output/usCountyChoropleth.html index 5a74545d3d..38678e42c1 100644 --- a/test/output/usCountyChoropleth.html +++ b/test/output/usCountyChoropleth.html @@ -65,7 +65,10 @@ white-space: pre; } - + + + + Mohave @@ -9760,7 +9763,10 @@ Yavapai - + + + + \ No newline at end of file diff --git a/test/output/usStateCapitals.svg b/test/output/usStateCapitals.svg index 1d7c52a496..0780681f9e 100644 --- a/test/output/usStateCapitals.svg +++ b/test/output/usStateCapitals.svg @@ -13,7 +13,10 @@ white-space: pre; } - + + + + @@ -71,7 +74,10 @@ - + + + + diff --git a/test/output/usStateCapitalsVoronoi.svg b/test/output/usStateCapitalsVoronoi.svg index 182f0577f4..5c66e5a395 100644 --- a/test/output/usStateCapitalsVoronoi.svg +++ b/test/output/usStateCapitalsVoronoi.svg @@ -13,7 +13,10 @@ white-space: pre; } - + + + + @@ -66,8 +69,8 @@ - - + + @@ -215,7 +218,10 @@ Wyoming - + + + + \ No newline at end of file diff --git a/test/output/walmarts.html b/test/output/walmarts.html index 393a3117c8..3a3577ee3d 100644 --- a/test/output/walmarts.html +++ b/test/output/walmarts.html @@ -43,7 +43,10 @@ white-space: pre; } - + + + + diff --git a/test/output/walmartsDecades.svg b/test/output/walmartsDecades.svg index 85be759078..b2dcebf6fe 100644 --- a/test/output/walmartsDecades.svg +++ b/test/output/walmartsDecades.svg @@ -31,57 +31,102 @@ - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + - + + + + diff --git a/test/output/walmartsDensity.svg b/test/output/walmartsDensity.svg index 87606c4e4d..0156bf85d5 100644 --- a/test/output/walmartsDensity.svg +++ b/test/output/walmartsDensity.svg @@ -3145,7 +3145,10 @@ - + + + + \ No newline at end of file From 1bc1edb82483034c7db00f55e1344853673cbf5b Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Wed, 30 Nov 2022 18:57:52 -0800 Subject: [PATCH 2/2] inset instead of margin --- test/output/armadillo.svg | 12 +- test/output/usStateCapitalsVoronoi.svg | 202 ++++++++++++------------ test/plots/armadillo.js | 2 +- test/plots/us-state-capitals-voronoi.js | 2 +- 4 files changed, 109 insertions(+), 109 deletions(-) diff --git a/test/output/armadillo.svg b/test/output/armadillo.svg index a5fe90f065..ce985ed363 100644 --- a/test/output/armadillo.svg +++ b/test/output/armadillo.svg @@ -15,20 +15,20 @@ - + - + - + - + - + - + \ No newline at end of file diff --git a/test/output/usStateCapitalsVoronoi.svg b/test/output/usStateCapitalsVoronoi.svg index 5c66e5a395..a472d4a736 100644 --- a/test/output/usStateCapitalsVoronoi.svg +++ b/test/output/usStateCapitalsVoronoi.svg @@ -15,213 +15,213 @@ - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + Alabama - + Arizona - + Arkansas - + California - + Colorado - + Connecticut - + Delaware - + Florida - + Georgia - + Idaho - + Illinois - + Indiana - + Iowa - + Kansas - + Kentucky - + Louisiana - + Maine - + Maryland - + Massachusetts - + Michigan - + Minnesota - + Mississippi - + Missouri - + Montana - + Nebraska - + Nevada - + New Hampshire - + New Jersey - + New Mexico - + North Carolina - + North Dakota - + New York - + Ohio - + Oklahoma - + Oregon - + Pennsylvania - + Rhode Island - + South Carolina - + South Dakota - + Tennessee - + Texas - + Utah - + Vermont - + Virginia - + Washington - + West Virginia - + Wisconsin - + Wyoming - + - + \ No newline at end of file diff --git a/test/plots/armadillo.js b/test/plots/armadillo.js index 73d69dc5b9..53c8c5417d 100644 --- a/test/plots/armadillo.js +++ b/test/plots/armadillo.js @@ -9,7 +9,7 @@ export default async function () { return Plot.plot({ width: 960, height: 548, - margin: 1, + inset: 1, projection: ({width, height}) => geoArmadillo().precision(0.2).fitSize([width, height], {type: "Sphere"}), marks: [Plot.geo(land, {clip: "sphere", fill: "currentColor"}), Plot.graticule({clip: "sphere"}), Plot.sphere()] }); diff --git a/test/plots/us-state-capitals-voronoi.js b/test/plots/us-state-capitals-voronoi.js index 88230d359d..7c72ab2a80 100644 --- a/test/plots/us-state-capitals-voronoi.js +++ b/test/plots/us-state-capitals-voronoi.js @@ -10,7 +10,7 @@ export default async function () { return Plot.plot({ width: 640, height: 640, - margin: 1, + inset: 1, projection: ({width, height}) => d3.geoAzimuthalEqualArea().rotate([96, -40]).clipAngle(24).fitSize([width, height], {type: "Sphere"}), marks: [