Streamlit Voronoi Treemap Component (V2)
A custom Streamlit component built on the Streamlit V2 Component Architecture that renders beautiful, dynamic Voronoi Treemaps from pandas DataFrames. It uses D3.js and d3-voronoi-treemap to lay out the data natively in the DOM, avoiding iframe overhead.
Features
- Native Rendering: Built with Streamlit V2 architecture, ensuring native DOM components without iframes.
- Grouped Hierarchies: Supports grouped data to visualize hierarchical relationships.
- Customization Options: Includes controls for color schemes, label scaling, borders, and legends.
- Responsive Sizing: Adapts dynamically to your Streamlit page width.
Installation
You can install this component in editable mode locally:
pip install -e .
To build the frontend, make sure you have npm installed:
cd st_vortree/frontend
npm install
npm run build
Quick Start
Import the custom component and pass a pandas DataFrame with your data. The DataFrame requires at a minimum a name column and a numeric value column.
import streamlit as st
import pandas as pd
from st_vortree import st_vortree
# Sample dataset
data = [
{"Company": "Apple", "Sector": "Tech", "MarketCap": 2800},
{"Company": "Microsoft", "Sector": "Tech", "MarketCap": 2900},
{"Company": "Johnson & Johnson", "Sector": "Healthcare", "MarketCap": 400},
{"Company": "Pfizer", "Sector": "Healthcare", "MarketCap": 200},
]
df = pd.DataFrame(data)
st.title("Voronoi Treemap Example")
# Render grouped Treemap
st_vortree(
df,
name_col="Company",
value_col="MarketCap",
group_col="Sector", # Groups polygons by 'Sector'
color_scheme="tableau10", # Available: tableau10, category10, pastel1, dark, cool, warm
show_values=True,
show_legend=True,
label_scale=1.0,
border_color="#ffffff",
border_width=2,
key="my_vortree"
)
API Reference
st_vortree(df, ...)
Renders a given pandas DataFrame as a Voronoi treemap visualization.
Arguments:
df (pandas.DataFrame): The DataFrame containing the input data.name_col (str): The name of the column containing the labels for the polygons. Defaults to"name".value_col (str): The name of the column containing the numeric sizes of the polygons. Defaults to"value".group_col (str, optional): The name of the column used for grouping features together into a hierarchy. Defaults toNone.color_scheme (str): D3 categorical color scale to apply. Options include"tableau10","category10","pastel1","dark","cool","warm", and"forest"(muted green–brown earth tones). Defaults to"tableau10".show_values (bool): Whether to show the metric value and relative percentage inside the polygon labels. Defaults toFalse.label_scale (float): Scale multiplier for the dynamically sized text labels. Defaults to1.0.border_color (str): Hex color of the polygon outlines. Defaults to"#ffffff".border_width (int): Thickness of the polygon outlines. Defaults to1.show_legend (bool): Whether to draw a legend beside the nodes. Defaults toTrue.key (str, optional): An optional Streamlit key to uniquely identify the component instance.
Architecture Highlights
This component does not use the deprecated V1 architecture's <iframe> mounting framework, making it significantly more performant and natively styled. The D3 logic parses and modifies standard DOM nodes wrapped by a generic Web Component interface (@streamlit/component-v2-lib).
Metadata
Release files for st-vortree 0.1.9
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| st_vortree-0.1.9.tar.gz | 97.3 kB | Without provenance | Details for st_vortree-0.1.9.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| st_vortree-0.1.9-py3-none-any.whl | Python 3 | none | any | Details for st_vortree-0.1.9-py3-none-any.whl |
Total release size: 194.0 kB
Release files / st_vortree-0.1.9.tar.gz
| Download URL | st_vortree-0.1.9.tar.gz |
|---|---|
| Size | 97.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e894cc83259e88f279a1f67ddbe7358e9e80be4796342add35aaf90b429397c9
|
|
BLAKE2b-256 checksum How to use checksums |
e220358fefe901e4c5a7ebc501dcd914b4ba80e8b077050b26f6ea3ef6e100ad
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / st_vortree-0.1.9-py3-none-any.whl
| Download URL | st_vortree-0.1.9-py3-none-any.whl |
|---|---|
| Size | 96.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
886d9c7dae464816929a0eb1676a4d26d323c81cc180a9abc3884eac12d29df8
|
|
BLAKE2b-256 checksum How to use checksums |
675697f56428322b98e7e70f153375db077572e420f5f7d6f127d6e381ee36dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for st-vortree 0.1.9
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.