From 4b6a490e6bfc87dba9c8d1a2e2465014b944de1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Mon, 30 May 2022 18:17:32 +0200 Subject: [PATCH 1/2] the default sorting of Plot.dot didn't work with Plot.hexbin MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … because options.r was undefined when we initialized the mark (i.e. before the initializer is called). In that case we now pass a channel (an empty array), allowing Plot.dot to set up the default sort. The channel will be overridden by the initializer. --- README.md | 2 - src/transforms/hexbin.js | 6 +- test/output/hexbin.svg | 168 +++++++-------- test/output/hexbinR.html | 392 +++++++++++++++++----------------- test/output/hexbinSymbol.html | 146 ++++++------- test/output/hexbinZ.html | 154 ++++++------- test/output/hexbinZNull.svg | 168 +++++++-------- 7 files changed, 519 insertions(+), 517 deletions(-) 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/transforms/hexbin.js b/src/transforms/hexbin.js index 0550044aaf..fcd06690e7 100644 --- a/src/transforms/hexbin.js +++ b/src/transforms/hexbin.js @@ -27,7 +27,11 @@ export function hexbin(outputs = {fill: "count"}, inputs = {}) { // Populate default values for the r and symbol options, as appropriate. if (options.symbol === undefined) options.symbol = "hexagon"; - if (options.r === undefined && !hasOutput(outputs, "r")) options.r = binWidth / 2; + if (hasOutput(outputs, "r")) { + options.r = []; // hint that options.r will be set by the initializer and that Plot.dot must sort + } else if (options.r === undefined) { + options.r = binWidth / 2; + } return initializer(options, (data, facets, {x: X, y: Y, z: Z, fill: F, stroke: S, symbol: Q}, scales) => { if (X === undefined) throw new Error("missing channel: x"); 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 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/test/output/hexbinR.html b/test/output/hexbinR.html index be583f3ae8..6d10c759ea 100644 --- a/test/output/hexbinR.html +++ b/test/output/hexbinR.html @@ -116,71 +116,128 @@ + + 8 + + + 8 + 7 - - 1 + + 7 - - 2 + + 7 + + + 6 + + + 6 + + + 6 5 - - 2 + + 5 + + + 5 + + + 5 + + + 5 + + + 4 + + + 4 3 - - 1 + + 3 - - 1 + + 3 - - 5 + + 3 - - 1 + + 3 - + + 3 + + 2 - - 4 + + 2 + + + 2 2 - - 6 + + 2 - - 1 + + 2 - - 6 + + 2 - + 2 - + 2 - - 3 + + 2 - + + 2 + + + 2 + + + 2 + + + 2 + + 1 - - 7 + + 1 - - 3 + + 1 + + + 1 + + + 1 + + + 1 1 @@ -200,30 +257,12 @@ 1 - - 5 - - - 3 - 1 - - 5 - 1 - - 2 - - - 2 - - - 2 - 1 @@ -233,15 +272,9 @@ 1 - - 2 - 1 - - 2 - 1 @@ -257,51 +290,18 @@ 1 - - 2 - - - 6 - - - 8 - - - 4 - 1 - - 8 - - - 5 - 1 - - 3 - 1 - - 7 - 1 - - 2 - - - 3 - - - 2 - 1 @@ -319,57 +319,138 @@ + + 11 + + + 10 + + + 9 + + + 8 + + + 6 + + + 6 + 5 - - 1 + + 5 + + + 4 + + + 4 3 - - 2 + + 3 - - 1 + + 3 - - 1 + + 3 - - 1 + + 3 - - 2 + + 3 - + 3 - - 1 + + 3 - - 10 + + 3 - - 9 + + 3 - + + 3 + + 3 + + 3 + + + 2 + + + 2 + 2 + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 2 + + + 1 + + + 1 + + + 1 + + + 1 + + + 1 + 1 1 - - 6 - 1 @@ -379,24 +460,12 @@ 1 - - 3 - - - 3 - 1 1 - - 3 - - - 2 - 1 @@ -406,90 +475,30 @@ 1 - - 2 - - - 3 - - - 8 - - - 3 - - - 2 - - - 2 - 1 - - 4 - - - 2 - 1 1 - - 3 - 1 - - 2 - 1 - - 11 - - - 6 - - - 3 - - - 5 - - - 4 - 1 - - 2 - 1 - - 2 - 1 - - 3 - - - 3 - - - 2 - 1 @@ -502,24 +511,15 @@ 1 - - 3 - 1 - - 2 - 1 1 - - 2 - 1 @@ -534,15 +534,15 @@ + + 2 + 1 1 - - 2 - 1 diff --git a/test/output/hexbinSymbol.html b/test/output/hexbinSymbol.html index 4badaf42c4..82439318dd 100644 --- a/test/output/hexbinSymbol.html +++ b/test/output/hexbinSymbol.html @@ -146,60 +146,113 @@ culmen_depth_mm → + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - @@ -219,30 +272,16 @@ - - - - - - - - - - - - - - @@ -251,46 +290,31 @@ - - - - - - - - - - - - - - - @@ -298,62 +322,38 @@ - - - - - - - - - - - - - - - - - - - - - - - - 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 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - From 5f4b6d4652547f37dda15dac3699632056062619 Mon Sep 17 00:00:00 2001 From: Mike Bostock Date: Mon, 30 May 2022 09:37:57 -0700 Subject: [PATCH 2/2] tweak style --- src/transforms/hexbin.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/transforms/hexbin.js b/src/transforms/hexbin.js index fcd06690e7..b958947837 100644 --- a/src/transforms/hexbin.js +++ b/src/transforms/hexbin.js @@ -27,11 +27,8 @@ export function hexbin(outputs = {fill: "count"}, inputs = {}) { // Populate default values for the r and symbol options, as appropriate. if (options.symbol === undefined) options.symbol = "hexagon"; - if (hasOutput(outputs, "r")) { - options.r = []; // hint that options.r will be set by the initializer and that Plot.dot must sort - } else if (options.r === undefined) { - options.r = binWidth / 2; - } + if (hasOutput(outputs, "r")) options.r = []; // hint that r channel will exist (e.g., for dot to sort) + else if (options.r === undefined) options.r = binWidth / 2; return initializer(options, (data, facets, {x: X, y: Y, z: Z, fill: F, stroke: S, symbol: Q}, scales) => { if (X === undefined) throw new Error("missing channel: x");