Move style properties from fig_obj to template_obj. Parameters ---------- fig_obj: plotly.basedatatypes.BasePlotlyType template_obj: plotly.basedatatypes.BasePlotlyType skip: set of str Set of names of properties to skip
(fig_obj, template_obj, skip)
| 273 | # Template utilities |
| 274 | # ------------------ |
| 275 | def walk_push_to_template(fig_obj, template_obj, skip): |
| 276 | """ |
| 277 | Move style properties from fig_obj to template_obj. |
| 278 | |
| 279 | Parameters |
| 280 | ---------- |
| 281 | fig_obj: plotly.basedatatypes.BasePlotlyType |
| 282 | template_obj: plotly.basedatatypes.BasePlotlyType |
| 283 | skip: set of str |
| 284 | Set of names of properties to skip |
| 285 | """ |
| 286 | from _plotly_utils.basevalidators import ( |
| 287 | CompoundValidator, |
| 288 | CompoundArrayValidator, |
| 289 | is_array, |
| 290 | ) |
| 291 | |
| 292 | for prop in list(fig_obj._props): |
| 293 | if prop == "template" or prop in skip: |
| 294 | # Avoid infinite recursion |
| 295 | continue |
| 296 | |
| 297 | fig_val = fig_obj[prop] |
| 298 | template_val = template_obj[prop] |
| 299 | |
| 300 | validator = fig_obj._get_validator(prop) |
| 301 | |
| 302 | if isinstance(validator, CompoundValidator): |
| 303 | walk_push_to_template(fig_val, template_val, skip) |
| 304 | if not fig_val._props: |
| 305 | # Check if we can remove prop itself |
| 306 | fig_obj[prop] = None |
| 307 | elif isinstance(validator, CompoundArrayValidator) and fig_val: |
| 308 | template_elements = list(template_val) |
| 309 | template_element_names = [el.name for el in template_elements] |
| 310 | template_propdefaults = template_obj[prop[:-1] + "defaults"] |
| 311 | |
| 312 | for fig_el in fig_val: |
| 313 | element_name = fig_el.name |
| 314 | if element_name: |
| 315 | # No properties are skipped inside a named array element |
| 316 | skip = set() |
| 317 | if fig_el.name in template_element_names: |
| 318 | item_index = template_element_names.index(fig_el.name) |
| 319 | template_el = template_elements[item_index] |
| 320 | walk_push_to_template(fig_el, template_el, skip) |
| 321 | else: |
| 322 | template_el = fig_el.__class__() |
| 323 | walk_push_to_template(fig_el, template_el, skip) |
| 324 | template_elements.append(template_el) |
| 325 | template_element_names.append(fig_el.name) |
| 326 | |
| 327 | # Restore element name |
| 328 | # since it was pushed to template above |
| 329 | fig_el.name = element_name |
| 330 | else: |
| 331 | walk_push_to_template(fig_el, template_propdefaults, skip) |
| 332 |
no test coverage detected