Skip to content

Commit

Permalink
Cleaned up Element range handling and fixed QuadMesh range
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Sep 12, 2017
1 parent c061b2b commit 5c493a4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
12 changes: 12 additions & 0 deletions holoviews/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,18 @@ def max_range(ranges):
return (np.NaN, np.NaN)


def dimension_range(lower, upper, dimension):
"""
Computes the range along a dimension by combining the data range
with the Dimension soft_range and range.
"""
lower, upper = max_range([(lower, upper), dimension.soft_range])
dmin, dmax = dimension.range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
return lower, upper


def max_extents(extents, zrange=False):
"""
Computes the maximal extent in 2D and 3D space from
Expand Down
6 changes: 1 addition & 5 deletions holoviews/element/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,7 @@ def range(self, dimension, data_range=True):
if self.get_dimension_index(dimension) == 0 and data_range:
dim = self.get_dimension(dimension)
lower, upper = np.min(self.edges), np.max(self.edges)
lower, upper = util.max_range([(lower, upper), dim.soft_range])
dmin, dmax = dim.range
lower = lower if dmin is None or not np.isfinite(dmin) else dmin
upper = upper if dmax is None or not np.isfinite(dmax) else dmax
return lower, upper
return util.dimension_range(lower, upper, dim)
else:
return super(Histogram, self).range(dimension, data_range)

Expand Down
23 changes: 8 additions & 15 deletions holoviews/element/raster.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from ..core import Dimension, Element2D, Overlay, Dataset
from ..core.boundingregion import BoundingRegion, BoundingBox
from ..core.sheetcoords import SheetCoordinateSystem, Slice
from ..core.util import max_range
from ..core.util import max_range, dimension_range
from .chart import Curve
from .tabular import Table
from .util import compute_edges, compute_slice_bounds, categorical_aggregate2d
Expand Down Expand Up @@ -71,14 +71,8 @@ def range(self, dim, data_range=True):
idx = self.get_dimension_index(dim)
if data_range and idx == 2:
dimension = self.get_dimension(dim)
drange = self.data.min(), self.data.max()
drange = max_range([drange, dimension.soft_range])
if dimension.range[0] is not None:
return (dimension.range[0], drange[1])
elif dimension.range[1] is not None:
return (drange[0], dimension.range[1])
else:
return drange
lower, upper = self.data.min(), self.data.max()
return dimension_range(lower, upper, dimension)
return super(Raster, self).range(dim, data_range)


Expand Down Expand Up @@ -720,14 +714,13 @@ def _coord2matrix(self, coord):
for i in [1, 0])


def range(self, dimension):
def range(self, dimension, data_range=True):
idx = self.get_dimension_index(dimension)
if idx in [0, 1]:
data = self.data[idx]
return np.min(data), np.max(data)
elif idx == 2:
dim = self.get_dimension(dimension)
if idx in [0, 1, 2] and data_range:
data = self.data[idx]
return np.nanmin(data), np.nanmax(data)
lower, upper = np.nanmin(data), np.nanmax(data)
return dimension_range(lower, upper, dim)
super(QuadMesh, self).range(dimension)


Expand Down

0 comments on commit 5c493a4

Please sign in to comment.