in chartify/_core/style.py [0:0]
def _apply_bokeh_setting(self, attribute, value, base_obj=None):
"""Recursively apply the settings value to the given settings attribute.
Recursion is necessary because some bokeh objects may
have multiple child objects.
E.g. figures can have more than one x-axis.
"""
# If not a bokeh attribute then we don't need to apply anything.
if "figure" not in attribute and base_obj is None:
return
split_attribute = attribute.split(".")
if base_obj is None:
base_obj = self._chart
if len(split_attribute) == 1:
setattr(base_obj, attribute, value)
else:
for i, attr in enumerate(split_attribute):
# If the attribute contains a list, the slice the list.
list_split = attr.split("[")
list_index = None
if len(list_split) > 1:
list_index = int(list_split[1].replace("]", ""))
attr = list_split[0]
if i < len(split_attribute) - 1:
base_obj = getattr(base_obj, attr)
# Slice the list if list_index is not None
if list_index is not None:
base_obj = base_obj[list_index]
# If the base object is a list, then apply settings to each
# element.
if isinstance(base_obj, (list,)):
for obj in base_obj:
self._apply_bokeh_setting(".".join(split_attribute[i + 1 :]), value, base_obj=obj)
break
else:
setattr(base_obj, attr, value)