@@ -60,7 +60,11 @@ export class Raster extends Mark {
6060 this . imageRendering = impliedString ( imageRendering , "auto" ) ;
6161 this . interpolate = interpolate ;
6262 }
63- render ( index , scales , channels , dimensions , context ) {
63+ // Ignore the color scale, so F is returned as unscaled values.
64+ scale ( channels , { color, ...scales } ) {
65+ return super . scale ( channels , scales ) ;
66+ }
67+ render ( index , { color, ...scales } , channels , dimensions , context ) {
6468 let { x : X , y : Y , fill : F , fillOpacity : FO } = channels ;
6569 const { x1 : [ x1 ] , y1 : [ y1 ] , x2 : [ x2 ] , y2 : [ y2 ] } = channels ; // prettier-ignore
6670 const { document} = context ;
@@ -86,20 +90,11 @@ export class Raster extends Mark {
8690 const ky = height / imageHeight ;
8791 X = X . slice ( ) ; // useless copy unless facets are overlapping; could be a Uint16
8892 Y = Y . slice ( ) ;
89- const R = F ? new Uint8Array ( F . length ) : undefined ;
90- const G = F ? new Uint8Array ( F . length ) : undefined ;
91- const B = F ? new Uint8Array ( F . length ) : undefined ;
9293 for ( const i of index ) {
9394 X [ i ] = ( X [ i ] - x1 ) * kx ;
9495 Y [ i ] = ( Y [ i ] - y2 ) * ky ;
95- if ( F ) {
96- const { r, g, b} = rgb ( F [ i ] ) ;
97- R [ i ] = r ;
98- G [ i ] = g ;
99- B [ i ] = b ;
100- }
10196 }
102- this . interpolate ( index , canvas , { X, Y, R , G , B , FO } , { r, g, b, a} ) ;
97+ this . interpolate ( index , canvas , { color } , { X, Y, F , FO } , { r, g, b, a} ) ;
10398 } else {
10499 // Otherwise if X and Y are not given, then assume that F is a dense array
105100 // of samples covering the entire grid in row-major order.
@@ -115,7 +110,7 @@ export class Raster extends Mark {
115110 imageData [ j + 3 ] = 0 ;
116111 continue ;
117112 }
118- const { r, g, b} = rgb ( fi ) ;
113+ const { r, g, b} = rgb ( color ( fi ) ) ;
119114 imageData [ j + 0 ] = r ;
120115 imageData [ j + 1 ] = g ;
121116 imageData [ j + 2 ] = b ;
@@ -196,18 +191,19 @@ function sampleFill({fill, fillOpacity, pixelRatio = 1, ...options} = {}) {
196191 } ) ;
197192}
198193
199- function interpolatePixel ( index , canvas , { X, Y, R , G , B , FO } , { r, g, b, a} ) {
194+ function interpolatePixel ( index , canvas , { color } , { X, Y, F , FO } , { r, g, b, a} ) {
200195 const { width, height} = canvas ;
201196 const context2d = canvas . getContext ( "2d" ) ;
202197 const image = context2d . createImageData ( width , height ) ;
203198 const imageData = image . data ;
204199 for ( const i of index ) {
205200 if ( X [ i ] < 0 || X [ i ] >= width || Y [ i ] < 0 || Y [ i ] >= height ) continue ;
206201 const j = ( Math . floor ( Y [ i ] ) * width + Math . floor ( X [ i ] ) ) << 2 ;
207- if ( R ) {
208- imageData [ j + 0 ] = R [ i ] ;
209- imageData [ j + 1 ] = G [ i ] ;
210- imageData [ j + 2 ] = B [ i ] ;
202+ if ( F ) {
203+ const { r, g, b} = rgb ( color ( F [ i ] ) ) ;
204+ imageData [ j + 0 ] = r ;
205+ imageData [ j + 1 ] = g ;
206+ imageData [ j + 2 ] = b ;
211207 } else {
212208 imageData [ j + 0 ] = r ;
213209 imageData [ j + 1 ] = g ;
0 commit comments