forked from deephaven/deephaven-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
112 lines (93 loc) · 2.57 KB
/
Copy path__init__.py
File metadata and controls
112 lines (93 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
from __future__ import annotations
import json
from typing import Any
from deephaven.plugin.object_type import BidirectionalObjectType, MessageStream
from plotly.graph_objs import Figure
from .communication.DeephavenFigureConnection import DeephavenFigureConnection
from .deephaven_figure import DeephavenFigure
from .plots import (
area,
bar,
frequency_bar,
timeline,
histogram,
box,
violin,
strip,
ohlc,
candlestick,
treemap,
sunburst,
icicle,
funnel,
funnel_area,
line,
line_polar,
line_ternary,
line_3d,
scatter,
scatter_3d,
scatter_polar,
scatter_ternary,
pie,
layer,
make_subplots,
scatter_geo,
scatter_mapbox,
density_mapbox,
line_geo,
line_mapbox,
density_heatmap,
indicator,
scatter_map,
density_map,
line_map,
)
from .data import data_generators
NAME = "deephaven.plot.express.DeephavenFigure"
class DeephavenFigureType(BidirectionalObjectType):
"""
DeephavenFigureType for plugin registration
"""
@property
def name(self) -> str:
"""
Returns the name of the plugin
Returns:
The name of the plugin
"""
return NAME
def is_type(self, obj: Any) -> bool:
"""
Check if an object is a DeephavenFigure or Plotly Figure
Plotly figures are wrapped in DeephavenFigure when sent to the client
Args:
obj: The object to check
Returns:
True if the object is of the correct type, False otherwise
"""
return isinstance(obj, DeephavenFigure) or isinstance(obj, Figure)
def create_client_connection(
self, obj: DeephavenFigure, connection: MessageStream
) -> MessageStream:
"""
Create a client connection for the DeephavenFigure.
This sends an initial figure to the client.
Args:
obj: The object to create the connection for
connection: The connection to use
Returns:
The client connection
"""
if isinstance(obj, Figure):
# this is a plotly figure, it will never be updated, so wrap once and send
obj = DeephavenFigure(obj, is_plotly_fig=True)
figure_connection = DeephavenFigureConnection(obj, connection)
initial_message = json.dumps(
{
"type": "RETRIEVE",
}
).encode()
payload, references = figure_connection.on_data(initial_message, [])
connection.on_data(payload, references)
return figure_connection