Skip to content
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

[WIP] Refactor chaco plot containers #674

Closed
wants to merge 15 commits into from
Closed

Conversation

rahulporuri
Copy link
Contributor

No description provided.

Poruri Sai Rahul added 13 commits April 16, 2021 13:25
instead import it from plot_component module where it is already
defined.

we might want to move this to chaco.base or something of that sort later

	modified:   chaco/plot_containers.py
i.e. from the chaco BasePlotContainer to the subclasses i.e.
OverlayPlotContainer, StackedPlotContainer and GridPlotContainer.

	modified:   chaco/plot_containers.py
instead of relying on BasePlotContainer which itself inherits from
Container.

We can do so now because we moved all of relevant traits down to the
subclasses from the BasePlotContainer in the previous commit. Note that
there are still a few traits on the BasePlotContainer but those are
deprecated and are being removed elsewhere

	modified:   chaco/plot_containers.py
the enable OverlayContainer inherits from the enable Container and
overrides the preferred size and layout methods - which are duplicated
in the chaco OverlayContainer.

So, we can simply update the chaco OverlayContainer to inherit from the
enable OverlayContainer - and simply override/set traits on the subclass
in Chaco

	modified:   chaco/plot_containers.py
specifically, in the methods StackedPlotContainer.get_preferred_size and
StackedPlotContainer._do_layout.

note that the get_preferred_size method is slightly non-trivial because
the underlying enable util stacked_preferred_size does not fully cover
the needs of the method - we might want to fix the underlying enable
util to do so.

	modified:   chaco/plot_containers.py
simply update the _do_layout methods in the subclasses and remove the
StackedPlotContainer._do_layout method

	modified:   chaco/plot_containers.py
by simply moving the method to the two subclasses

	modified:   chaco/plot_containers.py
and remove them from the chaco StackedPlotContainer

	modified:   chaco/plot_containers.py
from the baseclass StackedPlotContainer. Now, we are finally in a place
where we can simply remove the chaco baseclass StackedPlotContainer
completely because it now finally (almost) looks like the enable
StackedPlotContainer

	modified:   chaco/plot_containers.py
and remove the chaco StackedPlotContainer

	modified:   chaco/plot_containers.py
and a few duplicated traits on the subclass have been removed.

Sadly, it looks like there are bugs in the baseclass which need to be
fixed in enable before more code can be killed

	modified:   chaco/plot_containers.py
and we removed a bunch of traits from the subclass which are already
defined in the baseclass.

ideally, we would also be able to remove the get_preferred_size and
persistence (__getstate__) methods from the subclass but once those are
fixed in enable and a new version of enable is available, we can clean
this code up further.

	modified:   chaco/plot_containers.py
and replace the old/outdated String trait with the Str trait

	modified:   chaco/plot_containers.py

try:
from enable.api import ConstraintsContainer
except ImportError:
ConstraintsContainer = None

# Local relative imports
from .base_plot_container import BasePlotContainer
from .plot_component import DEFAULT_DRAWING_ORDER
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we might want to move DEFAULT_DRAWING_ORDER somewhere else/somewhere better e.g. chaco.base instead of leaving it in chaco.plot_component

valign = Enum("bottom", "top", "center")

_cached_preferred_size = Tuple(transient=True)
return stacked_preferred_size(self, components=components)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

        if self.resizable == "":
            self._cached_preferred_size = self.outer_bounds[:]
            return self.outer_bounds

isn't handled by enables stacked_preferred_size. If we can update the function in enable, after the next release of enable, we will be able to get rid of this method completely. both in this class and in VPlotContainer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -321,51 +140,59 @@ def _do_layout(self):
else:
align = "max"

return self._do_stack_layout(components, align)
return stack_layout(self, components=components, align=align)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are bugs in HStackedContainer and the HStackedContainer._do_layout - if those get fixed, we will be able to remove this HPlotContainer._do_layout method and HPlotContainer.valign trait.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state = super(VStackedContainer, self).__getstate__()
if "stack_index" in state:
del state["stack_index"]
return state
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can push this __getstate__ down into enable, we can get rid of these in the chaco subclasses. Note that this PR also removes a bunch of traits in the subclasses which were marked as transient in the subclasses but they are not transient in the superclasses e.g. _cached_preferred_size (which isn't even defined on the baseclasses in the first place)



class GridPlotContainer(BasePlotContainer):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we are now in a place where we can get rid of BasePlotContainer completely.

simple_container_do_layout,
)
from enable.api import Container, OverlayContainer
from enable.stacked_container import HStackedContainer, VStackedContainer
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

enable needs to expose these via the api module.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rahulporuri pushed a commit to enthought/enable that referenced this pull request Apr 16, 2021
this might have been a simple copy-paste mistake.
discovered when working on enthought/chaco#674

	modified:   enable/stacked_container.py
rahulporuri pushed a commit to enthought/enable that referenced this pull request Apr 19, 2021
)

this might have been a simple copy-paste mistake.
discovered when working on enthought/chaco#674

	modified:   enable/stacked_container.py
Poruri Sai Rahul added 2 commits June 1, 2021 16:32
the methods in the baseclasses got fixed so the inheriting classes can
remove the overridden methods

note that the __getstate__ methods also got removed - but the
corresponding change in enable needs to be made - specifically to make
stack_index a transient trait

	modified:   chaco/plot_containers.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants