-
Notifications
You must be signed in to change notification settings - Fork 98
Consolidate overlays into "chaco.overlays" #741
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5078f1f
copy modules into chaco/overlays
aaronayres35 cf940ba
make original modules stubs raising deprecation warnings
aaronayres35 82276fb
copy layers into overlays
aaronayres35 724469e
fully populate chaco.overlays.api and chaco.api
aaronayres35 4c4240e
flake8
aaronayres35 959d7c7
update tox.ini by running flake8 -q
aaronayres35 d411049
somehow this is also needed in tox.ini but I did not see this flake8 …
aaronayres35 a25de20
remove bad trailing comma
aaronayres35 7e4736a
move data label test to sit in chaco/overlays/tests
aaronayres35 eac7831
add stub modules in chaco/layers importing from new location and addi…
aaronayres35 f40b9ec
add layers to the chaco.api as well
aaronayres35 5118c58
Merge branch 'master' into overlays-reorg
aaronayres35 ce3a087
old files that were moved have since been changed on master and did n…
aaronayres35 6102ff3
flake8
aaronayres35 35b365e
typo
aaronayres35 76d65aa
update deprecation warning messages
aaronayres35 aeb598e
remove stub modules from autogenerated api docs
aaronayres35 ecda2bb
remove chaco/layers/data
aaronayres35 4b97d56
Merge branch 'master' into overlays-reorg
aaronayres35 db01d7b
import from chaco.plots in overlay modules
aaronayres35 582f076
import Legend from chaco.overlays.api
aaronayres35 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,191 +1,22 @@ | ||
| """ Defines the ColormappedSelectionOverlay class. | ||
| """ | ||
| import functools | ||
|
|
||
| from numpy import logical_and | ||
|
|
||
| # Enthought library imports | ||
| from traits.api import Any, Bool, Float, Instance, Property, Enum | ||
| from traits.observation.events import TraitChangeEvent | ||
|
|
||
| # Local imports | ||
| from .abstract_overlay import AbstractOverlay | ||
| from .plots.colormapped_scatterplot import ColormappedScatterPlot | ||
|
|
||
|
|
||
| class ColormappedSelectionOverlay(AbstractOverlay): | ||
| """ | ||
| Overlays and changes a ColormappedScatterPlot to fade its non-selected | ||
| points to a very low alpha. | ||
| """ | ||
|
|
||
| #: The ColormappedScatterPlot that this overlay is listening to. | ||
| #: By default, it looks at self.component | ||
| plot = Property | ||
|
|
||
| #: The amount to fade the unselected points. | ||
| fade_alpha = Float(0.15) | ||
|
|
||
| #: The minimum difference, in float percent, between the starting and ending | ||
| #: selection values, if range selection mode is enabled | ||
| minimum_delta = Float(0.01) | ||
|
|
||
| #: Outline width for selected points. | ||
| selected_outline_width = Float(1.0) | ||
| #: Outline width for unselected points. | ||
| unselected_outline_width = Float(0.0) | ||
|
|
||
| #: The type of selection used by the data source. | ||
| selection_type = Enum("range", "mask") | ||
|
|
||
| _plot = Instance(ColormappedScatterPlot) | ||
|
|
||
| _visible = Bool(False) | ||
|
|
||
| _old_alpha = Float | ||
| _old_outline_color = Any | ||
| _old_line_width = Float(0.0) | ||
|
|
||
| def __init__(self, component=None, **kw): | ||
| super().__init__(**kw) | ||
| self.component = component | ||
|
|
||
| def overlay(self, component, gc, view_bounds=None, mode="normal"): | ||
| """Draws this component overlaid on another component. | ||
|
|
||
| Implements AbstractOverlay. | ||
| """ | ||
| if not self._visible: | ||
| return | ||
|
|
||
| plot = self.plot | ||
| datasource = plot.color_data | ||
|
|
||
| if self.selection_type == "range": | ||
| selections = datasource.metadata["selections"] | ||
|
|
||
| if selections is not None and len(selections) == 0: | ||
| return | ||
|
|
||
| low, high = selections | ||
| if abs(high - low) / abs(high + low) < self.minimum_delta: | ||
| return | ||
|
|
||
| # Mask the data with just the points falling within the data | ||
| # range selected on the colorbar | ||
| data_pts = datasource.get_data() | ||
| mask = (data_pts >= low) & (data_pts <= high) | ||
|
|
||
| elif self.selection_type == "mask": | ||
| mask = functools.reduce( | ||
| logical_and, datasource.metadata["selection_masks"] | ||
| ) | ||
| if sum(mask) < 2: | ||
| return | ||
|
|
||
| datasource.set_mask(mask) | ||
|
|
||
| # Store the current plot color settings before overwriting them | ||
| fade_outline_color = plot.outline_color_ | ||
|
|
||
| # Overwrite marker outline color and fill alpha settings of | ||
| # the plot, then manually invoke the plot to draw onto the GC. | ||
| plot.outline_color = list(self._old_outline_color[:3]) + [1.0] | ||
| plot.fill_alpha = 1.0 | ||
| plot.line_width = self.selected_outline_width | ||
| plot._draw_plot(gc, view_bounds, mode) | ||
|
|
||
| # Restore the plot's previous color settings and data mask. | ||
| plot.fill_alpha = self.fade_alpha | ||
| plot.outline_color = fade_outline_color | ||
| plot.line_width = self.unselected_outline_width | ||
| datasource.remove_mask() | ||
|
|
||
| def _component_changed(self, old, new): | ||
| if old: | ||
| old.observe( | ||
| self.datasource_change_handler, "color_data", remove=True | ||
| ) | ||
| if new: | ||
| new.observe(self.datasource_change_handler, "color_data") | ||
| self._old_alpha = new.fill_alpha | ||
| self._old_outline_color = new.outline_color | ||
| self._old_line_width = new.line_width | ||
|
|
||
| self.datasource_change_handler( | ||
| TraitChangeEvent( | ||
| object=new, name="color_data", old=None, new=new.color_data | ||
| ) | ||
| ) | ||
|
|
||
| def datasource_change_handler(self, event): | ||
| obj, name, old, new = (event.object, event.name, event.old, event.new) | ||
|
|
||
| if old: | ||
| old.observe( | ||
| self.selection_change_handler, "metadata_changed", remove=True | ||
| ) | ||
| if new: | ||
| new.observe(self.selection_change_handler, "metadata_changed") | ||
| self.selection_change_handler( | ||
| TraitChangeEvent( | ||
| object=new, | ||
| name="metadata_changed", | ||
| old=None, | ||
| new=new.metadata, | ||
| ) | ||
| ) | ||
|
|
||
| def selection_change_handler(self, event): | ||
| obj, name, old, new = (event.object, event.name, event.old, event.new) | ||
|
|
||
| if self.selection_type == "range": | ||
| selection_key = "selections" | ||
| elif self.selection_type == "mask": | ||
| selection_key = "selection_masks" | ||
|
|
||
| if ( | ||
| type(new) == dict | ||
| and new.get(selection_key, None) is not None | ||
| and len(new[selection_key]) > 0 | ||
| ): | ||
| if not self._visible: | ||
| # We have a new selection, so replace the colors on the plot with the | ||
| # faded alpha and colors | ||
| plot = self.plot | ||
|
|
||
| # Save the line width and set it to zero for the unselected points | ||
| self._old_line_width = plot.line_width | ||
| plot.line_width = self.unselected_outline_width | ||
| # Save the outline color and set it to the faded version | ||
| self._old_outline_color = plot.outline_color_ | ||
| outline_color = list(plot.outline_color_) | ||
| if len(outline_color) == 3: | ||
| outline_color += [self.fade_alpha] | ||
| else: | ||
| outline_color[3] = self.fade_alpha | ||
| plot.outline_color = outline_color | ||
|
|
||
| # Save the alpha value and set it to a faded version | ||
| self._old_alpha = plot.fill_alpha | ||
| plot.fill_alpha = self.fade_alpha | ||
|
|
||
| self.plot.invalidate_draw() | ||
| self._visible = True | ||
| else: | ||
| self.plot.fill_alpha = self._old_alpha | ||
| self.plot.outline_color = self._old_outline_color | ||
| self.plot.line_width = self._old_line_width | ||
| self.plot.invalidate_draw() | ||
| self._visible = False | ||
|
|
||
| self.plot.request_redraw() | ||
|
|
||
| def _get_plot(self): | ||
| if self._plot is not None: | ||
| return self._plot | ||
| else: | ||
| return self.component | ||
|
|
||
| def _set_plot(self, val): | ||
| self._plot = val | ||
| # (C) Copyright 2006-2021 Enthought, Inc., Austin, TX | ||
| # All rights reserved. | ||
| # | ||
| # This software is provided without warranty under the terms of the BSD | ||
| # license included in LICENSE.txt and may be redistributed only under | ||
| # the conditions described in the aforementioned license. The license | ||
| # is also available online at http://www.enthought.com/licenses/BSD.txt | ||
| # | ||
| # Thanks for using Enthought open source! | ||
| import warnings | ||
|
|
||
| from chaco.overlays.colormapped_selection_overlay import ( # noqa: F401 | ||
| ColormappedSelectionOverlay | ||
| ) | ||
|
|
||
| warnings.warn( | ||
| "Importing ColormappedSelectionOverlay from this module is deprecated. " | ||
| "Please use chaco.api or chaco.overlays.api instead. This module will be " | ||
| "removed in the next major release.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.