Skip to content

Commit f130968

Browse files
refactor: change to OOP and support using svelte (e.g. tradingview's lightweight-charts)
1 parent 71b4023 commit f130968

38 files changed

+1562
-794
lines changed

docs/CONTRIBUTING.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,61 @@ The same logic can be applied to other plotting libraries as long as `panel` sup
6262
e.g. there are also `pn.pane.Bokeh`, `pn.pane.Matplotlib`, `pn.pane.ECharts`, `pn.pane.HoloViews`, etc.
6363

6464

65+
## Svelte + AnyWidget Integration
66+
67+
For advanced UI components not available in the Python ecosystem, we use **Svelte components with AnyWidget** integration:
68+
69+
### Architecture Overview
70+
```
71+
pfund-plot/
72+
├── ui/ # Frontend components
73+
│ ├── src/
74+
│ │ ├── components/ # Pure Svelte components
75+
│ │ │ └── tradingview/
76+
│ │ │ └── Candlestick.svelte
77+
│ │ └── widgets/ # AnyWidget wrappers
78+
│ │ └── tradingview/
79+
│ │ └── candlestick/
80+
│ │ ├── index.ts # AnyWidget export
81+
│ │ └── CandlestickWrapper.svelte
82+
├── vite.config.ts # SvelteKit web app & dashboards
83+
└── vite.widget.config.ts # AnyWidget builds for notebooks
84+
```
85+
86+
### Component Development Workflow
87+
88+
1. **Pure Svelte Components** (`ui/src/components/`)
89+
- Build reusable UI components independent of AnyWidget
90+
- Can be used in web apps via `pnpm dev`
91+
- Example: `Candlestick.svelte` takes `data` prop
92+
93+
2. **AnyWidget Wrappers** (`ui/src/widgets/`)
94+
- Thin wrappers that handle AnyWidget bindings
95+
- Each widget folder contains:
96+
- `index.ts` - exports `defineWidget()`
97+
- `*Wrapper.svelte` - handles `bindings` prop from Python
98+
99+
3. **Build Process**
100+
- `pnpm build:widget` - builds widgets for Jupyter/Marimo
101+
- Auto-discovers all `src/widgets/**/index.ts` files
102+
- Outputs standalone ES modules in `dist/`
103+
104+
105+
### When to Use Svelte Components
106+
- Complex interactive visualizations (TradingView charts, custom controls)
107+
- JavaScript libraries not available in Python ecosystem
108+
- Need for high-performance frontend interactions
109+
- Custom UI components that benefit from reactive frameworks
110+
111+
### Development Commands
112+
```bash
113+
cd ui/
114+
pnpm dev # Develop components in web app
115+
pnpm build:widget:watch # Build widgets with hot reload
116+
pnpm build:widget # Production widget builds
117+
```
118+
119+
65120
## Dataframe Manipulation
66121
`pfund-plot` supports `pandas`, `polars` and `dask` dataframes. If you need to manipulate the input dataframe, please use the [narwhals] library.
67122

pfund_plot/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
dataframe_plot as df,
1010
)
1111
from pfund_plot.plots.candlestick import (
12-
candlestick_plot as candlestick,
13-
candlestick_plot as ohlc,
14-
candlestick_plot as kline,
12+
candlestick,
13+
candlestick as ohlc,
14+
candlestick as kline,
1515
)
1616
from pfund_plot.layout import layout
1717

@@ -26,7 +26,7 @@
2626
Matplotlib = pn.pane.Matplotlib
2727
Bokeh = pn.pane.Bokeh
2828
Plotly = pn.pane.Plotly
29-
Vega = pn.pane.Vega
29+
Altair = Vega = pn.pane.Vega
3030

3131

3232
__version__ = version("pfund_plot")
@@ -35,7 +35,7 @@
3535
"Matplotlib",
3636
"Bokeh",
3737
"Plotly",
38-
"Vega",
38+
"Vega", "Altair",
3939
"get_config",
4040
"configure",
4141
"candlestick",

pfund_plot/_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212

1313

1414
tDisplayMode = Literal['notebook', 'browser', 'desktop']
15-
tPlottingBackend = Literal['bokeh', 'plotly']
15+
tPlottingBackend = Literal['bokeh', 'svelte'] # TODO: add 'plotly', 'altair', 'matplotlib' etc.
1616
tDataframeBackend = Literal['tabulator', 'perspective']

pfund_plot/const/enums/__init__.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

pfund_plot/const/enums/data_type.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

pfund_plot/enums/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from pfund_plot.enums.notebook_type import NotebookType
2+
from pfund_plot.enums.dashboard_type import DashboardType
3+
from pfund_plot.enums.plotting_backend import PlottingBackend
4+
from pfund_plot.enums.display_mode import DisplayMode
5+
from pfund_plot.enums.dataframe_backend import DataFrameBackend
File renamed without changes.

0 commit comments

Comments
 (0)