@@ -2,6 +2,7 @@ import {blurImage, Delaunay, randomLcg, rgb} from "d3";
2
2
import { valueObject } from "../channel.js" ;
3
3
import { create } from "../context.js" ;
4
4
import { map , first , second , third , isTuples , isNumeric , isTemporal , take , identity } from "../options.js" ;
5
+ import { maybeColorChannel , maybeNumberChannel } from "../options.js" ;
5
6
import { Mark } from "../plot.js" ;
6
7
import { applyAttr , applyDirectStyles , applyIndirectStyles , applyTransform , impliedString } from "../style.js" ;
7
8
import { initializer } from "../transforms/basic.js" ;
@@ -84,7 +85,12 @@ export class AbstractRaster extends Mark {
84
85
export class Raster extends AbstractRaster {
85
86
constructor ( data , options = { } ) {
86
87
const { imageRendering} = options ;
87
- super ( data , undefined , data == null ? sampler ( "fill" , sampler ( "fillOpacity" , options ) ) : options , defaults ) ;
88
+ if ( data == null ) {
89
+ const { fill, fillOpacity} = options ;
90
+ if ( maybeNumberChannel ( fillOpacity ) [ 0 ] !== undefined ) options = sampler ( "fillOpacity" , options ) ;
91
+ if ( maybeColorChannel ( fill ) [ 0 ] !== undefined ) options = sampler ( "fill" , options ) ;
92
+ }
93
+ super ( data , undefined , options , defaults ) ;
88
94
this . imageRendering = impliedString ( imageRendering , "auto" ) ;
89
95
}
90
96
// Ignore the color scale, so the fill channel is returned unscaled.
@@ -217,7 +223,7 @@ export function rasterBounds({x1, y1, x2, y2}, scales, dimensions, context) {
217
223
// generating a channel of the same name.
218
224
export function sampler ( name , options = { } ) {
219
225
const { [ name ] : value } = options ;
220
- if ( typeof value !== "function" ) return options ;
226
+ if ( typeof value !== "function" ) throw new Error ( `invalid ${ name } : not a function` ) ;
221
227
return initializer ( { ...options , [ name ] : undefined } , function ( data , facets , channels , scales , dimensions , context ) {
222
228
const { x, y} = scales ;
223
229
// TODO Allow projections, if invertible.
0 commit comments