@@ -81,6 +81,22 @@ function applyTextStyle(ctx, style) {
8181 ctx . font = `${ style . fontStyle } ${ style . fontSize } px ${ style . fontFamily } ` ;
8282}
8383
84+ function defaultGenerateTicks ( publicApi , model ) {
85+ return ( dataBounds ) => {
86+ const ticks = [ ] ;
87+ const tickStrings = [ ] ;
88+ for ( let i = 0 ; i < 3 ; i ++ ) {
89+ const scale = d3
90+ . scaleLinear ( )
91+ . domain ( [ dataBounds [ i * 2 ] , dataBounds [ i * 2 + 1 ] ] ) ;
92+ ticks [ i ] = scale . ticks ( 5 ) ;
93+ const format = scale . tickFormat ( 5 ) ;
94+ tickStrings [ i ] = ticks [ i ] . map ( format ) ;
95+ }
96+ return { ticks, tickStrings } ;
97+ } ;
98+ }
99+
84100// many properties of this actor depend on the API specific view The main
85101// dependency being the resolution as that drives what font sizes to use.
86102// Bacause of this we need to do some of the calculations in a API specific
@@ -643,27 +659,23 @@ function vtkCubeAxesActor(publicAPI, model) {
643659 }
644660
645661 // compute tick marks for axes
646- const ticks = [ ] ;
647- const tickStrings = [ ] ;
648- for ( let i = 0 ; i < 3 ; i ++ ) {
649- const scale = d3
650- . scaleLinear ( )
651- . domain ( [ model . dataBounds [ i * 2 ] , model . dataBounds [ i * 2 + 1 ] ] ) ;
652- ticks [ i ] = scale . ticks ( 5 ) ;
653- const format = scale . tickFormat ( 5 ) ;
654- tickStrings [ i ] = ticks [ i ] . map ( format ) ;
655- }
662+ const t = model . generateTicks ( model . dataBounds ) ;
656663
657664 // update gridlines / edge lines
658- publicAPI . updatePolyData ( facesToDraw , edgesToDraw , ticks ) ;
665+ publicAPI . updatePolyData ( facesToDraw , edgesToDraw , t . ticks ) ;
659666
660667 // compute label world coords and text
661- publicAPI . updateTextData ( facesToDraw , edgesToDraw , ticks , tickStrings ) ;
668+ publicAPI . updateTextData (
669+ facesToDraw ,
670+ edgesToDraw ,
671+ t . ticks ,
672+ t . tickStrings
673+ ) ;
662674
663675 // rebuild the texture only when force or changed bounds, face
664676 // visibility changes do to change the atlas
665677 if ( boundsChanged || model . forceUpdate ) {
666- publicAPI . updateTextureAtlas ( tickStrings ) ;
678+ publicAPI . updateTextureAtlas ( t . tickStrings ) ;
667679 }
668680 }
669681
@@ -802,7 +814,7 @@ function vtkCubeAxesActor(publicAPI, model) {
802814// Object factory
803815// ----------------------------------------------------------------------------
804816
805- function defaultValues ( initialValues ) {
817+ function defaultValues ( publicAPI , model , initialValues ) {
806818 return {
807819 boundsScaleFactor : 1.3 ,
808820 camera : null ,
@@ -811,30 +823,35 @@ function defaultValues(initialValues) {
811823 gridLines : true ,
812824 axisLabels : null ,
813825 axisTitlePixelOffset : 35.0 ,
826+ tickLabelPixelOffset : 12.0 ,
827+ generateTicks : defaultGenerateTicks ( publicAPI , model ) ,
828+ ...initialValues ,
814829 axisTextStyle : {
815830 fontColor : 'white' ,
816831 fontStyle : 'normal' ,
817832 fontSize : 18 ,
818833 fontFamily : 'serif' ,
834+ ...initialValues ?. axisTextStyle ,
819835 } ,
820- tickLabelPixelOffset : 12.0 ,
821836 tickTextStyle : {
822837 fontColor : 'white' ,
823838 fontStyle : 'normal' ,
824839 fontSize : 14 ,
825840 fontFamily : 'serif' ,
841+ ...initialValues ?. tickTextStyle ,
826842 } ,
827- ...initialValues ,
828843 } ;
829844}
830845
831846// ----------------------------------------------------------------------------
832847
833848export function extend ( publicAPI , model , initialValues = { } ) {
834- Object . assign ( model , defaultValues ( initialValues ) ) ;
835-
836849 // Inheritance
837- vtkActor . extend ( publicAPI , model , initialValues ) ;
850+ vtkActor . extend (
851+ publicAPI ,
852+ model ,
853+ defaultValues ( publicAPI , model , initialValues )
854+ ) ;
838855
839856 // internal variables
840857 model . lastFacesToDraw = [ false , false , false , false , false , false ] ;
@@ -870,6 +887,7 @@ export function extend(publicAPI, model, initialValues = {}) {
870887 'faceVisibilityAngle' ,
871888 'gridLines' ,
872889 'tickLabelPixelOffset' ,
890+ 'generateTicks' ,
873891 ] ) ;
874892
875893 macro . setGetArray ( publicAPI , model , [ 'dataBounds' ] , 6 ) ;
0 commit comments