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

Updated deephaven-plugin to latest, fixed API breaking changes #16

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
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ package_dir=
=src
packages=find_namespace:
install_requires =
deephaven-core>=0.14.0
jpy>=0.11.0
deephaven-plugin
deephaven-core>=0.27.0
jpy>=0.14.0
deephaven-plugin>=0.5.0
matplotlib
include_package_data = True

Expand Down
8 changes: 6 additions & 2 deletions src/deephaven/plugin/matplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from deephaven import numpy as dhnp
from deephaven.plugin import Registration
from deephaven.plugin import Registration, Callback
from deephaven.table_listener import listen
from importlib import resources
import matplotlib.pyplot as plt
Expand All @@ -8,6 +8,7 @@

__version__ = "0.1.2"


def _init_theme():
# Set the Deephaven style globally.
# We use the savefig function to export the Figure, and that uses the Figure's properties for colours rather than temporary styling.
Expand All @@ -17,14 +18,16 @@ def _init_theme():
with resources.path(__package__, 'deephaven.mplstyle') as p:
plt.style.use(['dark_background',p])


class MatplotlibRegistration(Registration):
@classmethod
def register_into(cls, callback: Registration.Callback) -> None:
def register_into(cls, callback: Callback) -> None:
_init_theme()
plt.switch_backend('AGG')
from . import figure_type
callback.register(figure_type.FigureType)


class TableEventSource:
"""
Makes an event source for matplotlib that triggers whenever Deephaven Table updates.
Expand Down Expand Up @@ -88,6 +91,7 @@ def stop(self):
self._listener.stop()
self._listener = None


class TableAnimation(Animation):
"""
Makes an animation by calling a function *func* whenever the Deephaven Table *table* is updated.
Expand Down
9 changes: 7 additions & 2 deletions src/deephaven/plugin/matplotlib/figure_type.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from io import BytesIO
from weakref import WeakKeyDictionary, WeakSet
from matplotlib.figure import Figure
from deephaven.plugin.object import Exporter, ObjectType
from deephaven.plugin.object_type import Exporter, FetchOnlyObjectType
from threading import Timer

# Name of the matplotlib figure object that was export
Expand All @@ -16,6 +16,7 @@
# Track the currently drawing figures, otherwise the stale_callback gets called when we call `savefig`
_exporting_figures = WeakSet()


def debounce(wait):
"""Postpone a functions execution until after some time has elapsed

Expand All @@ -39,6 +40,7 @@ def call_it():

return decorator


# Creates an input table that will update a figures size when the input is set
# Has three different key value pairs:
# revision: Increases whenever the figure 'ticks'
Expand Down Expand Up @@ -76,11 +78,13 @@ def handle_figure_update(self, value):

return input_table


def _get_input_table(figure):
if not figure in _figure_tables:
_figure_tables[figure] = _make_input_table(figure)
return _figure_tables[figure]


def _export_figure(figure):
buf = BytesIO()

Expand All @@ -93,7 +97,8 @@ def _export_figure(figure):

return buf.getvalue()

class FigureType(ObjectType):

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