@@ -5,13 +5,16 @@ import {isSymbol, maybeSymbol} from "./symbols.js";
55import { maybeReduce } from "./transforms/group.js" ;
66
77// TODO Type coercion?
8- export function Channel ( data , { scale, type, value, filter, hint} ) {
8+ export function Channel ( data , { scale, type, value, filter, hint} , scaleOverride ) {
99 let V = valueof ( data , value ) ;
1010
11- // For color and symbol scales, allow the channel to opt-out of the scale by
12- // providing literal values. In the case of symbols, we must further promote
13- // symbol names (e.g., "plus") to a symbol instance (symbolPlus).
14- if ( V ) {
11+ // For color and symbol scales, if a scale is not explicitly overridden,
12+ // ignore the channel’s default scale if the channel values are literal. In
13+ // the case of symbols, we must further promote symbol names (e.g., "plus") to
14+ // a symbol instance (symbolPlus).
15+ if ( scaleOverride !== undefined ) {
16+ scale = scaleOverride ;
17+ } else if ( V ) {
1518 const is = scale === "color" ? isColor : scale === "symbol" ? isSymbol : null ;
1619 if ( is && isFirst ( V , is ) && isEvery ( V , is ) ) {
1720 if ( is === isSymbol ) V = map ( V , maybeSymbol ) ;
@@ -29,18 +32,20 @@ export function Channel(data, {scale, type, value, filter, hint}) {
2932 } ;
3033}
3134
32- export function Channels ( descriptors , data ) {
33- return Object . fromEntries ( Object . entries ( descriptors ) . map ( ( [ name , channel ] ) => [ name , Channel ( data , channel ) ] ) ) ;
35+ export function Channels ( channels , data , scales ) {
36+ return Object . fromEntries (
37+ Object . entries ( channels ) . map ( ( [ name , channel ] ) => {
38+ return [ name , Channel ( data , channel , scales ?. [ name ] ) ] ;
39+ } )
40+ ) ;
3441}
3542
3643// TODO Use Float64Array for scales with numeric ranges, e.g. position?
3744export function valueObject ( channels , scales ) {
3845 return Object . fromEntries (
3946 Object . entries ( channels ) . map ( ( [ name , { scale : scaleName , value} ] ) => {
4047 let scale ;
41- if ( scaleName !== undefined ) {
42- scale = scales [ scaleName ] ;
43- }
48+ if ( scaleName != null ) scale = scales [ scaleName ] ;
4449 return [ name , scale === undefined ? value : map ( value , scale ) ] ;
4550 } )
4651 ) ;
0 commit comments