pfund-plot 0.0.1__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.
Files changed (57) hide show
  1. pfund_plot/__init__.py +183 -0
  2. pfund_plot/__main__.py +9 -0
  3. pfund_plot/cli/__init__.py +3 -0
  4. pfund_plot/cli/commands/gallery/__init__.py +15 -0
  5. pfund_plot/cli/commands/gallery/gallery_marimo.py +462 -0
  6. pfund_plot/cli/commands/serve.py +21 -0
  7. pfund_plot/cli/main.py +20 -0
  8. pfund_plot/config.py +109 -0
  9. pfund_plot/enums/__init__.py +16 -0
  10. pfund_plot/enums/dataframe_backend.py +6 -0
  11. pfund_plot/enums/display_mode.py +7 -0
  12. pfund_plot/enums/panel_design.py +8 -0
  13. pfund_plot/enums/panel_theme.py +6 -0
  14. pfund_plot/enums/plotting_backend.py +12 -0
  15. pfund_plot/js_tap/components/candlestick.js +9566 -0
  16. pfund_plot/mixins/streaming_market_feed_mixin.py +162 -0
  17. pfund_plot/plots/altair.py +32 -0
  18. pfund_plot/plots/area/__init__.py +82 -0
  19. pfund_plot/plots/area/bokeh.py +151 -0
  20. pfund_plot/plots/bar/__init__.py +80 -0
  21. pfund_plot/plots/bar/bokeh.py +128 -0
  22. pfund_plot/plots/bokeh.py +32 -0
  23. pfund_plot/plots/candlestick/__init__.py +77 -0
  24. pfund_plot/plots/candlestick/bokeh.py +124 -0
  25. pfund_plot/plots/candlestick/svelte.py +161 -0
  26. pfund_plot/plots/holoviews.py +32 -0
  27. pfund_plot/plots/label/__init__.py +43 -0
  28. pfund_plot/plots/label/bokeh.py +89 -0
  29. pfund_plot/plots/layout/__init__.py +98 -0
  30. pfund_plot/plots/layout/layout.py +116 -0
  31. pfund_plot/plots/layout/panel.py +51 -0
  32. pfund_plot/plots/layout/tabs/__init__.py +36 -0
  33. pfund_plot/plots/layout/tabs/panel.py +51 -0
  34. pfund_plot/plots/lazy.py +408 -0
  35. pfund_plot/plots/line/__init__.py +37 -0
  36. pfund_plot/plots/line/bokeh.py +137 -0
  37. pfund_plot/plots/matplotlib.py +32 -0
  38. pfund_plot/plots/plot.py +1131 -0
  39. pfund_plot/plots/plotly.py +32 -0
  40. pfund_plot/plots/scatter/__init__.py +62 -0
  41. pfund_plot/plots/scatter/bokeh.py +158 -0
  42. pfund_plot/plots/scatter/marker.py +107 -0
  43. pfund_plot/plots/ta.py +6 -0
  44. pfund_plot/renderers/base.py +84 -0
  45. pfund_plot/renderers/browser.py +28 -0
  46. pfund_plot/renderers/desktop.py +109 -0
  47. pfund_plot/renderers/notebook.py +92 -0
  48. pfund_plot/typing.py +29 -0
  49. pfund_plot/utils/__init__.py +176 -0
  50. pfund_plot/utils/bokeh.py +177 -0
  51. pfund_plot/widgets/base.py +76 -0
  52. pfund_plot/widgets/datetime_widget.py +221 -0
  53. pfund_plot/widgets/ticker_widget.py +82 -0
  54. pfund_plot-0.0.1.dist-info/METADATA +148 -0
  55. pfund_plot-0.0.1.dist-info/RECORD +57 -0
  56. pfund_plot-0.0.1.dist-info/WHEEL +4 -0
  57. pfund_plot-0.0.1.dist-info/entry_points.txt +6 -0
pfund_plot/config.py ADDED
@@ -0,0 +1,109 @@
1
+ from __future__ import annotations
2
+
3
+ from pathlib import Path
4
+ from typing import Any, ClassVar
5
+
6
+ import panel as pn
7
+ from pfund_kit.config import Configuration
8
+
9
+ from pfund_plot.enums import PanelDesign, PanelTheme
10
+
11
+ __all__ = [
12
+ "configure",
13
+ "get_config",
14
+ ]
15
+
16
+
17
+ project_name = "pfund_plot"
18
+ _config: PFundPlotConfig | None = None
19
+
20
+
21
+ def get_config() -> PFundPlotConfig:
22
+ """Lazy singleton - only creates config when first called.
23
+ Also loads the .env file.
24
+ """
25
+ global _config
26
+ if _config is None:
27
+ _config = PFundPlotConfig()
28
+ return _config
29
+
30
+
31
+ def configure(
32
+ data_path: str | None = None,
33
+ cache_path: str | None = None,
34
+ static_dirs: dict[str, str] | None = None,
35
+ disable_widgets: bool | None = None,
36
+ theme: PanelTheme | str | None = None,
37
+ design: PanelDesign | str | None = None,
38
+ persist: bool = False,
39
+ ):
40
+ """Configures the global config object.
41
+ It will override the existing config values from the existing config file or the default values.
42
+ Args:
43
+ theme: the theme to use for the panel, equivalent to pn.config.theme. default is 'default'.
44
+ static_dirs: a dict of static directories to be used in pn.serve(static_dirs=...)
45
+ write: If True, the config will be saved to the config file.
46
+ """
47
+ config = get_config()
48
+ config_dict = config.to_dict()
49
+ config_dict.pop("__version__")
50
+
51
+ static_dirs = static_dirs or {}
52
+ assert isinstance(static_dirs, dict), "static_dirs must be a dict"
53
+ assert "assets" not in static_dirs, "'assets' is a reserved key in static_dirs"
54
+
55
+ # Apply updates for non-None values
56
+ for k in config_dict:
57
+ v = locals().get(k)
58
+ if v is not None:
59
+ if "_path" in k:
60
+ v = Path(v)
61
+ elif k == "theme":
62
+ v = PanelTheme[v.lower()]
63
+ elif k == "design":
64
+ v = PanelDesign[v.lower()]
65
+ setattr(config, k, v)
66
+
67
+ config.ensure_dirs()
68
+
69
+ if persist:
70
+ config.save()
71
+
72
+ return config
73
+
74
+
75
+ class PFundPlotConfig(Configuration):
76
+ DEFAULT_FILES: ClassVar[dict[str, bool]] = {}
77
+
78
+ def __init__(self):
79
+ from pfund_kit.utils import load_env_file
80
+
81
+ _ = load_env_file(verbose=False)
82
+ super().__init__(project_name=project_name, source_file=__file__)
83
+
84
+ def _initialize_from_data(self):
85
+ assert isinstance(self._data, dict), "self._data is not a dict"
86
+
87
+ self.disable_widgets: bool = self._data.get("disable_widgets", False)
88
+ self.theme = self._data.get("theme", PanelTheme.default)
89
+ self.design = self._data.get("design", PanelDesign.native)
90
+ pn.extension(theme=self.theme)
91
+ pn.extension(design=self.design)
92
+
93
+ self.static_dirs = self._data.get("static_dirs", {})
94
+ project_root = self._paths.project_root
95
+ assert project_root is not None, "project_root is not set"
96
+ self.static_dirs["assets"] = str(project_root / "js-tap" / "static")
97
+
98
+ def to_dict(self) -> dict[str, Any]:
99
+ return {
100
+ **super().to_dict(),
101
+ "disable_widgets": self.disable_widgets,
102
+ "theme": self.theme,
103
+ "design": self.design,
104
+ "static_dirs": self.static_dirs,
105
+ }
106
+
107
+ def prepare_docker_context(self):
108
+ """Prepare docker context (e.g. env variables) before running compose.yml"""
109
+ pass
@@ -0,0 +1,16 @@
1
+ from pfund_kit.enums.notebook_type import NotebookType
2
+
3
+ from pfund_plot.enums.dataframe_backend import DataFrameBackend
4
+ from pfund_plot.enums.display_mode import DisplayMode
5
+ from pfund_plot.enums.panel_design import PanelDesign
6
+ from pfund_plot.enums.panel_theme import PanelTheme
7
+ from pfund_plot.enums.plotting_backend import PlottingBackend
8
+
9
+ __all__ = [
10
+ "DataFrameBackend",
11
+ "DisplayMode",
12
+ "NotebookType",
13
+ "PanelDesign",
14
+ "PanelTheme",
15
+ "PlottingBackend",
16
+ ]
@@ -0,0 +1,6 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class DataFrameBackend(StrEnum):
5
+ tabulator = "tabulator"
6
+ perspective = "perspective"
@@ -0,0 +1,7 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class DisplayMode(StrEnum):
5
+ notebook = "notebook"
6
+ browser = "browser"
7
+ desktop = "desktop"
@@ -0,0 +1,8 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class PanelDesign(StrEnum):
5
+ native = "native"
6
+ material = "material"
7
+ fast = "fast"
8
+ bootstrap = "bootstrap"
@@ -0,0 +1,6 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class PanelTheme(StrEnum):
5
+ default = light = "default"
6
+ dark = "dark"
@@ -0,0 +1,12 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class PlottingBackend(StrEnum):
5
+ panel = "panel" # HACK: for general stuff (e.g. GridStack) that don't fall into other plotting backends
6
+ holoviews = "holoviews" # for directly passing in holoviews objects only using plt.holoviews()
7
+ bokeh = "bokeh"
8
+ svelte = "svelte"
9
+ plotly = "plotly"
10
+ altair = "altair"
11
+ matplotlib = "matplotlib"
12
+ perspective = "perspective"