Elicit.js

Theming & style

The theme holds every default colour, font and affordance token. Pass a partial theme on Elicit or on any widget. It deep-merges over the built-in defaults, so you name only what you change. A per-datum paint channel (fill, stroke) wins over any theme token. A theme can also set effects defaults, and effects on the spec overrides them. Twenty named themes ship with the library: theme: "nyt" restyles a whole chart from one word.

API reference

theme (on Elicit)

The style layer, passed as theme on Elicit (or on any widget). A partial, deep-merged over the built-in DEFAULT_THEME — you name only the tokens you change. Precedence, most specific first: a per-datum channel/option > theme.marks[name] > the theme token > the renderer default.

theme: { extends, ink, accent, muted, handle, handleStroke, background, palette, ramp, diverging,
         font, title, subtitle, caption, axis, grid, panel, bandPadding, guide, constraint,
         effects, ghost, widget, marks }
theme: "nyt"   // a named theme — see /theming/themes
Options19
OptionType · defaultDescription
ink
stringdefaultsteelblue
The primary mark colour — every mark that has no explicit paint channel reads it (bar, point, line, area, rect, …).
accent
stringdefault#2563eb
Interactive emphasis: draggable handles, a committed survey answer, an editable-axis handle.
muted
stringdefault#9ca3af
Secondary ink — a de-emphasised mark, a supporting label.
handle / handleStroke
stringdefault#2563eb / #fff
Grip fill and rim. A line or area fills its grips with the series’ own colour instead, keeping handleStroke as the rim. A mark’s own handleColor still wins.
background
string | nulldefaultnull
The chart backdrop, applied as the svg/canvas CSS background (margin band included). null is transparent (the host page shows through); set it for a self-contained dark-mode chart — see themes.dark.
palette / ramp / diverging
string[]defaultTableau10 · blues · RdBu
Colour-scale defaults for a fill/stroke channel that names no explicit range or scheme.
font
{ family, size, labelSize, titleSize }defaultfamily: null
Typography. A non-null family is emitted on the root svg (and used by the canvas renderer) so every label inherits it; the default null inherits the host page's font.
extends
theme name
Start from a named theme; the rest of the object deep-merges over it. A bare string (theme: "nyt") is the same as { extends: "nyt" }.
axis
{ stroke, strokeWidth, line, tickSize, tickPadding, labelFill, fontSize, fontFamily, fontWeight, labelAngle, labelAlign, labelOffset, titleFill, titleFontSize, titleFontWeight, titlePadding, titleAnchor, handle, discrete, continuous }defaultgrey spine, 6px ticks
Axis chrome. Each token is also an axis() option of the same name, and the option wins. line: false drops the spine; tickSize: 0 the ticks. discrete and continuous override any token for axes of that kind — { continuous: { line: false } } drops the value-axis spine and keeps the category one.
grid
{ stroke, strokeWidth, strokeDash, opacity, show, zero, bandPosition }defaultshow: "none"
Gridline paint, and which implicit axes get a grid you did not ask for: "none", "value" (the axis the value runs along), "continuous" or "all". zero draws an emphasised line at 0, { stroke, strokeWidth, strokeDash }.

themes

The twenty named themes: default, survey, surveyBlocks, surveyLines, dark and dd, plus fourteen house styles from Flint. Each is a partial — pass it (or its name) as theme, or start from one with extends.

themes.default · survey · dark
themes.nyt · economist · bbc · datawrapper
themes.swiss · nature · deStijl
themes.mckinsey · powerbi · powerbiLight
themes.apple · material · pop · cartoon

setTheme(partial)

Set the application-wide default theme. Every chart created afterwards inherits it unless it passes its own theme, which layers on top. Pass null to reset.

setTheme(themes.survey)
setTheme('economist')
setTheme({ ink: '#4f46e5' })
setTheme(null)

A themed instrument

themes.survey is a built-in theme for survey widgets. Pass it to any widget to restyle the answer ink and the chrome. The behaviour stays the same. It also sets the widgets' design: survey draws outlined boxes, surveyBlocks filled blocks and surveyLines hairlines. The widget tokens are theme.widget, where design names the design and the rest are the colours and sizes it reads.

The survey theme

One object — themes.survey — restyles the ink, the chrome and the design.

// One object restyles the whole instrument: answer ink, chrome, and the
// affordance rings/track/labels all follow themes.survey.
const chart = Elicit(widgets.likert({
question: "How satisfied are you with the result?",
options: ["Very low", "Low", "Neutral", "High", "Very high"],
theme: themes.survey,
}));
mount(chart.dom());
Try: move across the options, click to answer — the look is the only change.

Dark mode

The background token paints the chart's own surface, margins included. themes.dark uses it with light ink, light labels and a slate grid, so it needs no host CSS. The same spec renders light or dark by changing only the theme.

themes.dark

A slate backdrop with light ink and chrome — the chart paints its own surface.

// themes.dark carries a `background` token, so the chart paints its own dark
// surface — light ink, light labels, slate grid, no host CSS required. The same
// spec renders identically light or dark; only the theme changes.
const chart = Elicit({
width: 440, height: 240,
margins: { top: 20, right: 20, bottom: 30, left: 36 },
data: [{ cat: "A", n: 30 }, { cat: "B", n: 55 }, { cat: "C", n: 40 }, { cat: "D", n: 22 }],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
theme: themes.dark,
axes: { x: {}, y: { grid: true } },
marks: [
barY({ channels: { x: { field: "cat" }, y: { field: "n", edit: move() } } }),
],
});
mount(chart.dom());
Try: drag a bar — the interaction is identical, only the palette is dark.

A theme on a plain chart

A theme is a plain object, so it deep-merges cleanly. ink is the primary mark colour, used by every mark with no paint channel of its own. axis and grid style the chrome. A token you name changes, and a token you leave out keeps its default.

Per-chart theme

ink recolours the bars; axis/grid restyle the chrome. Drag a bar — the value axis still works.

// A theme on a plain chart. `ink` recolours every mark that has no explicit
// paint channel; `axis`/`grid` restyle the chrome. A partial — you name only
// the tokens you change, the rest inherit the default.
const chart = Elicit({
width: 440, height: 240,
margins: { top: 20, right: 20, bottom: 30, left: 36 },
data: [{ cat: "A", n: 30 }, { cat: "B", n: 55 }, { cat: "C", n: 40 }, { cat: "D", n: 22 }],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
theme: {
ink: "#EE7B5E",
axis: { stroke: "#BCC9D4", labelFill: "#6F8294" },
grid: { stroke: "#EDF7F8" },
},
axes: { x: {}, y: { grid: true } },
marks: [
barY({ channels: { x: { field: "cat" }, y: { field: "n", edit: move() } } }),
],
});
mount(chart.dom());
Try: drag a bar up or down.

Axes, grids and the plot panel

The axis tokens style every axis: stroke and strokeWidth for the spine and ticks, line: false to drop the spine, tickSize (0 for none) and tickPadding for the gap to the label, labelAngle to turn the labels. Each is also an axis() option, and the option wins. grid.show adds gridlines without a grid() element. panel paints the plot area under the grid and can frame it; background covers the margins too. bandPadding sets the gap between bars.

axis.discrete and axis.continuous override any axis token for axes of that kind. Use them to drop the spine on the value axis and keep it under the categories. grid.show: "value" grids the axis the value runs along: the continuous one, or y when both are. grid.zero draws an emphasised line at 0.

A grey panel, white gridlines

panel, grid, axis and bandPadding tokens, and nothing else.

// The ggplot2 look from tokens alone: a grey panel under white gridlines,
// no spines or ticks, and wider gaps between the bars.
const chart = Elicit({
width: 440, height: 260,
theme: {
panel: { fill: "#EAF0F4" },
grid: { stroke: "#ffffff", strokeWidth: 1.2, show: "all" },
axis: { line: false, tickSize: 3, stroke: "#14283A", labelFill: "#46596B" },
bandPadding: 0.35,
ink: "#46596B",
},
data: [{ cat: "A", n: 30 }, { cat: "B", n: 55 }, { cat: "C", n: 40 }, { cat: "D", n: 22 }],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
axes: { y: { title: "count" } },
marks: [barY({ channels: { x: { field: "cat" }, y: { field: "n", edit: move() } } })],
});
mount(chart.dom());
Try: drag a bar.

Per-kind axes and a zero rule

A spine under the categories, none on the values, a dotted value grid and a rule at 0.

// `axis.discrete` / `axis.continuous` style each KIND of axis apart: a spine
// under the categories, none on the values, a dotted value grid and a rule at 0.
const chart = Elicit({
width: 440, height: 260,
theme: {
axis: {
tickSize: 0, tickPadding: 6,
discrete: { line: true, stroke: "#20555A" },
continuous: { line: false },
},
grid: { show: "value", strokeDash: "1 3", stroke: "#94A5B3", zero: { stroke: "#20555A", strokeWidth: 1.5 } },
},
data: [{ q: "Q1", d: 12 }, { q: "Q2", d: -8 }, { q: "Q3", d: 20 }, { q: "Q4", d: 5 }],
schema: {
q: { type: "categorical", domain: ["Q1", "Q2", "Q3", "Q4"] },
d: { type: "quantitative", domain: [-20, 30] },
},
marks: [barY({ channels: { x: { field: "q" }, y: { field: "d", edit: move() } } })],
});
mount(chart.dom());
Try: drag Q2 above zero.

Typography

font.family sets the chart's typeface. null inherits the page's. title, subtitle and caption each take fontFamily, fontStyle, fontWeight, fontSize and fill, so a headline can be a serif over sans-serif labels. The axis takes fontFamily and fontWeight for its labels and titleFill, titleFontSize and titleFontWeight for its title. A text mark takes fontWeight, fontStyle and fontFamily, each a constant or a channel.

A serif title over sans-serif labels

font, title, subtitle and axis tokens, and a bold text mark.

// Type from the theme: a body family, a serif title, bold axis titles. A text
// mark takes `fontWeight`, `fontStyle` and `fontFamily` per label.
const chart = Elicit({
width: 440, height: 280,
title: "How sure are you?",
subtitle: "Drag each bar to your confidence",
theme: {
font: { family: "'Helvetica Neue', Helvetica, Arial, sans-serif" },
title: { fontFamily: "Georgia, serif", fontSize: 20 },
subtitle: { fontStyle: "italic" },
axis: { titleFontWeight: "bold", titleFill: "#20555A" },
},
axes: { x: false, y: { title: "Confidence (%)" } },
data: [{ claim: "Claim 1", c: 70 }, { claim: "Claim 2", c: 35 }, { claim: "Claim 3", c: 55 }],
schema: {
claim: { type: "categorical", domain: ["Claim 1", "Claim 2", "Claim 3"] },
c: { type: "quantitative", domain: [0, 100] },
},
marks: [
barY({ cornerRadius: 3, channels: { x: { field: "claim" }, y: { field: "c", edit: move() } } }),
text({
dy: -10, fontWeight: "bold", fill: "white",
channels: { x: { field: "claim" }, y: { datum: 0 }, text: { field: "claim" } },
}),
],
});
mount(chart.dom());
Try: drag a bar.

Titles and captions

title, subtitle and caption on the Elicit spec draw text above and below the plot, left-aligned with it. They reserve space the way a legend does: the chart keeps its declared width and height, and the plot shrinks to make room. The theme's title, subtitle and caption tokens style them, each with fill, fontSize, fontWeight, fontFamily and fontStyle (see Typography). A token with no fill takes the axis label colour, so the titles follow a dark theme.

A titled chart with a caption

title, subtitle and caption on the spec; theme.title and theme.caption recolour two of them.

const chart = Elicit({
width: 440, height: 260,
margins: { top: 12, right: 40, bottom: 12, left: 56 },
title: "How will the vote split?",
subtitle: "Drag each bar to your estimate",
caption: "Shares in percent; they need not sum to 100.",
// Title tokens restyle all three; omitted ones keep their defaults.
theme: { title: { fill: "#50AEB7" }, caption: { fill: "#6F8294" } },
axes: { x: false },
data: [{ party: "Left", n: 38 }, { party: "Centre", n: 24 }, { party: "Right", n: 33 }],
schema: {
party: { type: "categorical", domain: ["Left", "Centre", "Right"] },
n: { type: "quantitative", domain: [0, 60] },
},
marks: [
barX({
fill: "#50AEB7",
channels: {
y: { field: "party", scale: { reverse: true } },
x: { field: "n", edit: move() },
},
}),
text({
dx: 6, textAnchor: "start", fontSize: 12, format: ".0f",
channels: { y: { field: "party" }, x: { field: "n" }, text: { field: "n" } },
}),
],
});
mount(chart.dom());
Try: drag a bar — the plot sits between the title block and the caption.

Overrides & precedence

The most specific setting wins. A per-datum channel or mark option beats theme.marks[name], which beats the theme token (ink), which beats the renderer default. A theme sets the overall look, and a single mark can still override it.

Per-mark override

ink colours the bars; theme.marks.point overrides just the dots.

// Precedence, most specific first: a per-datum channel > theme.marks[name] >
// the theme token > the renderer default. Here `ink` colours the bars, but
// theme.marks.point overrides just the dots — and a channel would still win.
const chart = Elicit({
width: 440, height: 240,
margins: { top: 20, right: 20, bottom: 30, left: 36 },
data: [{ cat: "A", n: 30 }, { cat: "B", n: 55 }, { cat: "C", n: 40 }, { cat: "D", n: 22 }],
schema: {
cat: { type: "categorical", domain: ["A", "B", "C", "D"] },
n: { type: "quantitative", domain: [0, 60] },
},
theme: {
ink: "#2B5D87",
marks: { point: { fill: "#F2B94B" } },
},
marks: [
barY({ channels: { x: { field: "cat" }, y: { field: "n" } } }),
point({
size: 6,
channels: { x: { field: "cat" }, y: { field: "n", edit: move() } },
}),
],
});
mount(chart.dom());
Try: drag a dot — its colour comes from theme.marks.point, not ink.

App-wide defaults

Call setTheme(partial) once at startup to theme a whole application. Every chart built afterwards inherits it, and a chart's own theme layers on top. setTheme(themes.survey) makes the survey look the default. setTheme(null) resets to the built-in theme.

import { setTheme, themes } from "elicit-js";
setTheme(themes.survey); // app-wide default
// …every Elicit(...) after this inherits it
setTheme("economist"); // or a named theme by name
setTheme({ ink: "#4f46e5" }); // or just a token or two