Skip to content

Commit 79c6e8a

Browse files
committed
bin reduce: extent
1 parent ca66b97 commit 79c6e8a

2 files changed

Lines changed: 20 additions & 6 deletions

File tree

src/reducer.d.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ export type ReducerName =
2929

3030
export type ReducerFunction = (values: any[]) => any;
3131

32-
export type ReducerImplementation<T> = (
32+
export type ReducerImplementation = (
3333
| {
34-
reduce: T;
34+
reduce: ReducerName;
3535
scale?: Channel["scale"];
3636
}
3737
| {
@@ -43,10 +43,24 @@ export type ReducerImplementation<T> = (
4343
}
4444
) & {label?: string | null};
4545

46-
export type Reducer = ReducerName | ReducerFunction | ReducerImplementation<ReducerName>;
46+
export type BinReducerImplementation = (
47+
| {
48+
reduce: BinReducerName;
49+
scale?: Channel["scale"];
50+
}
51+
| {
52+
reduce(index: number[], values: any[], extent: {x1: any; y1: any; x2: any; y2: any}): any;
53+
}
54+
| {
55+
reduce(index: number[], values: any[], summary?: any, extent?: {x1: any; y1: any; x2: any; y2: any}): any;
56+
scope: "data" | "facet";
57+
}
58+
) & {label?: string | null};
59+
60+
export type Reducer = ReducerName | ReducerFunction | ReducerImplementation;
4761

4862
type BinReducerFunction = (values: any[], extent: {x1: any; y1: any; x2: any; y2: any}) => any;
4963

5064
type BinReducerName = ReducerName | "x" | "x1" | "x2" | "y" | "y1" | "y2";
5165

52-
export type BinReducer = BinReducerName | BinReducerFunction | ReducerImplementation<BinReducerName>;
66+
export type BinReducer = BinReducerName | BinReducerFunction | BinReducerImplementation;

test/plots/reducers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ async function reducerBinScope(scope) {
2222
{
2323
y: "count",
2424
fill: {
25-
reduce: function (index, values, summary) {
25+
reduce: function (index: number[], values: any[], summary?: any, extent?: any) {
2626
const mode = d3.mode(index, (i) => values[i]);
27-
return arguments.length === 4 ? summary === mode : mode;
27+
return extent === undefined ? mode : summary === mode;
2828
},
2929
scope
3030
}

0 commit comments

Comments
 (0)