@@ -58,8 +58,8 @@ export function density(data, {x, y, ...options} = {}) {
5858
5959function densityInitializer ( options , bandwidth , thresholds , f , s ) {
6060 return initializer ( options , function ( data , facets , channels , scales , dimensions ) {
61- const X = valueof ( channels . x . value , scales . x ) ;
62- const Y = valueof ( channels . y . value , scales . y ) ;
61+ const X = channels . x . scale ? valueof ( channels . x . value , scales [ channels . x . scale ] ) : channels . x . value ;
62+ const Y = channels . y . scale ? valueof ( channels . y . value , scales [ channels . y . scale ] ) : channels . y . value ;
6363 const W = channels . weight ?. value ;
6464 const Z = channels . z ?. value ;
6565 const { z} = this ;
@@ -81,17 +81,20 @@ function densityInitializer(options, bandwidth, thresholds, f, s) {
8181
8282 // First pass: seek the maximum density across all facets and series; memoize for performance.
8383 const memo = [ ] ;
84+ thresholds = [ ] ;
8485 for ( const [ facetIndex , facet ] of facets . entries ( ) ) {
8586 newFacets . push ( [ ] ) ;
8687 for ( const index of Z ? groupZ ( facet , Z , z ) : [ facet ] ) {
8788 const c = density ( index ) ;
8889 const d = c [ c . length - 1 ] ;
89- if ( d . value > max ) {
90- max = d . value ;
91- maxn = c . length ;
92- thresholds = c . map ( d => d . value ) ;
90+ if ( d ) {
91+ if ( d . value > max ) {
92+ max = d . value ;
93+ maxn = c . length ;
94+ thresholds = c . map ( d => d . value ) ;
95+ }
96+ memo . push ( { facetIndex, index, c, top : d . value } ) ;
9397 }
94- memo . push ( { facetIndex, index, c, top : d . value } ) ;
9598 }
9699 }
97100
0 commit comments