Skip to content

Commit 3dc06a7

Browse files
setup svelte ui
1 parent 301ae9d commit 3dc06a7

34 files changed

+9632
-7844
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.ipynb -linguist-detectable
2+
# SCM syntax highlighting & preventing 3-way merges
3+
pixi.lock merge=binary linguist-language=YAML linguist-generated=true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,9 @@ docs/_build/*
187187

188188
# tests data
189189
tests/data/
190+
191+
# pixi environments
192+
.pixi
193+
*.egg-info
194+
195+
.python-version

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ We created a high-level plotting library that combines the best features from ex
2929

3030
---
3131

32-
PFund-Plot is a super high-level, out-of-the-box, domain-specific plotting library designed for traders that supports **financial data visualization**, **dashboard creation**, and **template sharing**.
32+
`pfund-plot` is a super high-level, out-of-the-box, domain-specific plotting library designed for traders, supporting **financial data visualization**, **dashboard creation**, and **template sharing**.
3333

3434

3535
## Core Features
@@ -55,5 +55,5 @@ import pfund_plot as plt
5555
feed = pe.YahooFinanceFeed()
5656
df = feed.get_historical_data(product='AAPL_USD_STK', resolution='1d', rollback_period='1y')
5757

58-
fig = plt.ohlc(df, display_mode='browser', streaming=False)
58+
fig = plt.ohlc(df, mode='browser', streaming=False)
5959
```

docs/getting-started/quickstart/candlestick.ipynb

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
},
1010
{
1111
"cell_type": "code",
12-
"execution_count": 3,
12+
"execution_count": null,
1313
"metadata": {},
1414
"outputs": [
1515
{
@@ -144,13 +144,18 @@
144144
"feed = pe.YahooFinanceFeed(data_tool='pandas')\n",
145145
"df = feed.get_historical_data(product='AAPL_USD_STK', resolution='1d', rollback_period='1y')\n",
146146
"\n",
147-
"fig = plt.ohlc(df, display_mode='notebook', streaming=False)"
147+
"fig = plt.ohlc(df, display_mode='notebook', streaming=False)\n",
148+
"fig"
148149
]
149150
},
150151
{
151152
"cell_type": "code",
152153
"execution_count": 4,
153-
"metadata": {},
154+
"metadata": {
155+
"tags": [
156+
"hide-cell"
157+
]
158+
},
154159
"outputs": [
155160
{
156161
"data": {

pfund_plot/layout.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
@contextmanager
1818
def layout(
1919
streaming: bool = False,
20-
display_mode: Literal['browser', 'desktop'] = 'browser',
20+
mode: Literal['browser', 'desktop'] = 'browser',
2121
num_cols: int = 3,
2222
allow_drag: bool = True,
2323
# FIXME: plots can't be resized when using GridStack, not sure if it's a bottleneck or a bug
2424
# allow_resize: bool = True,
2525
):
26-
assert display_mode.lower() in ['browser', 'desktop'], "display_mode must be 'browser' or 'desktop'"
26+
assert mode.lower() in ['browser', 'desktop'], "mode must be 'browser' or 'desktop'"
2727

2828
# Setup state
2929
state.layout.in_layout = True
@@ -36,7 +36,7 @@ def layout(
3636
components = state.layout.components
3737
return _layout_plot(
3838
*components,
39-
display_mode=display_mode,
39+
mode=mode,
4040
num_cols=num_cols,
4141
allow_drag=allow_drag,
4242
# allow_resize=allow_resize,
@@ -45,7 +45,7 @@ def layout(
4545

4646
def _layout_plot(
4747
*figs: tFigure,
48-
display_mode: Literal['browser', 'desktop'] = 'browser',
48+
mode: Literal['browser', 'desktop'] = 'browser',
4949
num_cols: int = 3,
5050
allow_drag: bool = True,
5151
# allow_resize: bool = False,
@@ -71,4 +71,4 @@ def _layout_plot(
7171

7272
periodic_callbacks = state.layout.periodic_callbacks
7373
state.reset_layout()
74-
return render(gstack, display_mode, periodic_callbacks=periodic_callbacks)
74+
return render(gstack, mode, periodic_callbacks=periodic_callbacks)

pfund_plot/plots/candlestick.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def _create_hover_tool(df: Frame) -> HoverTool:
9494
def candlestick_plot(
9595
data: GenericFrame | BaseFeed,
9696
streaming: bool = False,
97-
display_mode: tDISPLAY_MODE = "notebook",
97+
mode: tDISPLAY_MODE = "notebook",
9898
num_data: int = 100,
9999
raw_figure: bool = False,
100100
slider_step: int = 100,
@@ -112,7 +112,7 @@ def candlestick_plot(
112112
Args:
113113
data: the data to plot, either a dataframe or pfeed's feed object
114114
streaming: if True, the plot will be updated in real-time as new data is received
115-
display_mode: where to display the plot, either "notebook", "browser", or "desktop"
115+
mode: where to display the plot, either "notebook", "browser", or "desktop"
116116
streaming_freq: the update frequency of the streaming data in milliseconds
117117
raw_figure: if True, returns the raw figure object (e.g. bokeh.plotting.figure or plotly.graph_objects.Figure)
118118
if False, returns the holoviews.core.overlay.Overlay object
@@ -130,7 +130,7 @@ def candlestick_plot(
130130
# TODO: using tick data to update the current candlestick
131131

132132

133-
display_mode = DisplayMode[display_mode.lower()]
133+
mode = DisplayMode[mode.lower()]
134134
if state.layout.in_layout:
135135
streaming = streaming or state.layout.streaming
136136
data_type: DataType = validate_data_type(data, streaming, import_hvplot=True)
@@ -141,7 +141,7 @@ def candlestick_plot(
141141
else:
142142
df = data
143143
df: Frame = _validate_df(df)
144-
if display_mode == DisplayMode.notebook:
144+
if mode == DisplayMode.notebook:
145145
height = height or DEFAULT_HEIGHT_FOR_NOTEBOOK
146146

147147

@@ -239,4 +239,4 @@ def _update_plot():
239239
height=height,
240240
width=width,
241241
)
242-
return render(fig, display_mode, periodic_callbacks=[periodic_callback])
242+
return render(fig, mode, periodic_callbacks=[periodic_callback])

pfund_plot/plots/dataframe.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
# EXTEND: maybe add some common functionalities here, e.g. search, sort, filter etc. not sure what users want for now.
3636
def dataframe_plot(
3737
data: GenericFrame | BaseFeed,
38-
display_mode: tDISPLAY_MODE = "notebook",
38+
mode: tDISPLAY_MODE = "notebook",
3939
backend: tDATAFRAME_BACKEND = "tabulator",
4040
streaming: bool = False,
4141
streaming_freq: int = 1000, # in milliseconds
@@ -50,7 +50,7 @@ def dataframe_plot(
5050
'''
5151
Args:
5252
data: the data to plot, either a dataframe or pfeed's feed object
53-
display_mode: where to display the plot, either "notebook", "browser", or "desktop"
53+
mode: where to display the plot, either "notebook", "browser", or "desktop"
5454
streaming: if True, the plot will be updated in real-time as new data is received
5555
streaming_freq: the update frequency of the streaming data in milliseconds
5656
max_streaming_data: maximum number of data points used when streaming.
@@ -71,7 +71,7 @@ def dataframe_plot(
7171
and https://panel.holoviz.org/reference/panes/Perspective.html for Perspective backend.
7272
'''
7373

74-
display_mode, backend = DisplayMode[display_mode.lower()], DataFrameBackend[backend.lower()]
74+
mode, backend = DisplayMode[mode.lower()], DataFrameBackend[backend.lower()]
7575
if state.layout.in_layout:
7676
streaming = streaming or state.layout.streaming
7777
data_type: DataType = validate_data_type(data, streaming, import_hvplot=False)
@@ -84,7 +84,7 @@ def dataframe_plot(
8484
df = convert_to_pandas_df(df)
8585

8686
use_iframe_in_notebook, iframe_style = False, None
87-
if display_mode == DisplayMode.notebook:
87+
if mode == DisplayMode.notebook:
8888
use_iframe_in_notebook = (backend == DataFrameBackend.perspective)
8989
height = height or DEFAULT_HEIGHT_FOR_NOTEBOOK
9090
if 'sizing_mode' not in kwargs:
@@ -101,7 +101,7 @@ def dataframe_plot(
101101
max_streaming_data = SUGGESTED_MIN_STREAMING_DATA_FOR_TABULATOR
102102
notebook_type: NotebookType = get_notebook_type()
103103
# FIXME: this is a workaround for a bug in panel Tabulator, see if panel will fix it, or create a github issue
104-
if display_mode == DisplayMode.notebook and notebook_type in [NotebookType.jupyter, NotebookType.marimo]:
104+
if mode == DisplayMode.notebook and notebook_type in [NotebookType.jupyter, NotebookType.marimo]:
105105
pagination = 'remote'
106106
else:
107107
pagination = 'local'
@@ -166,7 +166,7 @@ def _update_table():
166166

167167
return render(
168168
table,
169-
display_mode,
169+
mode,
170170
periodic_callbacks=[periodic_callback],
171171
use_iframe_in_notebook=use_iframe_in_notebook,
172172
iframe_style=iframe_style,

pfund_plot/plots/orderbook.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# TODO: use perspective to plot orderbook
2121
def orderbook_plot(
2222
data: GenericFrame | BaseFeed,
23-
display_mode: tDISPLAY_MODE = 'notebook',
23+
mode: tDISPLAY_MODE = 'notebook',
2424
streaming: bool = False,
2525
streaming_freq: int = 1000, # in milliseconds
2626
height: int = 600,
@@ -29,15 +29,15 @@ def orderbook_plot(
2929
'''
3030
Args:
3131
height: height of the orderbook plot in pixels.
32-
Only applicable when display_mode is 'notebook'.
32+
Only applicable when mode is 'notebook'.
3333
kwargs: kwargs for pn.pane.Perspective
3434
3535
For all the supported kwargs, and more customization examples,
3636
please refer to https://panel.holoviz.org/reference/panes/Perspective.html.
3737
'''
3838
return dataframe_plot(
3939
data,
40-
display_mode=display_mode,
40+
mode=mode,
4141
streaming=streaming,
4242
streaming_freq=streaming_freq,
4343
backend='perspective',

pfund_plot/renderer.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def run_callbacks(periodic_callbacks: list[PeriodicCallback], notebook_type: Not
6565

6666
def render(
6767
fig: Panel | Pane | Widget,
68-
display_mode: Literal["notebook", "browser", "desktop"] | DisplayMode,
68+
mode: Literal["notebook", "browser", "desktop"] | DisplayMode,
6969
periodic_callbacks: list[PeriodicCallback] | PeriodicCallback | None = None,
7070
use_iframe_in_notebook: bool = False,
7171
iframe_style: str | None = None,
@@ -74,7 +74,7 @@ def render(
7474
Args:
7575
fig: the figure to render.
7676
supports plots from "hvplot", "holoviews" and panels, panes or widgets from "panel"
77-
display_mode: the mode to display the plot.
77+
mode: the mode to display the plot.
7878
supports "notebook", "browser" and "desktop"
7979
plotting_backend: the backend to use for rendering the figure.
8080
supports "bokeh" and "plotly"
@@ -84,8 +84,8 @@ def render(
8484
It is a workaround when the plot can't be displayed in a notebook.
8585
iframe_style: the style of the iframe when use_iframe_in_notebook is True.
8686
'''
87-
if isinstance(display_mode, str):
88-
display_mode = DisplayMode[display_mode.lower()]
87+
if isinstance(mode, str):
88+
mode = DisplayMode[mode.lower()]
8989

9090
if isinstance(periodic_callbacks, PeriodicCallback):
9191
periodic_callbacks = [periodic_callbacks]
@@ -94,7 +94,7 @@ def render(
9494
# NOTE: handling differs between notebook environment and python script
9595
is_notebook_env = (notebook_type is not None)
9696

97-
if display_mode == DisplayMode.notebook:
97+
if mode == DisplayMode.notebook:
9898
if not use_iframe_in_notebook:
9999
panel_fig: Panel | Pane | Widget = fig
100100
run_callbacks(periodic_callbacks, notebook_type)
@@ -121,22 +121,22 @@ def render(
121121
if is_notebook_env:
122122
server: StoppableThread = pn.serve(fig, show=False, threaded=True, port=port)
123123
run_callbacks(periodic_callbacks, notebook_type)
124-
else: # only happens when running layout_plot() where components are all using display_mode="notebook" in a python script
124+
else: # only happens when running layout_plot() where components are all using mode="notebook" in a python script
125125
def run_server():
126126
run_callbacks(periodic_callbacks, notebook_type)
127127
pn.serve(fig, show=False, threaded=True, port=port) # this will block the main thread
128128
thread = Thread(target=run_server, daemon=True)
129129
thread.start()
130130
return panel_fig
131-
elif display_mode == DisplayMode.browser:
131+
elif mode == DisplayMode.browser:
132132
if is_notebook_env:
133133
server: StoppableThread = pn.serve(fig, show=True, threaded=True)
134134
run_callbacks(periodic_callbacks, notebook_type)
135135
return server
136136
else: # run in a python script
137137
run_callbacks(periodic_callbacks, notebook_type)
138138
pn.serve(fig, show=True, threaded=False) # this will block the main thread
139-
elif display_mode == DisplayMode.desktop:
139+
elif mode == DisplayMode.desktop:
140140
port = get_free_port()
141141
title = getattr(fig, 'name', "PFund Plot")
142142
window_ready = Event()
@@ -168,4 +168,4 @@ def run_server():
168168
thread.start()
169169
process.join()
170170
else:
171-
raise ValueError(f"Invalid display mode: {display_mode}")
171+
raise ValueError(f"Invalid display mode: {mode}")

pfund_plot/templates/spreadsheet.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)