@@ -1740,7 +1740,7 @@ class SubplotidValidator(BaseValidator):
17401740 }
17411741 """
17421742
1743- def __init__ (self , plotly_name , parent_name , dflt = None , regex = None , ** kwargs ):
1743+ def __init__ (self , plotly_name , parent_name , dflt = None , regex = None , array_ok = False , ** kwargs ):
17441744 if dflt is None and regex is None :
17451745 raise ValueError ("One or both of regex and deflt must be specified" )
17461746
@@ -1755,6 +1755,7 @@ def __init__(self, plotly_name, parent_name, dflt=None, regex=None, **kwargs):
17551755 self .base = re .match (r"/\^(\w+)" , regex ).group (1 )
17561756
17571757 self .regex = self .base + r"(\d*)"
1758+ self .array_ok = array_ok
17581759
17591760 def description (self ):
17601761 desc = """\
@@ -1763,31 +1764,49 @@ def description(self):
17631764 optionally followed by an integer >= 1
17641765 (e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)
17651766 """ .format (plotly_name = self .plotly_name , base = self .base )
1767+
1768+ desc = """\
1769+ The '{plotly_name}' property is an identifier of a particular
1770+ subplot, of type '{base}', that may be specified as:
1771+ - the string '{base}'
1772+ optionally followed by an integer >= 1
1773+ (e.g. '{base}', '{base}1', '{base}2', '{base}3', etc.)""" .format (plotly_name = self .plotly_name , base = self .base )
1774+ if self .array_ok :
1775+ desc += """
1776+ - A tuple or list of the above"""
17661777 return desc
17671778
17681779 def validate_coerce (self , v ):
1769- if v is None :
1770- pass
1771- elif not isinstance (v , str ):
1772- self .raise_invalid_val (v )
1773- else :
1774- # match = re.fullmatch(self.regex, v)
1775- match = fullmatch (self .regex , v )
1780+ def coerce (value , invalid_els ):
1781+ if not isinstance (value , str ):
1782+ invalid_els .append (value )
1783+ return value
1784+ match = fullmatch (self .regex , value )
17761785 if not match :
1777- is_valid = False
1786+ invalid_els .append (value )
1787+ return value
17781788 else :
17791789 digit_str = match .group (1 )
17801790 if len (digit_str ) > 0 and int (digit_str ) == 0 :
1781- is_valid = False
1791+ invalid_els .append (value )
1792+ return value
17821793 elif len (digit_str ) > 0 and int (digit_str ) == 1 :
1783- # Remove 1 suffix (e.g. x1 -> x)
1784- v = self .base
1785- is_valid = True
1794+ return self .base
17861795 else :
1787- is_valid = True
1796+ return value
17881797
1789- if not is_valid :
1790- self .raise_invalid_val (v )
1798+ if v is None :
1799+ pass
1800+ elif self .array_ok and is_simple_array (v ):
1801+ invalid_els = []
1802+ v = [e for e in v if coerce (e , invalid_els )]
1803+ if invalid_els :
1804+ self .raise_invalid_elements (invalid_els [:10 ])
1805+ else :
1806+ invalid_els = []
1807+ v = coerce (v , invalid_els )
1808+ if invalid_els :
1809+ self .raise_invalid_val (self .base )
17911810 return v
17921811
17931812
0 commit comments