Skip to content

fix hexbin + dot sort #891

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 1 commit into from
May 31, 2022
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
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2250,8 +2250,6 @@ The following aggregation methods are supported:
* a function to be passed the array of values for each bin and the extent of the bin
* an object with a *reduce* method

When the hexbin transform has an *r* output channel, bins are returned in order of descending radius.

See also the [hexgrid](#hexgrid) mark.

### Custom initializers
Expand Down
11 changes: 7 additions & 4 deletions src/channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,20 @@ export function channelDomain(channels, facetChannels, data, options) {
}
}

function sortInitializer(name, compare = ascendingDefined) {
function sortInitializer(name, optional, compare = ascendingDefined) {
return (data, facets, {[name]: V}) => {
if (!V) throw new Error(`missing channel: ${name}`);
if (!V) {
if (optional) return {}; // do nothing if given channel does not exist
throw new Error(`missing channel: ${name}`);
}
V = V.value;
const compareValue = (i, j) => compare(V[i], V[j]);
return {facets: facets.map(I => I.slice().sort(compareValue))};
};
}

export function channelSort(initializer, {channel, reverse}) {
return composeInitializer(initializer, sortInitializer(channel, reverse ? descendingDefined : ascendingDefined));
export function channelSort(initializer, {channel, optional, reverse}) {
return composeInitializer(initializer, sortInitializer(channel, optional, reverse ? descendingDefined : ascendingDefined));
}

function findScaleChannel(channels, scale) {
Expand Down
2 changes: 1 addition & 1 deletion src/marks/dot.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Dot extends Mark {
{name: "rotate", value: vrotate, optional: true},
{name: "symbol", value: vsymbol, scale: "symbol", optional: true}
],
vr === undefined || options.sort !== undefined ? options : {...options, sort: {channel: "r", reverse: true}},
options.sort === undefined ? {...options, sort: {channel: "r", optional: true, reverse: true}} : options,
defaults
);
this.r = cr;
Expand Down
168 changes: 84 additions & 84 deletions test/output/hexbin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
392 changes: 196 additions & 196 deletions test/output/hexbinR.html

Large diffs are not rendered by default.

146 changes: 73 additions & 73 deletions test/output/hexbinSymbol.html

Large diffs are not rendered by default.

136 changes: 68 additions & 68 deletions test/output/hexbinText.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 77 additions & 77 deletions test/output/hexbinZ.html

Large diffs are not rendered by default.

168 changes: 84 additions & 84 deletions test/output/hexbinZNull.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions test/output/penguinDodgeHexbin.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.