@@ -18,6 +18,13 @@ var axes = module.exports = {};
1818axes . layoutAttributes = require ( './layout_attributes' ) ;
1919
2020
21+ var utils = require ( './utils' ) ;
22+ axes . id2name = utils . id2name ;
23+ axes . cleanId = utils . cleanId ;
24+ axes . list = utils . list ;
25+ axes . listIds = utils . listIds ;
26+ axes . getFromId = utils . getFromId ;
27+ axes . getFromTrace = utils . getFromTrace ;
2128axes . supplyLayoutDefaults = function ( layoutIn , layoutOut , fullData ) {
2229 // get the full list of axes already defined
2330 var layoutKeys = Object . keys ( layoutIn ) ,
@@ -366,41 +373,6 @@ axes.clearTypes = function(gd, traces) {
366373 } ) ;
367374} ;
368375
369- // convert between axis names (xaxis, xaxis2, etc, elements of td.layout)
370- // and axis id's (x, x2, etc). Would probably have ditched 'xaxis'
371- // completely in favor of just 'x' if it weren't ingrained in the API etc.
372- axes . id2name = function ( id ) {
373- if ( typeof id !== 'string' || ! id . match ( AX_ID_PATTERN ) ) return ;
374- var axNum = id . substr ( 1 ) ;
375- if ( axNum === '1' ) axNum = '' ;
376- return id . charAt ( 0 ) + 'axis' + axNum ;
377- } ;
378-
379- axes . name2id = function ( name ) {
380- if ( ! name . match ( AX_NAME_PATTERN ) ) return ;
381- var axNum = name . substr ( 5 ) ;
382- if ( axNum === '1' ) axNum = '' ;
383- return name . charAt ( 0 ) + axNum ;
384- } ;
385-
386- axes . cleanId = function ( id , axLetter ) {
387- if ( ! id . match ( AX_ID_PATTERN ) ) return ;
388- if ( axLetter && id . charAt ( 0 ) !== axLetter ) return ;
389-
390- var axNum = id . substr ( 1 ) . replace ( / ^ 0 + / , '' ) ;
391- if ( axNum === '1' ) axNum = '' ;
392- return id . charAt ( 0 ) + axNum ;
393- } ;
394-
395- axes . cleanName = function ( name , axLetter ) {
396- if ( ! name . match ( AX_ID_PATTERN ) ) return ;
397- if ( axLetter && name . charAt ( 0 ) !== axLetter ) return ;
398-
399- var axNum = name . substr ( 5 ) . replace ( / ^ 0 + / , '' ) ;
400- if ( axNum === '1' ) axNum = '' ;
401- return name . charAt ( 0 ) + 'axis' + axNum ;
402- } ;
403-
404376// get counteraxis letter for this axis (name or id)
405377// this can also be used as the id for default counter axis
406378axes . counterLetter = function ( id ) {
@@ -1862,81 +1834,6 @@ function numSeparate(nStr, separators) {
18621834 return x1 + x2 ;
18631835}
18641836
1865- // get all axis object names
1866- // optionally restricted to only x or y or z by string axLetter
1867- // and optionally 2D axes only, not those inside 3D scenes
1868- function listNames ( td , axLetter , only2d ) {
1869- var fullLayout = td . _fullLayout ;
1870- if ( ! fullLayout ) return [ ] ;
1871-
1872- function filterAxis ( obj , extra ) {
1873- var keys = Object . keys ( obj ) ,
1874- axMatch = / ^ [ x y z ] a x i s [ 0 - 9 ] * / ,
1875- out = [ ] ;
1876-
1877- for ( var i = 0 ; i < keys . length ; i ++ ) {
1878- var k = keys [ i ] ;
1879- if ( axLetter && k . charAt ( 0 ) !== axLetter ) continue ;
1880- if ( axMatch . test ( k ) ) out . push ( extra + k ) ;
1881- }
1882-
1883- return out . sort ( ) ;
1884- }
1885-
1886- var names = filterAxis ( fullLayout , '' ) ;
1887- if ( only2d ) return names ;
1888-
1889- var sceneIds3D = Plotly . Plots . getSubplotIds ( fullLayout , 'gl3d' ) || [ ] ;
1890- for ( var i = 0 ; i < sceneIds3D . length ; i ++ ) {
1891- var sceneId = sceneIds3D [ i ] ;
1892- names = names . concat (
1893- filterAxis ( fullLayout [ sceneId ] , sceneId + '.' )
1894- ) ;
1895- }
1896-
1897- return names ;
1898- }
1899-
1900- // get all axis objects, as restricted in listNames
1901- axes . list = function ( td , axletter , only2d ) {
1902- return listNames ( td , axletter , only2d )
1903- . map ( function ( axName ) {
1904- return Plotly . Lib . nestedProperty ( td . _fullLayout , axName ) . get ( ) ;
1905- } ) ;
1906- } ;
1907-
1908- // get all axis ids, optionally restricted by letter
1909- // this only makes sense for 2d axes
1910- axes . listIds = function ( td , axletter ) {
1911- return listNames ( td , axletter , true ) . map ( axes . name2id ) ;
1912- } ;
1913-
1914- // get an axis object from its id 'x','x2' etc
1915- // optionally, id can be a subplot (ie 'x2y3') and type gets x or y from it
1916- axes . getFromId = function ( td , id , type ) {
1917- var fullLayout = td . _fullLayout ;
1918-
1919- if ( type === 'x' ) id = id . replace ( / y [ 0 - 9 ] * / , '' ) ;
1920- else if ( type === 'y' ) id = id . replace ( / x [ 0 - 9 ] * / , '' ) ;
1921-
1922- return fullLayout [ axes . id2name ( id ) ] ;
1923- } ;
1924-
1925- // get an axis object of specified type from the containing trace
1926- axes . getFromTrace = function ( td , fullTrace , type ) {
1927- var fullLayout = td . _fullLayout ;
1928- var ax = null ;
1929- if ( Plotly . Plots . traceIs ( fullTrace , 'gl3d' ) ) {
1930- var scene = fullTrace . scene ;
1931- if ( scene . substr ( 0 , 5 ) === 'scene' ) {
1932- ax = fullLayout [ scene ] [ type + 'axis' ] ;
1933- }
1934- } else {
1935- ax = axes . getFromId ( td , fullTrace [ type + 'axis' ] || type ) ;
1936- }
1937-
1938- return ax ;
1939- } ;
19401837
19411838axes . subplotMatch = / ^ x ( [ 0 - 9 ] * ) y ( [ 0 - 9 ] * ) $ / ;
19421839
0 commit comments