Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2121,6 +2121,7 @@ The following aggregation methods are supported:
* *pXX* - the percentile value, where XX is a number in [00,99]
* *deviation* - the standard deviation
* *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
* *identity* - the array of values
* *x* - the middle of the bin’s *x* extent (when binning on *x*)
* *x1* - the lower bound of the bin’s *x* extent (when binning on *x*)
* *x2* - the upper bound of the bin’s *x* extent (when binning on *x*)
Expand Down Expand Up @@ -2278,6 +2279,7 @@ The following aggregation methods are supported:
* *pXX* - the percentile value, where XX is a number in [00,99]
* *deviation* - the standard deviation
* *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
* *identity* - the array of values
* a function - passed the array of values for each group
* an object with a *reduceIndex* method, an optionally a *scope*

Expand Down Expand Up @@ -2852,6 +2854,7 @@ The following aggregation methods are supported:
* *deviation* - the standard deviation
* *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
* *mode* - the value with the most occurrences
* *identity* - the array of values
* a function to be passed the array of values for each bin and the extent of the bin
* an object with a *reduceIndex* method

Expand Down
2 changes: 2 additions & 0 deletions src/reducer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ export type ReducerPercentile =
* - *variance* - the variance per [Welford’s algorithm][1]
* - *mode* - the value with the most occurrences
* - *pXX* - the percentile value, where XX is a number in [00,99]
* - *identity* - the array of values
*
* [1]: https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm
*/
export type ReducerName =
| "first"
| "last"
| "identity"
| "count"
| "distinct"
| "sum"
Expand Down
2 changes: 2 additions & 0 deletions src/transforms/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ export function maybeReduce(reduce, value, fallback = invalidReduce) {
return reduceFirst;
case "last":
return reduceLast;
case "identity":
return reduceIdentity;
case "count":
return reduceCount;
case "distinct":
Expand Down
79 changes: 79 additions & 0 deletions test/output/gridReduceIdentity.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
397 changes: 397 additions & 0 deletions test/output/hexbinIdentityReduce.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
46 changes: 0 additions & 46 deletions test/plots/grid-choropleth-dx.ts

This file was deleted.

56 changes: 56 additions & 0 deletions test/plots/grid-choropleth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,62 @@ export async function gridChoropleth() {
});
}

export async function gridChoroplethDx() {
const [grid, data] = await Promise.all([
await d3.csv<any>("data/us-state-grid.csv", d3.autoType).then(gridmap),
await d3.csv<any>("data/us-state-population-2010-2019.csv", d3.autoType)
]);
const states = data.filter((d) => grid.has(d.State)).map((d) => ({...d, ...grid.get(d.State)}));
return Plot.plot({
height: 420,
x: {
axis: null
},
y: {
axis: null
},
color: {
type: "diverging-log",
scheme: "piyg"
},
marks: [
Plot.cell(states, {x: "x", y: "y", fill: change, dx: -1.5, dy: -1.5}),
Plot.cell(states, {x: "x", y: "y", stroke: "black", dx: 1.5, dy: 1.5}),
Plot.text(states, {x: "x", y: "y", text: "key", dy: -6}),
Plot.text(states, {
x: "x",
y: "y",
text: (
(f) => (d) =>
f(change(d) - 1)
)(d3.format("+.0%")),
dy: 6,
fillOpacity: 0.6
})
]
});
}

export async function gridReduceIdentity() {
const grid = await d3.csv<any>("data/us-state-grid.csv", d3.autoType);
return Plot.plot({
axis: null,
x: {insetRight: 200},
y: {reverse: true},
aspectRatio: true,
marks: [
Plot.rect(grid, {x: "x", y: "y", stroke: "currentColor", interval: 1, inset: 3}),
Plot.text(
grid,
Plot.groupY(
{y: ([y]) => y + 0.5, text: "identity"},
{sort: "x", frameAnchor: "right", y: "y", text: "key", dx: -10, stroke: "white", fill: "currentColor"}
)
)
]
});
}

function gridmap(states: {name: string}[]) {
return new Map(states.map((state) => [state.name, state]));
}
Expand Down
19 changes: 19 additions & 0 deletions test/plots/hexbin-z.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ export async function hexbinZ() {
]
});
}

export async function hexbinIdentityReduce() {
const penguins = await d3.csv<any>("data/penguins.csv", d3.autoType);
return Plot.plot({
inset: 10,
height: 600,
marks: [
Plot.hexgrid({binWidth: 8, strokeOpacity: 0.05}),
Plot.frame(),
Plot.text(
penguins,
Plot.hexbin(
{text: "identity"},
{x: "culmen_length_mm", y: "body_mass_g", text: (d) => d.species[0], binWidth: 8, fontSize: 7}
)
)
]
});
}
1 change: 0 additions & 1 deletion test/plots/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ export * from "./gistemp-anomaly.js";
export * from "./google-trends-ridgeline.js";
export * from "./graticule.js";
export * from "./greek-gods.js";
export * from "./grid-choropleth-dx.js";
export * from "./grid-choropleth.js";
export * from "./grouped-rects.js";
export * from "./hadcrut-warming-stripes.js";
Expand Down