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