python-pptx icon indicating copy to clipboard operation
python-pptx copied to clipboard

chart.category_axis.visible = False not Working

Open benaustin2000 opened this issue 3 years ago • 0 comments

Hi , When I setting the

chart.category_axis.visible = False

, but axis still in the chart.This bug affects all axis.visible function. In xmlchemy.py,

@property
    def _setter(self) -> Callable[[BaseOxmlElement, Any], None]:
        """Callable suitable for the "set" side of the attribute property descriptor."""

        def set_attr_value(obj: BaseOxmlElement, value: Any) -> None:
            # -- when an XML attribute has a default value, setting it to that default removes the
            # -- attribute from the element (when it is present)
            if value == self._default:
                if self._clark_name in obj.attrib:
                    del obj.attrib[self._clark_name]
                return
            str_value = self._simple_type.to_xml(value)
            obj.set(self._clark_name, str_value)

        return set_attr_value
 Due to default value of delete_ is set True(Should be **_False_**), when setting visible=False, delete.val = True,  the _setter found  value == self._default, then return. The fix version as following
    @property
    def _setter(self) -> Callable[[BaseOxmlElement, Any], None]:
        """Callable suitable for the "set" side of the attribute property descriptor."""

        def set_attr_value(obj: BaseOxmlElement, value: Any) -> None:
            # -- when an XML attribute has a default value, setting it to that default removes the
            # -- attribute from the element (when it is present)
            if value == self._default:
                if self._clark_name in obj.attrib:
                     if obj.attrib[self._clark_name] != str_value:
                        obj.set(self._clark_name, str_value)
                    else:
                        del obj.attrib[self._clark_name]
                return
            str_value = self._simple_type.to_xml(value)
            obj.set(self._clark_name, str_value)

        return set_attr_value

benaustin2000 avatar Oct 18 '22 07:10 benaustin2000