Skip to content

Commit 949f9b5

Browse files
authored
fix hexbin + dot sort (#891)
1 parent 48115f9 commit 949f9b5

File tree

10 files changed

+594
-593
lines changed

10 files changed

+594
-593
lines changed

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2250,8 +2250,6 @@ The following aggregation methods are supported:
22502250
* a function to be passed the array of values for each bin and the extent of the bin
22512251
* an object with a *reduce* method
22522252
2253-
When the hexbin transform has an *r* output channel, bins are returned in order of descending radius.
2254-
22552253
See also the [hexgrid](#hexgrid) mark.
22562254
22572255
### Custom initializers

src/channel.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,20 @@ export function channelDomain(channels, facetChannels, data, options) {
7373
}
7474
}
7575

76-
function sortInitializer(name, compare = ascendingDefined) {
76+
function sortInitializer(name, optional, compare = ascendingDefined) {
7777
return (data, facets, {[name]: V}) => {
78-
if (!V) throw new Error(`missing channel: ${name}`);
78+
if (!V) {
79+
if (optional) return {}; // do nothing if given channel does not exist
80+
throw new Error(`missing channel: ${name}`);
81+
}
7982
V = V.value;
8083
const compareValue = (i, j) => compare(V[i], V[j]);
8184
return {facets: facets.map(I => I.slice().sort(compareValue))};
8285
};
8386
}
8487

85-
export function channelSort(initializer, {channel, reverse}) {
86-
return composeInitializer(initializer, sortInitializer(channel, reverse ? descendingDefined : ascendingDefined));
88+
export function channelSort(initializer, {channel, optional, reverse}) {
89+
return composeInitializer(initializer, sortInitializer(channel, optional, reverse ? descendingDefined : ascendingDefined));
8790
}
8891

8992
function findScaleChannel(channels, scale) {

src/marks/dot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class Dot extends Mark {
2828
{name: "rotate", value: vrotate, optional: true},
2929
{name: "symbol", value: vsymbol, scale: "symbol", optional: true}
3030
],
31-
vr === undefined || options.sort !== undefined ? options : {...options, sort: {channel: "r", reverse: true}},
31+
options.sort === undefined ? {...options, sort: {channel: "r", optional: true, reverse: true}} : options,
3232
defaults
3333
);
3434
this.r = cr;

test/output/hexbin.svg

Lines changed: 84 additions & 84 deletions
Loading

test/output/hexbinR.html

Lines changed: 196 additions & 196 deletions
Large diffs are not rendered by default.

test/output/hexbinSymbol.html

Lines changed: 73 additions & 73 deletions
Large diffs are not rendered by default.

test/output/hexbinText.svg

Lines changed: 68 additions & 68 deletions
Loading

test/output/hexbinZ.html

Lines changed: 77 additions & 77 deletions
Large diffs are not rendered by default.

test/output/hexbinZNull.svg

Lines changed: 84 additions & 84 deletions
Loading

test/output/penguinDodgeHexbin.svg

Lines changed: 4 additions & 4 deletions
Loading

0 commit comments

Comments
 (0)