Skip to content
Merged
Show file tree
Hide file tree
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 May 17, 2021
cf940ba
make original modules stubs raising deprecation warnings
aaronayres35 May 17, 2021
82276fb
copy layers into overlays
aaronayres35 May 17, 2021
724469e
fully populate chaco.overlays.api and chaco.api
aaronayres35 May 18, 2021
4c4240e
flake8
aaronayres35 May 19, 2021
959d7c7
update tox.ini by running flake8 -q
aaronayres35 May 19, 2021
d411049
somehow this is also needed in tox.ini but I did not see this flake8 …
aaronayres35 May 19, 2021
a25de20
remove bad trailing comma
aaronayres35 May 19, 2021
7e4736a
move data label test to sit in chaco/overlays/tests
aaronayres35 May 24, 2021
eac7831
add stub modules in chaco/layers importing from new location and addi…
aaronayres35 Jun 1, 2021
f40b9ec
add layers to the chaco.api as well
aaronayres35 Jun 1, 2021
5118c58
Merge branch 'master' into overlays-reorg
aaronayres35 Jun 1, 2021
ce3a087
old files that were moved have since been changed on master and did n…
aaronayres35 Jun 1, 2021
6102ff3
flake8
aaronayres35 Jun 1, 2021
35b365e
typo
aaronayres35 Jun 1, 2021
76d65aa
update deprecation warning messages
aaronayres35 Jun 2, 2021
aeb598e
remove stub modules from autogenerated api docs
aaronayres35 Jun 2, 2021
ecda2bb
remove chaco/layers/data
aaronayres35 Jun 2, 2021
4b97d56
Merge branch 'master' into overlays-reorg
aaronayres35 Jun 2, 2021
db01d7b
import from chaco.plots in overlay modules
aaronayres35 Jun 2, 2021
582f076
import Legend from chaco.overlays.api
aaronayres35 Jun 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
include chaco/*.h
include chaco/layers/data/*.svg
include chaco/overlays/layers/data/*.svg
include chaco/tests/data/PngSuite/*.png
include chaco/tools/toolbars/images*.png
recursive-include chaco *.pyx
Expand Down
69 changes: 52 additions & 17 deletions chaco/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
- :class:`~.BandedMapper`
- :class:`~.PolarMapper`

Visual Components
-----------------
Visual Components / Overlays
----------------------------

- :class:`~.AbstractPlotRenderer`
- :class:`~.AbstractOverlay`
Expand All @@ -71,15 +71,30 @@
- :class:`~.VPlotContainer`
- :class:`~.GridPlotContainer`
- :class:`~.Label`
- :class:`~.PlotLabel`
- :class:`~.Legend`
- :class:`~.ToolTip`
- :class:`~.ColorBar`
- :class:`~.AlignedContainerOverlay`
- :class:`~.ColormappedSelectionOverlay`
- :class:`~.ContainerOverlay`
- :class:`~.CoordinateLineOverlay`
- :class:`~.DataBox`
- :class:`~.DataLabel`
- :class:`~.LassoOverlay`
- :class:`~.ColorBar`
- :class:`~.TextBoxOverlay`
- :class:`~.AbstractCompositeIconRenderer`
- :class:`~.CompositeIconRenderer`
- :class:`~.PlotLabel`
- :class:`~.ScatterInspectorOverlay`
- :class:`~.ColormappedSelectionOverlay`
- :func:`~.basic_formatter`
- :func:`~.datetime_formatter`
- :func:`~.date_formatter`
- :class:`~.SimpleInspectorOverlay`
- :func:`~.time_formatter`
- :class:`~.TextBoxOverlay`
- :class:`~.TextGridOverlay`
- :class:`~.ToolTip`
- :class:`~.ImageInspectorOverlay`
- :class:`~.ErrorLayer`
- :class:`~.StatusLayer`
- :class:`~.WarningLayer`
- :class:`~.ColormappedScatterPlotView`
- :class:`~.ScatterPlotView`

Expand Down Expand Up @@ -298,7 +313,7 @@
from .plots.horizon_plot import BandedMapper
from .polar_mapper import PolarMapper

# Visual components
# Visual components / Overlays
from .abstract_plot_renderer import AbstractPlotRenderer
from .abstract_overlay import AbstractOverlay
from .base_plot_container import BasePlotContainer
Expand All @@ -323,15 +338,35 @@
pass

from .label import Label
from .plot_label import PlotLabel
from .legend import Legend
from .tooltip import ToolTip
from .data_label import DataLabel
from .lasso_overlay import LassoOverlay

from chaco.overlays.api import (
AlignedContainerOverlay,
ColormappedSelectionOverlay,
ContainerOverlay,
CoordinateLineOverlay,
DataBox,
DataLabel,
LassoOverlay,
AbstractCompositeIconRenderer,
CompositeIconRenderer,
Legend,
PlotLabel,
ScatterInspectorOverlay,
basic_formatter,
datetime_formatter,
date_formatter,
SimpleInspectorOverlay,
time_formatter,
TextBoxOverlay,
TextGridOverlay,
ToolTip,
ImageInspectorOverlay,
ErrorLayer,
StatusLayer,
WarningLayer,
)

from .plots.color_bar import ColorBar
from .text_box_overlay import TextBoxOverlay
from .scatter_inspector_overlay import ScatterInspectorOverlay
from .colormapped_selection_overlay import ColormappedSelectionOverlay

# Renderers
from .base_1d_plot import Base1DPlot
Expand Down
213 changes: 22 additions & 191 deletions chaco/colormapped_selection_overlay.py
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
Comment thread
aaronayres35 marked this conversation as resolved.
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,
)
Loading