@@ -14,10 +14,7 @@ var Cartesian = require('../../../src/plots/cartesian');
1414var Axes = require ( '../../../src/plots/cartesian/axes' ) ;
1515var Fx = require ( '../../../src/components/fx' ) ;
1616var supplyLayoutDefaults = require ( '../../../src/plots/cartesian/layout_defaults' ) ;
17- var numerical = require ( '../../../src/constants/numerical' ) ;
18- var BADNUM = numerical . BADNUM ;
19- var ONEDAY = numerical . ONEDAY ;
20- var ONEWEEK = numerical . ONEWEEK ;
17+ const { BADNUM , MINUS_SIGN , ONEDAY , ONEWEEK } = require ( '../../../src/constants/numerical' ) ;
2118
2219var createGraphDiv = require ( '../assets/create_graph_div' ) ;
2320var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
@@ -3502,29 +3499,50 @@ describe('Test axes', function() {
35023499 ] ) ;
35033500 } ) ;
35043501
3505- it ( 'snaps a near-zero tick to exactly tick0 so d3-format specs do not show float artefacts (issue 7765)' , function ( ) {
3506- // With this range the increments accumulate a roundoff error and the
3507- // tick that should be exactly 0 comes out as ~-8.9e-17. The default
3508- // format rounds that away, but `~r` would render it literally as
3509- // -0.0000000000000000888178 without the snap-to-tick0 correction.
3510- var spec = {
3502+ it ( 'snaps a near-zero tick to exactly tick0' , ( ) => {
3503+ const spec = {
35113504 type : 'linear' ,
35123505 tickmode : 'linear' ,
35133506 tick0 : 0 ,
35143507 dtick : 0.2 ,
35153508 range : [ - 0.65 , 0.65 ]
35163509 } ;
35173510
3518- expect ( mockCalc ( Lib . extendDeep ( { } , spec , { tickformat : '~r' } ) ) ) . toEqual ( [
3519- '−0.6' , '−0.4' , '−0.2' , '0' , '0.2' , '0.4' , '0.6'
3511+ expect ( mockCalc ( { ...spec , tickformat : '~r' } ) ) . toEqual ( [
3512+ MINUS_SIGN + '0.6' ,
3513+ MINUS_SIGN + '0.4' ,
3514+ MINUS_SIGN + '0.2' ,
3515+ '0' ,
3516+ '0.2' ,
3517+ '0.4' ,
3518+ '0.6'
35203519 ] ) ;
35213520
35223521 // the default numeric format was already fine; make sure it stays fine
3523- expect ( mockCalc ( Lib . extendDeep ( { } , spec ) ) ) . toEqual ( [
3524- '−0.6' , '−0.4' , '−0.2' , '0' , '0.2' , '0.4' , '0.6'
3522+ expect ( mockCalc ( spec ) ) . toEqual ( [
3523+ MINUS_SIGN + '0.6' ,
3524+ MINUS_SIGN + '0.4' ,
3525+ MINUS_SIGN + '0.2' ,
3526+ '0' ,
3527+ '0.2' ,
3528+ '0.4' ,
3529+ '0.6'
35253530 ] ) ;
35263531 } ) ;
35273532
3533+ it ( 'snaps ticks to non-tick0 grid positions' , ( ) => {
3534+ const textOut = mockCalc ( {
3535+ type : 'linear' ,
3536+ tickmode : 'linear' ,
3537+ tick0 : 1 ,
3538+ dtick : 0.1 ,
3539+ range : [ - 0.05 , 0.05 ] ,
3540+ tickformat : '~r'
3541+ } ) ;
3542+
3543+ expect ( textOut ) . toEqual ( [ '0' ] ) ;
3544+ } ) ;
3545+
35283546 it ( 'reverts to "power" for SI/B exponentformat beyond the prefix range (log case)' , function ( ) {
35293547 var textOut = mockCalc ( {
35303548 type : 'log' ,
0 commit comments