@@ -9,7 +9,7 @@ import React from "react";
99import * as d3 from "d3" ;
1010import style from "../hiplot.module.css" ;
1111import { create_d3_scale_without_outliers , ParamDef } from "../infertypes" ;
12- import { convert_to_categorical_input } from "../lib/d3_scales" ;
12+ import { convert_to_categorical_input , getLogScaleTickValues } from "../lib/d3_scales" ;
1313import { ParamType , Datapoint } from "../types" ;
1414
1515function labelTextFromHtml ( html : string , fallback : string ) : string {
@@ -85,12 +85,25 @@ export class DistributionPlot extends React.Component<DistributionPlotData, {}>
8585 figureHeight ( ) {
8686 return this . props . height - margin . top - margin . bottom ;
8787 }
88+ applyLogScaleTicks ( axis : any , tickCount : number ) : void {
89+ if ( this . props . param_def . type !== ParamType . NUMERICLOG ) {
90+ return ;
91+ }
92+ const tickValues = getLogScaleTickValues ( this . dataScale . domain ( ) , tickCount ) ;
93+ if ( tickValues ) {
94+ axis . tickValues ( tickValues ) ;
95+ }
96+ if ( this . props . param_def . ticks_format ) {
97+ axis . tickFormat ( d3 . format ( this . props . param_def . ticks_format ) ) ;
98+ }
99+ }
88100 createDataAxis ( dataScale : any , animate : boolean ) : void {
89101 if ( this . isVertical ( ) ) {
90102 dataScale . range ( [ 0 , this . figureWidth ( ) ] ) ;
91- d3 . select ( this . axisBottom . current ) . call (
92- d3 . axisBottom ( dataScale ) . ticks ( 1 + this . props . width / 50 ) ,
93- ) ;
103+ const tickCount = 1 + this . props . width / 50 ;
104+ const axis = d3 . axisBottom ( dataScale ) . ticks ( tickCount ) ;
105+ this . applyLogScaleTicks ( axis , tickCount ) ;
106+ d3 . select ( this . axisBottom . current ) . call ( axis ) ;
94107 d3 . select ( this . axisBottomName . current )
95108 . html ( null )
96109 . append ( "text" )
@@ -101,15 +114,20 @@ export class DistributionPlot extends React.Component<DistributionPlotData, {}>
101114 this . axisRight . current . innerHTML = "" ;
102115 } else {
103116 dataScale . range ( [ this . figureHeight ( ) , 0 ] ) ;
117+ const tickCount = 1 + this . props . height / 50 ;
118+ const axisRight = d3 . axisRight ( dataScale ) . ticks ( tickCount ) ;
119+ const axisLeft = d3 . axisLeft ( dataScale ) . ticks ( tickCount ) ;
120+ this . applyLogScaleTicks ( axisRight , tickCount ) ;
121+ this . applyLogScaleTicks ( axisLeft , tickCount ) ;
104122 d3 . select ( this . axisRight . current )
105123 . transition ( )
106124 . duration ( animate ? this . props . animateMs : 0 )
107- . call ( d3 . axisRight ( dataScale ) . ticks ( 1 + this . props . height / 50 ) )
125+ . call ( axisRight )
108126 . attr ( "text-anchor" , "end" ) ;
109127 d3 . select ( this . axisLeft . current )
110128 . transition ( )
111129 . duration ( animate ? this . props . animateMs : 0 )
112- . call ( d3 . axisLeft ( dataScale ) . ticks ( 1 + this . props . height / 50 ) ) ;
130+ . call ( axisLeft ) ;
113131 d3 . select ( this . axisBottomName . current )
114132 . html ( null )
115133 . append ( "text" )
0 commit comments