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

Update deephaven-plugin to latest, fixed API breaking changes #8

Merged
merged 1 commit into from
Aug 10, 2023
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
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ package_dir=
=src
packages=find_namespace:
install_requires =
deephaven-plugin
deephaven-plugin>=0.5.0
plotly
include_package_data = True

Expand Down
6 changes: 4 additions & 2 deletions src/deephaven/plugin/plotly/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
from deephaven.plugin import Registration
from deephaven.plugin import Registration, Callback
from plotly import io as pio

__version__ = "0.1.0"


def _init_theme():
# Set the Deephaven style globally
from . import theme_deephaven
pio.templates.default = "deephaven"
# Disable default renderer to ignore figure.show()
pio.renderers.default = None


class PlotlyRegistration(Registration):
@classmethod
def register_into(cls, callback: Registration.Callback) -> None:
def register_into(cls, callback: Callback) -> None:
_init_theme()
from . import figure_type
callback.register(figure_type.FigureType)
11 changes: 6 additions & 5 deletions src/deephaven/plugin/plotly/figure_type.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
from plotly.graph_objects import Figure
from deephaven.plugin.object import Exporter, ObjectType
import json
from deephaven.plugin.object_type import Exporter, FetchOnlyObjectType

# Name of the plotly figure object that was exported
NAME = "plotly.figure"


def _export_figure(figure):
return figure.to_json().encode()

class FigureType(ObjectType):

class FigureType(FetchOnlyObjectType):
@property
def name(self) -> str:
return NAME

def is_type(self, object) -> bool:
return isinstance(object, Figure)
def is_type(self, obj) -> bool:
return isinstance(obj, Figure)

def to_bytes(self, exporter: Exporter, figure: Figure) -> bytes:
return _export_figure(figure)