@@ -14,6 +14,7 @@ var Drawing = require('../../components/drawing');
1414
1515var axAttrs = require ( './layout_attributes' ) ;
1616var cleanTicks = require ( './clean_ticks' ) ;
17+ var cartesianConstants = require ( './constants' ) ;
1718
1819var constants = require ( '../../constants/numerical' ) ;
1920var ONEMAXYEAR = constants . ONEMAXYEAR ;
@@ -124,6 +125,44 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
124125 return Lib . coerce ( containerIn , containerOut , attrDef , refAttr ) ;
125126} ;
126127
128+ /*
129+ * Coerce an array of axis references. Used by shapes for per-coordinate axis references.
130+ *
131+ * attr: the attribute we're generating a reference for. Should end in 'x' or 'y'
132+ * but can be prefixed, like 'ax' for annotation's arrow x
133+ * dflt: the default to coerce to, or blank to use the first axis (falling back on
134+ * extraOption if there is no axis)
135+ * extraOption: aside from existing axes with this letter, what non-axis value is allowed?
136+ * Only required if it's different from `dflt`
137+ */
138+ axes . coerceRefArray = function ( containerIn , containerOut , gd , attr , expectedLen ) {
139+ var axLetter = attr . charAt ( attr . length - 1 ) ;
140+ var axlist = gd . _fullLayout . _subplots [ axLetter + 'axis' ] ;
141+ axlist = axlist . concat ( axlist . map ( function ( x ) { return x + ' domain' ; } ) ) ;
142+ var refAttr = attr + 'ref' ;
143+ var axRef = containerIn [ refAttr ] ;
144+ var dflt = axlist . length ? axlist [ 0 ] : 'paper' ;
145+
146+ // Handle array length mismatch
147+ if ( axRef . length > expectedLen ) {
148+ // if the array is longer than the expected length, truncate it
149+ axRef = axRef . slice ( 0 , expectedLen ) ;
150+ } else if ( axRef . length < expectedLen ) {
151+ // if the array is shorter than the expected length, extend using the default value
152+ axRef = axRef . concat ( Array ( expectedLen - axRef . length ) . fill ( dflt ) ) ;
153+ }
154+
155+ // Check all references, replace with default if invalid
156+ for ( var i = 0 ; i < axRef . length ; i ++ ) {
157+ if ( ! ( axRef [ i ] === 'paper' || cartesianConstants . idRegex [ axLetter ] . test ( axRef [ i ] ) ) ) {
158+ axRef [ i ] = dflt ;
159+ }
160+ }
161+
162+ containerOut [ refAttr ] = axRef ;
163+ return axRef ;
164+ } ;
165+
127166/*
128167 * Get the type of an axis reference. This can be 'range', 'domain', or 'paper'.
129168 * This assumes ar is a valid axis reference and returns 'range' if it doesn't
@@ -134,6 +173,7 @@ axes.coerceRef = function(containerIn, containerOut, gd, attr, dflt, extraOption
134173 */
135174axes . getRefType = function ( ar ) {
136175 if ( ar === undefined ) { return ar ; }
176+ if ( Array . isArray ( ar ) ) { return 'array' ; }
137177 if ( ar === 'paper' ) { return 'paper' ; }
138178 if ( ar === 'pixel' ) { return 'pixel' ; }
139179 if ( / ( d o m a i n ) $ / . test ( ar ) ) { return 'domain' ; } else { return 'range' ; }
0 commit comments