From 643fa8f8386acbb9c163f18955509e989dcd0316 Mon Sep 17 00:00:00 2001 From: Philipp Rudiger Date: Tue, 12 Sep 2017 11:37:59 +0100 Subject: [PATCH] Cleaned up Element range handling and fixed QuadMesh range --- holoviews/core/util.py | 12 ++++++++++++ holoviews/element/chart.py | 6 +----- holoviews/element/raster.py | 23 ++++++++--------------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/holoviews/core/util.py b/holoviews/core/util.py index d51eb3914f..e08b5af4d9 100644 --- a/holoviews/core/util.py +++ b/holoviews/core/util.py @@ -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 diff --git a/holoviews/element/chart.py b/holoviews/element/chart.py index 13befc9d6d..26a4c23fc3 100644 --- a/holoviews/element/chart.py +++ b/holoviews/element/chart.py @@ -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) diff --git a/holoviews/element/raster.py b/holoviews/element/raster.py index ad3d25a7c0..4d3b08151b 100644 --- a/holoviews/element/raster.py +++ b/holoviews/element/raster.py @@ -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 @@ -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) @@ -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, dimension) super(QuadMesh, self).range(dimension)