@@ -81,6 +81,22 @@ function applyTextStyle(ctx, style) {
81
81
ctx . font = `${ style . fontStyle } ${ style . fontSize } px ${ style . fontFamily } ` ;
82
82
}
83
83
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
+
84
100
// many properties of this actor depend on the API specific view The main
85
101
// dependency being the resolution as that drives what font sizes to use.
86
102
// Bacause of this we need to do some of the calculations in a API specific
@@ -643,27 +659,23 @@ function vtkCubeAxesActor(publicAPI, model) {
643
659
}
644
660
645
661
// 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 ) ;
656
663
657
664
// update gridlines / edge lines
658
- publicAPI . updatePolyData ( facesToDraw , edgesToDraw , ticks ) ;
665
+ publicAPI . updatePolyData ( facesToDraw , edgesToDraw , t . ticks ) ;
659
666
660
667
// 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
+ ) ;
662
674
663
675
// rebuild the texture only when force or changed bounds, face
664
676
// visibility changes do to change the atlas
665
677
if ( boundsChanged || model . forceUpdate ) {
666
- publicAPI . updateTextureAtlas ( tickStrings ) ;
678
+ publicAPI . updateTextureAtlas ( t . tickStrings ) ;
667
679
}
668
680
}
669
681
@@ -802,7 +814,7 @@ function vtkCubeAxesActor(publicAPI, model) {
802
814
// Object factory
803
815
// ----------------------------------------------------------------------------
804
816
805
- function defaultValues ( initialValues ) {
817
+ function defaultValues ( publicAPI , model , initialValues ) {
806
818
return {
807
819
boundsScaleFactor : 1.3 ,
808
820
camera : null ,
@@ -811,30 +823,35 @@ function defaultValues(initialValues) {
811
823
gridLines : true ,
812
824
axisLabels : null ,
813
825
axisTitlePixelOffset : 35.0 ,
826
+ tickLabelPixelOffset : 12.0 ,
827
+ generateTicks : defaultGenerateTicks ( publicAPI , model ) ,
828
+ ...initialValues ,
814
829
axisTextStyle : {
815
830
fontColor : 'white' ,
816
831
fontStyle : 'normal' ,
817
832
fontSize : 18 ,
818
833
fontFamily : 'serif' ,
834
+ ...initialValues ?. axisTextStyle ,
819
835
} ,
820
- tickLabelPixelOffset : 12.0 ,
821
836
tickTextStyle : {
822
837
fontColor : 'white' ,
823
838
fontStyle : 'normal' ,
824
839
fontSize : 14 ,
825
840
fontFamily : 'serif' ,
841
+ ...initialValues ?. tickTextStyle ,
826
842
} ,
827
- ...initialValues ,
828
843
} ;
829
844
}
830
845
831
846
// ----------------------------------------------------------------------------
832
847
833
848
export function extend ( publicAPI , model , initialValues = { } ) {
834
- Object . assign ( model , defaultValues ( initialValues ) ) ;
835
-
836
849
// Inheritance
837
- vtkActor . extend ( publicAPI , model , initialValues ) ;
850
+ vtkActor . extend (
851
+ publicAPI ,
852
+ model ,
853
+ defaultValues ( publicAPI , model , initialValues )
854
+ ) ;
838
855
839
856
// internal variables
840
857
model . lastFacesToDraw = [ false , false , false , false , false , false ] ;
@@ -870,6 +887,7 @@ export function extend(publicAPI, model, initialValues = {}) {
870
887
'faceVisibilityAngle' ,
871
888
'gridLines' ,
872
889
'tickLabelPixelOffset' ,
890
+ 'generateTicks' ,
873
891
] ) ;
874
892
875
893
macro . setGetArray ( publicAPI , model , [ 'dataBounds' ] , 6 ) ;
0 commit comments