-
Notifications
You must be signed in to change notification settings - Fork 99
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
Remove all definitions / uses of _draw_component #743
Changes from 3 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 |
---|---|---|
|
@@ -474,12 +474,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
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 |
---|---|---|
|
@@ -333,31 +333,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.
Show resolved
Hide 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) | ||
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() | ||
|
||
|
@@ -393,6 +421,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 |
---|---|---|
|
@@ -60,8 +60,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"): | ||
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_overlay
andoverlay
are 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 haveoverlay
call_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_overlay
is needed by the new (and currently used) way of drawing the various layers in a chaco plot. Not sure whatoverlay
is 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
overlay
and_draw_overlay
do 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:
overlay
is a method defined onAbstractOverlay
, and it takesother_component
as an argument. Effectively the overlay draws itself on top of another component._draw_overlay
originates fromComponent
which keeps track of a list ofAbstractOverlays
, and when_draw_overlay
is called, it iterates over each of those overlays and calls their respectiveoverlay
methods, 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
AbstractOverlay
should only need to defineoverlay
not_draw_overlay
.It is a bit strange because
AbstractOverlay
subclassesComponent
so it does technically have a_draw_overlay
method. However, forComponent
_draw_overlay
gets called via the_draw
method. But_draw
is overridden byAbstractOverlay
and simply callsoverlay
ifself.component
is notNone
.So, in summary, I believe we can delete all the definitions of
_draw_overlay
on subclasses ofAbstractOverlay
since they are actually unused.overlay
is the method that actually does the work. Since the current classes which do override_draw_overlay
do 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.AbstractOverlay
andchaco.AbstractOverlay
include:_do_layout
(default is justpass
), anddo_layout
methods, which chaco does not.do_layout
(per the docstring) differs from theComponent.do_layout
method in that it allows passing an optionalcomponent
arg._draw
method, chaco callssuper
ifself.component
isNone
. enable simply returns.Number 2 is what makes me think maybe there are scenarios in which
_draw_component
gets called / is needed if we try to draw anOverlay
for whichcomponent
isNone
. 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_overlay
use onTooltip
and its subclassDataLabel
is needed, since they overridedraw
and callPlotComponent._draw
directly.I do not see any cases in which
PlotAxis
does 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_overlay
will cause a break...I am of two minds if it should be removed or not for the cases of
PlotAxis
andGrid
here. 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 (ieoverlay
can'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