Skip to content

Commit de388b8

Browse files
committed
fix ignored {label} on outputs
1 parent 2e52bef commit de388b8

4 files changed

Lines changed: 6 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2126,7 +2126,7 @@ The following aggregation methods are supported:
21262126
* *y1* - the lower bound of the bin’s *y* extent (when binning on *y*)
21272127
* *y2* - the upper bound of the bin’s *y* extent (when binning on *y*)
21282128
* a function to be passed the array of values for each bin and the extent of the bin
2129-
* an object with a *reduce* method, and optionally a *scope*
2129+
* an object with a *reduce* method, and optionally a *scope* and a *label*
21302130
21312131
In the last case, the *reduce* method is repeatedly passed three arguments: the index for each bin (an array of integers), the input channel’s array of values, and the extent of the bin (an object {x1, x2, y1, y2}); it must then return the corresponding aggregate value for the bin. If the reducer object’s *scope* is “data”, then the *reduce* method is first invoked for the full data; the return value of the *reduce* method is then made available as a third argument (making the extent the fourth argument). Similarly if the *scope* is “facet”, then the *reduce* method is invoked for each facet, and the resulting reduce value is made available while reducing the facet’s bins. (This optional *scope* is used by the *proportion* and *proportion-facet* reducers.)
21322132
@@ -2277,7 +2277,7 @@ The following aggregation methods are supported:
22772277
* *deviation* - the standard deviation
22782278
* *variance* - the variance per [Welford’s algorithm](https://en.wikipedia.org/wiki/Algorithms_for_calculating_variance#Welford's_online_algorithm)
22792279
* a function - passed the array of values for each group
2280-
* an object with a *reduce* method, an optionally a *scope*
2280+
* an object with a *reduce* method, an optionally a *scope* and a *label*
22812281
22822282
In the last case, the *reduce* method is repeatedly passed two arguments: the index for each group (an array of integers), and the input channel’s array of values; it must then return the corresponding aggregate value for the group. If the reducer object’s *scope* is “data”, then the *reduce* method is first invoked for the full data; the return value of the *reduce* method is then made available as a third argument. Similarly if the *scope* is “facet”, then the *reduce* method is invoked for each facet, and the resulting reduce value is made available while reducing the facet’s groups. (This optional *scope* is used by the *proportion* and *proportion-facet* reducers.)
22832283

src/transforms/group.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,9 +178,10 @@ export function maybeOutputs(outputs, inputs, asOutput = maybeOutput) {
178178

179179
export function maybeOutput(name, reduce, inputs, asEvaluator = maybeEvaluator) {
180180
let scale; // optional per-channel scale override
181+
let {label} = reduce;
181182
if (isObject(reduce) && typeof reduce.reduce !== "function") (scale = reduce.scale), (reduce = reduce.reduce);
182183
const evaluator = asEvaluator(name, reduce, inputs);
183-
const [output, setOutput] = column(evaluator.label);
184+
const [output, setOutput] = column(label !== undefined ? label : evaluator.label);
184185
let O;
185186
return {
186187
name,

test/output/reducerGroupFunction.svg

Lines changed: 1 addition & 1 deletion
Loading

test/plots/reducers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export async function reducerGroupFunction() {
220220
penguins,
221221
Plot.groupX(
222222
{
223-
y: "count",
223+
y: {reduce: "count", label: "# of specimens"},
224224
fill: (values) => d3.mode(values)
225225
},
226226
{x: "species", fill: "island", fy: "sex"}

0 commit comments

Comments
 (0)