Skip to content

Commit

Permalink
feat(delayspectrum): give user control over datashade function
Browse files Browse the repository at this point in the history
Allow user to select datashade or renderize. datashade automatically
sets the colormap for each zoom level and it does not support displaying
the colormap. Default: renderize.
  • Loading branch information
nritsche committed Jun 25, 2020
1 parent ece43c0 commit f4e2233
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
16 changes: 9 additions & 7 deletions bondia/plot/delayspectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import panel
import param
import holoviews as hv
from holoviews.operation.datashader import datashade
from holoviews.operation.datashader import datashade, rasterize
from holoviews.plotting.util import process_cmap
import numpy as np

Expand Down Expand Up @@ -38,8 +38,10 @@ class DelaySpectrumPlot(param.Parameterized, BondiaPlot):
helper_lines = param.Boolean(default=True)

# Default: turn on datashader and disable colormap range
serverside_rendering = param.Boolean(default=True)
colormap_range = param.Range(default=(0.1, 10000), constant=True)
serverside_rendering = param.Selector(
objects=[None, rasterize, datashade], default=rasterize
)
colormap_range = param.Range(default=(0.1, 10000), constant=False)

# Hide lsd selector by setting precedence < 0
lsd = param.Selector(precedence=-1)
Expand All @@ -53,7 +55,7 @@ def __init__(self, data, **params):
@param.depends("serverside_rendering", watch=True)
def update_serverside_rendering(self):
# Disable colormap range selection if using datashader (because it uses auto values)
self.param["colormap_range"].constant = self.serverside_rendering
self.param["colormap_range"].constant = self.serverside_rendering == datashade

@param.depends(
"lsd",
Expand Down Expand Up @@ -131,7 +133,7 @@ def view(self):
ylim=ylim,
)

if not self.serverside_rendering:
if self.serverside_rendering is None:
if self.helper_lines:
img = (img * hv.VLine(0) * hv.HLine(0)).opts(
hv.opts.VLine(color="white", line_width=3, line_dash="dotted"),
Expand All @@ -149,8 +151,8 @@ def view(self):
else:
normalization = "linear"

# datashade
img = datashade(
# datashade/rasterize the image
img = self.serverside_rendering(
img,
cmap=cmap_inferno,
precompute=True,
Expand Down
9 changes: 7 additions & 2 deletions bondia/plot/plot.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from panel import Column, Row
from panel import Column, Row, Param


class BondiaPlot:
Expand Down Expand Up @@ -26,7 +26,12 @@ def panel_row(self):
if self._panel_col_active:

self._panel_col = Column(
self.title, Row(self.view, self.param), width_policy="max"
self.title,
# Stop param from showing the expand button of the datashading function
# selector. It would be nice to show it, but there are options that can make
# the whole server crash.
Row(self.view, Param(self, expand_button=False)),
width_policy="max",
)
else:
self._panel_col = Column(None, Row())
Expand Down

0 comments on commit f4e2233

Please sign in to comment.