figpack 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of figpack might be problematic. Click here for more details.
- figpack/__init__.py +5 -1
- figpack/cli.py +2 -118
- figpack/core/_bundle_utils.py +3 -4
- figpack/core/_save_figure.py +31 -0
- figpack/core/_server_manager.py +9 -5
- figpack/core/_show_view.py +20 -21
- figpack/core/_upload_bundle.py +46 -22
- figpack/core/_view_figure.py +138 -0
- figpack/core/config.py +2 -0
- figpack/core/figpack_view.py +79 -22
- figpack/figpack-gui-dist/assets/{index-DUR9Dmwh.js → index-CrYQmIda.js} +70 -70
- figpack/figpack-gui-dist/index.html +1 -1
- figpack/spike_sorting/views/RasterPlot.py +77 -0
- figpack/spike_sorting/views/RasterPlotItem.py +28 -0
- figpack/spike_sorting/views/__init__.py +4 -0
- figpack/views/Gallery.py +88 -0
- figpack/views/GalleryItem.py +47 -0
- figpack/views/Image.py +37 -0
- figpack/views/__init__.py +2 -0
- figpack-0.2.5.dist-info/METADATA +96 -0
- {figpack-0.2.3.dist-info → figpack-0.2.5.dist-info}/RECORD +25 -19
- figpack-0.2.3.dist-info/METADATA +0 -168
- {figpack-0.2.3.dist-info → figpack-0.2.5.dist-info}/WHEEL +0 -0
- {figpack-0.2.3.dist-info → figpack-0.2.5.dist-info}/entry_points.txt +0 -0
- {figpack-0.2.3.dist-info → figpack-0.2.5.dist-info}/licenses/LICENSE +0 -0
- {figpack-0.2.3.dist-info → figpack-0.2.5.dist-info}/top_level.txt +0 -0
figpack/core/figpack_view.py
CHANGED
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
Base view class for figpack visualization components
|
|
3
3
|
"""
|
|
4
4
|
|
|
5
|
+
import os
|
|
6
|
+
import random
|
|
7
|
+
import string
|
|
5
8
|
from typing import Union
|
|
6
9
|
|
|
7
10
|
import zarr
|
|
@@ -15,31 +18,38 @@ class FigpackView:
|
|
|
15
18
|
def show(
|
|
16
19
|
self,
|
|
17
20
|
*,
|
|
21
|
+
title: str,
|
|
22
|
+
description: Union[str, None] = None,
|
|
18
23
|
port: Union[int, None] = None,
|
|
19
|
-
open_in_browser: bool =
|
|
20
|
-
allow_origin: Union[str, None] = None,
|
|
24
|
+
open_in_browser: Union[bool, None] = None,
|
|
21
25
|
upload: Union[bool, None] = None,
|
|
22
|
-
ephemeral: Union[bool, None] = None,
|
|
23
|
-
_dev: bool = False,
|
|
24
|
-
title: Union[str, None] = None,
|
|
25
|
-
description: Union[str, None] = None,
|
|
26
26
|
inline: Union[bool, None] = None,
|
|
27
27
|
inline_height: int = 600,
|
|
28
|
+
ephemeral: Union[bool, None] = None,
|
|
29
|
+
allow_origin: Union[str, None] = None,
|
|
30
|
+
wait_for_input: Union[bool, None] = None,
|
|
31
|
+
_dev: Union[bool, None] = None,
|
|
28
32
|
):
|
|
29
33
|
"""
|
|
30
|
-
Display
|
|
34
|
+
Display a figpack view component with intelligent environment detection and flexible display options.
|
|
35
|
+
See https://flatironinstitute.github.io/figpack/show_function.html for complete documentation.
|
|
36
|
+
|
|
37
|
+
Automatically adapts behavior based on context (Jupyter, Colab, JupyterHub, standalone).
|
|
38
|
+
Display modes include local browser, inline notebook, and remote upload with ephemeral options.
|
|
39
|
+
Environment variables (FIGPACK_UPLOAD, FIGPACK_INLINE, FIGPACK_OPEN_IN_BROWSER) can control default behaviors.
|
|
31
40
|
|
|
32
41
|
Args:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
title: Title for browser tab and figure (required)
|
|
43
|
+
description: Description text with markdown support (optional)
|
|
44
|
+
port: Local server port, random if None
|
|
45
|
+
open_in_browser: Auto-open in browser, auto-detects by environment
|
|
46
|
+
upload: Upload figure to figpack servers, auto-detects by environment
|
|
47
|
+
ephemeral: Use temporary figure for cloud notebooks, auto-detects
|
|
48
|
+
inline: Display inline in notebook, auto-detects by environment
|
|
49
|
+
inline_height: Height in pixels for inline display (default: 600)
|
|
50
|
+
allow_origin: CORS allow-origin header for local server
|
|
51
|
+
wait_for_input: Wait for Enter before continuing, auto-detects
|
|
52
|
+
_dev: Developer mode for figpack development
|
|
43
53
|
"""
|
|
44
54
|
from ._show_view import (
|
|
45
55
|
_show_view,
|
|
@@ -48,25 +58,55 @@ class FigpackView:
|
|
|
48
58
|
_is_in_jupyterhub,
|
|
49
59
|
)
|
|
50
60
|
|
|
51
|
-
|
|
52
|
-
|
|
61
|
+
# determine upload
|
|
62
|
+
if upload is None:
|
|
63
|
+
upload = os.environ.get("FIGPACK_UPLOAD") == "1"
|
|
64
|
+
else:
|
|
65
|
+
if upload is True and ephemeral is True:
|
|
66
|
+
# ephemeral is reserved for the case where we don't specify upload
|
|
67
|
+
# and we are in a notebook in a remote environment such as
|
|
68
|
+
# colab or jupyterhub
|
|
69
|
+
raise ValueError("ephemeral cannot be set if upload is set")
|
|
70
|
+
|
|
71
|
+
# determine inline
|
|
72
|
+
if inline is None:
|
|
73
|
+
inline = _is_in_notebook() or os.environ.get("FIGPACK_INLINE") == "1"
|
|
74
|
+
|
|
75
|
+
# determine open_in_browser
|
|
76
|
+
if open_in_browser is None:
|
|
77
|
+
open_in_browser = os.environ.get("FIGPACK_OPEN_IN_BROWSER") == "1"
|
|
78
|
+
|
|
79
|
+
# determine ephemeral
|
|
80
|
+
if ephemeral is None:
|
|
81
|
+
ephemeral = False # default to False
|
|
53
82
|
if _is_in_notebook():
|
|
54
83
|
if _is_in_colab():
|
|
55
84
|
# if we are in a notebook and in colab, we should show as uploaded ephemeral
|
|
56
85
|
print("Detected Google Colab notebook environment.")
|
|
57
86
|
upload = True
|
|
58
87
|
ephemeral = True
|
|
59
|
-
|
|
88
|
+
elif _is_in_jupyterhub():
|
|
60
89
|
# if we are in a notebook and in jupyterhub, we should show as uploaded ephemeral
|
|
61
90
|
print("Detected JupyterHub notebook environment.")
|
|
62
91
|
upload = True
|
|
63
92
|
ephemeral = True
|
|
64
93
|
|
|
94
|
+
# determine _dev
|
|
95
|
+
if _dev is None:
|
|
96
|
+
_dev = os.environ.get("FIGPACK_DEV") == "1"
|
|
97
|
+
|
|
98
|
+
# determine wait_for_input
|
|
99
|
+
if wait_for_input is None:
|
|
100
|
+
wait_for_input = not _is_in_notebook()
|
|
101
|
+
|
|
65
102
|
# Validate ephemeral parameter
|
|
66
103
|
if ephemeral and not upload:
|
|
67
104
|
raise ValueError("ephemeral=True requires upload=True to be set")
|
|
68
105
|
|
|
69
106
|
if _dev:
|
|
107
|
+
if open_in_browser:
|
|
108
|
+
print("** Note: In dev mode, open_in_browser is forced to False **")
|
|
109
|
+
open_in_browser = False
|
|
70
110
|
if port is None:
|
|
71
111
|
port = 3004
|
|
72
112
|
if allow_origin is not None:
|
|
@@ -75,10 +115,15 @@ class FigpackView:
|
|
|
75
115
|
if upload:
|
|
76
116
|
raise ValueError("Cannot upload when _dev is True.")
|
|
77
117
|
|
|
118
|
+
# make a random figure name
|
|
119
|
+
_local_figure_name = "fig_" + "".join(
|
|
120
|
+
random.choices(string.ascii_lowercase + string.digits, k=8)
|
|
121
|
+
)
|
|
122
|
+
print("** Development mode **")
|
|
78
123
|
print(
|
|
79
|
-
f"For development, run figpack-gui in dev mode and use http://localhost:5173?data=http://localhost:{port}/data.zarr"
|
|
124
|
+
f"For development, run figpack-gui in dev mode and use http://localhost:5173?data=http://localhost:{port}/{_local_figure_name}/data.zarr"
|
|
80
125
|
)
|
|
81
|
-
|
|
126
|
+
print("")
|
|
82
127
|
|
|
83
128
|
_show_view(
|
|
84
129
|
self,
|
|
@@ -91,8 +136,20 @@ class FigpackView:
|
|
|
91
136
|
description=description,
|
|
92
137
|
inline=inline,
|
|
93
138
|
inline_height=inline_height,
|
|
139
|
+
wait_for_input=wait_for_input,
|
|
140
|
+
_local_figure_name=_local_figure_name if _dev else None,
|
|
94
141
|
)
|
|
95
142
|
|
|
143
|
+
def save(self, output_path: str) -> None:
|
|
144
|
+
"""
|
|
145
|
+
Save as figure either to a folder or to a .tar.gz file
|
|
146
|
+
Args:
|
|
147
|
+
output_path: Output path (destination folder or .tar.gz file path)
|
|
148
|
+
"""
|
|
149
|
+
from ._save_figure import _save_figure
|
|
150
|
+
|
|
151
|
+
_save_figure(self, output_path)
|
|
152
|
+
|
|
96
153
|
def _write_to_zarr_group(self, group: zarr.Group) -> None:
|
|
97
154
|
"""
|
|
98
155
|
Write the view data to a Zarr group. Must be implemented by subclasses.
|