diff --git a/README.md b/README.md
index fa161d1b4c..073043c083 100644
--- a/README.md
+++ b/README.md
@@ -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
diff --git a/src/channel.js b/src/channel.js
index 9f013238cd..2492b52845 100644
--- a/src/channel.js
+++ b/src/channel.js
@@ -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) {
diff --git a/src/marks/dot.js b/src/marks/dot.js
index 1af725bd40..6e50b98866 100644
--- a/src/marks/dot.js
+++ b/src/marks/dot.js
@@ -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;
diff --git a/test/output/hexbin.svg b/test/output/hexbin.svg
index 7072850287..ca403822cc 100644
--- a/test/output/hexbin.svg
+++ b/test/output/hexbin.svg
@@ -88,191 +88,191 @@
+
+
+
+
+
+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+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -219,30 +272,16 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -251,46 +290,31 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -298,62 +322,38 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/output/hexbinText.svg b/test/output/hexbinText.svg
index b251c8c6f7..eee645ce84 100644
--- a/test/output/hexbinText.svg
+++ b/test/output/hexbinText.svg
@@ -86,58 +86,64 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
7447546101148212213115315122311311111115712313414662111
@@ -146,81 +152,75 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
5141131318111414541111112111225522111138131466654241110113111211
-
-
-
-
-
-
-
-
+
+
+
+
+
+
11211111
diff --git a/test/output/hexbinZ.html b/test/output/hexbinZ.html
index 2ed1230a13..588aba446e 100644
--- a/test/output/hexbinZ.html
+++ b/test/output/hexbinZ.html
@@ -95,60 +95,106 @@
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
@@ -156,12 +202,10 @@
-
-
@@ -169,40 +213,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -213,59 +243,29 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/output/hexbinZNull.svg b/test/output/hexbinZNull.svg
index 0b15f2e56f..90a829fc41 100644
--- a/test/output/hexbinZNull.svg
+++ b/test/output/hexbinZNull.svg
@@ -88,59 +88,114 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -152,18 +207,12 @@
-
-
-
-
-
-
@@ -171,30 +220,17 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -202,12 +238,8 @@
-
-
-
-
@@ -216,58 +248,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/test/output/penguinDodgeHexbin.svg b/test/output/penguinDodgeHexbin.svg
index 2a4b7b57fd..863a0fb098 100644
--- a/test/output/penguinDodgeHexbin.svg
+++ b/test/output/penguinDodgeHexbin.svg
@@ -360,6 +360,8 @@
+
+
@@ -435,8 +437,6 @@
-
-
@@ -503,6 +503,8 @@
+
+
@@ -633,8 +635,6 @@
-
-