@@ -11,14 +11,14 @@ import {hasOutput, maybeOutputs} from "./group.js";
11
11
export const ox = 0.5 , oy = 0 ;
12
12
13
13
export function hexbin ( outputs = { fill : "count" } , options = { } ) {
14
- const { radius , ...rest } = outputs ;
15
- return hexbinn ( rest , { radius , ...options } ) ;
14
+ const { binWidth , ...rest } = outputs ;
15
+ return hexbinn ( rest , { binWidth , ...options } ) ;
16
16
}
17
17
18
18
// TODO filter e.g. to show empty hexbins?
19
19
// TODO disallow x, x1, x2, y, y1, y2 reducers?
20
- function hexbinn ( outputs , { radius = 10 , fill, stroke, z, ...options } ) {
21
- radius = + radius ;
20
+ function hexbinn ( outputs , { binWidth = 20 , fill, stroke, z, ...options } ) {
21
+ binWidth = + binWidth ;
22
22
const [ GZ , setGZ ] = maybeChannel ( z ) ;
23
23
const [ vfill ] = maybeColorChannel ( fill ) ;
24
24
const [ vstroke ] = maybeColorChannel ( stroke ) ;
@@ -31,7 +31,7 @@ function hexbinn(outputs, {radius = 10, fill, stroke, z, ...options}) {
31
31
} , { fill, stroke, ...options } ) ;
32
32
return {
33
33
symbol : "hexagon" ,
34
- ...! hasOutput ( outputs , "r" ) && { r : radius } ,
34
+ ...! hasOutput ( outputs , "r" ) && { r : binWidth / 2 } ,
35
35
...! setGF && { fill} ,
36
36
...( ( hasOutput ( outputs , "fill" ) || setGF ) && stroke === undefined ) ? { stroke : "none" } : { stroke} ,
37
37
...options ,
@@ -55,7 +55,7 @@ function hexbinn(outputs, {radius = 10, fill, stroke, z, ...options}) {
55
55
const binFacet = [ ] ;
56
56
for ( const o of outputs ) o . scope ( "facet" , facet ) ;
57
57
for ( const index of Z ? group ( facet , i => Z [ i ] ) . values ( ) : [ facet ] ) {
58
- for ( const bin of hbin ( index , X , Y , radius ) ) {
58
+ for ( const bin of hbin ( index , X , Y , binWidth ) ) {
59
59
binFacet . push ( ++ i ) ;
60
60
BX . push ( bin . x ) ;
61
61
BY . push ( bin . y ) ;
@@ -67,7 +67,7 @@ function hexbinn(outputs, {radius = 10, fill, stroke, z, ...options}) {
67
67
const channels = {
68
68
x : { value : BX } ,
69
69
y : { value : BY } ,
70
- ...Object . fromEntries ( outputs . map ( ( { name, output} ) => [ name , { scale : true , radius : name === "r" ? radius : undefined , value : output . transform ( ) } ] ) )
70
+ ...Object . fromEntries ( outputs . map ( ( { name, output} ) => [ name , { scale : true , binWidth : name === "r" ? binWidth : undefined , value : output . transform ( ) } ] ) )
71
71
} ;
72
72
if ( "r" in channels ) {
73
73
const R = channels . r . value ;
@@ -78,9 +78,8 @@ function hexbinn(outputs, {radius = 10, fill, stroke, z, ...options}) {
78
78
} ;
79
79
}
80
80
81
- function hbin ( I , X , Y , r ) {
82
- const dx = r * 2 ;
83
- const dy = r * sqrt3 ;
81
+ function hbin ( I , X , Y , dx ) {
82
+ const dy = dx * sqrt3 / 2 ;
84
83
const bins = new Map ( ) ;
85
84
for ( const i of I ) {
86
85
let px = X [ i ] / dx ;
0 commit comments