Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bokeh_wegbl backend #413

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Improvements

- Added `before_first` and `after_last` parameters to `EventSet.tick` and `EventSet.tick_calendar`
- Added `bokeh_webgl` as a possible `backend` for `tp.plot`.

### Fixes

Expand Down
9 changes: 8 additions & 1 deletion temporian/implementation/numpy/data/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,16 @@ def bokeh_backend():
return plotter_bokeh.Plotter


def bokeh_webgl_backend():
from temporian.implementation.numpy.data import plotter_bokeh

return plotter_bokeh.PlotterWebGL


BACKENDS: Dict[str, Callable] = {
"matplotlib": matplotlib_backend,
"bokeh": bokeh_backend,
"bokeh_webgl": bokeh_webgl_backend,
}


Expand Down Expand Up @@ -279,7 +286,7 @@ def plot(
effectively selects a backend that support interactive plotting.
Ignored if "backend" is set.
backend: Plotting library to use. Possible values are: matplotlib,
bokeh. If set, overrides the "interactive" argument.
bokeh, and bokeh_webgl. If set, overrides the "interactive" argument.
merge: If true, plots all features in the same plots. If false, plots
features in separate plots. merge=True on event-sets [e1, e2] is
equivalent to plotting (e1, e2).
Expand Down
109 changes: 58 additions & 51 deletions temporian/implementation/numpy/data/plotter_bokeh.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@


class Plotter(PlotterBackend):
output_backend = "canvas"

def __init__(self, num_plots: int, options: Options):
super().__init__(num_plots, options)

Expand All @@ -46,7 +48,7 @@ def finalize_subplot(

def ensure_cur_is_available(self, categorical_values: Optional[List[str]]):
if self.cur_fig is None:
self.cur_fig = create_fig(
self.cur_fig = self.create_fig(
self.cur_title,
self.cur_is_unix_timestamp,
self.options,
Expand Down Expand Up @@ -152,57 +154,62 @@ def finalize(self):
show(figure_set)
return figure_set

def create_fig(
self,
title: Optional[str],
is_unix_timestamp: bool,
options: Options,
categorical_values: Optional[List[str]],
):
tools = [
"xpan",
"pan",
"xwheel_zoom",
"ywheel_zoom",
"box_zoom",
"reset",
"undo",
"save",
"hover",
]

fig_args = {}
if is_unix_timestamp:
fig_args["x_axis_type"] = "datetime"
if title:
fig_args["title"] = title

if options.min_time is not None or options.max_time is not None:
args = {}
if options.min_time is not None:
args["start"] = (
convert_timestamp_to_datetime(options.min_time)
if is_unix_timestamp
else options.min_time
)
if options.max_time is not None:
args["end"] = (
convert_timestamp_to_datetime(options.max_time)
if is_unix_timestamp
else options.max_time
)
fig_args["x_range"] = Range1d(**args)

if categorical_values is not None:
fig_args["y_range"] = categorical_values

def create_fig(
title: Optional[str],
is_unix_timestamp: bool,
options: Options,
categorical_values: Optional[List[str]],
):
tools = [
"xpan",
"pan",
"xwheel_zoom",
"ywheel_zoom",
"box_zoom",
"reset",
"undo",
"save",
"hover",
]

fig_args = {}
if is_unix_timestamp:
fig_args["x_axis_type"] = "datetime"
if title:
fig_args["title"] = title

if options.min_time is not None or options.max_time is not None:
args = {}
if options.min_time is not None:
args["start"] = (
convert_timestamp_to_datetime(options.min_time)
if is_unix_timestamp
else options.min_time
)
if options.max_time is not None:
args["end"] = (
convert_timestamp_to_datetime(options.max_time)
if is_unix_timestamp
else options.max_time
)
fig_args["x_range"] = Range1d(**args)
# Note: Ranges cannot be set after the figure is created see:
# https://discourse.bokeh.org/t/updating-y-range-to-categorical/2397/3
fig = figure(
width=options.width_px,
height=options.height_per_plot_px,
tools=tools,
output_backend=self.output_backend,
**fig_args,
)

if categorical_values is not None:
fig_args["y_range"] = categorical_values
return fig

# Note: Ranges cannot be set after the figure is created see:
# https://discourse.bokeh.org/t/updating-y-range-to-categorical/2397/3
fig = figure(
width=options.width_px,
height=options.height_per_plot_px,
tools=tools,
**fig_args,
)

return fig
class PlotterWebGL(Plotter):
output_backend = "webgl"
Loading