figpack 0.2.16__py3-none-any.whl → 0.2.18__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.

Files changed (45) hide show
  1. figpack/__init__.py +2 -3
  2. figpack/cli.py +74 -0
  3. figpack/core/__init__.py +2 -2
  4. figpack/core/_bundle_utils.py +85 -18
  5. figpack/core/_file_handler.py +192 -0
  6. figpack/core/_server_manager.py +42 -6
  7. figpack/core/_show_view.py +1 -1
  8. figpack/core/_view_figure.py +43 -12
  9. figpack/core/extension_view.py +7 -25
  10. figpack/core/figpack_extension.py +0 -71
  11. figpack/extensions.py +356 -0
  12. figpack/figpack-figure-dist/assets/{index-D9a3K6eW.css → index-BJUFDPIM.css} +1 -1
  13. figpack/figpack-figure-dist/assets/index-nBpxgXXT.js +91 -0
  14. figpack/figpack-figure-dist/index.html +2 -2
  15. figpack/views/PlotlyExtension/PlotlyExtension.py +4 -50
  16. figpack/views/PlotlyExtension/_plotly_extension.py +46 -0
  17. figpack/views/PlotlyExtension/plotly_view.js +84 -80
  18. figpack/views/__init__.py +1 -0
  19. {figpack-0.2.16.dist-info → figpack-0.2.18.dist-info}/METADATA +1 -1
  20. figpack-0.2.18.dist-info/RECORD +45 -0
  21. figpack/figpack-figure-dist/assets/index-DtOnN02w.js +0 -846
  22. figpack/franklab/__init__.py +0 -5
  23. figpack/franklab/views/TrackAnimation.py +0 -154
  24. figpack/franklab/views/__init__.py +0 -9
  25. figpack/spike_sorting/__init__.py +0 -5
  26. figpack/spike_sorting/views/AutocorrelogramItem.py +0 -32
  27. figpack/spike_sorting/views/Autocorrelograms.py +0 -116
  28. figpack/spike_sorting/views/AverageWaveforms.py +0 -146
  29. figpack/spike_sorting/views/CrossCorrelogramItem.py +0 -35
  30. figpack/spike_sorting/views/CrossCorrelograms.py +0 -131
  31. figpack/spike_sorting/views/RasterPlot.py +0 -284
  32. figpack/spike_sorting/views/RasterPlotItem.py +0 -28
  33. figpack/spike_sorting/views/SpikeAmplitudes.py +0 -364
  34. figpack/spike_sorting/views/SpikeAmplitudesItem.py +0 -38
  35. figpack/spike_sorting/views/UnitMetricsGraph.py +0 -127
  36. figpack/spike_sorting/views/UnitSimilarityScore.py +0 -40
  37. figpack/spike_sorting/views/UnitsTable.py +0 -82
  38. figpack/spike_sorting/views/UnitsTableColumn.py +0 -40
  39. figpack/spike_sorting/views/UnitsTableRow.py +0 -36
  40. figpack/spike_sorting/views/__init__.py +0 -41
  41. figpack-0.2.16.dist-info/RECORD +0 -61
  42. {figpack-0.2.16.dist-info → figpack-0.2.18.dist-info}/WHEEL +0 -0
  43. {figpack-0.2.16.dist-info → figpack-0.2.18.dist-info}/entry_points.txt +0 -0
  44. {figpack-0.2.16.dist-info → figpack-0.2.18.dist-info}/licenses/LICENSE +0 -0
  45. {figpack-0.2.16.dist-info → figpack-0.2.18.dist-info}/top_level.txt +0 -0
@@ -5,8 +5,8 @@
5
5
  <link rel="icon" type="image/png" href="./assets/neurosift-logo-CLsuwLMO.png" />
6
6
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7
7
  <title>figpack figure</title>
8
- <script type="module" crossorigin src="./assets/index-DtOnN02w.js"></script>
9
- <link rel="stylesheet" crossorigin href="./assets/index-D9a3K6eW.css">
8
+ <script type="module" crossorigin src="./assets/index-nBpxgXXT.js"></script>
9
+ <link rel="stylesheet" crossorigin href="./assets/index-BJUFDPIM.css">
10
10
  </head>
11
11
  <body>
12
12
  <div id="root"></div>
@@ -1,57 +1,10 @@
1
1
  import json
2
2
  import numpy as np
3
- import zarr
4
- import urllib.request
5
- import urllib.error
6
3
  from datetime import date, datetime
7
4
 
8
5
  import figpack
9
6
 
10
7
 
11
- def _download_plotly_library():
12
- url = "https://cdn.plot.ly/plotly-2.35.2.min.js"
13
- try:
14
- with urllib.request.urlopen(url) as response:
15
- return response.read().decode("utf-8")
16
- except urllib.error.URLError as e:
17
- raise RuntimeError(f"Failed to download plotly library from {url}: {e}")
18
-
19
-
20
- def _load_javascript_code():
21
- """Load the JavaScript code from the plotly.js file"""
22
- import os
23
-
24
- js_path = os.path.join(os.path.dirname(__file__), "plotly_view.js")
25
- try:
26
- with open(js_path, "r", encoding="utf-8") as f:
27
- return f.read()
28
- except FileNotFoundError:
29
- raise FileNotFoundError(
30
- f"Could not find plotly.js at {js_path}. "
31
- "Make sure the JavaScript file is present in the package."
32
- )
33
-
34
-
35
- # Download the plotly library and create the extension with additional files
36
- try:
37
- plotly_lib_js = _download_plotly_library()
38
- additional_files = {"plotly.min.js": plotly_lib_js}
39
- except Exception as e:
40
- print(f"Warning: Could not download plotly library: {e}")
41
- print("Extension will fall back to CDN loading")
42
- additional_files = {}
43
-
44
- # Create and register the plotly extension
45
- _plotly_extension = figpack.FigpackExtension(
46
- name="figpack_plotly",
47
- javascript_code=_load_javascript_code(),
48
- additional_files=additional_files,
49
- version="1.0.0",
50
- )
51
-
52
- figpack.ExtensionRegistry.register(_plotly_extension)
53
-
54
-
55
8
  class PlotlyFigure(figpack.ExtensionView):
56
9
  """
57
10
  A Plotly graph visualization view using the plotly library.
@@ -66,9 +19,10 @@ class PlotlyFigure(figpack.ExtensionView):
66
19
  Args:
67
20
  fig: The plotly figure object
68
21
  """
69
- # for some reason, we need to reregister here to avoid issues with pytest
70
- figpack.ExtensionRegistry.register(_plotly_extension)
71
- super().__init__(extension_name="figpack_plotly")
22
+ # It's important that we only import conditionally, so we are not always downloading plotly
23
+ from ._plotly_extension import _plotly_extension
24
+
25
+ super().__init__(extension=_plotly_extension, view_type="plotly.PlotlyFigure")
72
26
 
73
27
  self.fig = fig
74
28
 
@@ -0,0 +1,46 @@
1
+ import urllib.request
2
+ import urllib.error
3
+
4
+ from ...core.figpack_extension import FigpackExtension
5
+
6
+
7
+ def _load_javascript_code():
8
+ """Load the JavaScript code from the plotly.js file"""
9
+ import os
10
+
11
+ js_path = os.path.join(os.path.dirname(__file__), "plotly_view.js")
12
+ try:
13
+ with open(js_path, "r", encoding="utf-8") as f:
14
+ return f.read()
15
+ except FileNotFoundError:
16
+ raise FileNotFoundError(
17
+ f"Could not find plotly.js at {js_path}. "
18
+ "Make sure the JavaScript file is present in the package."
19
+ )
20
+
21
+
22
+ def _download_plotly_library():
23
+ url = "https://cdn.plot.ly/plotly-2.35.2.min.js"
24
+ try:
25
+ with urllib.request.urlopen(url) as response:
26
+ return response.read().decode("utf-8")
27
+ except urllib.error.URLError as e:
28
+ raise RuntimeError(f"Failed to download plotly library from {url}: {e}")
29
+
30
+
31
+ # Download the plotly library and create the extension with additional files
32
+ try:
33
+ plotly_lib_js = _download_plotly_library()
34
+ additional_files = {"plotly.min.js": plotly_lib_js}
35
+ except Exception as e:
36
+ print(f"Warning: Could not download plotly library: {e}")
37
+ print("Extension will fall back to CDN loading")
38
+ additional_files = {}
39
+
40
+ # Create and register the plotly extension
41
+ _plotly_extension = FigpackExtension(
42
+ name="figpack-plotly",
43
+ javascript_code=_load_javascript_code(),
44
+ additional_files=additional_files,
45
+ version="1.0.0",
46
+ )
@@ -5,8 +5,8 @@
5
5
 
6
6
  const loadFigureData = async (zarrGroup) => {
7
7
  // Get the figure data from the zarr array
8
- const data = await zarrGroup.file.getDatasetData(
9
- joinPath(zarrGroup.path, "figure_data"),
8
+ const data = await zarrGroup.getDatasetData(
9
+ "figure_data",
10
10
  {},
11
11
  );
12
12
  if (!data || data.length === 0) {
@@ -24,83 +24,87 @@ const loadFigureData = async (zarrGroup) => {
24
24
  return parsedData;
25
25
  };
26
26
 
27
- (function() {
28
- window.figpackExtensions = window.figpackExtensions || {};
29
-
30
- window.figpackExtensions['figpack_plotly'] = {
31
- render: async function(container, zarrGroup, width, height, onResize) {
32
- container.innerHTML = '';
33
-
34
- try {
35
- const figureData = await loadFigureData(zarrGroup);
36
-
37
- const makePlot = () => {
38
- window.Plotly.newPlot(
39
- container,
40
- figureData.data || [],
41
- {
42
- ...figureData.layout,
43
- width: width,
44
- height: height,
45
- margin: { l: 50, r: 50, t: 50, b: 50 },
46
- },
47
- {
48
- responsive: true,
49
- displayModeBar: true,
50
- displaylogo: false,
51
- },
52
- )
53
- };
54
-
55
- makePlot();
56
-
57
- // Handle resize events
58
- onResize((newWidth, newHeight) => {
59
- window.Plotly.relayout(container, {width: newWidth, height: newHeight});
60
- });
61
-
62
- return {
63
- destroy: () => {
64
- window.Plotly.purge(container);
65
- }
66
- };
67
-
68
- } catch (error) {
69
- console.error('Error rendering plotly figure:', error);
70
- this.renderError(container, width, height, error.message);
71
- return { destroy: () => {} };
27
+ const renderPlotlyFigure = async (params) => {
28
+ const { container, zarrGroup, width, height, onResize } = params;
29
+ container.innerHTML = "";
30
+
31
+ try {
32
+ const figureData = await loadFigureData(zarrGroup);
33
+
34
+ const makePlot = () => {
35
+ window.Plotly.newPlot(
36
+ container,
37
+ figureData.data || [],
38
+ {
39
+ ...figureData.layout,
40
+ width: width,
41
+ height: height,
42
+ margin: { l: 50, r: 50, t: 50, b: 50 },
43
+ },
44
+ {
45
+ responsive: true,
46
+ displayModeBar: true,
47
+ displaylogo: false,
48
+ },
49
+ );
50
+ };
51
+
52
+ makePlot();
53
+
54
+ // Handle resize events
55
+ onResize((newWidth, newHeight) => {
56
+ window.Plotly.relayout(container, { width: newWidth, height: newHeight });
57
+ });
58
+
59
+ return {
60
+ destroy: () => {
61
+ window.Plotly.purge(container);
72
62
  }
73
- },
74
-
75
- renderError: function(container, width, height, message) {
76
- container.innerHTML = `
77
- <div style="
78
- width: ${width}px;
79
- height: ${height}px;
80
- display: flex;
81
- align-items: center;
82
- justify-content: center;
83
- background-color: #f8f9fa;
84
- border: 1px solid #dee2e6;
85
- color: #6c757d;
86
- font-family: system-ui, -apple-system, sans-serif;
87
- font-size: 14px;
88
- text-align: center;
89
- padding: 20px;
90
- box-sizing: border-box;
91
- ">
92
- <div>
93
- <div style="margin-bottom: 10px; font-weight: 500;">Force Graph Error</div>
94
- <div style="font-size: 12px;">${message}</div>
95
- </div>
96
- </div>
97
- `;
98
- }
99
- };
100
- })();
101
-
102
- const joinPath = function(p1, p2) {
103
- if (p1.endsWith('/')) p1 = p1.slice(0, -1);
104
- if (p2.startsWith('/')) p2 = p2.slice(1);
105
- return p1 + '/' + p2;
63
+ };
64
+
65
+ } catch (error) {
66
+ console.error('Error rendering plotly figure:', error);
67
+ renderError(container, width, height, error.message);
68
+ return { destroy: () => {} };
69
+ }
106
70
  };
71
+
72
+ const renderError = (container, width, height, message) => {
73
+ container.innerHTML = `
74
+ <div style="
75
+ width: ${width}px;
76
+ height: ${height}px;
77
+ display: flex;
78
+ align-items: center;
79
+ justify-content: center;
80
+ background-color: #f8f9fa;
81
+ border: 1px solid #dee2e6;
82
+ color: #6c757d;
83
+ font-family: system-ui, -apple-system, sans-serif;
84
+ font-size: 14px;
85
+ text-align: center;
86
+ padding: 20px;
87
+ box-sizing: border-box;
88
+ ">
89
+ <div>
90
+ <div style="margin-bottom: 10px; font-weight: 500;">Plotly Figure Error</div>
91
+ <div style="font-size: 12px;">${message}</div>
92
+ </div>
93
+ </div>
94
+ `;
95
+ };
96
+
97
+ const registerExtension = () => {
98
+ const registerFPViewComponent = window.figpack_p1.registerFPViewComponent;
99
+ registerFPViewComponent({
100
+ name: "plotly.PlotlyFigure",
101
+ render: renderPlotlyFigure,
102
+ });
103
+
104
+ // const registerFPViewContextCreator = window.figpack_p1.registerFPViewContextCreator;
105
+
106
+ const registerFPExtension = window.figpack_p1.registerFPExtension;
107
+ registerFPExtension({ name: "figpack-plotly" });
108
+ };
109
+
110
+ registerExtension();
figpack/views/__init__.py CHANGED
@@ -12,4 +12,5 @@ from .Splitter import Splitter
12
12
  from .TabLayout import TabLayout
13
13
  from .TabLayoutItem import TabLayoutItem
14
14
  from .TimeseriesGraph import TimeseriesGraph
15
+
15
16
  from .PlotlyExtension import PlotlyFigure
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: figpack
3
- Version: 0.2.16
3
+ Version: 0.2.18
4
4
  Summary: A Python package for creating shareable, interactive visualizations in the browser
5
5
  Author-email: Jeremy Magland <jmagland@flatironinstitute.org>
6
6
  License: Apache-2.0
@@ -0,0 +1,45 @@
1
+ figpack/__init__.py,sha256=fyEw3EIabN2VtuUA2uUaDiGpV6iudketMIOnR1TIvDs,358
2
+ figpack/cli.py,sha256=s1mGQuFSntxiIvU6OWwHVlM9Cj-l1zMQ3OzFFe1-5ZE,11089
3
+ figpack/extensions.py,sha256=mILB4_F1RHkca4I7t88zh74IX8VCmfT7XFZZT4XYdNw,13009
4
+ figpack/core/__init__.py,sha256=7zU6O1piTk07aeCfbU81QqTgSHIO2n5MZ4LFNmsrtfs,192
5
+ figpack/core/_bundle_utils.py,sha256=xJafDtH9M575usys8t2S8qOJT1a1xLcI6-m2oD18rFU,9064
6
+ figpack/core/_file_handler.py,sha256=TC4Z23Xy4dKky8BEwyp3Gj4K9-gpnKRiF1u6KkxWprc,6984
7
+ figpack/core/_save_figure.py,sha256=52ny-m1ThGgxY4ZgMn7m33n8A2OCyezj8H8TMvw0Y8Q,1043
8
+ figpack/core/_server_manager.py,sha256=I8PQImUa4C0L6LfIiCnpRnfQT7B-XVseCs80qnUvIlI,12374
9
+ figpack/core/_show_view.py,sha256=noADkomP1ovH-Jb7Bj0unmkPXvS_uOkkCILJSWag1RI,5171
10
+ figpack/core/_upload_bundle.py,sha256=54hdWayJJdRZdx7N9V2aH_X33KkR6hImMjN6tkBTLi8,14894
11
+ figpack/core/_view_figure.py,sha256=GYTgSCWBxi1pR16aBgAYRcEuFcgj0vjsrLIVfy1HYzM,5374
12
+ figpack/core/config.py,sha256=oOR7SlP192vuFhYlS-h14HnG-kd_3gaz0vshXch2RNc,173
13
+ figpack/core/extension_view.py,sha256=MUj66ccjQJGyOyHzyYNwMd84isN2DfEoZ3X-TSzemAs,1257
14
+ figpack/core/figpack_extension.py,sha256=KSJKlnLYueFnGa8QFMpbIF3CDMwnIZJOqsI0smz6cUc,2252
15
+ figpack/core/figpack_view.py,sha256=L--pBg-PjEiAE2Ry4u-1eZsRVu4j4-p-NKwtJSVnGj0,6304
16
+ figpack/core/zarr.py,sha256=LTWOIX6vuH25STYTQS9_apfnfYXmATAEQkil3z9eYKE,1634
17
+ figpack/figpack-figure-dist/index.html,sha256=20dz5NDpdIBVqFeC6T9TmMGvoaN4aYKDaFZuqwQjg2U,486
18
+ figpack/figpack-figure-dist/assets/index-BJUFDPIM.css,sha256=XTxNlUgQVylnLK7KoN0psOmascor1pEIkYT4tnLmruE,7295
19
+ figpack/figpack-figure-dist/assets/index-nBpxgXXT.js,sha256=OBbpRFyiDBcLeJiyWtLOaLRJX6B7uLdByLneUh6kW0o,1111999
20
+ figpack/figpack-figure-dist/assets/neurosift-logo-CLsuwLMO.png,sha256=g5m-TwrGh5f6-9rXtWV-znH4B0nHgc__0GWclRDLUHs,9307
21
+ figpack/views/Box.py,sha256=dH4Vxax4NPJExZSx8jAG6feMgkNU5mOPEf-lLOd41-4,2421
22
+ figpack/views/DataFrame.py,sha256=FAqrEddh3v0MNXlXA1DQzN34d9gacDXHUdiahIKlgOI,3401
23
+ figpack/views/Gallery.py,sha256=D6drCKfnPN6MNn3wjQV0i5FW2s3q9xP-X75q-PR4Sc8,3326
24
+ figpack/views/GalleryItem.py,sha256=b_upJno5P3ANSulbG-h3t6Xj56tPGJ7iVxqyiZu3zaQ,1244
25
+ figpack/views/Image.py,sha256=8eNWzednvpsz0EcaoK3GdWGBfCybT2pXnBhMlZMr4yA,3742
26
+ figpack/views/LayoutItem.py,sha256=wy8DggkIzZpU0F1zFIBceS7HpBb6lu-A3hpYINQzedk,1595
27
+ figpack/views/Markdown.py,sha256=8kScwS1XaiQt5KRcbWG1B4RNUbA_FG5fIUJcv6csB8g,1134
28
+ figpack/views/MatplotlibFigure.py,sha256=v4rc8sT9FcuHPrwljq9s-BUT5vlJiRDAf5tBP4YujAE,2423
29
+ figpack/views/MultiChannelTimeseries.py,sha256=loZ1zGyIC_VJbduR7EIBbFHFPEr8DRQw-QNQSFVSdHQ,8292
30
+ figpack/views/Spectrogram.py,sha256=9aJpzlOsOo7ReddR-i6riN2MG2RdveRS7m6MI2cCYjM,9336
31
+ figpack/views/Splitter.py,sha256=q29pBu4RJgr0o_m1Jliv5FrGGCm5_jhowMg8Xgh70gk,2019
32
+ figpack/views/TabLayout.py,sha256=bKLjeI_CnllThB6t7AwlP-Oh5mKbWt8hpubW5Zyj420,1910
33
+ figpack/views/TabLayoutItem.py,sha256=xmHA0JsW_6naJze4_mQuP_Fy0Nm17p2N7w_AsmVRp8k,880
34
+ figpack/views/TimeseriesGraph.py,sha256=VErwmzRqNFq1i2XEWzAHM6csbHry064did32AbxLMms,17700
35
+ figpack/views/__init__.py,sha256=jquSaF1bU_oT9oV-2KfFKiRb_CG-UGXFpFygGswHO2k,547
36
+ figpack/views/PlotlyExtension/PlotlyExtension.py,sha256=W8ucSnAaPOHVGvOXRt0DpdgGNLQRmfUUdKzHICuJKJ0,2151
37
+ figpack/views/PlotlyExtension/__init__.py,sha256=80Wy1mDMWyagjuR99ECxJePIYpRQ6TSyHkB0uZoBZ_0,70
38
+ figpack/views/PlotlyExtension/_plotly_extension.py,sha256=yZjG1NMGlQedeeLdV6TQWpi_NTm5Wfk5eWbXEdZbbFE,1455
39
+ figpack/views/PlotlyExtension/plotly_view.js,sha256=9BjgOPkqGl87SSonnb48nFeQV3UTIi1trpSPxd9qlKo,3055
40
+ figpack-0.2.18.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
41
+ figpack-0.2.18.dist-info/METADATA,sha256=yED-BH_tj3beTQoufKeSR0QLqhr56mHFokQs4TlJWIQ,4501
42
+ figpack-0.2.18.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
43
+ figpack-0.2.18.dist-info/entry_points.txt,sha256=l6d3siH2LxXa8qJGbjAqpIZtI5AkMSyDeoRDCzdrUto,45
44
+ figpack-0.2.18.dist-info/top_level.txt,sha256=lMKGaC5xWmAYBx9Ac1iMokm42KFnJFjmkP2ldyvOo-c,8
45
+ figpack-0.2.18.dist-info/RECORD,,