Skip to content

Commit 395f571

Browse files
authored
jsdocs: contour, raster (#1234)
* jsdocs: contour, raster * centroid, geoCentroid * identity * add Plot.identity in the release notes * jsdoc for spatial interpolation
1 parent 96e4ea0 commit 395f571

File tree

5 files changed

+26
-3
lines changed

5 files changed

+26
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Plot.plot({
124124
});
125125
```
126126

127-
The new [geoCentroid transform](./README.md#plotgeocentroidoptions) and [centroid initializer](./README.md#plotcentroidoptions) compute the spherical and projected planar centroids of geometry, respectively.
127+
The new [geoCentroid transform](./README.md#plotgeocentroidoptions) and [centroid initializer](./README.md#plotcentroidoptions) compute the spherical and projected planar centroids of geometry, respectively. The new [identity](./README.md#plotidentity) channel helper returns a source array as-is, avoiding an extra copy.
128128

129129
The **interval** option now supports named time intervals such as “sunday” and “hour”, equivalent to the corresponding d3-time interval (_e.g._, d3.utcSunday and d3.utcHour). The [bin transform](./README.md#bin) is now many times faster, especially when there are many bins and when binning temporal data.
130130

README.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2190,7 +2190,7 @@ Bins on *y*. Also groups on *x* and first channel of *z*, *fill*, or *stroke*, i
21902190
21912191
<!-- jsdoc centroid -->
21922192
2193-
The centroid initializer derives **x** and **y** channels representing the planar (projected) centroids for the the given GeoJSON geometry. If the **geometry** option is not specified, the mark’s data is assumed to be GeoJSON objects.
2193+
The centroid initializer derives **x** and **y** channels representing the planar (projected) centroids for the given GeoJSON geometry. If the **geometry** option is not specified, the mark’s data is assumed to be GeoJSON objects.
21942194
21952195
```js
21962196
Plot.dot(regions.features, Plot.centroid()).plot({projection: "reflect-y"})
@@ -2202,7 +2202,7 @@ Plot.dot(regions.features, Plot.centroid()).plot({projection: "reflect-y"})
22022202
22032203
<!-- jsdoc geoCentroid -->
22042204
2205-
The geoCentroid transform derives **x** and **y** channels representing the spherical centroids for the the given GeoJSON geometry. If the **geometry** option is not specified, the mark’s data is assumed to be GeoJSON objects.
2205+
The geoCentroid transform derives **x** and **y** channels representing the spherical centroids for the given GeoJSON geometry. If the **geometry** option is not specified, the mark’s data is assumed to be GeoJSON objects.
22062206
22072207
```js
22082208
Plot.dot(counties.features, Plot.geoCentroid()).plot({projection: "albers-usa"})
@@ -3038,20 +3038,36 @@ So, *x*[*index*[0]] represents the *x*-position of the first sample, *y*[*index*
30383038
30393039
#### Plot.interpolateNone(*index*, *width*, *height*, *x*, *y*, *value*)
30403040
3041+
<!-- jsdoc interpolateNone -->
3042+
30413043
Applies a simple forward mapping of samples, binning them into pixels in the raster grid without any blending or interpolation. If multiple samples map to the same pixel, the last one wins; this can introduce bias if the points are not in random order, so use [Plot.shuffle](#plotshuffleoptions) to randomize the input if needed.
30423044
3045+
<!-- jsdocEnd interpolateNone -->
3046+
30433047
#### Plot.interpolateNearest(*index*, *width*, *height*, *x*, *y*, *value*)
30443048
3049+
<!-- jsdoc interpolateNearest -->
3050+
30453051
Assigns each pixel in the raster grid the value of the closest sample; effectively a Voronoi diagram.
30463052
3053+
<!-- jsdocEnd interpolateNearest -->
3054+
30473055
#### Plot.interpolatorBarycentric({*random*})
30483056
3057+
<!-- jsdoc interpolatorBarycentric -->
3058+
30493059
Constructs a Delaunay triangulation of the samples, and then for each pixel in the raster grid, determines the triangle that covers the pixel’s centroid and interpolates the values associated with the triangle’s vertices using [barycentric coordinates](https://en.wikipedia.org/wiki/Barycentric_coordinate_system). If the interpolated values are ordinal or categorical (_i.e._, anything other than numbers or dates), then one of the three values will be picked randomly weighted by the barycentric coordinates; the given *random* number generator will be used, which defaults to a [linear congruential generator](https://github.com/d3/d3-random/blob/main/README.md#randomLcg) with a fixed seed (for deterministic results).
30503060
3061+
<!-- jsdocEnd interpolatorBarycentric -->
3062+
30513063
#### Plot.interpolatorRandomWalk({*random*, *minDistance* = 0.5, *maxSteps* = 2})
30523064
3065+
<!-- jsdoc interpolatorRandomWalk -->
3066+
30533067
For each pixel in the raster grid, initiates a random walk, stopping when either the walk is within a given distance (*minDistance*) of a sample or the maximum allowable number of steps (*maxSteps*) have been taken, and then assigning the current pixel the closest sample’s value. The random walk uses the “walk on spheres” algorithm in two dimensions described by [Sawhney and Crane](https://www.cs.cmu.edu/~kmcrane/Projects/MonteCarloGeometryProcessing/index.html), SIGGRAPH 2020.
30543068
3069+
<!-- jsdocEnd interpolatorRandomWalk -->
3070+
30553071
## Markers
30563072
30573073
A [marker](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/marker) defines a graphic drawn on vertices of a [line](#line) or a [link](#link) mark. The supported marker options are:

src/marks/contour.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ function maybeTicks(thresholds, V, min, max) {
195195
return tz;
196196
}
197197

198+
/** @jsdoc contour */
198199
export function contour() {
199200
return new Contour(...maybeTuples("value", ...arguments));
200201
}

src/marks/raster.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export function maybeTuples(k, data, options) {
186186
return [data, {...rest, x, y, [k]: z}];
187187
}
188188

189+
/** @jsdoc raster */
189190
export function raster() {
190191
const [data, options] = maybeTuples("fill", ...arguments);
191192
return new Raster(
@@ -271,6 +272,7 @@ function maybeInterpolate(interpolate) {
271272
// any blending or interpolation. Note: if multiple samples map to the same
272273
// pixel, the last one wins; this can introduce bias if the points are not in
273274
// random order, so use Plot.shuffle to randomize the input if needed.
275+
/** @jsdoc interpolateNone */
274276
export function interpolateNone(index, width, height, X, Y, V) {
275277
const W = new Array(width * height);
276278
for (const i of index) {
@@ -280,6 +282,7 @@ export function interpolateNone(index, width, height, X, Y, V) {
280282
return W;
281283
}
282284

285+
/** @jsdoc interpolatorBarycentric */
283286
export function interpolatorBarycentric({random = randomLcg(42)} = {}) {
284287
return (index, width, height, X, Y, V) => {
285288
// Flatten the input coordinates to prepare to insert extrapolated points
@@ -345,6 +348,7 @@ export function interpolatorBarycentric({random = randomLcg(42)} = {}) {
345348
};
346349
}
347350

351+
/** @jsdoc interpolateNearest */
348352
export function interpolateNearest(index, width, height, X, Y, V) {
349353
const W = new V.constructor(width * height);
350354
const delaunay = Delaunay.from(
@@ -366,6 +370,7 @@ export function interpolateNearest(index, width, height, X, Y, V) {
366370
}
367371

368372
// https://observablehq.com/@observablehq/walk-on-spheres-precision
373+
/** @jsdoc interpolatorRandomWalk */
369374
export function interpolatorRandomWalk({random = randomLcg(42), minDistance = 0.5, maxSteps = 2} = {}) {
370375
return (index, width, height, X, Y, V) => {
371376
const W = new V.constructor(width * height);

src/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ export function valueof(data, value, type) {
2222

2323
export const field = (name) => (d) => d[name];
2424
export const indexOf = (d, i) => i;
25+
/** @jsdoc identity */
2526
export const identity = {transform: (d) => d};
2627
export const zero = () => 0;
2728
export const one = () => 1;

0 commit comments

Comments
 (0)