@@ -25,10 +25,20 @@ export interface GeometryId {
2525 seriesKey : any [ ] ;
2626}
2727
28+ /**
29+ * The accessor type
30+ */
31+ export const AccessorType = Object . freeze ( {
32+ Y0 : 'y0' as 'y0' ,
33+ Y1 : 'y1' as 'y1' ,
34+ } ) ;
35+
36+ export type AccessorType = typeof AccessorType . Y0 | typeof AccessorType . Y1 ;
37+
2838export interface GeometryValue {
2939 y : any ;
3040 x : any ;
31- accessor : 'y1' | 'y0' ;
41+ accessor : AccessorType ;
3242}
3343
3444/** Shared style properties for varies geometries */
@@ -187,19 +197,18 @@ export function renderPoints(
187197 const isLogScale = isLogarithmicScale ( yScale ) ;
188198 const pointGeometries = dataset . reduce (
189199 ( acc , datum ) => {
200+ const { x : xValue , y0, y1, initialY0, initialY1 } = datum ;
190201 // don't create the point if not within the xScale domain
191- if ( ! xScale . isValueInDomain ( datum . x ) ) {
202+ if ( ! xScale . isValueInDomain ( xValue ) ) {
192203 return acc ;
193204 }
194- const x = xScale . scale ( datum . x ) ;
205+ const x = xScale . scale ( xValue ) ;
195206 const points : PointGeometry [ ] = [ ] ;
196- const yDatums = [ datum . y1 ] ;
197- if ( hasY0Accessors ) {
198- yDatums . unshift ( datum . y0 ) ;
199- }
207+ const yDatums = hasY0Accessors ? [ y0 , y1 ] : [ y1 ] ;
208+
200209 yDatums . forEach ( ( yDatum , index ) => {
201210 // skip rendering point if y1 is null
202- if ( datum . y1 === null ) {
211+ if ( y1 === null ) {
203212 return ;
204213 }
205214 let y ;
@@ -212,7 +221,7 @@ export function renderPoints(
212221 } else {
213222 y = yScale . scale ( yDatum ) ;
214223 }
215- const originalY = hasY0Accessors && index === 0 ? datum . initialY0 : datum . initialY1 ;
224+ const originalY = hasY0Accessors && index === 0 ? initialY0 : initialY1 ;
216225 const geometryId = {
217226 specId,
218227 seriesKey,
@@ -224,9 +233,9 @@ export function renderPoints(
224233 y,
225234 color,
226235 value : {
227- x : datum . x ,
236+ x : xValue ,
228237 y : originalY ,
229- accessor : hasY0Accessors && index === 0 ? 'y0' : 'y1' ,
238+ accessor : hasY0Accessors && index === 0 ? AccessorType . Y0 : AccessorType . Y1 ,
230239 } ,
231240 transform : {
232241 x : shift ,
@@ -235,7 +244,7 @@ export function renderPoints(
235244 geometryId,
236245 styleOverrides,
237246 } ;
238- mutableIndexedGeometryMapUpsert ( indexedGeometries , datum . x , pointGeometry ) ;
247+ mutableIndexedGeometryMapUpsert ( indexedGeometries , xValue , pointGeometry ) ;
239248 // use the geometry only if the yDatum in contained in the current yScale domain
240249 if ( ! isHidden && yScale . isValueInDomain ( yDatum ) ) {
241250 points . push ( pointGeometry ) ;
@@ -358,7 +367,7 @@ export function renderBars(
358367 value : {
359368 x : datum . x ,
360369 y : initialY1 ,
361- accessor : 'y1' ,
370+ accessor : AccessorType . Y1 ,
362371 } ,
363372 geometryId,
364373 seriesStyle,
@@ -395,10 +404,10 @@ export function renderLine(
395404 const isLogScale = isLogarithmicScale ( yScale ) ;
396405
397406 const pathGenerator = line < DataSeriesDatum > ( )
398- . x ( ( datum : DataSeriesDatum ) => xScale . scale ( datum . x ) - xScaleOffset )
399- . y ( ( datum : DataSeriesDatum ) => yScale . scale ( datum . y1 ) )
400- . defined ( ( datum : DataSeriesDatum ) => {
401- return datum . y1 !== null && ! ( isLogScale && datum . y1 <= 0 ) && xScale . isValueInDomain ( datum . x ) ;
407+ . x ( ( { x } ) => xScale . scale ( x ) - xScaleOffset )
408+ . y ( ( { y1 } ) => yScale . scale ( y1 ) )
409+ . defined ( ( { x , y1 } ) => {
410+ return y1 !== null && ! ( isLogScale && y1 <= 0 ) && xScale . isValueInDomain ( x ) ;
402411 } )
403412 . curve ( getCurveFactory ( curve ) ) ;
404413 const y = 0 ;
@@ -458,16 +467,16 @@ export function renderArea(
458467 const isLogScale = isLogarithmicScale ( yScale ) ;
459468
460469 const pathGenerator = area < DataSeriesDatum > ( )
461- . x ( ( datum : DataSeriesDatum ) => xScale . scale ( datum . x ) - xScaleOffset )
462- . y1 ( ( datum : DataSeriesDatum ) => yScale . scale ( datum . y1 ) )
463- . y0 ( ( datum : DataSeriesDatum ) => {
464- if ( datum . y0 === null || ( isLogScale && datum . y0 <= 0 ) ) {
470+ . x ( ( { x } ) => xScale . scale ( x ) - xScaleOffset )
471+ . y1 ( ( { y1 } ) => yScale . scale ( y1 ) )
472+ . y0 ( ( { y0 } ) => {
473+ if ( y0 === null || ( isLogScale && y0 <= 0 ) ) {
465474 return yScale . range [ 0 ] ;
466475 }
467- return yScale . scale ( datum . y0 ) ;
476+ return yScale . scale ( y0 ) ;
468477 } )
469- . defined ( ( datum : DataSeriesDatum ) => {
470- return datum . y1 !== null && ! ( isLogScale && datum . y1 <= 0 ) && xScale . isValueInDomain ( datum . x ) ;
478+ . defined ( ( { y1 , x } ) => {
479+ return y1 !== null && ! ( isLogScale && y1 <= 0 ) && xScale . isValueInDomain ( x ) ;
471480 } )
472481 . curve ( getCurveFactory ( curve ) ) ;
473482
0 commit comments