Skip to content

Commit b4e6b01

Browse files
committed
Added new SrcValidator base class for src properties (e.g. xsrc)
This validator accepts plotly.grid_objs.Column objects along with strings
1 parent f3c69cd commit b4e6b01

File tree

904 files changed

+2116
-2781
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

904 files changed

+2116
-2781
lines changed

_plotly_utils/basevalidators.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,33 @@ def validate_coerce(self, v):
519519
return v
520520

521521

522+
class SrcValidator(BaseValidator):
523+
524+
def __init__(self, plotly_name, parent_name, **kwargs):
525+
super(SrcValidator, self).__init__(
526+
plotly_name=plotly_name, parent_name=parent_name, **kwargs)
527+
528+
def description(self):
529+
return ("""\
530+
The '{plotly_name}' property must be specified as a string or
531+
as a plotly.grid_objs.Column object""".format(plotly_name=self.plotly_name))
532+
533+
def validate_coerce(self, v):
534+
from plotly.grid_objs import Column
535+
if v is None:
536+
# Pass None through
537+
pass
538+
elif isinstance(v, string_types):
539+
pass
540+
elif isinstance(v, Column):
541+
# Convert to id string
542+
v = v.id
543+
else:
544+
self.raise_invalid_val(v)
545+
546+
return v
547+
548+
522549
class NumberValidator(BaseValidator):
523550
"""
524551
"number": {

codegen/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,9 @@ def name_base_validator(self) -> str:
360360
"""
361361
if self.path_str in CUSTOM_VALIDATOR_DATATYPES:
362362
validator_base = f"{CUSTOM_VALIDATOR_DATATYPES[self.path_str]}"
363+
elif self.plotly_name.endswith('src') and self.datatype == 'string':
364+
validator_base = (f"_plotly_utils.basevalidators."
365+
f"SrcValidator")
363366
else:
364367
datatype_title_case = self.datatype.title().replace('_', '')
365368
validator_base = (f"_plotly_utils.basevalidators."

plotly/graph_objs/_area.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ def customdatasrc(self):
3333
"""
3434
Sets the source reference on plot.ly for customdata .
3535
36-
The 'customdatasrc' property is a string and must be specified as:
37-
- A string
38-
- A number that will be converted to a string
36+
The 'customdatasrc' property must be specified as a string or
37+
as a plotly.grid_objs.Column object
3938
4039
Returns
4140
-------
@@ -80,9 +79,8 @@ def hoverinfosrc(self):
8079
"""
8180
Sets the source reference on plot.ly for hoverinfo .
8281
83-
The 'hoverinfosrc' property is a string and must be specified as:
84-
- A string
85-
- A number that will be converted to a string
82+
The 'hoverinfosrc' property must be specified as a string or
83+
as a plotly.grid_objs.Column object
8684
8785
Returns
8886
-------
@@ -173,9 +171,8 @@ def idssrc(self):
173171
"""
174172
Sets the source reference on plot.ly for ids .
175173
176-
The 'idssrc' property is a string and must be specified as:
177-
- A string
178-
- A number that will be converted to a string
174+
The 'idssrc' property must be specified as a string or
175+
as a plotly.grid_objs.Column object
179176
180177
Returns
181178
-------
@@ -333,9 +330,8 @@ def rsrc(self):
333330
"""
334331
Sets the source reference on plot.ly for r .
335332
336-
The 'rsrc' property is a string and must be specified as:
337-
- A string
338-
- A number that will be converted to a string
333+
The 'rsrc' property must be specified as a string or
334+
as a plotly.grid_objs.Column object
339335
340336
Returns
341337
-------
@@ -453,9 +449,8 @@ def tsrc(self):
453449
"""
454450
Sets the source reference on plot.ly for t .
455451
456-
The 'tsrc' property is a string and must be specified as:
457-
- A string
458-
- A number that will be converted to a string
452+
The 'tsrc' property must be specified as a string or
453+
as a plotly.grid_objs.Column object
459454
460455
Returns
461456
-------

plotly/graph_objs/_bar.py

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ def basesrc(self):
3131
"""
3232
Sets the source reference on plot.ly for base .
3333
34-
The 'basesrc' property is a string and must be specified as:
35-
- A string
36-
- A number that will be converted to a string
34+
The 'basesrc' property must be specified as a string or
35+
as a plotly.grid_objs.Column object
3736
3837
Returns
3938
-------
@@ -120,9 +119,8 @@ def customdatasrc(self):
120119
"""
121120
Sets the source reference on plot.ly for customdata .
122121
123-
The 'customdatasrc' property is a string and must be specified as:
124-
- A string
125-
- A number that will be converted to a string
122+
The 'customdatasrc' property must be specified as a string or
123+
as a plotly.grid_objs.Column object
126124
127125
Returns
128126
-------
@@ -367,9 +365,8 @@ def hoverinfosrc(self):
367365
"""
368366
Sets the source reference on plot.ly for hoverinfo .
369367
370-
The 'hoverinfosrc' property is a string and must be specified as:
371-
- A string
372-
- A number that will be converted to a string
368+
The 'hoverinfosrc' property must be specified as a string or
369+
as a plotly.grid_objs.Column object
373370
374371
Returns
375372
-------
@@ -464,9 +461,8 @@ def hovertextsrc(self):
464461
"""
465462
Sets the source reference on plot.ly for hovertext .
466463
467-
The 'hovertextsrc' property is a string and must be specified as:
468-
- A string
469-
- A number that will be converted to a string
464+
The 'hovertextsrc' property must be specified as a string or
465+
as a plotly.grid_objs.Column object
470466
471467
Returns
472468
-------
@@ -507,9 +503,8 @@ def idssrc(self):
507503
"""
508504
Sets the source reference on plot.ly for ids .
509505
510-
The 'idssrc' property is a string and must be specified as:
511-
- A string
512-
- A number that will be converted to a string
506+
The 'idssrc' property must be specified as a string or
507+
as a plotly.grid_objs.Column object
513508
514509
Returns
515510
-------
@@ -752,9 +747,8 @@ def offsetsrc(self):
752747
"""
753748
Sets the source reference on plot.ly for offset .
754749
755-
The 'offsetsrc' property is a string and must be specified as:
756-
- A string
757-
- A number that will be converted to a string
750+
The 'offsetsrc' property must be specified as a string or
751+
as a plotly.grid_objs.Column object
758752
759753
Returns
760754
-------
@@ -891,9 +885,8 @@ def rsrc(self):
891885
"""
892886
Sets the source reference on plot.ly for r .
893887
894-
The 'rsrc' property is a string and must be specified as:
895-
- A string
896-
- A number that will be converted to a string
888+
The 'rsrc' property must be specified as a string or
889+
as a plotly.grid_objs.Column object
897890
898891
Returns
899892
-------
@@ -1149,9 +1142,8 @@ def textpositionsrc(self):
11491142
"""
11501143
Sets the source reference on plot.ly for textposition .
11511144
1152-
The 'textpositionsrc' property is a string and must be specified as:
1153-
- A string
1154-
- A number that will be converted to a string
1145+
The 'textpositionsrc' property must be specified as a string or
1146+
as a plotly.grid_objs.Column object
11551147
11561148
Returns
11571149
-------
@@ -1170,9 +1162,8 @@ def textsrc(self):
11701162
"""
11711163
Sets the source reference on plot.ly for text .
11721164
1173-
The 'textsrc' property is a string and must be specified as:
1174-
- A string
1175-
- A number that will be converted to a string
1165+
The 'textsrc' property must be specified as a string or
1166+
as a plotly.grid_objs.Column object
11761167
11771168
Returns
11781169
-------
@@ -1191,9 +1182,8 @@ def tsrc(self):
11911182
"""
11921183
Sets the source reference on plot.ly for t .
11931184
1194-
The 'tsrc' property is a string and must be specified as:
1195-
- A string
1196-
- A number that will be converted to a string
1185+
The 'tsrc' property must be specified as a string or
1186+
as a plotly.grid_objs.Column object
11971187
11981188
Returns
11991189
-------
@@ -1305,9 +1295,8 @@ def widthsrc(self):
13051295
"""
13061296
Sets the source reference on plot.ly for width .
13071297
1308-
The 'widthsrc' property is a string and must be specified as:
1309-
- A string
1310-
- A number that will be converted to a string
1298+
The 'widthsrc' property must be specified as a string or
1299+
as a plotly.grid_objs.Column object
13111300
13121301
Returns
13131302
-------
@@ -1416,9 +1405,8 @@ def xsrc(self):
14161405
"""
14171406
Sets the source reference on plot.ly for x .
14181407
1419-
The 'xsrc' property is a string and must be specified as:
1420-
- A string
1421-
- A number that will be converted to a string
1408+
The 'xsrc' property must be specified as a string or
1409+
as a plotly.grid_objs.Column object
14221410
14231411
Returns
14241412
-------
@@ -1527,9 +1515,8 @@ def ysrc(self):
15271515
"""
15281516
Sets the source reference on plot.ly for y .
15291517
1530-
The 'ysrc' property is a string and must be specified as:
1531-
- A string
1532-
- A number that will be converted to a string
1518+
The 'ysrc' property must be specified as a string or
1519+
as a plotly.grid_objs.Column object
15331520
15341521
Returns
15351522
-------

plotly/graph_objs/_box.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,8 @@ def customdatasrc(self):
8282
"""
8383
Sets the source reference on plot.ly for customdata .
8484
85-
The 'customdatasrc' property is a string and must be specified as:
86-
- A string
87-
- A number that will be converted to a string
85+
The 'customdatasrc' property must be specified as a string or
86+
as a plotly.grid_objs.Column object
8887
8988
Returns
9089
-------
@@ -190,9 +189,8 @@ def hoverinfosrc(self):
190189
"""
191190
Sets the source reference on plot.ly for hoverinfo .
192191
193-
The 'hoverinfosrc' property is a string and must be specified as:
194-
- A string
195-
- A number that will be converted to a string
192+
The 'hoverinfosrc' property must be specified as a string or
193+
as a plotly.grid_objs.Column object
196194
197195
Returns
198196
-------
@@ -306,9 +304,8 @@ def idssrc(self):
306304
"""
307305
Sets the source reference on plot.ly for ids .
308306
309-
The 'idssrc' property is a string and must be specified as:
310-
- A string
311-
- A number that will be converted to a string
307+
The 'idssrc' property must be specified as a string or
308+
as a plotly.grid_objs.Column object
312309
313310
Returns
314311
-------
@@ -710,9 +707,8 @@ def textsrc(self):
710707
"""
711708
Sets the source reference on plot.ly for text .
712709
713-
The 'textsrc' property is a string and must be specified as:
714-
- A string
715-
- A number that will be converted to a string
710+
The 'textsrc' property must be specified as a string or
711+
as a plotly.grid_objs.Column object
716712
717713
Returns
718714
-------
@@ -910,9 +906,8 @@ def xsrc(self):
910906
"""
911907
Sets the source reference on plot.ly for x .
912908
913-
The 'xsrc' property is a string and must be specified as:
914-
- A string
915-
- A number that will be converted to a string
909+
The 'xsrc' property must be specified as a string or
910+
as a plotly.grid_objs.Column object
916911
917912
Returns
918913
-------
@@ -1020,9 +1015,8 @@ def ysrc(self):
10201015
"""
10211016
Sets the source reference on plot.ly for y .
10221017
1023-
The 'ysrc' property is a string and must be specified as:
1024-
- A string
1025-
- A number that will be converted to a string
1018+
The 'ysrc' property must be specified as a string or
1019+
as a plotly.grid_objs.Column object
10261020
10271021
Returns
10281022
-------

0 commit comments

Comments
 (0)