@@ -229,21 +229,37 @@ export class PlotXY extends React.Component<PlotXYProps, PlotXYState> {
229229 if (
230230 ! paramDef ||
231231 paramDef . type !== ParamType . NUMERICLOG ||
232- typeof scale . ticks !== "function"
232+ typeof scale . domain !== "function"
233233 ) {
234234 return null ;
235235 }
236- const ticks = scale . ticks ( approxTickCount ) ;
237- if ( ! Array . isArray ( ticks ) ) {
236+ const domain = scale . domain ( ) ;
237+ if ( ! Array . isArray ( domain ) || domain . length < 2 ) {
238+ return null ;
239+ }
240+ const dMin = Number ( domain [ 0 ] ) ;
241+ const dMax = Number ( domain [ domain . length - 1 ] ) ;
242+ if ( ! Number . isFinite ( dMin ) || ! Number . isFinite ( dMax ) || dMin <= 0 || dMax <= 0 ) {
238243 return null ;
239244 }
240- const majorTicks = ticks . filter ( ( tick : number ) => {
241- if ( ! Number . isFinite ( tick ) || tick <= 0 ) {
242- return false ;
245+ // Generate powers of 10 spanning the domain, including boundary powers
246+ // so that e.g. domain [1.05, 99.3] produces ticks [1, 10, 100]
247+ const minExp = Math . floor ( Math . log10 ( dMin ) ) ;
248+ const maxExp = Math . ceil ( Math . log10 ( dMax ) ) ;
249+ const majorTicks : number [ ] = [ ] ;
250+ for ( let exp = minExp ; exp <= maxExp ; exp ++ ) {
251+ majorTicks . push ( Math . pow ( 10 , exp ) ) ;
252+ }
253+ // Thin out if there are too many powers of 10 for the available space
254+ if ( majorTicks . length > approxTickCount && majorTicks . length > 2 ) {
255+ const step = Math . ceil ( majorTicks . length / approxTickCount ) ;
256+ const thinned : number [ ] = [ majorTicks [ 0 ] ] ;
257+ for ( let i = step ; i < majorTicks . length - 1 ; i += step ) {
258+ thinned . push ( majorTicks [ i ] ) ;
243259 }
244- const lg = Math . log10 ( tick ) ;
245- return Math . abs ( lg - Math . round ( lg ) ) < 1e-10 ;
246- } ) ;
260+ thinned . push ( majorTicks [ majorTicks . length - 1 ] ) ;
261+ return thinned ;
262+ }
247263 return majorTicks . length > 1 ? majorTicks : null ;
248264 }
249265 function redraw_axis ( ) {
0 commit comments