@@ -69,14 +69,14 @@ export function inferChannelScale(name, channel) {
6969// Note: mutates channel.domain! This is set to a function so that it is lazily
7070// computed; i.e., if the scale’s domain is set explicitly, that takes priority
7171// over the sort option, and we don’t need to do additional work.
72- export function channelDomain ( channels , facetChannels , data , options ) {
72+ export function channelDomain ( data , facets , channels , facetChannels , options ) {
7373 const { reverse : defaultReverse , reduce : defaultReduce = true , limit : defaultLimit } = options ;
7474 for ( const x in options ) {
7575 if ( ! registry . has ( x ) ) continue ; // ignore unknown scale keys (including generic options)
7676 let { value : y , reverse = defaultReverse , reduce = defaultReduce , limit = defaultLimit } = maybeValue ( options [ x ] ) ;
7777 if ( reverse === undefined ) reverse = y === "width" || y === "height" ; // default to descending for lengths
7878 if ( reduce == null || reduce === false ) continue ; // disabled reducer
79- const X = findScaleChannel ( channels , x ) || ( facetChannels && findScaleChannel ( facetChannels , x ) ) ;
79+ const X = x === "fx" || x === "fy" ? reindexFacetChannel ( facets , facetChannels [ x ] ) : findScaleChannel ( channels , x ) ;
8080 if ( ! X ) throw new Error ( `missing channel for scale: ${ x } ` ) ;
8181 const XV = X . value ;
8282 const [ lo = 0 , hi = Infinity ] = isIterable ( limit ) ? limit : limit < 0 ? [ limit ] : [ 0 , limit ] ;
@@ -118,6 +118,21 @@ function findScaleChannel(channels, scale) {
118118 }
119119}
120120
121+ // Facet channels are not affected by transforms; so, to compute the domain of a
122+ // facet scale, we must first re-index the facet channel according to the
123+ // transformed mark index. Note: mutates channel, but that should be safe here?
124+ function reindexFacetChannel ( facets , channel ) {
125+ const originalFacets = facets . original ;
126+ if ( originalFacets === facets ) return channel ; // not transformed
127+ const V1 = channel . value ;
128+ const V2 = ( channel . value = [ ] ) ; // mutates channel!
129+ for ( let i = 0 ; i < originalFacets . length ; ++ i ) {
130+ const vi = V1 [ originalFacets [ i ] [ 0 ] ] ;
131+ for ( const j of facets [ i ] ) V2 [ j ] = vi ;
132+ }
133+ return channel ;
134+ }
135+
121136function difference ( channels , k1 , k2 ) {
122137 const X1 = values ( channels , k1 ) ;
123138 const X2 = values ( channels , k2 ) ;
0 commit comments