Skip to content

document hexbin #1359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Mar 24, 2023
Merged
Changes from 4 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
54 changes: 51 additions & 3 deletions src/transforms/hexbin.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,56 @@
import type {ChannelReducers} from "../channel.js";
import type {Transformed} from "./basic.js";
import type {ChannelReducers, ChannelValue} from "../channel.js";
import type {Initialized} from "./basic.js";

/** Options for the hexbin transform. */
export interface HexbinOptions {
/**
* The horizontal distance between centers of neighboring (pointy-topped)
* hexagons, in pixels; defaults to 20.
Comment on lines +7 to +8
Copy link
Contributor Author

@Fil Fil Mar 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The distance between centers of neighboring hexagons is complete and correct :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course! Oops. Thanks for the correction.

*/
binWidth?: number;

/**
* How to group data prior to binning. If not specified, defaults to the
* *fill* channel, if any, or the *stroke* channel, if any. If null, bins will
* not be subdivided.
*/
z?: ChannelValue;
}

export function hexbin<T>(outputs?: ChannelReducers, options?: T & HexbinOptions): Transformed<T>;
/**
* Groups points specified by the *x* and *y* channels into hexagonal bins in
* scaled coordinates (pixels), computing new *x* and *y* channels as the
* centers of each bin, and deriving new output channels by applying the
* specified reducers (such as *count*) to each bin’s values. The first of the
* *z*, *fill*, or *stroke* channels, if any, will be used to subdivide bins.
*
* The hexbin transform can be applied to any mark that consumes *x* and *y*,
* such as the dot, image, text, and vector marks. For the dot mark, the
* **symbol** option defaults to *hexagon*, and the *r* option defaults to half
* the **binWidth**. If a **fill** output channel is declared, the **stroke**
* option defaults to *none*.
*
* The reducer for each channel in *outputs* may be specified as:
*
* * *first* - the first value, in input order
* * *last* - the last value, in input order
* * *count* - the number of elements (frequency)
* * *distinct* - the number of distinct values
* * *sum* - the sum of values
* * *proportion* - the sum proportional to the overall total (weighted frequency)
* * *proportion-facet* - the sum proportional to the facet total
* * *min* - the minimum value
* * *min-index* - the zero-based index of the minimum value
* * *max* - the maximum value
* * *max-index* - the zero-based index of the maximum value
* * *mean* - the mean value (average)
* * *median* - the median value
* * *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
* * a function to be passed the array of values for each bin
* * an object with a *reduceIndex* method
*
* See also the hexgrid mark.
*/
export function hexbin<T>(outputs?: ChannelReducers, options?: T & HexbinOptions): Initialized<T>;