Skip to content

Commit

Permalink
Ensure overlay_aggregate is not applied for anti-aliased lines (#5266)
Browse files Browse the repository at this point in the history
* Ensure overlay_aggregate is not applied for anti-aliased lines

* Small fixes
  • Loading branch information
philippjfr committed Apr 10, 2022
1 parent 770d50f commit ab7122d
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions holoviews/operation/datashader.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def _process(self, element, key=None):
else:
category = agg_fn.column if isinstance(agg_fn, ds.count_cat) else None

if overlay_aggregate.applies(element, agg_fn):
if overlay_aggregate.applies(element, agg_fn, line_width=self.p.line_width):
params = dict(
{p: v for p, v in self.param.get_param_values() if p != 'name'},
dynamic=False, **{p: v for p, v in self.p.items()
Expand Down Expand Up @@ -534,20 +534,21 @@ class overlay_aggregate(aggregate):
"""

@classmethod
def applies(cls, element, agg_fn):
def applies(cls, element, agg_fn, line_width=None):
return (isinstance(element, NdOverlay) and
((isinstance(agg_fn, (ds.count, ds.sum, ds.mean)) and
(element.type is not Curve or line_width is None) and
((isinstance(agg_fn, (ds.count, ds.sum, ds.mean, ds.any)) and
(agg_fn.column is None or agg_fn.column not in element.kdims)) or
(isinstance(agg_fn, ds.count_cat) and agg_fn.column in element.kdims)))


def _process(self, element, key=None):
agg_fn = self._get_aggregator(element)

if not self.applies(element, agg_fn):
raise ValueError('overlay_aggregate only handles aggregation '
'of NdOverlay types with count, sum or mean '
'reduction.')
if not self.applies(element, agg_fn, line_width=self.p.line_width):
raise ValueError(
'overlay_aggregate only handles aggregation of NdOverlay types '
'with count, sum or mean reduction.'
)

# Compute overall bounds
dims = element.last.dimensions()[0:2]
Expand Down Expand Up @@ -590,11 +591,11 @@ def _process(self, element, key=None):
else:
agg_fn1 = aggregate.instance(**agg_params)
agg_fn2 = None
is_sum = isinstance(agg_fn1.aggregator, ds.sum)
is_sum = isinstance(agg_fn, ds.sum)
is_any = isinstance(agg_fn, ds.any)

# Accumulate into two aggregates and mask
agg, agg2, mask = None, None, None
mask = None
for v in element:
# Compute aggregates and mask
new_agg = agg_fn1.process_element(v, None)
Expand All @@ -609,7 +610,10 @@ def _process(self, element, key=None):
if is_sum: mask = new_mask
if agg_fn2: agg2 = new_agg2
else:
agg.data += new_agg.data
if is_any:
agg.data |= new_agg.data
else:
agg.data += new_agg.data
if is_sum: mask &= new_mask
if agg_fn2: agg2.data += new_agg2.data

Expand Down

0 comments on commit ab7122d

Please sign in to comment.