11import { gStyle , settings , constants , clTAxis , clTGaxis , isFunc , isStr } from '../core.mjs' ;
2- import {
3- select as d3_select , drag as d3_drag , timeFormat as d3_timeFormat , utcFormat as d3_utcFormat ,
4- scaleTime as d3_scaleTime , scaleSymlog as d3_scaleSymlog ,
5- scaleLog as d3_scaleLog , scaleLinear as d3_scaleLinear
6- } from '../d3.mjs' ;
2+ import { select as d3_select , drag as d3_drag , timeFormat as d3_timeFormat , utcFormat as d3_utcFormat ,
3+ scaleTime as d3_scaleTime , scaleSymlog as d3_scaleSymlog ,
4+ scaleLog as d3_scaleLog , scaleLinear as d3_scaleLinear } from '../d3.mjs' ;
75import { floatToString , makeTranslate , addHighlightStyle } from '../base/BasePainter.mjs' ;
86import { ObjectPainter , EAxisBits , kAxisLabels , kAxisNormal , kAxisFunc , kAxisTime } from '../base/ObjectPainter.mjs' ;
97import { FontHandler } from '../base/FontHandler.mjs' ;
@@ -43,12 +41,12 @@ function getTimeOffset(axis) {
4341 } ;
4442 // eslint-disable-next-line one-var
4543 const year = next ( '-' , 1900 , 2900 ) ,
46- month = next ( '-' , 1 , 12 ) - 1 ,
47- day = next ( ' ' , 1 , 31 ) ,
48- hour = next ( ':' , 0 , 23 ) ,
49- min = next ( ':' , 0 , 59 ) ,
50- sec = next ( 's' , 0 , 59 ) ,
51- msec = next ( ' ' , 0 , 999 ) ;
44+ month = next ( '-' , 1 , 12 ) - 1 ,
45+ day = next ( ' ' , 1 , 31 ) ,
46+ hour = next ( ':' , 0 , 23 ) ,
47+ min = next ( ':' , 0 , 59 ) ,
48+ sec = next ( 's' , 0 , 59 ) ,
49+ msec = next ( ' ' , 0 , 999 ) ;
5250
5351 let offset = Date . UTC ( year , month , day , hour , min , sec , msec ) ;
5452
@@ -273,7 +271,7 @@ const AxisPainterMethods = {
273271 sum2 += diff ** 2 ;
274272 }
275273 const mean = sum1 / ( arr . length - 1 ) ,
276- dev = sum2 / ( arr . length - 1 ) - mean ** 2 ;
274+ dev = sum2 / ( arr . length - 1 ) - mean ** 2 ;
277275
278276 if ( dev <= 0 )
279277 return true ;
@@ -313,13 +311,13 @@ const AxisPainterMethods = {
313311 return this . poduceLogTicks ( this . func , total ) ;
314312
315313 const dom = this . func . domain ( ) ,
316- check = ticks => {
317- if ( ticks . length <= total )
318- return true ;
319- if ( ticks . length > total + 1 )
320- return false ;
321- return ( ticks [ 0 ] === dom [ 0 ] ) || ( ticks [ total ] === dom [ 1 ] ) ; // special case of N+1 ticks, but match any range
322- } , res1 = this . func . ticks ( total ) ;
314+ check = ticks => {
315+ if ( ticks . length <= total )
316+ return true ;
317+ if ( ticks . length > total + 1 )
318+ return false ;
319+ return ( ticks [ 0 ] === dom [ 0 ] ) || ( ticks [ total ] === dom [ 1 ] ) ; // special case of N+1 ticks, but match any range
320+ } , res1 = this . func . ticks ( total ) ;
323321 if ( ndiv2 || check ( res1 ) )
324322 return res1 ;
325323
@@ -364,9 +362,9 @@ const AxisPainterMethods = {
364362 delta_right *= delta ;
365363
366364 const lmin = item . min = this . scale_min ,
367- lmax = item . max = this . scale_max ,
368- gmin = this . full_min ,
369- gmax = this . full_max ;
365+ lmax = item . max = this . scale_max ,
366+ gmin = this . full_min ,
367+ gmax = this . full_max ;
370368
371369 if ( ( item . min === item . max ) && ( delta < 0 ) ) {
372370 item . min = gmin ;
@@ -424,7 +422,7 @@ const AxisPainterMethods = {
424422 else if ( delta_left !== delta_right ) {
425423 // extra check case when moving left or right
426424 if ( ( ( item . min < gmin ) && ( lmin === gmin ) ) ||
427- ( ( item . max > gmax ) && ( lmax === gmax ) ) )
425+ ( ( item . max > gmax ) && ( lmax === gmax ) ) )
428426 item . min = item . max = undefined ;
429427 } else {
430428 item . min = Math . max ( item . min , gmin ) ;
@@ -602,8 +600,8 @@ class TAxisPainter extends ObjectPainter {
602600 this . nticks = Math . min ( this . nticks , 8 ) ;
603601
604602 const scale_range = this . scale_max - this . scale_min ,
605- idF = axis . fTimeFormat . indexOf ( '%F' ) ,
606- tf2 = chooseTimeFormat ( scale_range / gr_range , false ) ;
603+ idF = axis . fTimeFormat . indexOf ( '%F' ) ,
604+ tf2 = chooseTimeFormat ( scale_range / gr_range , false ) ;
607605 let tf1 = ( idF >= 0 ) ? axis . fTimeFormat . slice ( 0 , idF ) : axis . fTimeFormat ;
608606
609607 if ( ! tf1 || ( scale_range < 0.1 * ( this . full_max - this . full_min ) ) )
@@ -634,7 +632,7 @@ class TAxisPainter extends ObjectPainter {
634632
635633 if ( axis ?. fNbins && axis ?. fLabels ) {
636634 if ( ( axis . fNbins !== Math . round ( axis . fXmax - axis . fXmin ) ) ||
637- axis . fXmin || ( axis . fXmax !== axis . fNbins ) )
635+ axis . fXmin || ( axis . fXmax !== axis . fNbins ) )
638636 this . regular_labels = false ;
639637 }
640638
@@ -741,11 +739,11 @@ class TAxisPainter extends ObjectPainter {
741739 }
742740 }
743741
744- handle . reset = function ( ) {
742+ handle . reset = function ( ) {
745743 this . nminor = this . nmiddle = this . nmajor = 0 ;
746744 } ;
747745
748- handle . next = function ( doround ) {
746+ handle . next = function ( doround ) {
749747 if ( this . nminor >= this . minor . length )
750748 return false ;
751749
@@ -767,15 +765,15 @@ class TAxisPainter extends ObjectPainter {
767765 return true ;
768766 } ;
769767
770- handle . last_major = function ( ) {
768+ handle . last_major = function ( ) {
771769 return ( this . kind !== 1 ) ? false : this . nmajor === this . major . length ;
772770 } ;
773771
774- handle . next_major_grpos = function ( ) {
772+ handle . next_major_grpos = function ( ) {
775773 return this . nmajor >= this . major . length ? null : this . func ( this . major [ this . nmajor ] ) ;
776774 } ;
777775
778- handle . get_modifier = function ( ) {
776+ handle . get_modifier = function ( ) {
779777 return this . painter . findLabelModifier ( this . painter . getObject ( ) , this . nmajor - 1 , this . major ) ;
780778 } ;
781779
@@ -788,9 +786,9 @@ class TAxisPainter extends ObjectPainter {
788786
789787 if ( ! optionNoexp && ! this . cutLabels ( ) ) {
790788 const maxtick = Math . max ( Math . abs ( handle . major . at ( 0 ) ) , Math . abs ( handle . major . at ( - 1 ) ) ) ,
791- mintick = Math . min ( Math . abs ( handle . major . at ( 0 ) ) , Math . abs ( handle . major . at ( - 1 ) ) ) ,
792- ord1 = ( maxtick > 0 ) ? Math . round ( Math . log10 ( maxtick ) / 3 ) * 3 : 0 ,
793- ord2 = ( mintick > 0 ) ? Math . round ( Math . log10 ( mintick ) / 3 ) * 3 : 0 ;
789+ mintick = Math . min ( Math . abs ( handle . major . at ( 0 ) ) , Math . abs ( handle . major . at ( - 1 ) ) ) ,
790+ ord1 = ( maxtick > 0 ) ? Math . round ( Math . log10 ( maxtick ) / 3 ) * 3 : 0 ,
791+ ord2 = ( mintick > 0 ) ? Math . round ( Math . log10 ( mintick ) / 3 ) * 3 : 0 ;
794792
795793 exclorder3 = ( maxtick < 2e4 ) ; // do not show 10^3 for values below 20000
796794
@@ -811,7 +809,7 @@ class TAxisPainter extends ObjectPainter {
811809 let lbls = [ ] , indx = 0 , totallen = 0 ;
812810 while ( indx < handle . major . length ) {
813811 const v0 = handle . major [ indx ] ,
814- lbl = this . format ( v0 , true ) ;
812+ lbl = this . format ( v0 , true ) ;
815813
816814 let bad_value = lbls . indexOf ( lbl ) >= 0 ;
817815 if ( ! bad_value ) {
@@ -894,15 +892,15 @@ class TAxisPainter extends ObjectPainter {
894892 return ;
895893
896894 let drag_rect = null , x_0 , y_0 , i_0 ,
897- acc_x , acc_y , new_x , new_y , sign_0 , alt_pos , curr_indx , can_indx0 = true ;
895+ acc_x , acc_y , new_x , new_y , sign_0 , alt_pos , curr_indx , can_indx0 = true ;
898896 const drag_move = d3_drag ( ) . subject ( Object ) ;
899897
900898 drag_move . on ( 'start' , evnt => {
901899 evnt . sourceEvent . preventDefault ( ) ;
902900 evnt . sourceEvent . stopPropagation ( ) ;
903901
904902 const box = title_g . node ( ) . getBBox ( ) , // check that elements visible, request precise value
905- title_length = vertical ? box . height : box . width ;
903+ title_length = vertical ? box . height : box . width ;
906904
907905 x_0 = new_x = acc_x = title_g . property ( 'shift_x' ) ;
908906 y_0 = new_y = acc_y = title_g . property ( 'shift_y' ) ;
@@ -981,13 +979,13 @@ class TAxisPainter extends ObjectPainter {
981979 evnt . sourceEvent . stopPropagation ( ) ;
982980
983981 title_g . property ( 'shift_x' , new_x )
984- . property ( 'shift_y' , new_y ) ;
982+ . property ( 'shift_y' , new_y ) ;
985983
986984 const axis = this . getObject ( ) , axis2 = this . source_axis ,
987- setBit = ( bit , on ) => {
988- axis ?. SetBit ( bit , on ) ;
989- axis2 ?. SetBit ( bit , on ) ;
990- } ;
985+ setBit = ( bit , on ) => {
986+ axis ?. SetBit ( bit , on ) ;
987+ axis2 ?. SetBit ( bit , on ) ;
988+ } ;
991989
992990 this . titleOffset = ( vertical ? new_x : new_y ) / offset_k ;
993991 const offset = this . titleOffset / this . offsetScaling / this . titleSize ;
@@ -1092,7 +1090,7 @@ class TAxisPainter extends ObjectPainter {
10921090 }
10931091
10941092 if ( ( mod . fLabNum === nlabel + 1 ) ||
1095- ( ( mod . fLabNum < 0 ) && ( nlabel === positions . length + mod . fLabNum ) ) )
1093+ ( ( mod . fLabNum < 0 ) && ( nlabel === positions . length + mod . fLabNum ) ) )
10961094 return mod ;
10971095 }
10981096 return null ;
@@ -1102,12 +1100,12 @@ class TAxisPainter extends ObjectPainter {
11021100 * @return {Promise } with array label size and max width */
11031101 async drawLabels ( axis_g , axis , w , h , handle , labelsside , labelsFont , labeloffset , tickSize , ticksPlusMinus , max_text_width , frame_ygap ) {
11041102 const center_lbls = this . isCenteredLabels ( ) ,
1105- label_g = [ axis_g . append ( 'svg:g' ) . attr ( 'class' , 'axis_labels' ) ] ,
1106- lbl_pos = handle . lbl_pos || handle . major ,
1107- tilt_angle = gStyle . AxisTiltAngle ?? 25 ;
1103+ label_g = [ axis_g . append ( 'svg:g' ) . attr ( 'class' , 'axis_labels' ) ] ,
1104+ lbl_pos = handle . lbl_pos || handle . major ,
1105+ tilt_angle = gStyle . AxisTiltAngle ?? 25 ;
11081106 let rotate_lbls = this . isRotateLabels ( ) ,
1109- textscale = 1 , flipscale = 1 , maxtextlen = 0 , applied_scale = 0 ,
1110- lbl_tilt = false , any_modified = false , max_textwidth = 0 , max_tiltsize = 0 ;
1107+ textscale = 1 , flipscale = 1 , maxtextlen = 0 , applied_scale = 0 ,
1108+ lbl_tilt = false , any_modified = false , max_textwidth = 0 , max_tiltsize = 0 ;
11111109
11121110 if ( this . lbls_both_sides )
11131111 label_g . push ( axis_g . append ( 'svg:g' ) . attr ( 'class' , 'axis_labels' ) . attr ( 'transform' , this . vertical ? `translate(${ w } )` : `translate(0,${ - h } )` ) ) ;
@@ -1132,7 +1130,7 @@ class TAxisPainter extends ObjectPainter {
11321130 textscale = Math . min ( textscale , ( max_text_width - labeloffset ) / textwidth ) ;
11331131
11341132 if ( ( textscale > 0.0001 ) && ( textscale < 0.7 ) && ! any_modified &&
1135- ! painter . vertical && ! rotate_lbls && ( label_g . length === 1 ) && ( lbl_tilt === false ) ) {
1133+ ! painter . vertical && ! rotate_lbls && ( label_g . length === 1 ) && ( lbl_tilt === false ) ) {
11361134 if ( maxtextlen > 5 )
11371135 lbl_tilt = true ;
11381136 }
@@ -1303,7 +1301,7 @@ class TAxisPainter extends ObjectPainter {
13031301 this . _maxlbllen = maxtextlen ; // for internal use in palette painter
13041302
13051303 if ( lbl_tilt ) {
1306- label_g [ 0 ] . selectAll ( 'text' ) . each ( function ( ) {
1304+ label_g [ 0 ] . selectAll ( 'text' ) . each ( function ( ) {
13071305 const txt = d3_select ( this ) , tr = txt . attr ( 'transform' ) ;
13081306 if ( lbl_tilt )
13091307 txt . attr ( 'transform' , `${ tr } rotate(${ tilt_angle } )` ) . style ( 'text-anchor' , 'start' ) ;
@@ -1322,10 +1320,10 @@ class TAxisPainter extends ObjectPainter {
13221320 if ( axis . $use_top_pad )
13231321 pp = pp ?. getPadPainter ( ) ; // workaround for ratio plot
13241322 const pad_w = pp ?. getPadWidth ( ) || scalingSize || w / 0.8 , // use factor 0.8 as ratio between frame and pad size
1325- pad_h = pp ?. getPadHeight ( ) || scalingSize || h / 0.8 ,
1326- // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor
1327- tickScalingSize = scalingSize || ( this . vertical ? h / pad_h * pad_w : w / pad_w * pad_h ) ,
1328- bit_plus = axis . TestBit ( EAxisBits . kTickPlus ) , bit_minus = axis . TestBit ( EAxisBits . kTickMinus ) ;
1323+ pad_h = pp ?. getPadHeight ( ) || scalingSize || h / 0.8 ,
1324+ // if no external scaling size use scaling as in TGaxis.cxx:1448 - NDC axis length is in the scaling factor
1325+ tickScalingSize = scalingSize || ( this . vertical ? h / pad_h * pad_w : w / pad_w * pad_h ) ,
1326+ bit_plus = axis . TestBit ( EAxisBits . kTickPlus ) , bit_minus = axis . TestBit ( EAxisBits . kTickMinus ) ;
13291327
13301328 let tickSize , titleColor , titleFontId , offset ;
13311329
@@ -1421,7 +1419,7 @@ class TAxisPainter extends ObjectPainter {
14211419 * @return {Promise } for drawing ready */
14221420 async drawAxis ( layer , w , h , transform , secondShift , disable_axis_drawing , max_text_width , calculate_position , frame_ygap ) {
14231421 const axis = this . getObject ( ) ,
1424- swap_side = this . swap_side || false ;
1422+ swap_side = this . swap_side || false ;
14251423 let axis_g = layer , draw_lines = true ;
14261424
14271425 // shift for second ticks set (if any)
@@ -1469,44 +1467,44 @@ class TAxisPainter extends ObjectPainter {
14691467
14701468 if ( ! disable_axis_drawing && axis_lines && ! this . lineatt . empty ( ) ) {
14711469 axis_g . append ( 'svg:path' )
1472- . attr ( 'd' , axis_lines )
1473- . call ( this . lineatt . func ) ;
1470+ . attr ( 'd' , axis_lines )
1471+ . call ( this . lineatt . func ) ;
14741472 }
14751473
14761474 let title_shift_x = 0 , title_shift_y = 0 , title_g , labelsMaxWidth = 0 ;
14771475 // draw labels (sometime on both sides)
14781476 const labelSize = Math . max ( this . labelsFont . size , 5 ) ,
1479- pr = ( disable_axis_drawing || this . optionUnlab )
1480- ? Promise . resolve ( 0 )
1481- : this . drawLabels ( axis_g , axis , w , h , handle , side , this . labelsFont , this . labelsOffset , this . ticksSize , ticksPlusMinus , max_text_width , frame_ygap ) ;
1477+ pr = ( disable_axis_drawing || this . optionUnlab )
1478+ ? Promise . resolve ( 0 )
1479+ : this . drawLabels ( axis_g , axis , w , h , handle , side , this . labelsFont , this . labelsOffset , this . ticksSize , ticksPlusMinus , max_text_width , frame_ygap ) ;
14821480
14831481 return pr . then ( maxw => {
14841482 labelsMaxWidth = maxw ;
14851483
14861484 if ( settings . Zooming && ! this . disable_zooming && ! this . isBatchMode ( ) ) {
14871485 const r = axis_g . append ( 'svg:rect' )
1488- . attr ( 'class' , 'axis_zoom' )
1489- . style ( 'opacity' , '0' )
1490- . style ( 'cursor' , 'crosshair' ) ;
1486+ . attr ( 'class' , 'axis_zoom' )
1487+ . style ( 'opacity' , '0' )
1488+ . style ( 'cursor' , 'crosshair' ) ;
14911489
14921490 if ( this . vertical ) {
14931491 const rw = Math . max ( labelsMaxWidth , 2 * labelSize ) + 3 ;
14941492 r . attr ( 'x' , ( side > 0 ) ? - rw : 0 ) . attr ( 'y' , 0 )
1495- . attr ( 'width' , rw ) . attr ( 'height' , h ) ;
1493+ . attr ( 'width' , rw ) . attr ( 'height' , h ) ;
14961494 } else {
14971495 r . attr ( 'x' , 0 ) . attr ( 'y' , ( side > 0 ) ? 0 : - labelSize - 3 )
1498- . attr ( 'width' , w ) . attr ( 'height' , labelSize + 3 ) ;
1496+ . attr ( 'width' , w ) . attr ( 'height' , labelSize + 3 ) ;
14991497 }
15001498 }
15011499
15021500 this . position = 0 ;
15031501
15041502 if ( calculate_position ) {
15051503 const node1 = axis_g . node ( ) ,
1506- node2 = this . getPadPainter ( ) ?. getPadSvg ( ) . node ( ) ;
1504+ node2 = this . getPadPainter ( ) ?. getPadSvg ( ) . node ( ) ;
15071505 if ( isFunc ( node1 ?. getBoundingClientRect ) && isFunc ( node2 ?. getBoundingClientRect ) ) {
15081506 const rect1 = node1 . getBoundingClientRect ( ) ,
1509- rect2 = node2 . getBoundingClientRect ( ) ;
1507+ rect2 = node2 . getBoundingClientRect ( ) ;
15101508 this . position = rect1 . left - rect2 . left ; // use to control left position of Y scale
15111509 }
15121510 if ( node1 && ! node2 )
@@ -1524,7 +1522,7 @@ class TAxisPainter extends ObjectPainter {
15241522 return ;
15251523
15261524 const rotate = this . isRotateTitle ( ) ? - 1 : 1 ,
1527- xor_reverse = swap_side ^ this . titleOpposite , myxor = ( rotate < 0 ) ^ xor_reverse ;
1525+ xor_reverse = swap_side ^ this . titleOpposite , myxor = ( rotate < 0 ) ^ xor_reverse ;
15281526
15291527 let title_offest_k = side ;
15301528
@@ -1563,7 +1561,7 @@ class TAxisPainter extends ObjectPainter {
15631561 title_shift_x = Math . round ( - side * ( ( labelsMaxWidth || labelSize ) + 0.7 * this . offsetScaling * this . titleSize ) ) ;
15641562 makeTranslate ( title_g , title_shift_x , title_shift_y ) ;
15651563 title_g . property ( 'shift_x' , title_shift_x )
1566- . property ( 'shift_y' , title_shift_y ) ;
1564+ . property ( 'shift_y' , title_shift_y ) ;
15671565 }
15681566
15691567 return this ;
0 commit comments