1
1
from io import StringIO
2
2
from os import path as opath
3
3
4
- from _plotly_utils .basevalidators import (
5
- BaseDataValidator ,
6
- CompoundValidator ,
7
- CompoundArrayValidator ,
8
- )
9
4
from codegen .datatypes import (
10
5
reindent_validator_description ,
11
6
add_constructor_params ,
12
7
add_docstring ,
13
8
)
14
- from codegen .utils import PlotlyNode , write_source_py
9
+ from codegen .utils import write_source_py
15
10
16
11
import inflect
12
+ from plotly .basedatatypes import BaseFigure
17
13
18
14
19
15
def build_figure_py (
@@ -118,6 +114,82 @@ def __init__(self, data=None, layout=None,
118
114
"""
119
115
)
120
116
117
+ def add_wrapper (wrapped_name , full_params , param_list ):
118
+ buffer .write (
119
+ f"""
120
+ def { wrapped_name } (self, { full_params } ) -> "{ fig_classname } ":
121
+ '''
122
+ { getattr (BaseFigure , wrapped_name ).__doc__ }
123
+ '''
124
+ return super({ fig_classname } , self).{ wrapped_name } ({ param_list } )
125
+ """
126
+ )
127
+
128
+ add_wrapper (
129
+ "update" ,
130
+ "dict1=None, overwrite=False, **kwargs" ,
131
+ "dict1, overwrite, **kwargs" ,
132
+ )
133
+
134
+ add_wrapper (
135
+ "update_traces" ,
136
+ "patch=None, selector=None, row=None, col=None, secondary_y=None, overwrite=False, **kwargs" ,
137
+ "patch, selector, row, col, secondary_y, overwrite, **kwargs" ,
138
+ )
139
+
140
+ add_wrapper (
141
+ "update_layout" ,
142
+ "dict1=None, overwrite=False, **kwargs" ,
143
+ "dict1, overwrite, **kwargs" ,
144
+ )
145
+
146
+ add_wrapper (
147
+ "for_each_trace" ,
148
+ "fn, selector=None, row=None, col=None, secondary_y=None" ,
149
+ "fn, selector, row, col, secondary_y" ,
150
+ )
151
+
152
+ add_wrapper (
153
+ "add_trace" ,
154
+ "trace, row=None, col=None, secondary_y=None, exclude_empty_subplots=False" ,
155
+ "trace, row, col, secondary_y, exclude_empty_subplots" ,
156
+ )
157
+
158
+ add_wrapper (
159
+ "add_traces" ,
160
+ "data,rows=None,cols=None,secondary_ys=None,exclude_empty_subplots=False" ,
161
+ "data,rows,cols,secondary_ys,exclude_empty_subplots" ,
162
+ )
163
+
164
+ add_wrapper (
165
+ "add_vline" ,
166
+ 'x,row="all",col="all",exclude_empty_subplots=True,annotation=None,**kwargs' ,
167
+ "x,row,col,exclude_empty_subplots,annotation,**kwargs" ,
168
+ )
169
+
170
+ add_wrapper (
171
+ "add_hline" ,
172
+ 'y,row="all",col="all",exclude_empty_subplots=True,annotation=None,**kwargs' ,
173
+ "y,row,col,exclude_empty_subplots,annotation,**kwargs" ,
174
+ )
175
+
176
+ add_wrapper (
177
+ "add_vrect" ,
178
+ 'x0,x1,row="all",col="all",exclude_empty_subplots=True,annotation=None,**kwargs' ,
179
+ "x0,x1,row,col,exclude_empty_subplots,annotation,**kwargs" ,
180
+ )
181
+
182
+ add_wrapper (
183
+ "add_hrect" ,
184
+ 'y0,y1,row="all",col="all",exclude_empty_subplots=True,annotation=None,**kwargs' ,
185
+ "y0,y1,row,col,exclude_empty_subplots,annotation,**kwargs" ,
186
+ )
187
+ add_wrapper (
188
+ "set_subplots" ,
189
+ "rows=None, cols=None, **make_subplots_args" ,
190
+ "rows, cols, **make_subplots_args" ,
191
+ )
192
+
121
193
# ### add_trace methods for each trace type ###
122
194
for trace_node in trace_nodes :
123
195
@@ -136,7 +208,10 @@ def add_{trace_node.plotly_name}(self"""
136
208
if include_secondary_y :
137
209
param_extras .append ("secondary_y" )
138
210
add_constructor_params (
139
- buffer , trace_node .child_datatypes , append_extras = param_extras
211
+ buffer ,
212
+ trace_node .child_datatypes ,
213
+ append_extras = param_extras ,
214
+ output_type = fig_classname ,
140
215
)
141
216
142
217
# #### Docstring ####
@@ -193,15 +268,15 @@ def add_{trace_node.plotly_name}(self"""
193
268
"""
194
269
)
195
270
196
- for i , subtype_node in enumerate (trace_node .child_datatypes ):
271
+ for _ , subtype_node in enumerate (trace_node .child_datatypes ):
197
272
subtype_prop_name = subtype_node .name_property
198
273
buffer .write (
199
274
f"""
200
275
{ subtype_prop_name } ={ subtype_prop_name } ,"""
201
276
)
202
277
203
278
buffer .write (
204
- f """
279
+ """
205
280
**kwargs)"""
206
281
)
207
282
@@ -226,7 +301,7 @@ def add_{trace_node.plotly_name}(self"""
226
301
if singular_name == "yaxis" :
227
302
secondary_y_1 = ", secondary_y=None"
228
303
secondary_y_2 = ", secondary_y=secondary_y"
229
- secondary_y_docstring = f """
304
+ secondary_y_docstring = """
230
305
secondary_y: boolean or None (default None)
231
306
* If True, only select yaxis objects associated with the secondary
232
307
y-axis of the subplot.
@@ -283,7 +358,7 @@ def select_{plural_name}(
283
358
'{ singular_name } ', selector, row, col{ secondary_y_2 } )
284
359
285
360
def for_each_{ singular_name } (
286
- self, fn, selector=None, row=None, col=None{ secondary_y_1 } ):
361
+ self, fn, selector=None, row=None, col=None{ secondary_y_1 } ) -> ' { fig_classname } ' :
287
362
\" \" \"
288
363
Apply a function to all { singular_name } objects that satisfy the
289
364
specified selection criteria
@@ -311,7 +386,7 @@ def for_each_{singular_name}(
311
386
Returns
312
387
-------
313
388
self
314
- Returns the Figure object that the method was called on
389
+ Returns the { fig_classname } object that the method was called on
315
390
\" \" \"
316
391
for obj in self.select_{ plural_name } (
317
392
selector=selector, row=row, col=col{ secondary_y_2 } ):
@@ -325,7 +400,7 @@ def update_{plural_name}(
325
400
selector=None,
326
401
overwrite=False,
327
402
row=None, col=None{ secondary_y_1 } ,
328
- **kwargs):
403
+ **kwargs) -> ' { fig_classname } ' :
329
404
\" \" \"
330
405
Perform a property update operation on all { singular_name } objects
331
406
that satisfy the specified selection criteria
@@ -363,7 +438,7 @@ def update_{plural_name}(
363
438
Returns
364
439
-------
365
440
self
366
- Returns the Figure object that the method was called on
441
+ Returns the { fig_classname } object that the method was called on
367
442
\" \" \"
368
443
for obj in self.select_{ plural_name } (
369
444
selector=selector, row=row, col=col{ secondary_y_2 } ):
@@ -477,7 +552,7 @@ def for_each_{method_prefix}{singular_name}(
477
552
Returns
478
553
-------
479
554
self
480
- Returns the Figure object that the method was called on
555
+ Returns the { fig_classname } object that the method was called on
481
556
\" \" \"
482
557
for obj in self._select_annotations_like(
483
558
prop='{ plural_name } ',
@@ -498,7 +573,7 @@ def update_{method_prefix}{plural_name}(
498
573
col=None,
499
574
secondary_y=None,
500
575
**kwargs
501
- ):
576
+ ) -> ' { fig_classname } ' :
502
577
\" \" \"
503
578
Perform a property update operation on all { plural_name } that satisfy the
504
579
specified selection criteria
@@ -545,7 +620,7 @@ def update_{method_prefix}{plural_name}(
545
620
Returns
546
621
-------
547
622
self
548
- Returns the Figure object that the method was called on
623
+ Returns the { fig_classname } object that the method was called on
549
624
\" \" \"
550
625
for obj in self._select_annotations_like(
551
626
prop='{ plural_name } ',
@@ -610,7 +685,7 @@ def add_{method_prefix}{singular_name}(self"""
610
685
"""
611
686
)
612
687
613
- for i , subtype_node in enumerate (node .child_datatypes ):
688
+ for _ , subtype_node in enumerate (node .child_datatypes ):
614
689
subtype_prop_name = subtype_node .name_property
615
690
buffer .write (
616
691
f"""
0 commit comments