-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
promote geometry to x and y for tip (#2088)
* promote geometry to x and y for tip * update docs * data provenance * geo mark x & y * move defaults to geo --------- Co-authored-by: Philippe Rivière <[email protected]>
- Loading branch information
Showing
18 changed files
with
1,119 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,40 @@ | ||
import {geoCentroid as GeoCentroid, geoPath} from "d3"; | ||
import {memoize1} from "../memoize.js"; | ||
import {identity, valueof} from "../options.js"; | ||
import {initializer} from "./basic.js"; | ||
|
||
export function centroid({geometry = identity, ...options} = {}) { | ||
// Suppress defaults for x and y since they will be computed by the initializer. | ||
return initializer({...options, x: null, y: null}, (data, facets, channels, scales, dimensions, {projection}) => { | ||
const G = valueof(data, geometry); | ||
const n = G.length; | ||
const X = new Float64Array(n); | ||
const Y = new Float64Array(n); | ||
const path = geoPath(projection); | ||
for (let i = 0; i < n; ++i) [X[i], Y[i]] = path.centroid(G[i]); | ||
return { | ||
data, | ||
facets, | ||
channels: { | ||
x: {value: X, scale: projection == null ? "x" : null, source: null}, | ||
y: {value: Y, scale: projection == null ? "y" : null, source: null} | ||
} | ||
}; | ||
}); | ||
const getG = memoize1((data) => valueof(data, geometry)); | ||
return initializer( | ||
// Suppress defaults for x and y since they will be computed by the initializer. | ||
// Propagate the (memoized) geometry channel in case it’s still needed. | ||
{...options, x: null, y: null, geometry: {transform: getG}}, | ||
(data, facets, channels, scales, dimensions, {projection}) => { | ||
const G = getG(data); | ||
const n = G.length; | ||
const X = new Float64Array(n); | ||
const Y = new Float64Array(n); | ||
const path = geoPath(projection); | ||
for (let i = 0; i < n; ++i) [X[i], Y[i]] = path.centroid(G[i]); | ||
return { | ||
data, | ||
facets, | ||
channels: { | ||
x: {value: X, scale: projection == null ? "x" : null, source: null}, | ||
y: {value: Y, scale: projection == null ? "y" : null, source: null} | ||
} | ||
}; | ||
} | ||
); | ||
} | ||
|
||
export function geoCentroid({geometry = identity, ...options} = {}) { | ||
let C; | ||
const getG = memoize1((data) => valueof(data, geometry)); | ||
const getC = memoize1((data) => valueof(getG(data), GeoCentroid)); | ||
return { | ||
...options, | ||
x: {transform: (data) => Float64Array.from((C = valueof(valueof(data, geometry), GeoCentroid)), ([x]) => x)}, | ||
y: {transform: () => Float64Array.from(C, ([, y]) => y)} | ||
x: {transform: (data) => Float64Array.from(getC(data), ([x]) => x)}, | ||
y: {transform: (data) => Float64Array.from(getC(data), ([, y]) => y)}, | ||
geometry: {transform: getG} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
borough,y2001,y2011,y2021 | ||
City of London,0.380,0.306,0.228 | ||
Barking and Dagenham,0.621,0.604,0.652 | ||
Barnet,0.733,0.713,0.701 | ||
Bexley,0.763,0.763,0.776 | ||
Brent,0.627,0.570,0.559 | ||
Bromley,0.770,0.765,0.771 | ||
Camden,0.444,0.389,0.364 | ||
Croydon,0.702,0.665,0.664 | ||
Ealing,0.683,0.647,0.632 | ||
Enfield,0.715,0.675,0.690 | ||
Greenwich,0.592,0.580,0.569 | ||
Hammersmith and Fulham,0.514,0.448,0.425 | ||
Haringey,0.535,0.482,0.473 | ||
Harrow,0.773,0.765,0.753 | ||
Havering,0.767,0.770,0.785 | ||
Hillingdon,0.783,0.773,0.777 | ||
Hounslow,0.714,0.684,0.672 | ||
Islington,0.424,0.353,0.331 | ||
Kensington and Chelsea,0.496,0.440,0.417 | ||
Kingston upon Thames,0.762,0.749,0.743 | ||
Lambeth,0.491,0.422,0.420 | ||
Lewisham,0.572,0.519,0.523 | ||
Merton,0.699,0.674,0.670 | ||
Newham,0.511,0.479,0.483 | ||
Redbridge,0.738,0.721,0.725 | ||
Richmond upon Thames,0.763,0.753,0.746 | ||
Southwark,0.481,0.416,0.397 | ||
Sutton,0.767,0.766,0.772 | ||
Tower Hamlets,0.432,0.370,0.336 | ||
Waltham Forest,0.610,0.581,0.579 | ||
Wandsworth,0.593,0.547,0.521 | ||
Westminster,0.436,0.371,0.338 | ||
Hackney,0.440,0.354,0.351 |
Oops, something went wrong.