@@ -69,14 +69,14 @@ export function inferChannelScale(name, channel) {
69
69
// Note: mutates channel.domain! This is set to a function so that it is lazily
70
70
// computed; i.e., if the scale’s domain is set explicitly, that takes priority
71
71
// 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 ) {
73
73
const { reverse : defaultReverse , reduce : defaultReduce = true , limit : defaultLimit } = options ;
74
74
for ( const x in options ) {
75
75
if ( ! registry . has ( x ) ) continue ; // ignore unknown scale keys (including generic options)
76
76
let { value : y , reverse = defaultReverse , reduce = defaultReduce , limit = defaultLimit } = maybeValue ( options [ x ] ) ;
77
77
if ( reverse === undefined ) reverse = y === "width" || y === "height" ; // default to descending for lengths
78
78
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 ) ;
80
80
if ( ! X ) throw new Error ( `missing channel for scale: ${ x } ` ) ;
81
81
const XV = X . value ;
82
82
const [ lo = 0 , hi = Infinity ] = isIterable ( limit ) ? limit : limit < 0 ? [ limit ] : [ 0 , limit ] ;
@@ -118,6 +118,21 @@ function findScaleChannel(channels, scale) {
118
118
}
119
119
}
120
120
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
+
121
136
function difference ( channels , k1 , k2 ) {
122
137
const X1 = values ( channels , k1 ) ;
123
138
const X2 = values ( channels , k2 ) ;
0 commit comments