@@ -2,7 +2,7 @@ import {map, number, valueof} from "../options.js";
2
2
import { applyPosition } from "../projection.js" ;
3
3
import { sqrt3 } from "../symbol.js" ;
4
4
import { initializer } from "./basic.js" ;
5
- import { hasOutput , maybeGroup , maybeOutputs , maybeSubgroup } from "./group.js" ;
5
+ import { hasOutput , maybeGroup , maybeGroupOutputs , maybeSubgroup } from "./group.js" ;
6
6
7
7
// We don’t want the hexagons to align with the edges of the plot frame, as that
8
8
// would cause extreme x-values (the upper bound of the default x-scale domain)
@@ -16,9 +16,8 @@ export function hexbin(outputs = {fill: "count"}, {binWidth, ...options} = {}) {
16
16
const { z} = options ;
17
17
18
18
// TODO filter e.g. to show empty hexbins?
19
- // TODO disallow x, x1, x2, y, y1, y2 reducers?
20
19
binWidth = binWidth === undefined ? 20 : number ( binWidth ) ;
21
- outputs = maybeOutputs ( outputs , options ) ;
20
+ outputs = maybeGroupOutputs ( outputs , options ) ;
22
21
23
22
// A fill output means a fill channel; declaring the channel here instead of
24
23
// waiting for the initializer allows the mark constructor to determine that
@@ -65,15 +64,15 @@ export function hexbin(outputs = {fill: "count"}, {binWidth, ...options} = {}) {
65
64
const binFacet = [ ] ;
66
65
for ( const o of outputs ) o . scope ( "facet" , facet ) ;
67
66
for ( const [ f , I ] of maybeGroup ( facet , G ) ) {
68
- for ( const bin of hbin ( I , X , Y , binWidth ) ) {
67
+ for ( const { index : b , extent } of hbin ( data , I , X , Y , binWidth ) ) {
69
68
binFacet . push ( ++ i ) ;
70
- BX . push ( bin . x ) ;
71
- BY . push ( bin . y ) ;
72
- if ( Z ) GZ . push ( G === Z ? f : Z [ bin [ 0 ] ] ) ;
73
- if ( F ) GF . push ( G === F ? f : F [ bin [ 0 ] ] ) ;
74
- if ( S ) GS . push ( G === S ? f : S [ bin [ 0 ] ] ) ;
75
- if ( Q ) GQ . push ( G === Q ? f : Q [ bin [ 0 ] ] ) ;
76
- for ( const o of outputs ) o . reduce ( bin ) ;
69
+ BX . push ( extent . x ) ;
70
+ BY . push ( extent . y ) ;
71
+ if ( Z ) GZ . push ( G === Z ? f : Z [ b [ 0 ] ] ) ;
72
+ if ( F ) GF . push ( G === F ? f : F [ b [ 0 ] ] ) ;
73
+ if ( S ) GS . push ( G === S ? f : S [ b [ 0 ] ] ) ;
74
+ if ( Q ) GQ . push ( G === Q ? f : Q [ b [ 0 ] ] ) ;
75
+ for ( const o of outputs ) o . reduce ( b , extent ) ;
77
76
}
78
77
}
79
78
binFacets . push ( binFacet ) ;
@@ -106,7 +105,7 @@ export function hexbin(outputs = {fill: "count"}, {binWidth, ...options} = {}) {
106
105
} ) ;
107
106
}
108
107
109
- function hbin ( I , X , Y , dx ) {
108
+ function hbin ( data , I , X , Y , dx ) {
110
109
const dy = dx * ( 1.5 / sqrt3 ) ;
111
110
const bins = new Map ( ) ;
112
111
for ( const i of I ) {
@@ -127,11 +126,10 @@ function hbin(I, X, Y, dx) {
127
126
const key = `${ pi } ,${ pj } ` ;
128
127
let bin = bins . get ( key ) ;
129
128
if ( bin === undefined ) {
130
- bins . set ( key , ( bin = [ ] ) ) ;
131
- bin . x = ( pi + ( pj & 1 ) / 2 ) * dx + ox ;
132
- bin . y = pj * dy + oy ;
129
+ bin = { index : [ ] , extent : { data, x : ( pi + ( pj & 1 ) / 2 ) * dx + ox , y : pj * dy + oy } } ;
130
+ bins . set ( key , bin ) ;
133
131
}
134
- bin . push ( i ) ;
132
+ bin . index . push ( i ) ;
135
133
}
136
134
return bins . values ( ) ;
137
135
}
0 commit comments