Skip to content
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

Refactor image plot #147

Merged
merged 19 commits into from
Jan 8, 2015
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Use Traits properties instead of plain Python properties
  • Loading branch information
tonysyu committed Nov 7, 2013
commit 43f12803ac48a8a006c53b86d0a1dc8e097c7bbc
26 changes: 18 additions & 8 deletions chaco/image_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
import numpy as np

# Enthought library imports.
from traits.api import Bool, Either, Enum, Instance, List, Range, Trait, Tuple
from traits.api import (Bool, Either, Enum, Instance, List, Range, Trait,
Tuple, Property, cached_property)
from kiva.agg import GraphicsContextArray

# Local relative imports
Expand Down Expand Up @@ -51,6 +52,12 @@ class ImagePlot(Base2DPlot):
# The interpolation method to use when rendering an image onto the GC.
interpolation = Enum("nearest", "bilinear", "bicubic")

# Bool indicating whether x-axis is flipped.
x_axis_is_flipped = Property(depends_on=['orientation', 'origin'])

# Bool indicating whether y-axis is flipped.
y_axis_is_flipped = Property(depends_on=['orientation', 'origin'])

#------------------------------------------------------------------------
# Private traits
#------------------------------------------------------------------------
Expand All @@ -65,17 +72,21 @@ class ImagePlot(Base2DPlot):
# **_cached_image** is to be drawn.
_cached_dest_rect = Either(Tuple, List)

# Bool indicating whether the origin is top-left or bottom-right.
# The name "principal diagonal" is borrowed from linear algebra.
_origin_on_principal_diagonal = Property(depends_on='origin')

#------------------------------------------------------------------------
# Properties
#------------------------------------------------------------------------

@property
def x_axis_is_flipped(self):
@cached_property
def _get_x_axis_is_flipped(self):
return ((self.orientation == 'h' and 'right' in self.origin) or
(self.orientation == 'v' and 'top' in self.origin))

@property
def y_axis_is_flipped(self):
@cached_property
def _get_y_axis_is_flipped(self):
return ((self.orientation == 'h' and 'top' in self.origin) or
(self.orientation == 'v' and 'right' in self.origin))

Expand Down Expand Up @@ -152,9 +163,8 @@ def map_index(self, screen_pt, threshold=0.0, outside_returns_none=True,
# Private methods
#------------------------------------------------------------------------

@property
def _origin_on_principal_diagonal(self):
# The name "principal diagonal" comes from linear algebra.
@cached_property
def _get__origin_on_principal_diagonal(self):
bottom_right = 'bottom' in self.origin and 'right' in self.origin
top_left = 'top' in self.origin and 'left' in self.origin
return bottom_right or top_left
Expand Down