Metadata-Version: 2.4
Name: xpectral-chart
Version: 1.0.0
Summary: Fluent Bokeh charting for Polars and Pandas DataFrames
Project-URL: Homepage, https://github.com/bayquant/xpectral-chart
Author: BayQuant
License: MIT License
        
        Copyright (c) 2025 BayQuant
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Keywords: bokeh,charting,pandas,polars,visualization
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.12
Requires-Python: >=3.12
Requires-Dist: bokeh==3.8.1
Requires-Dist: pandas>=2.3.3
Requires-Dist: polars>=1.34.0
Requires-Dist: pyarrow>=21.0.0
Description-Content-Type: text/markdown

# Xpectral Chart

![Spectral decomposition](assets/xpectral_banner.gif)

Fluent Bokeh charting that extends **Polars** and **Pandas** DataFrames via the
accessor pattern: `df.bokeh.line(...)`, `df.bokeh.scatter(...)`, and more.

Part of the Xpectral project, alongside [`xpectral-quant`](https://github.com/bayquant/xpectral-quant)
(financial metrics and market data). Both install into the shared `xpectral`
namespace and can be used together.

## Usage

```python
import xpectral.charts  # registers the df.bokeh accessor
from xpectral.charts import PandasDataFrame
from xpectral.charts import PolarsDataFrame

df: PolarsDataFrame = pl.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
fig = df.bokeh(title="Example", width=600, height=400)
fig.line(x="x", y="y")

pd_df: PandasDataFrame = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]})
pd_fig = pd_df.bokeh(title="Example", width=600, height=400)
pd_fig.line(x="x", y="y")
```

Importing `xpectral.charts` is what registers the accessor on Polars and Pandas
DataFrames. Annotate sample DataFrames with `PolarsDataFrame` or
`PandasDataFrame` when you want the editor (pyright) to resolve the
`df.bokeh(...)` parameters and chained accessor methods — annotation is
necessary for type hinting, as accessors are not discovered dynamically.

### Custom chart methods

Use `BokehAccessor.register` to add your own methods to the accessor. The
decorated function receives `self` — the accessor instance — giving access to
`self._df`, `self.source`, `self.plot`, and all built-in glyph methods.

```python
from xpectral.charts import BokehAccessor

@BokehAccessor.register
def price_band(self, mid, upper, lower, **kwargs):
    self.line(y=mid, **kwargs)
    self.varea(y1=lower, y2=upper, fill_alpha=0.2, **kwargs)

fig = df.bokeh(title="Bands", width=800, height=400)
fig.price_band(mid="close", upper="upper", lower="lower")
```

The method is available on both Polars and Pandas accessors immediately after
registration.

See [`xpectral/charts/README.md`](xpectral/charts/README.md) for the module-level
documentation (glyph methods, stacks, auto-color, themes, datetime axes).

## Install

```bash
pip install xpectral-chart
```

```bash
uv add xpectral-chart
```

For development:

```bash
uv sync
```
