From ec33d33ea89ce9cf724954472a8ec95d17f6678d Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:25:04 +0530 Subject: [PATCH 01/14] CLN : Dont redefine DEFAULT_DRAWING_ORDER 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 --- chaco/plot_containers.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 7b8bcada7..954ddc677 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -40,6 +40,7 @@ # Local relative imports from .base_plot_container import BasePlotContainer +from .plot_component import DEFAULT_DRAWING_ORDER __all__ = [ @@ -49,17 +50,6 @@ "GridPlotContainer", ] -DEFAULT_DRAWING_ORDER = [ - "background", - "image", - "underlay", - "plot", - "selection", - "border", - "annotation", - "overlay", -] - # Enable constraints layout is only available if kiwisolver is installed! if ConstraintsContainer is not None: From 7c5a4e4899190df976ce1431c820d463be4417f7 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:28:47 +0530 Subject: [PATCH 02/14] REF : Push down traits from super class to subclasses i.e. from the chaco BasePlotContainer to the subclasses i.e. OverlayPlotContainer, StackedPlotContainer and GridPlotContainer. modified: chaco/plot_containers.py --- chaco/plot_containers.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 954ddc677..b59637744 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -23,6 +23,7 @@ Instance, List, Property, + Str, String, Trait, Tuple, @@ -74,6 +75,14 @@ class OverlayPlotContainer(BasePlotContainer): space. All of its components must therefore be resizable. """ + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") + + #: Redefine the draw layer to "plot" instead of "mainlayer" + draw_layer = Str("plot") + + #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) #: Do not use an off-screen backbuffer. @@ -99,6 +108,14 @@ class StackedPlotContainer(BasePlotContainer): Base class for 1-D stacked plot containers, both horizontal and vertical. """ + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") + + #: Redefine the draw layer to "plot" instead of "mainlayer" + draw_layer = Str("plot") + + #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) # The dimension along which to stack components that are added to @@ -366,6 +383,14 @@ class GridPlotContainer(BasePlotContainer): **shape** trait. """ + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") + + #: Redefine the draw layer to "plot" instead of "mainlayer" + draw_layer = Str("plot") + + #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) #: The amount of space to put on either side of each component, expressed From fb701ab30a7f3ee33c3edcd5a488de046b3b5f39 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:34:04 +0530 Subject: [PATCH 03/14] REF : Use enable Container directly for chaco plot containers 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 --- chaco/plot_containers.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index b59637744..262e59be1 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -29,6 +29,7 @@ Tuple, Int, ) +from enable.api import Container from enable.simple_layout import ( simple_container_get_preferred_size, simple_container_do_layout, @@ -40,7 +41,6 @@ ConstraintsContainer = None # Local relative imports -from .base_plot_container import BasePlotContainer from .plot_component import DEFAULT_DRAWING_ORDER @@ -69,7 +69,7 @@ class ConstraintsPlotContainer(ConstraintsContainer): __all__.append("ConstraintsPlotContainer") -class OverlayPlotContainer(BasePlotContainer): +class OverlayPlotContainer(Container): """ A plot container that stretches all its components to fit within its space. All of its components must therefore be resizable. @@ -103,7 +103,7 @@ def _do_layout(self): simple_container_do_layout(self) -class StackedPlotContainer(BasePlotContainer): +class StackedPlotContainer(Container): """ Base class for 1-D stacked plot containers, both horizontal and vertical. """ @@ -372,7 +372,7 @@ def _do_layout(self): return self._do_stack_layout(components, align) -class GridPlotContainer(BasePlotContainer): +class GridPlotContainer(Container): """A GridPlotContainer consists of rows and columns in a tabular format. Each cell's width is the same as all other cells in its column, and each From 1fbda3e59dee6f8814e9416e9e04b0c5a27ade22 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:37:19 +0530 Subject: [PATCH 04/14] DEV : Chaco OverlayContainer now inherits from enable OverlayContainer 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 --- chaco/plot_containers.py | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 262e59be1..0089269a7 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -29,11 +29,7 @@ Tuple, Int, ) -from enable.api import Container -from enable.simple_layout import ( - simple_container_get_preferred_size, - simple_container_do_layout, -) +from enable.api import Container, OverlayContainer try: from enable.api import ConstraintsContainer @@ -69,7 +65,7 @@ class ConstraintsPlotContainer(ConstraintsContainer): __all__.append("ConstraintsPlotContainer") -class OverlayPlotContainer(Container): +class OverlayPlotContainer(OverlayContainer): """ A plot container that stretches all its components to fit within its space. All of its components must therefore be resizable. @@ -91,17 +87,6 @@ class OverlayPlotContainer(Container): # Cache (width, height) of the container's preferred size. _cached_preferred_size = Tuple - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent - """ - return simple_container_get_preferred_size(self, components=components) - - def _do_layout(self): - """Actually performs a layout (called by do_layout()).""" - simple_container_do_layout(self) - class StackedPlotContainer(Container): """ From 4a2926dcca43a4b3b8c92436ea54795cbeb30168 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:45:04 +0530 Subject: [PATCH 05/14] REF : Use enable utils in chaco StackedPlotContainer 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 --- chaco/plot_containers.py | 138 +-------------------------------------- 1 file changed, 3 insertions(+), 135 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 0089269a7..1dee04116 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -30,6 +30,7 @@ Int, ) from enable.api import Container, OverlayContainer +from enable.stacked_layout import stack_layout, stacked_preferred_size try: from enable.api import ConstraintsContainer @@ -128,145 +129,12 @@ def get_preferred_size(self, components=None): self._cached_preferred_size = self.outer_bounds[:] return self.outer_bounds - if components is None: - components = self.components - - ndx = self.stack_index - other_ndx = 1 - ndx - - no_visible_components = True - total_size = 0 - max_other_size = 0 - for component in components: - if not self._should_layout(component): - continue - - no_visible_components = False - - pref_size = component.get_preferred_size() - total_size += pref_size[ndx] + self.spacing - if pref_size[other_ndx] > max_other_size: - max_other_size = pref_size[other_ndx] - - if total_size >= self.spacing: - total_size -= self.spacing - - if (self.stack_dimension not in self.resizable) and ( - self.stack_dimension not in self.fit_components - ): - total_size = self.bounds[ndx] - elif no_visible_components or (total_size == 0): - total_size = self.default_size[ndx] - - if (self.other_dimension not in self.resizable) and ( - self.other_dimension not in self.fit_components - ): - max_other_size = self.bounds[other_ndx] - elif no_visible_components or (max_other_size == 0): - max_other_size = self.default_size[other_ndx] - - if ndx == 0: - self._cached_preferred_size = ( - total_size + self.hpadding, - max_other_size + self.vpadding, - ) - else: - self._cached_preferred_size = ( - max_other_size + self.hpadding, - total_size + self.vpadding, - ) - - return self._cached_preferred_size + return stacked_preferred_size(self, components=components) def _do_stack_layout(self, components, align): """Helper method that does the actual work of layout.""" - size = list(self.bounds) - if self.fit_components != "": - self.get_preferred_size() - if "h" in self.fit_components: - size[0] = self._cached_preferred_size[0] - self.hpadding - if "v" in self.fit_components: - size[1] = self._cached_preferred_size[1] - self.vpadding - - ndx = self.stack_index - other_ndx = 1 - ndx - other_dim = self.other_dimension - - # Assign sizes of non-resizable components, and compute the total size - # used by them (along the stack dimension). - total_fixed_size = 0 - resizable_components = [] - size_prefs = {} - total_resizable_size = 0 - - for component in components: - if not self._should_layout(component): - continue - if self.stack_dimension not in component.resizable: - total_fixed_size += component.outer_bounds[ndx] - else: - preferred_size = component.get_preferred_size() - size_prefs[component] = preferred_size - total_resizable_size += preferred_size[ndx] - resizable_components.append(component) - - new_bounds_dict = {} - - # Assign sizes of all the resizable components along the stack dimension - if resizable_components: - space = self.spacing * (len(self.components) - 1) - avail_size = size[ndx] - total_fixed_size - space - if total_resizable_size > 0: - scale = avail_size / float(total_resizable_size) - for component in resizable_components: - tmp = list(component.outer_bounds) - tmp[ndx] = int(size_prefs[component][ndx] * scale) - new_bounds_dict[component] = tmp - else: - each_size = int(avail_size / len(resizable_components)) - for component in resizable_components: - tmp = list(component.outer_bounds) - tmp[ndx] = each_size - new_bounds_dict[component] = tmp - - # Loop over all the components, assigning position and computing the - # size in the other dimension and its position. - cur_pos = 0 - for component in components: - if not self._should_layout(component): - continue - - position = list(component.outer_position) - position[ndx] = cur_pos - - bounds = new_bounds_dict.get( - component, list(component.outer_bounds) - ) - cur_pos += bounds[ndx] + self.spacing - - if (bounds[other_ndx] > size[other_ndx]) or ( - other_dim in component.resizable - ): - # If the component is resizable in the other dimension or it exceeds the - # container bounds, set it to the maximum size of the container - - position[other_ndx] = 0 - bounds[other_ndx] = size[other_ndx] - else: - position[other_ndx] = 0 - if align == "min": - pass - elif align == "max": - position[other_ndx] = size[other_ndx] - bounds[other_ndx] - elif align == "center": - position[other_ndx] = ( - size[other_ndx] - bounds[other_ndx] - ) / 2.0 - - component.outer_position = position - component.outer_bounds = bounds - component.do_layout() + stack_layout(self, components=components, align=align) ### Persistence ########################################################### From 608621933d94cea51823a6fc42cfb5efadc40038 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:49:08 +0530 Subject: [PATCH 06/14] REF : Remove the need for StackedPlotContainer._do_layout simply update the _do_layout methods in the subclasses and remove the StackedPlotContainer._do_layout method modified: chaco/plot_containers.py --- chaco/plot_containers.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 1dee04116..b5777cfad 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -131,11 +131,6 @@ def get_preferred_size(self, components=None): return stacked_preferred_size(self, components=components) - def _do_stack_layout(self, components, align): - """Helper method that does the actual work of layout.""" - - stack_layout(self, components=components, align=align) - ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. @@ -181,7 +176,7 @@ def _do_layout(self): else: align = "max" - return self._do_stack_layout(components, align) + return stack_layout(self, components=components, align=align) class VPlotContainer(StackedPlotContainer): @@ -222,7 +217,7 @@ def _do_layout(self): else: align = "max" - return self._do_stack_layout(components, align) + return stack_layout(self, components=components, align=align) class GridPlotContainer(Container): From 08ffe73a77eb7c86cf6368dae192e12988f68208 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:50:26 +0530 Subject: [PATCH 07/14] REF : Remove the need for StackedPlotContainer.get_preferred_size by simply moving the method to the two subclasses modified: chaco/plot_containers.py --- chaco/plot_containers.py | 45 ++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index b5777cfad..c6120097f 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -116,21 +116,6 @@ class StackedPlotContainer(Container): # attribute. It must be 0 or 1. stack_index = 0 - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - if self.fixed_preferred_size is not None: - self._cached_preferred_size = self.fixed_preferred_size - return self.fixed_preferred_size - - if self.resizable == "": - self._cached_preferred_size = self.outer_bounds[:] - return self.outer_bounds - - return stacked_preferred_size(self, components=components) - ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. @@ -162,6 +147,21 @@ class HPlotContainer(StackedPlotContainer): _cached_preferred_size = Tuple(transient=True) + def get_preferred_size(self, components=None): + """Returns the size (width,height) that is preferred for this component. + + Overrides PlotComponent. + """ + if self.fixed_preferred_size is not None: + self._cached_preferred_size = self.fixed_preferred_size + return self.fixed_preferred_size + + if self.resizable == "": + self._cached_preferred_size = self.outer_bounds[:] + return self.outer_bounds + + return stacked_preferred_size(self, components=components) + def _do_layout(self): """Actually performs a layout (called by do_layout()).""" if self.stack_order == "left_to_right": @@ -204,6 +204,21 @@ class VPlotContainer(StackedPlotContainer): #: The amount of space to put between components. spacing = Float(0.0) + def get_preferred_size(self, components=None): + """Returns the size (width,height) that is preferred for this component. + + Overrides PlotComponent. + """ + if self.fixed_preferred_size is not None: + self._cached_preferred_size = self.fixed_preferred_size + return self.fixed_preferred_size + + if self.resizable == "": + self._cached_preferred_size = self.outer_bounds[:] + return self.outer_bounds + + return stacked_preferred_size(self, components=components) + def _do_layout(self): """Actually performs a layout (called by do_layout()).""" if self.stack_order == "bottom_to_top": From 8200d2a4d12902f3e9818588769850d4f3736b61 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:52:22 +0530 Subject: [PATCH 08/14] REF : Move chaco-specific traits to subclasses and remove them from the chaco StackedPlotContainer modified: chaco/plot_containers.py --- chaco/plot_containers.py | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index c6120097f..654365258 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -94,16 +94,6 @@ class StackedPlotContainer(Container): Base class for 1-D stacked plot containers, both horizontal and vertical. """ - #: Redefine the container layers to name the main layer as "plot" instead - #: of the Enable default of "mainlayer" - container_under_layers = Tuple("background", "image", "underlay", "plot") - - #: Redefine the draw layer to "plot" instead of "mainlayer" - draw_layer = Str("plot") - - #: Redefine the draw order - draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - # The dimension along which to stack components that are added to # this container. stack_dimension = Enum("h", "v", transient=True) @@ -134,6 +124,14 @@ class HPlotContainer(StackedPlotContainer): **components** list. """ + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") + + #: Redefine the draw layer to "plot" instead of "mainlayer" + draw_layer = Str("plot") + + #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) #: The order in which components in the plot container are laid out. @@ -184,6 +182,14 @@ class VPlotContainer(StackedPlotContainer): A plot container that stacks plot components vertically. """ + #: Redefine the container layers to name the main layer as "plot" instead + #: of the Enable default of "mainlayer" + container_under_layers = Tuple("background", "image", "underlay", "plot") + + #: Redefine the draw layer to "plot" instead of "mainlayer" + draw_layer = Str("plot") + + #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) #: Overrides StackedPlotContainer. From da794ca66633d3d496396bdeaf28070aa772023b Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:53:20 +0530 Subject: [PATCH 09/14] REF : Move the persistence methods to the subclasses 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 --- chaco/plot_containers.py | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 654365258..0a2b88166 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -106,15 +106,6 @@ class StackedPlotContainer(Container): # attribute. It must be 0 or 1. stack_index = 0 - ### Persistence ########################################################### - - # PICKLE FIXME: blocked with _pickles, but not sure that was correct. - def __getstate__(self): - state = super(StackedPlotContainer, self).__getstate__() - if "stack_index" in state: - del state["stack_index"] - return state - class HPlotContainer(StackedPlotContainer): """ @@ -176,6 +167,15 @@ def _do_layout(self): return stack_layout(self, components=components, align=align) + ### Persistence ########################################################### + + # PICKLE FIXME: blocked with _pickles, but not sure that was correct. + def __getstate__(self): + state = super(StackedPlotContainer, self).__getstate__() + if "stack_index" in state: + del state["stack_index"] + return state + class VPlotContainer(StackedPlotContainer): """ @@ -240,6 +240,15 @@ def _do_layout(self): return stack_layout(self, components=components, align=align) + ### Persistence ########################################################### + + # PICKLE FIXME: blocked with _pickles, but not sure that was correct. + def __getstate__(self): + state = super(StackedPlotContainer, self).__getstate__() + if "stack_index" in state: + del state["stack_index"] + return state + class GridPlotContainer(Container): """A GridPlotContainer consists of rows and columns in a tabular format. From 4887dee6f133ddbf2923b4eec11e3cb529968e33 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 13:56:24 +0530 Subject: [PATCH 10/14] REF : Use enable StackedContainer instead of chaco StackedPlotContainer and remove the chaco StackedPlotContainer modified: chaco/plot_containers.py --- chaco/plot_containers.py | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 0a2b88166..141149817 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -30,6 +30,7 @@ Int, ) from enable.api import Container, OverlayContainer +from enable.stacked_container import StackedContainer from enable.stacked_layout import stack_layout, stacked_preferred_size try: @@ -89,25 +90,7 @@ class OverlayPlotContainer(OverlayContainer): _cached_preferred_size = Tuple -class StackedPlotContainer(Container): - """ - Base class for 1-D stacked plot containers, both horizontal and vertical. - """ - - # The dimension along which to stack components that are added to - # this container. - stack_dimension = Enum("h", "v", transient=True) - - # The "other" dimension, i.e., the dual of the stack dimension. - other_dimension = Enum("v", "h", transient=True) - - # The index into obj.position and obj.bounds that corresponds to - # **stack_dimension**. This is a class-level and not an instance-level - # attribute. It must be 0 or 1. - stack_index = 0 - - -class HPlotContainer(StackedPlotContainer): +class HPlotContainer(StackedContainer): """ A plot container that stacks all of its components horizontally. Resizable components share the free space evenly. All components are stacked from @@ -171,13 +154,13 @@ def _do_layout(self): # PICKLE FIXME: blocked with _pickles, but not sure that was correct. def __getstate__(self): - state = super(StackedPlotContainer, self).__getstate__() + state = super(StackedContainer, self).__getstate__() if "stack_index" in state: del state["stack_index"] return state -class VPlotContainer(StackedPlotContainer): +class VPlotContainer(StackedContainer): """ A plot container that stacks plot components vertically. """ @@ -244,7 +227,7 @@ def _do_layout(self): # PICKLE FIXME: blocked with _pickles, but not sure that was correct. def __getstate__(self): - state = super(StackedPlotContainer, self).__getstate__() + state = super(StackedContainer, self).__getstate__() if "stack_index" in state: del state["stack_index"] return state From 9b63c1bc8b7c70739d44d6761211055459ae6ec5 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 14:02:03 +0530 Subject: [PATCH 11/14] REF : chaco HPlotContainer now inherits from enable HStackedContainer 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 --- chaco/plot_containers.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 141149817..cfc001131 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -30,7 +30,7 @@ Int, ) from enable.api import Container, OverlayContainer -from enable.stacked_container import StackedContainer +from enable.stacked_container import HStackedContainer, StackedContainer from enable.stacked_layout import stack_layout, stacked_preferred_size try: @@ -90,7 +90,7 @@ class OverlayPlotContainer(OverlayContainer): _cached_preferred_size = Tuple -class HPlotContainer(StackedContainer): +class HPlotContainer(HStackedContainer): """ A plot container that stacks all of its components horizontally. Resizable components share the free space evenly. All components are stacked from @@ -108,12 +108,6 @@ class HPlotContainer(StackedContainer): #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - #: The order in which components in the plot container are laid out. - stack_order = Enum("left_to_right", "right_to_left") - - #: The amount of space to put between components. - spacing = Float(0.0) - #: The vertical alignment of objects that don't span the full height. valign = Enum("bottom", "top", "center") @@ -154,7 +148,7 @@ def _do_layout(self): # PICKLE FIXME: blocked with _pickles, but not sure that was correct. def __getstate__(self): - state = super(StackedContainer, self).__getstate__() + state = super(HStackedContainer, self).__getstate__() if "stack_index" in state: del state["stack_index"] return state From 1e1653408fe81e47889c033425e049c0282a30cd Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 14:05:51 +0530 Subject: [PATCH 12/14] REF : Chaco VPlotContainer now inherits from enable VStackedContainer 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 --- chaco/plot_containers.py | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index cfc001131..653617bec 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -30,7 +30,7 @@ Int, ) from enable.api import Container, OverlayContainer -from enable.stacked_container import HStackedContainer, StackedContainer +from enable.stacked_container import HStackedContainer, VStackedContainer from enable.stacked_layout import stack_layout, stacked_preferred_size try: @@ -154,7 +154,7 @@ def __getstate__(self): return state -class VPlotContainer(StackedContainer): +class VPlotContainer(VStackedContainer): """ A plot container that stacks plot components vertically. """ @@ -169,24 +169,6 @@ class VPlotContainer(StackedContainer): #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - #: Overrides StackedPlotContainer. - stack_dimension = "v" - #: Overrides StackedPlotContainer. - other_dimension = "h" - #: Overrides StackedPlotContainer. - stack_index = 1 - - # VPlotContainer attributes - - #: The horizontal alignment of objects that don't span the full width. - halign = Enum("left", "right", "center") - - #: The order in which components in the plot container are laid out. - stack_order = Enum("bottom_to_top", "top_to_bottom") - - #: The amount of space to put between components. - spacing = Float(0.0) - def get_preferred_size(self, components=None): """Returns the size (width,height) that is preferred for this component. @@ -202,26 +184,11 @@ def get_preferred_size(self, components=None): return stacked_preferred_size(self, components=components) - def _do_layout(self): - """Actually performs a layout (called by do_layout()).""" - if self.stack_order == "bottom_to_top": - components = self.components - else: - components = self.components[::-1] - if self.halign == "left": - align = "min" - elif self.halign == "center": - align = "center" - else: - align = "max" - - return stack_layout(self, components=components, align=align) - ### Persistence ########################################################### # PICKLE FIXME: blocked with _pickles, but not sure that was correct. def __getstate__(self): - state = super(StackedContainer, self).__getstate__() + state = super(VStackedContainer, self).__getstate__() if "stack_index" in state: del state["stack_index"] return state From c1cc082770b9b908e44aa4d32b59282230020bdf Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Fri, 16 Apr 2021 14:08:45 +0530 Subject: [PATCH 13/14] CLN : Remove an unused import and replace the old/outdated String trait with the Str trait modified: chaco/plot_containers.py --- chaco/plot_containers.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 653617bec..28a5162d7 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -19,12 +19,10 @@ Array, Either, Enum, - Float, Instance, List, Property, Str, - String, Trait, Tuple, Int, @@ -61,7 +59,7 @@ class ConstraintsPlotContainer(ConstraintsContainer): "background", "image", "underlay", "plot" ) draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - draw_layer = String("plot") + draw_layer = Str("plot") # !! Bits copied from BasePlotContainer !! __all__.append("ConstraintsPlotContainer") From 8b6505d8cbcc84445e29cd8bdec6b65399d5bcc5 Mon Sep 17 00:00:00 2001 From: Poruri Sai Rahul Date: Tue, 1 Jun 2021 16:41:35 +0530 Subject: [PATCH 14/14] CLN : Remove overridden methods - which are now unnecessary 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 --- chaco/plot_containers.py | 64 ---------------------------------------- 1 file changed, 64 deletions(-) diff --git a/chaco/plot_containers.py b/chaco/plot_containers.py index 28a5162d7..30698d264 100644 --- a/chaco/plot_containers.py +++ b/chaco/plot_containers.py @@ -111,46 +111,6 @@ class HPlotContainer(HStackedContainer): _cached_preferred_size = Tuple(transient=True) - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - if self.fixed_preferred_size is not None: - self._cached_preferred_size = self.fixed_preferred_size - return self.fixed_preferred_size - - if self.resizable == "": - self._cached_preferred_size = self.outer_bounds[:] - return self.outer_bounds - - return stacked_preferred_size(self, components=components) - - def _do_layout(self): - """Actually performs a layout (called by do_layout()).""" - if self.stack_order == "left_to_right": - components = self.components - else: - components = self.components[::-1] - - if self.valign == "bottom": - align = "min" - elif self.valign == "center": - align = "center" - else: - align = "max" - - return stack_layout(self, components=components, align=align) - - ### Persistence ########################################################### - - # PICKLE FIXME: blocked with _pickles, but not sure that was correct. - def __getstate__(self): - state = super(HStackedContainer, self).__getstate__() - if "stack_index" in state: - del state["stack_index"] - return state - class VPlotContainer(VStackedContainer): """ @@ -167,30 +127,6 @@ class VPlotContainer(VStackedContainer): #: Redefine the draw order draw_order = Instance(list, args=(DEFAULT_DRAWING_ORDER,)) - def get_preferred_size(self, components=None): - """Returns the size (width,height) that is preferred for this component. - - Overrides PlotComponent. - """ - if self.fixed_preferred_size is not None: - self._cached_preferred_size = self.fixed_preferred_size - return self.fixed_preferred_size - - if self.resizable == "": - self._cached_preferred_size = self.outer_bounds[:] - return self.outer_bounds - - return stacked_preferred_size(self, components=components) - - ### Persistence ########################################################### - - # PICKLE FIXME: blocked with _pickles, but not sure that was correct. - def __getstate__(self): - state = super(VStackedContainer, self).__getstate__() - if "stack_index" in state: - del state["stack_index"] - return state - class GridPlotContainer(Container): """A GridPlotContainer consists of rows and columns in a tabular format.