@@ -49,7 +49,7 @@ export class Mark {
4949 const { name} = channel ;
5050 return [ name == null ? undefined : name + "" , Channel ( data , channel ) ] ;
5151 } ) ;
52- if ( this . sort != null ) channelSort ( channels , facetChannels , this . sort ) ;
52+ if ( this . sort != null ) channelSort ( channels , facetChannels , data , this . sort ) ;
5353 return { index, channels} ;
5454 }
5555 plot ( { marks = [ ] , ...options } = { } ) {
@@ -67,7 +67,7 @@ function Channel(data, {scale, type, value}) {
6767 } ;
6868}
6969
70- function channelSort ( channels , facetChannels , options ) {
70+ function channelSort ( channels , facetChannels , data , options ) {
7171 const { reverse : defaultReverse , reduce : defaultReduce = true , limit : defaultLimit } = options ;
7272 for ( const x in options ) {
7373 if ( ! registry . has ( x ) ) continue ; // ignore unknown scale keys
@@ -85,9 +85,14 @@ function channelSort(channels, facetChannels, options) {
8585 return domain ;
8686 } ;
8787 } else {
88- const Y = channels . find ( ( [ name ] ) => name === y ) ;
89- if ( ! Y ) throw new Error ( `missing channel: ${ y } ` ) ;
90- const YV = Y [ 1 ] . value ;
88+ let YV ;
89+ if ( y === "data" ) {
90+ YV = data ;
91+ } else {
92+ const Y = channels . find ( ( [ name ] ) => name === y ) ;
93+ if ( ! Y ) throw new Error ( `missing channel: ${ y } ` ) ;
94+ YV = Y [ 1 ] . value ;
95+ }
9196 const reducer = maybeReduce ( reduce === true ? "max" : reduce , YV ) ;
9297 X [ 1 ] . domain = ( ) => {
9398 let domain = rollup ( range ( XV ) , I => reducer . reduce ( I , YV ) , i => XV [ i ] ) ;
0 commit comments