How to use the chaco.abstract_overlay.AbstractOverlay function in chaco

To help you get started, we’ve selected a few chaco examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NMGRL / pychron / pychron / processing / tasks / analysis_edit / plot_editor_pane.py View on Github external
self.editor_event = self.editor
        else:
            self.event_state = 'normal'
            self.editor_event = None

        self.component.invalidate_and_redraw()


#     def normal_left_dclick(self, event):

#     def select_left_dclick(self, event):
#         self.event_state = 'normal'
#         self.editor_event = None
#         self.component.invalidate_and_redraw()

class SelectorOverlay(AbstractOverlay):
    tool = Any
    color = ColorTrait('green')

    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        if self.tool.event_state == 'select':
            with gc:
                w, h = self.component.bounds
                x, y = self.component.x, self.component.y

                gc.set_stroke_color(self.color_)
                gc.set_line_width(4)
                gc.rect(x, y, w, h)
                gc.stroke_path()


def flatten_container(container):
github enthought / chaco / chaco / tools / rectangle_selection.py View on Github external
""" Defines the RectangleSelectionTool class.
"""
# Major library imports
import numpy

# Enthought library imports
from traits.api import Bool, Enum, Trait, Int, Float, Tuple, Array
from enable.api import ColorTrait, KeySpec
from chaco.abstract_overlay import AbstractOverlay


class RectangleSelection(AbstractOverlay):
    """ Selection tool which allows the user to draw a box which defines a
    selected region and draw an overlay for the selected region.
    """

    #: Is the tool always "on"? If True, left-clicking always initiates a
    #: selection operation; if False, the user must press a key to enter
    #: selection mode.
    always_on = Bool(False)

    #: Defines a meta-key, that works with always_on to set the selection mode.
    #: This is useful when the selection tool is used in conjunction with the
    #: pan tool.
    always_on_modifier = Enum('control', 'shift', 'control', 'alt')

    #: The minimum amount of screen space the user must select in order for
    #: the tool to actually take effect.
github NMGRL / pychron / pychron / spectrometer / graph / marker_overlay.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from __future__ import absolute_import
from chaco.abstract_overlay import AbstractOverlay
from traits.has_traits import on_trait_change
from traits.trait_types import List
# ============= standard library imports ========================
# ============= local library imports  ==========================
from pychron.spectrometer.graph.marker_label import MarkerLabel


class MarkerOverlay(AbstractOverlay):
    labels = List
    _cached_labels = List
    indicator_height = 10
    use_vertical_markers = False
    @on_trait_change('_cached_labels:[text, visible]')
    def _handle_text_change(self):
        self.request_redraw()

    def add_marker(self, x, y, text, bgcolor='white',
                   vertical_marker=False, **kw):
        m = MarkerLabel(data_x=self.component.index_mapper.map_data(x),
                        data_y=self.component.value_mapper.map_data(y),
                        indicator_height=self.indicator_height,
                        zero_y=self.component.y - self.indicator_height / 2.0,
                        zero_y_vert = self.component.padding_bottom,
                        bgcolor=bgcolor,
github enthought / chaco / chaco / tools / better_selecting_zoom.py View on Github external
def __init__(self, component=None, *args, **kw):
        # Since this class uses multiple inheritance (eek!), lets be
        # explicit about the order of the parent class constructors
        AbstractOverlay.__init__(self, component, *args, **kw)
        BetterZoom.__init__(self, component, *args, **kw)
        # Store the original range settings
        x_range = self._get_x_mapper().range
        y_range = self._get_y_mapper().range
        self._orig_low_setting = (x_range.low_setting, y_range.low_setting)
        self._orig_high_setting = (x_range.high_setting, y_range.high_setting)
github NMGRL / pychron / pychron / pipeline / graphical_filter.py View on Github external
cdx, cx = self._get_divider(event)
            for dx, x in self.dividers:
                if abs(cx - x) <= self.threshold:
                    break
            else:
                self.dividers.append((cdx, cx))
                self.grouping_event = True
                self.component.invalidate_and_redraw()

    def _get_divider(self, event):
        x = event.x
        dx = self.component.index_mapper.map_data(x)
        return dx, x


class GroupingOverlay(AbstractOverlay):
    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        for dx, d in self.tool.dividers:
            gc.move_to(d, other_component.y)
            gc.line_to(d, other_component.y2 + 5)
            gc.rect(d - 3, other_component.y2 + 5, 6, 6)
            gc.draw_path()


class SelectionGraph(Graph):
    scatter = None
    grouping_tool = None

    def setup(self, x, y, ans):
        from pychron.pipeline.plot.plotter.ticks import tick_formatter, StaticTickGenerator, TICKS

        p = self.new_plot()
github NMGRL / pychron / pychron / spectrometer / jobs / dac_scanner.py View on Github external
self.low = self.component.map_data((event.x, 0))[0]
        elif self._high_drag:
            self.high = self.component.map_data((event.x, 0))[0]
        self.updated = (self.low, self.high)

    def dragging(self, event):
        v = self.component.map_data((event.x, 0))[0]
        if self._low_drag:
            self.overlay.low = v
        elif self._high_drag:
            self.overlay.high = v
        self.component.request_redraw()
        self.updated = (self.overlay.low, self.overlay.high)


class ScannerBoundsOverlay(AbstractOverlay):
    low = Float(2)
    high = Float(6)

    def overlay(self, component, gc, view_bounds=None, mode="normal"):
        with gc:
            gc.clip_to_rect(component.x, component.y, component.width, component.height)
            y, y2 = component.y, component.y2

            (x1, _), (x2, _) = component.map_screen([(self.low, 0), (self.high, 0)])

            gc.set_stroke_color((0, 0.5, 0))
            gc.set_line_width(2.5)
            gc.move_to(x1, y)
            gc.line_to(x1, y2)

            gc.move_to(x2, y)
github NMGRL / pychron / pychron / spectrometer / jobs / dac_scanner.py View on Github external
y, y2 = component.y, component.y2

            (x1, _), (x2, _) = component.map_screen([(self.low, 0), (self.high, 0)])

            gc.set_stroke_color((0, 0.5, 0))
            gc.set_line_width(2.5)
            gc.move_to(x1, y)
            gc.line_to(x1, y2)

            gc.move_to(x2, y)
            gc.line_to(x2, y2)

            gc.draw_path()


class MFTableOverlay(AbstractOverlay):
    dacs = List
    one_amu_dac = Float
    isotopes = List
    font = KivaFont('Helvetica 10')

    def overlay(self, component, gc, view_bounds=None, mode="normal"):
        with gc:
            gc.clip_to_rect(component.x, component.y, component.width, component.height)
            y, y2 = component.y, component.y2

            color = (0.615, 0.823, 0.929, 0.631)
            gc.set_stroke_color(color)
            gc.set_fill_color(color)
            a, b = component.map_screen([(0, 0), (self.one_amu_dac, 0)])
            w = b[0] - a[0]
            h = y2 - y
github NMGRL / pychron / pychron / processing / plotters / spectrum / label_overlay.py View on Github external
# x_offset, y_offset=0,0
        # print self.x, self.y, self.width, self.height, self.bounds
        with gc:
            # XXX: Uncomment this after we fix kiva GL backend's clip stack
            # gc.clip_to_rect(self.x, self.y, self.width, self.height)

            # We have to translate to our position because the label
            # tries to draw at (0,0).

            gc.translate_ctm(self.x + x_offset, y)
            self._label.draw(gc)

        return


class SpectrumLabelOverlay(AbstractOverlay):
    display_extract_value = Bool(True)
    display_step = Bool(True)
    nsigma = Int
    font_size = Int
    _cached_labels = List
    use_user_color = Bool
    user_color = Color

    # _mlayout_needed = Bool

    def overlay(self, other_component, gc, view_bounds=None, mode="normal"):
        labels = self._get_labels()
        for label in labels:
            label.overlay(other_component, gc)

    def _get_labels(self):
github NMGRL / pychron / pychron / graph / error_envelope_overlay.py View on Github external
# See the License for the specific language governing permissions and
# limitations under the License.
# ===============================================================================

# ============= enthought library imports =======================
from chaco.abstract_overlay import AbstractOverlay
from enable.colors import black_color_trait
from traits.api import Array

# ============= standard library imports ========================
from numpy import array, zeros


# ============= local library imports  ==========================

class ErrorEnvelopeOverlay(AbstractOverlay):
    _cache_valid = False
    _screen_cache_valid = False

    upper = Array
    lower = Array
    use_downsampling = False
    line_color = black_color_trait

    xs = None

    def invalidate(self):
        self._cache_valid = False
        self._screen_cache_valid = False

    def _gather_points(self):
        if not self._cache_valid:
github enthought / chaco / chaco / overlays / coordinate_line_overlay.py View on Github external
""" An overlay for drawing "infinite" vertical and horizontal lines.

This module defines the CoordinateLineOverlay class, a Chaco overlay
for Plot (and similar) objects.
"""

from __future__ import with_statement

from traits.api import Instance, Float, Array
from enable.api import black_color_trait, LineStyle, Component
from chaco.abstract_overlay import AbstractOverlay


class CoordinateLineOverlay(AbstractOverlay):

    # The data coordinates of the lines to be drawn perpendicular to the
    # index axis.
    index_data = Array

    # The data coordinates of the lines to be drawn perpendicular to the
    # value axis.
    value_data = Array

    # Width of the lines.
    line_width = Float(1.0)

    # Color of the lines.
    color = black_color_trait

    # Style of the lines ('solid', 'dash' or 'dot').