/usr/lib/python2.7/dist-packages/chaco/scatter_inspector_overlay.py is in python-chaco 4.4.1-1.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | from __future__ import with_statement
# Major library imports
from numpy import array, asarray
# Enthought library imports
from enable.api import ColorTrait, MarkerTrait
from traits.api import Float, Int, Str, Trait
# Local, relative imports
from abstract_overlay import AbstractOverlay
from scatterplot import render_markers
class ScatterInspectorOverlay(AbstractOverlay):
"""
Highlights points on a scatterplot as the mouse moves over them.
Can render the points in a different style, as well as display a
DataLabel.
Used in conjuction with ScatterInspector.
"""
# The style to use when a point is hovered over
hover_metadata_name = Str('hover')
hover_marker = Trait(None, None, MarkerTrait)
hover_marker_size = Trait(None, None, Int)
hover_line_width = Trait(None, None, Float)
hover_color = Trait(None, None, ColorTrait)
hover_outline_color = Trait(None, None, ColorTrait)
# The style to use when a point has been selected by a click
selection_metadata_name = Str('selections')
selection_marker = Trait(None, None, MarkerTrait)
selection_marker_size = Trait(None, None, Int)
selection_line_width = Trait(None, None, Float)
selection_color = Trait(None, None, ColorTrait)
selection_outline_color = Trait(None, None, ColorTrait)
# For now, implement the equivalent of this Traits 3 feature manually
# using a series of trait change handlers (defined at the end of the
# class)
#@on_trait_change('component.index.metadata_changed,component.value.metadata_changed')
def metadata_changed(self, object, name, old, new):
if self.component is not None:
self.component.request_redraw()
return
def overlay(self, component, gc, view_bounds=None, mode="normal"):
plot = self.component
if not plot or not plot.index or not getattr(plot, "value", True):
return
for inspect_type in (self.hover_metadata_name, self.selection_metadata_name):
if inspect_type in plot.index.metadata:
#if hasattr(plot,"value") and not inspect_type in plot.value.metadata:
# continue
index = plot.index.metadata.get(inspect_type, None)
if index is not None and len(index) > 0:
index = asarray(index)
index_data = plot.index.get_data()
# Only grab the indices which fall within the data range.
index = index[index < len(index_data)]
# FIXME: In order to work around some problems with the
# selection model, we will only use the selection on the
# index. The assumption that they are the same is
# implicit, though unchecked, already.
#value = plot.value.metadata.get(inspect_type, None)
value = index
if hasattr(plot, "value"):
value_data = plot.value.get_data()
screen_pts = plot.map_screen(array([index_data[index],
value_data[value]]).T)
else:
screen_pts = plot.map_screen(index_data[index])
if inspect_type == self.selection_metadata_name:
prefix = "selection"
else:
prefix = "hover"
self._render_at_indices(gc, screen_pts, prefix)
return
def _render_at_indices(self, gc, screen_pts, inspect_type):
""" screen_pt should always be a list """
self._render_marker_at_indices(gc, screen_pts, inspect_type)
def _render_marker_at_indices(self, gc, screen_pts, prefix, sep="_"):
""" screen_pt should always be a list """
if len(screen_pts) == 0:
return
plot = self.component
mapped_attribs = ("color", "outline_color", "marker")
other_attribs = ("marker_size", "line_width")
kwargs = {}
for attr in mapped_attribs + other_attribs:
if attr in mapped_attribs:
# Resolve the mapped trait
valname = attr + "_"
else:
valname = attr
tmp = getattr(self, prefix+sep+valname)
if tmp is not None:
kwargs[attr] = tmp
else:
kwargs[attr] = getattr(plot, valname)
# If the marker type is 'custom', we have to pass in the custom_symbol
# kwarg to render_markers.
if kwargs.get("marker", None) == "custom":
kwargs["custom_symbol"] = plot.custom_symbol
with gc:
gc.clip_to_rect(plot.x, plot.y, plot.width, plot.height)
render_markers(gc, screen_pts, **kwargs)
def _draw_overlay(self, gc, view_bounds=None, mode="normal"):
self.overlay(self.component, gc, view_bounds, mode)
def _component_changed(self, old, new):
if old:
old.on_trait_change(self._ds_changed, 'index', remove=True)
if hasattr(old, "value"):
old.on_trait_change(self._ds_changed, 'value', remove=True)
if new:
for dsname in ("index", "value"):
if not hasattr(new, dsname):
continue
new.on_trait_change(self._ds_changed, dsname)
if getattr(new, dsname):
self._ds_changed(new, dsname, None, getattr(new,dsname))
return
def _ds_changed(self, object, name, old, new):
if old:
old.on_trait_change(self.metadata_changed, 'metadata_changed', remove=True)
if new:
new.on_trait_change(self.metadata_changed, 'metadata_changed')
return
|