Skip to content

Commit

Permalink
bin reduce: extent
Browse files Browse the repository at this point in the history
  • Loading branch information
Fil committed Mar 21, 2023
1 parent ca66b97 commit 79c6e8a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
22 changes: 18 additions & 4 deletions src/reducer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ export type ReducerName =

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

export type ReducerImplementation<T> = (
export type ReducerImplementation = (
| {
reduce: T;
reduce: ReducerName;
scale?: Channel["scale"];
}
| {
Expand All @@ -43,10 +43,24 @@ export type ReducerImplementation<T> = (
}
) & {label?: string | null};

export type Reducer = ReducerName | ReducerFunction | ReducerImplementation<ReducerName>;
export type BinReducerImplementation = (
| {
reduce: BinReducerName;
scale?: Channel["scale"];
}
| {
reduce(index: number[], values: any[], extent: {x1: any; y1: any; x2: any; y2: any}): any;
}
| {
reduce(index: number[], values: any[], summary?: any, extent?: {x1: any; y1: any; x2: any; y2: any}): any;
scope: "data" | "facet";
}
) & {label?: string | null};

export type Reducer = ReducerName | ReducerFunction | ReducerImplementation;

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

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

export type BinReducer = BinReducerName | BinReducerFunction | ReducerImplementation<BinReducerName>;
export type BinReducer = BinReducerName | BinReducerFunction | BinReducerImplementation;
4 changes: 2 additions & 2 deletions test/plots/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ async function reducerBinScope(scope) {
{
y: "count",
fill: {
reduce: function (index, values, summary) {
reduce: function (index: number[], values: any[], summary?: any, extent?: any) {
const mode = d3.mode(index, (i) => values[i]);
return arguments.length === 4 ? summary === mode : mode;
return extent === undefined ? mode : summary === mode;
},
scope
}
Expand Down

0 comments on commit 79c6e8a

Please sign in to comment.