Skip to content

Commit afaaec8

Browse files
committed
Updated codegen to add support for elementdefaults properties
e.g. `layout.template.layout.annotationdefaults`
1 parent 106426e commit afaaec8

File tree

216 files changed

+3152
-5
lines changed

Some content is hidden

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

216 files changed

+3152
-5
lines changed

Diff for: codegen/__init__.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
DEPRECATED_DATATYPES)
99
from codegen.figure import write_figure_classes
1010
from codegen.utils import (TraceNode, PlotlyNode, LayoutNode, FrameNode,
11-
write_init_py)
11+
write_init_py, ElementDefaultsNode)
1212
from codegen.validators import (write_validator_py,
1313
write_data_validator_py,
1414
get_data_validator_instance)
@@ -28,9 +28,10 @@ def preprocess_schema(plotly_schema):
2828
Central location to make changes to schema before it's seen by the
2929
PlotlyNode classes
3030
"""
31-
layout = plotly_schema['layout']['layoutAttributes']
3231

33-
template_description = layout['template']['description']
32+
# Update template
33+
# ---------------
34+
layout = plotly_schema['layout']['layoutAttributes']
3435

3536
# Create codegen-friendly template scheme
3637
template = {
@@ -112,7 +113,8 @@ def perform_codegen():
112113
all_frame_nodes)
113114

114115
all_compound_nodes = [node for node in all_datatype_nodes
115-
if node.is_compound]
116+
if node.is_compound and
117+
not isinstance(node, ElementDefaultsNode)]
116118

117119
# Write out validators
118120
# --------------------

Diff for: codegen/utils.py

+63-1
Original file line numberDiff line numberDiff line change
@@ -787,7 +787,16 @@ def child_datatypes(self):
787787
nodes = []
788788
for n in self.children:
789789
if n.is_array:
790+
# Add array element node
790791
nodes.append(n.children[0].children[0])
792+
793+
# Add elementdefaults node. Require parent_path_parts not
794+
# empty to avoid creating defaults classes for traces
795+
if (n.parent_path_parts and
796+
n.parent_path_parts != ('layout', 'template', 'data')):
797+
798+
nodes.append(ElementDefaultsNode(n, self.plotly_schema))
799+
791800
elif n.is_datatype:
792801
nodes.append(n)
793802

@@ -898,7 +907,11 @@ def get_all_compound_datatype_nodes(plotly_schema, node_class):
898907
if node.plotly_name and not node.is_array:
899908
nodes.append(node)
900909

901-
nodes_to_process.extend(node.child_compound_datatypes)
910+
non_defaults_compound_children = [
911+
node for node in node.child_compound_datatypes
912+
if not isinstance(node, ElementDefaultsNode)]
913+
914+
nodes_to_process.extend(non_defaults_compound_children)
902915

903916
return nodes
904917

@@ -1101,3 +1114,52 @@ def node_data(self) -> dict:
11011114
node_data = node_data[prop_name]
11021115

11031116
return node_data
1117+
1118+
1119+
class ElementDefaultsNode(PlotlyNode):
1120+
1121+
def __init__(self, array_node, plotly_schema):
1122+
"""
1123+
1124+
Parameters
1125+
----------
1126+
array_node: PlotlyNode
1127+
"""
1128+
super().__init__(plotly_schema,
1129+
node_path=array_node.node_path,
1130+
parent=array_node.parent)
1131+
1132+
assert array_node.is_array
1133+
self.array_node = array_node
1134+
self.element_node = array_node.children[0].children[0]
1135+
1136+
@property
1137+
def node_data(self):
1138+
return {}
1139+
1140+
@property
1141+
def description(self):
1142+
return ''
1143+
1144+
@property
1145+
def name_base_datatype(self):
1146+
return self.element_node.name_base_datatype
1147+
1148+
@property
1149+
def root_name(self):
1150+
return self.array_node.root_name
1151+
1152+
@property
1153+
def plotly_name(self):
1154+
return self.element_node.plotly_name + 'defaults'
1155+
1156+
@property
1157+
def name_datatype_class(self):
1158+
"""
1159+
Name of the Python datatype class representing this node
1160+
1161+
Returns
1162+
-------
1163+
str
1164+
"""
1165+
return self.element_node.name_datatype_class

Diff for: plotly/graph_objs/_carpet.py

+6
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@ def aaxis(self):
225225
tickformatstops
226226
plotly.graph_objs.carpet.aaxis.Tickformatstop
227227
instance or dict with compatible properties
228+
tickformatstopdefaults
229+
plotly.graph_objs.carpet.aaxis.Tickformatstop
230+
instance or dict with compatible properties
228231
tickmode
229232
230233
tickprefix
@@ -510,6 +513,9 @@ def baxis(self):
510513
tickformatstops
511514
plotly.graph_objs.carpet.baxis.Tickformatstop
512515
instance or dict with compatible properties
516+
tickformatstopdefaults
517+
plotly.graph_objs.carpet.baxis.Tickformatstop
518+
instance or dict with compatible properties
513519
tickmode
514520
515521
tickprefix

Diff for: plotly/graph_objs/_choropleth.py

+4
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ def colorbar(self):
170170
plotly.graph_objs.choropleth.colorbar.Tickforma
171171
tstop instance or dict with compatible
172172
properties
173+
tickformatstopdefaults
174+
plotly.graph_objs.choropleth.colorbar.Tickforma
175+
tstop instance or dict with compatible
176+
properties
173177
ticklen
174178
Sets the tick length (in px).
175179
tickmode

Diff for: plotly/graph_objs/_cone.py

+3
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,9 @@ def colorbar(self):
259259
tickformatstops
260260
plotly.graph_objs.cone.colorbar.Tickformatstop
261261
instance or dict with compatible properties
262+
tickformatstopdefaults
263+
plotly.graph_objs.cone.colorbar.Tickformatstop
264+
instance or dict with compatible properties
262265
ticklen
263266
Sets the tick length (in px).
264267
tickmode

Diff for: plotly/graph_objs/_contour.py

+3
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ def colorbar(self):
192192
tickformatstops
193193
plotly.graph_objs.contour.colorbar.Tickformatst
194194
op instance or dict with compatible properties
195+
tickformatstopdefaults
196+
plotly.graph_objs.contour.colorbar.Tickformatst
197+
op instance or dict with compatible properties
195198
ticklen
196199
Sets the tick length (in px).
197200
tickmode

Diff for: plotly/graph_objs/_contourcarpet.py

+4
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,10 @@ def colorbar(self):
385385
plotly.graph_objs.contourcarpet.colorbar.Tickfo
386386
rmatstop instance or dict with compatible
387387
properties
388+
tickformatstopdefaults
389+
plotly.graph_objs.contourcarpet.colorbar.Tickfo
390+
rmatstop instance or dict with compatible
391+
properties
388392
ticklen
389393
Sets the tick length (in px).
390394
tickmode

Diff for: plotly/graph_objs/_figure.py

+25
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def __init__(
5858
annotations
5959
plotly.graph_objs.layout.Annotation instance or
6060
dict with compatible properties
61+
annotationdefaults
62+
plotly.graph_objs.layout.Annotation instance or
63+
dict with compatible properties
6164
autosize
6265
Determines whether or not a layout width or
6366
height that has been left undefined by the user
@@ -208,6 +211,9 @@ def __init__(
208211
images
209212
plotly.graph_objs.layout.Image instance or dict
210213
with compatible properties
214+
imagedefaults
215+
plotly.graph_objs.layout.Image instance or dict
216+
with compatible properties
211217
legend
212218
plotly.graph_objs.layout.Legend instance or
213219
dict with compatible properties
@@ -258,6 +264,9 @@ def __init__(
258264
shapes
259265
plotly.graph_objs.layout.Shape instance or dict
260266
with compatible properties
267+
shapedefaults
268+
plotly.graph_objs.layout.Shape instance or dict
269+
with compatible properties
261270
showlegend
262271
Determines whether or not a legend is drawn.
263272
Default is `true` if there is a trace to show
@@ -268,6 +277,9 @@ def __init__(
268277
sliders
269278
plotly.graph_objs.layout.Slider instance or
270279
dict with compatible properties
280+
sliderdefaults
281+
plotly.graph_objs.layout.Slider instance or
282+
dict with compatible properties
271283
spikedistance
272284
Sets the default distance (in pixels) to look
273285
for data to draw spikelines to (-1 means no
@@ -289,6 +301,9 @@ def __init__(
289301
updatemenus
290302
plotly.graph_objs.layout.Updatemenu instance or
291303
dict with compatible properties
304+
updatemenudefaults
305+
plotly.graph_objs.layout.Updatemenu instance or
306+
dict with compatible properties
292307
violingap
293308
Sets the gap (in plot fraction) between violins
294309
of adjacent location coordinates.
@@ -4902,6 +4917,7 @@ def add_parcoords(
49024917
customdata=None,
49034918
customdatasrc=None,
49044919
dimensions=None,
4920+
dimensiondefaults=None,
49054921
domain=None,
49064922
hoverinfo=None,
49074923
hoverinfosrc=None,
@@ -4943,6 +4959,9 @@ def add_parcoords(
49434959
dimensions
49444960
The dimensions (variables) of the parallel coordinates
49454961
chart. 2..60 dimensions are supported.
4962+
dimensiondefaults
4963+
plotly.graph_objs.parcoords.Dimension instance or dict
4964+
with compatible properties
49464965
domain
49474966
plotly.graph_objs.parcoords.Domain instance or dict
49484967
with compatible properties
@@ -5017,6 +5036,7 @@ def add_parcoords(
50175036
customdata=customdata,
50185037
customdatasrc=customdatasrc,
50195038
dimensions=dimensions,
5039+
dimensiondefaults=dimensiondefaults,
50205040
domain=domain,
50215041
hoverinfo=hoverinfo,
50225042
hoverinfosrc=hoverinfosrc,
@@ -8112,6 +8132,7 @@ def add_splom(
81128132
customdatasrc=None,
81138133
diagonal=None,
81148134
dimensions=None,
8135+
dimensiondefaults=None,
81158136
hoverinfo=None,
81168137
hoverinfosrc=None,
81178138
hoverlabel=None,
@@ -8164,6 +8185,9 @@ def add_splom(
81648185
dimensions
81658186
plotly.graph_objs.splom.Dimension instance or dict with
81668187
compatible properties
8188+
dimensiondefaults
8189+
plotly.graph_objs.splom.Dimension instance or dict with
8190+
compatible properties
81678191
hoverinfo
81688192
Determines which trace information appear on hover. If
81698193
`none` or `skip` are set, no information is displayed
@@ -8258,6 +8282,7 @@ def add_splom(
82588282
customdatasrc=customdatasrc,
82598283
diagonal=diagonal,
82608284
dimensions=dimensions,
8285+
dimensiondefaults=dimensiondefaults,
82618286
hoverinfo=hoverinfo,
82628287
hoverinfosrc=hoverinfosrc,
82638288
hoverlabel=hoverlabel,

Diff for: plotly/graph_objs/_figurewidget.py

+25
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ def __init__(
5858
annotations
5959
plotly.graph_objs.layout.Annotation instance or
6060
dict with compatible properties
61+
annotationdefaults
62+
plotly.graph_objs.layout.Annotation instance or
63+
dict with compatible properties
6164
autosize
6265
Determines whether or not a layout width or
6366
height that has been left undefined by the user
@@ -208,6 +211,9 @@ def __init__(
208211
images
209212
plotly.graph_objs.layout.Image instance or dict
210213
with compatible properties
214+
imagedefaults
215+
plotly.graph_objs.layout.Image instance or dict
216+
with compatible properties
211217
legend
212218
plotly.graph_objs.layout.Legend instance or
213219
dict with compatible properties
@@ -258,6 +264,9 @@ def __init__(
258264
shapes
259265
plotly.graph_objs.layout.Shape instance or dict
260266
with compatible properties
267+
shapedefaults
268+
plotly.graph_objs.layout.Shape instance or dict
269+
with compatible properties
261270
showlegend
262271
Determines whether or not a legend is drawn.
263272
Default is `true` if there is a trace to show
@@ -268,6 +277,9 @@ def __init__(
268277
sliders
269278
plotly.graph_objs.layout.Slider instance or
270279
dict with compatible properties
280+
sliderdefaults
281+
plotly.graph_objs.layout.Slider instance or
282+
dict with compatible properties
271283
spikedistance
272284
Sets the default distance (in pixels) to look
273285
for data to draw spikelines to (-1 means no
@@ -289,6 +301,9 @@ def __init__(
289301
updatemenus
290302
plotly.graph_objs.layout.Updatemenu instance or
291303
dict with compatible properties
304+
updatemenudefaults
305+
plotly.graph_objs.layout.Updatemenu instance or
306+
dict with compatible properties
292307
violingap
293308
Sets the gap (in plot fraction) between violins
294309
of adjacent location coordinates.
@@ -4902,6 +4917,7 @@ def add_parcoords(
49024917
customdata=None,
49034918
customdatasrc=None,
49044919
dimensions=None,
4920+
dimensiondefaults=None,
49054921
domain=None,
49064922
hoverinfo=None,
49074923
hoverinfosrc=None,
@@ -4943,6 +4959,9 @@ def add_parcoords(
49434959
dimensions
49444960
The dimensions (variables) of the parallel coordinates
49454961
chart. 2..60 dimensions are supported.
4962+
dimensiondefaults
4963+
plotly.graph_objs.parcoords.Dimension instance or dict
4964+
with compatible properties
49464965
domain
49474966
plotly.graph_objs.parcoords.Domain instance or dict
49484967
with compatible properties
@@ -5017,6 +5036,7 @@ def add_parcoords(
50175036
customdata=customdata,
50185037
customdatasrc=customdatasrc,
50195038
dimensions=dimensions,
5039+
dimensiondefaults=dimensiondefaults,
50205040
domain=domain,
50215041
hoverinfo=hoverinfo,
50225042
hoverinfosrc=hoverinfosrc,
@@ -8112,6 +8132,7 @@ def add_splom(
81128132
customdatasrc=None,
81138133
diagonal=None,
81148134
dimensions=None,
8135+
dimensiondefaults=None,
81158136
hoverinfo=None,
81168137
hoverinfosrc=None,
81178138
hoverlabel=None,
@@ -8164,6 +8185,9 @@ def add_splom(
81648185
dimensions
81658186
plotly.graph_objs.splom.Dimension instance or dict with
81668187
compatible properties
8188+
dimensiondefaults
8189+
plotly.graph_objs.splom.Dimension instance or dict with
8190+
compatible properties
81678191
hoverinfo
81688192
Determines which trace information appear on hover. If
81698193
`none` or `skip` are set, no information is displayed
@@ -8258,6 +8282,7 @@ def add_splom(
82588282
customdatasrc=customdatasrc,
82598283
diagonal=diagonal,
82608284
dimensions=dimensions,
8285+
dimensiondefaults=dimensiondefaults,
82618286
hoverinfo=hoverinfo,
82628287
hoverinfosrc=hoverinfosrc,
82638288
hoverlabel=hoverlabel,

Diff for: plotly/graph_objs/_heatmap.py

+3
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ def colorbar(self):
169169
tickformatstops
170170
plotly.graph_objs.heatmap.colorbar.Tickformatst
171171
op instance or dict with compatible properties
172+
tickformatstopdefaults
173+
plotly.graph_objs.heatmap.colorbar.Tickformatst
174+
op instance or dict with compatible properties
172175
ticklen
173176
Sets the tick length (in px).
174177
tickmode

0 commit comments

Comments
 (0)