Skip to content

Update to plotlyjs 1.43.1 #1376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Dec 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
17 changes: 17 additions & 0 deletions _plotly_utils/basevalidators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2107,6 +2107,23 @@ def validate_coerce(self, v, skip_invalid=False):
return v


class TitleValidator(CompoundValidator):
"""
This is a special validator to allow compound title properties
(e.g. layout.title, layout.xaxis.title, etc.) to be set as strings
or numbers. These strings are mapped to the 'text' property of the
compound validator.
"""
def __init__(self, *args, **kwargs):
super(TitleValidator, self).__init__(*args, **kwargs)

def validate_coerce(self, v, skip_invalid=False):
if isinstance(v, string_types + (int, float)):
v = {'text': v}
return super(TitleValidator, self).validate_coerce(
v, skip_invalid=skip_invalid)


class CompoundArrayValidator(BaseValidator):

def __init__(self, plotly_name, parent_name, data_class_str, data_docs,
Expand Down
2 changes: 2 additions & 0 deletions codegen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ def perform_codegen():
# ### Write __init__.py files for each validator package ###
path_to_validator_import_info = {}
for node in all_datatype_nodes:
if node.is_mapped:
continue
key = node.parent_path_parts
path_to_validator_import_info.setdefault(key, []).append(
(f"._{node.name_property}", node.name_validator_class)
Expand Down
23 changes: 18 additions & 5 deletions codegen/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ class {datatype_class}({node.name_base_datatype}):\n""")
elif subtype_node.is_compound:
prop_type = (f"plotly.graph_objs{node.dotpath_str}." +
f"{subtype_node.name_datatype_class}")
elif subtype_node.is_mapped:
prop_type = ''
else:
prop_type = get_typing_type(
subtype_node.datatype, subtype_node.is_array_ok)
Expand Down Expand Up @@ -196,6 +198,13 @@ def _prop_descriptions(self):
buffer.write(f"""
\"\"\"""")

mapped_nodes = [n for n in subtype_nodes if n.is_mapped]
mapped_properties = {n.plotly_name: n.relative_path for n in mapped_nodes}
if mapped_properties:
buffer.write(f"""

_mapped_properties = {repr(mapped_properties)}""")

# ### Constructor ###
buffer.write(f"""
def __init__(self""")
Expand Down Expand Up @@ -245,9 +254,10 @@ def __init__(self""")
# Initialize validators
# ---------------------""")
for subtype_node in subtype_nodes:
sub_name = subtype_node.name_property
sub_validator = subtype_node.name_validator_class
buffer.write(f"""
if not subtype_node.is_mapped:
sub_name = subtype_node.name_property
sub_validator = subtype_node.name_validator_class
buffer.write(f"""
self._validators['{sub_name}'] = v_{undercase}.{sub_validator}()""")

buffer.write(f"""
Expand All @@ -256,10 +266,13 @@ def __init__(self""")
# ----------------------------------""")
for subtype_node in subtype_nodes:
name_prop = subtype_node.name_property
if name_prop == 'template':
if name_prop == 'template' or subtype_node.is_mapped:
# Special handling for layout.template to avoid infinite
# recursion. Only initialize layout.template object if non-None
# value specified
# value specified.
#
# Same special handling for mapped nodes (e.g. layout.titlefont)
# to keep them for overriding mapped property with None
buffer.write(f"""
_v = arg.pop('{name_prop}', None)
_v = {name_prop} if {name_prop} is not None else _v
Expand Down
112 changes: 110 additions & 2 deletions codegen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ def name_base_validator(self) -> str:
elif self.plotly_name.endswith('src') and self.datatype == 'string':
validator_base = (f"_plotly_utils.basevalidators."
f"SrcValidator")
elif self.plotly_name == 'title' and self.datatype == 'compound':
validator_base = "_plotly_utils.basevalidators.TitleValidator"
else:
datatype_title_case = self.datatype.title().replace('_', '')
validator_base = (f"_plotly_utils.basevalidators."
Expand Down Expand Up @@ -565,7 +567,7 @@ def is_compound(self) -> bool:
bool
"""
return (isinstance(self.node_data, dict_like) and
not self.is_simple and
not self.is_simple and not self.is_mapped and
self.plotly_name not in ('items', 'impliedEdits', 'transforms'))

@property
Expand Down Expand Up @@ -629,7 +631,22 @@ def is_datatype(self) -> bool:
-------
bool
"""
return self.is_simple or self.is_compound or self.is_array
return (self.is_simple
or self.is_compound
or self.is_array
or self.is_mapped)

@property
def is_mapped(self) -> bool:
"""
Node represents a mapping from a deprecated property to a
normal property

Returns
-------
bool
"""
return False

# Node path
# ---------
Expand Down Expand Up @@ -798,6 +815,29 @@ def child_datatypes(self):
n.parent_path_parts != ('layout', 'template', 'data')):

nodes.append(ElementDefaultsNode(n, self.plotly_schema))
elif n.is_compound and n.plotly_name == 'title':
nodes.append(n)

# Remap deprecated title properties
deprecated_data = n.parent.node_data.get('_deprecated', {})
deprecated_title_prop_names = [
p for p in deprecated_data
if p.startswith('title') and p != 'title']
for prop_name in deprecated_title_prop_names:

mapped_prop_name = prop_name.replace('title', '')

mapped_prop_node = [
title_prop for title_prop in n.child_datatypes
if title_prop.plotly_name == mapped_prop_name][0]

prop_parent = n.parent

legacy_node = MappedPropNode(
mapped_prop_node, prop_parent,
prop_name, self.plotly_schema)

nodes.append(legacy_node)

elif n.is_datatype:
nodes.append(n)
Expand Down Expand Up @@ -1177,3 +1217,71 @@ def plotly_name(self):
@property
def name_datatype_class(self):
return self.element_node.name_datatype_class


class MappedPropNode(PlotlyNode):

def __init__(self, mapped_prop_node, parent,
prop_name, plotly_schema):
"""
Create node that represents a legacy title property.
e.g. layout.titlefont. These properties are now subproperties under
the sibling `title` property. e.g. layout.title.font.

Parameters
----------
title_node: PlotlyNode
prop_name: str
The name of the propery (without the title prefix)
e.g. 'font' to represent the layout.titlefont property.
"""
node_path = parent.node_path + (prop_name,)
super().__init__(plotly_schema,
node_path=node_path,
parent=parent)

self.mapped_prop_node = mapped_prop_node
self.prop_name = prop_name

@property
def node_data(self):
return {}

@property
def description(self):
res = f"""\
Deprecated: Please use {self.mapped_prop_node.path_str} instead.
""" + self.mapped_prop_node.description
return res

@property
def name_base_datatype(self):
return self.mapped_prop_node.description

@property
def root_name(self):
return self.parent.root_name

@property
def plotly_name(self):
return self.prop_name

@property
def name_datatype_class(self):
return self.mapped_prop_node.name_datatype_class

@property
def is_mapped(self):
return True

@property
def datatype(self):
return self.mapped_prop_node.datatype

def get_validator_instance(self):
return self.mapped_prop_node.get_validator_instance()

@property
def relative_path(self):
return (self.mapped_prop_node.parent.plotly_name,
self.mapped_prop_node.plotly_name)
6 changes: 6 additions & 0 deletions codegen/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def write_validator_py(outdir,
-------
None
"""
if node.is_mapped:
# No validator written for mapped nodes
# e.g. no validator for layout.titlefont since ths is mapped to
# layout.title.font
return

# Generate source code
# --------------------
validator_source = build_validator_py(node)
Expand Down
Loading