Skip to content

Commit

Permalink
Slightly refactored compute_sizes utility
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Dec 11, 2016
1 parent dfb8bb7 commit 0970453
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
14 changes: 7 additions & 7 deletions holoviews/plotting/bokeh/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,16 @@ def get_data(self, element, ranges=None, empty=False):
else:
ms = style.get('size', np.sqrt(6))**2
sizes = element.dimension_values(self.size_index)
if sizes.dtype.kind in ('i', 'f'):
sizes = compute_sizes(sizes, self.size_fn,
self.scaling_factor,
self.scaling_method, ms)
data[map_key] = np.sqrt(sizes)
mapping['size'] = map_key
else:
sizes = compute_sizes(sizes, self.size_fn,
self.scaling_factor,
self.scaling_method, ms)
if sizes is None:
eltype = type(element).__name__
self.warning('%s dimension is not numeric, cannot '
'use to scale %s size.' % (sdim, eltype))
else:
data[map_key] = np.sqrt(sizes)
mapping['size'] = map_key

data[dims[xidx]] = [] if empty else element.dimension_values(xidx)
data[dims[yidx]] = [] if empty else element.dimension_values(yidx)
Expand Down
12 changes: 6 additions & 6 deletions holoviews/plotting/mpl/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@ def _compute_styles(self, element, ranges, style):
sdim = element.get_dimension(self.size_index)
if sdim:
sizes = element.dimension_values(self.size_index)
if sizes.dtype.kind in ('i', 'f'):
style['s'] = compute_sizes(sizes, self.size_fn, self.scaling_factor,
self.scaling_method, ms)
ms = style.pop('s') if 's' in style else plt.rcParams['lines.markersize']
else:
ms = style['s'] if 's' in style else plt.rcParams['lines.markersize']
sizes = compute_sizes(sizes, self.size_fn, self.scaling_factor,
self.scaling_method, ms)
if sizes is None:
eltype = type(element).__name__
self.warning('%s dimension is not numeric, cannot '
'use to scale %s size.' % (sdim, eltype))

else:
style['s'] = sizes
style['edgecolors'] = style.pop('edgecolors', 'none')


Expand Down
2 changes: 2 additions & 0 deletions holoviews/plotting/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ def compute_sizes(sizes, size_fn, scaling_factor, scaling_method, base_size):
base size and size_fn, which will be applied before
scaling.
"""
if sizes.dtype.kind not in ('i', 'f'):
return None
if scaling_method == 'area':
pass
elif scaling_method == 'width':
Expand Down

0 comments on commit 0970453

Please sign in to comment.