-
Notifications
You must be signed in to change notification settings - Fork 98
Remove all definitions / uses of _draw_component #743
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -484,12 +484,6 @@ def get_screen_points(self): | |
|
|
||
| def _draw_plot(self, gc, view_bounds=None, mode="normal"): | ||
| """Draws the 'plot' layer.""" | ||
| self._draw_component(gc, view_bounds, mode) | ||
|
|
||
| def _draw_component(self, gc, view_bounds=None, mode="normal"): | ||
| # This method should be folded into self._draw_plot(), but is here for | ||
| # backwards compatibilty with non-draw-order stuff. | ||
|
Comment on lines
-490
to
-491
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment effectively sums up the aim of this PR |
||
|
|
||
| pts = self.get_screen_points() | ||
| self._render(gc, pts) | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -343,31 +343,59 @@ def _draw_overlay(self, gc, view_bounds=None, mode="normal"): | |
|
|
||
| Overrides PlotComponent. | ||
| """ | ||
| self._draw_component(gc, view_bounds, mode) | ||
| # What we're really trying to do with a grid is plot contour lines in | ||
| # the space of the plot. In a rectangular plot, these will always be | ||
| # straight lines. | ||
| if not self.visible: | ||
| return | ||
|
|
||
| def overlay(self, other_component, gc, view_bounds=None, mode="normal"): | ||
| """Draws this component overlaid on another component. | ||
| if not self._cache_valid: | ||
| self._compute_ticks() | ||
|
|
||
| Overrides AbstractOverlay. | ||
| """ | ||
| if not self.visible: | ||
| if len(self._tick_positions) == 0: | ||
| return | ||
| self._compute_ticks(other_component) | ||
| self._draw_component(gc, view_bounds, mode) | ||
| self._cache_valid = False | ||
|
|
||
| def _draw_component(self, gc, view_bounds=None, mode="normal"): | ||
|
rahulporuri marked this conversation as resolved.
|
||
| """Draws the component. | ||
| with gc: | ||
| gc.set_line_width(self.line_weight) | ||
| gc.set_line_dash(self.line_style_) | ||
| gc.set_stroke_color(self.line_color_) | ||
| gc.set_antialias(False) | ||
|
|
||
| This method is preserved for backwards compatibility. Overrides | ||
| PlotComponent. | ||
| if self.component is not None: | ||
| gc.clip_to_rect( | ||
| *(self.component.position + self.component.bounds) | ||
| ) | ||
| else: | ||
| gc.clip_to_rect(*(self.position + self.bounds)) | ||
|
|
||
| gc.begin_path() | ||
| if self.orientation == "horizontal": | ||
| starts = self._tick_positions.copy() | ||
| starts[:, 0] = self._tick_extents[:, 0] | ||
| ends = self._tick_positions.copy() | ||
| ends[:, 0] = self._tick_extents[:, 1] | ||
| else: | ||
| starts = self._tick_positions.copy() | ||
| starts[:, 1] = self._tick_extents[:, 0] | ||
| ends = self._tick_positions.copy() | ||
| ends[:, 1] = self._tick_extents[:, 1] | ||
| if self.flip_axis: | ||
| starts, ends = ends, starts | ||
| gc.line_set(starts, ends) | ||
| gc.stroke_path() | ||
|
|
||
| def overlay(self, other_component, gc, view_bounds=None, mode="normal"): | ||
| """Draws this component overlaid on another component. | ||
|
|
||
| Overrides AbstractOverlay. | ||
| """ | ||
| # What we're really trying to do with a grid is plot contour lines in | ||
| # the space of the plot. In a rectangular plot, these will always be | ||
| # straight lines. | ||
| if not self.visible: | ||
| return | ||
|
|
||
| self._compute_ticks(other_component) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method now only differs from |
||
|
|
||
| if not self._cache_valid: | ||
| self._compute_ticks() | ||
|
|
||
|
|
@@ -403,6 +431,8 @@ def _draw_component(self, gc, view_bounds=None, mode="normal"): | |
| gc.line_set(starts, ends) | ||
| gc.stroke_path() | ||
|
|
||
| self._cache_valid = False | ||
|
|
||
| def _mapper_changed(self, old, new): | ||
| if old is not None: | ||
| old.observe(self.mapper_updated, "updated", remove=True) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -70,8 +70,8 @@ class RegressionOverlay(LassoOverlay): | |
| ), | ||
| ) | ||
|
|
||
| def _draw_component(self, gc, view_bounds=None, mode="normal"): | ||
| super()._draw_component(gc, view_bounds, mode) | ||
| def overlay(self, other_component, gc, view_bounds=None, mode="normal"): | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this by running |
||
| super().overlay(other_component, gc, view_bounds, mode) | ||
| selection = self.lasso_selection | ||
|
|
||
| if selection.fit_params is not None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_draw_overlayandoverlayare now currently the exact same method. Perhaps one should just call the other to avoid the duplication. I think it would make more sense to haveoverlaycall_draw_overlay.AFAIK we need to keep both methods, but this should be investigated more closely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good to me.
I'm not a 100% sure why both methods need to exist. I know that
_draw_overlayis needed by the new (and currently used) way of drawing the various layers in a chaco plot. Not sure whatoverlayis used for.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this PR again I realize that
overlayand_draw_overlaydo very slightly different things. I think it is going to be worth the deeper investigation into what both are uesd for / if we can refine things down so only 1 is necessary at all.If they are in fact both needed it is possible they will need to exist stand alone with very similar (largely copied) code, but some minor discrepancies.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Digging into enable:
overlayis a method defined onAbstractOverlay, and it takesother_componentas an argument. Effectively the overlay draws itself on top of another component._draw_overlayoriginates fromComponentwhich keeps track of a list ofAbstractOverlays, and when_draw_overlayis called, it iterates over each of those overlays and calls their respectiveoverlaymethods, passing in itself as theother_component.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, I think what makes sense is that classes which are decedents from
AbstractOverlayshould only need to defineoverlaynot_draw_overlay.It is a bit strange because
AbstractOverlaysubclassesComponentso it does technically have a_draw_overlaymethod. However, forComponent_draw_overlaygets called via the_drawmethod. But_drawis overridden byAbstractOverlayand simply callsoverlayifself.componentis notNone.So, in summary, I believe we can delete all the definitions of
_draw_overlayon subclasses ofAbstractOverlaysince they are actually unused.overlayis the method that actually does the work. Since the current classes which do override_draw_overlaydo not also override_draw, nothing ever actually calls_draw_overlay.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking closer, some differences between
enable.AbstractOverlayandchaco.AbstractOverlayinclude:_do_layout(default is justpass), anddo_layoutmethods, which chaco does not.do_layout(per the docstring) differs from theComponent.do_layoutmethod in that it allows passing an optionalcomponentarg._drawmethod, chaco callssuperifself.componentisNone. enable simply returns.Number 2 is what makes me think maybe there are scenarios in which
_draw_componentgets called / is needed if we try to draw anOverlayfor whichcomponentisNone. ie a stand alone overlay (which I will have to look for use cases / examples of ...)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For instance, the
_draw_overlayuse onTooltipand its subclassDataLabelis needed, since they overridedrawand callPlotComponent._drawdirectly.I do not see any cases in which
PlotAxisdoes not have a component set (every time it is instantiated in the chaco codebase a component is passed in), however theoretically one could try drawing an Axis standalone (although i can't imagine why) in which case not having_draw_overlaywill cause a break...I am of two minds if it should be removed or not for the cases of
PlotAxisandGridhere. If it is to stay, because the two methods do slightly different things, I believe they will both need to stay as is with some duplication (ieoverlaycan't just call_draw_overlay).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rahulporuri I apologize in advance that this is an overly wordy brain dump, but what are your thoughts on this? I hope my findings make sense
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't fully digest these findings at the moment - so my instinct is to simply defer this question to a later time. Can you write up these findings in an issue? I apologize for the delay in responding to your comments - it'll probably involve additional effort to recollect everything and put together a meaningful PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries, I will open an issue