Themes & Palettes¶
django-d3-bridge includes a theme system that controls colors, typography, and styling.
Built-in Themes¶
| Theme | Description |
|---|---|
default |
Neutral, Tableau 10 palette, transparent background |
dark |
Dark background, cool palette |
bootstrap |
Matches Bootstrap 5 colors |
terraf |
Earth tones, DM Sans font |
auto |
Follows the browser's prefers-color-scheme (see below) |
Or override in the template:
Auto Theme (light/dark)¶
With theme="auto", the chart follows the browser's prefers-color-scheme:
light mode renders the default theme, dark mode the dark theme — and the
chart re-renders live when the OS or browser switches mode.
The light/dark pair is configurable globally:
# settings.py
D3_BRIDGE = {
"AUTO_THEMES": ("bootstrap", "dark"), # (light, dark) — default: ("default", "dark")
}
Custom themes registered with register_theme() can be used in the pair.
Built-in Palettes¶
| Palette | Colors |
|---|---|
tableau10 |
Classic 10-color categorical (default) |
warm |
Oranges and reds |
cool |
Blues |
earth |
Greens (agriculture, environment) |
sahel |
Warm browns and oranges |
ocean |
Deep blues and teals |
categorical8 |
8-color categorical |
Override the palette independently of the theme:
Or pass a custom list:
Note
CSS custom properties and modern color functions (var(--brand-500),
oklch(60% 0.15 250), ...) work too — the runtime resolves them
through the browser's own style engine before handing them to D3, so
they behave the same as a plain hex value on every chart type,
including sequential color scales (Contour, Density, Choropleth).
Theme Properties¶
Each theme is a dictionary with these keys:
| Property | Description |
|---|---|
palette |
List of colors for data encoding — hex, rgb()/hsl(), named colors, CSS custom properties (var(--brand-500)), or modern color functions (oklch(), color-mix(), ...) |
background |
Chart background ("transparent" or hex) |
fontFamily |
Font family ("inherit" = from page CSS) |
fontSize |
Base font size (px) |
titleFontSize |
Title font size (px) |
axisColor |
Axis line color |
gridColor |
Grid line color |
gridOpacity |
Grid line opacity |
textColor |
Text color |
tooltipBg |
Tooltip background |
tooltipBorder |
Tooltip border color |
tooltipColor |
Tooltip text color |
animationDuration |
Default animation duration (ms) |
animationEasing |
D3 easing function name |
Register Custom Themes¶
from d3_bridge.themes import register_theme, register_palette
# Custom palette
register_palette("brand", ["#1a1a2e", "#16213e", "#0f3460", "#e94560"])
# Custom theme
register_theme("brand_theme", {
"palette": ["#1a1a2e", "#16213e", "#0f3460", "#e94560"],
"background": "transparent",
"fontFamily": "'Inter', sans-serif",
"fontSize": 13,
"titleFontSize": 18,
"axisColor": "#555",
"gridColor": "#ddd",
"gridOpacity": 0.3,
"textColor": "#1a1a2e",
"tooltipBg": "#fff",
"tooltipBorder": "#ddd",
"tooltipColor": "#1a1a2e",
"animationDuration": 600,
"animationEasing": "easeCubicOut",
})
Then use it:
Tip
Register themes in your Django app's AppConfig.ready() method so they're available everywhere.