Render
# render function
packages/forge/src/render.ts:78render(arg1: RenderOptions): (args_0: Fact) => string
render(options: RenderOptions, fact: Fact): stringTurns a {@link Fact} into a sentence.
Rendering is deliberately separate from fact generation: one claim can be
spoken at several lengths, in several languages, with the consumer’s own axis
names — none of which is possible once prose has been baked into the result.
Swap this function out entirely to localise.
Parameters
| Name | Type | Description |
|---|---|---|
| options | RenderOptions | Axis labels, units, and verbosity. |
| fact | Fact | The fact to render. |
Returns
stringA sentence describing the fact.
Examples
const speak = render({ labels: { x: "week", y: "signups" }, units: { y: "users" } });
speak(fact);
// "Each additional unit of week is associated with an increase of 8.23 users
// in signups. At week = 0 the fitted value of signups is 3.53 users."
render({ labels: { x: "week", y: "signups" }, verbosity: "terse" })(fact);
// "signups: up 8.23 per additional unit of week."
# renderAnnotation function
packages/forge/src/render.ts:463renderAnnotation(arg1: RenderOptions): (args_0: Annotation) => string
renderAnnotation(options: RenderOptions, annotation: Annotation): stringTurns an {@link Annotation} into a display label — a legend entry for a
curve, a plot-line caption for a marker.
Lives here for the same reason {@link render} does: without it every consumer
reimplements the
"vertex" → "Vertex" mapping, and they drift apart the
moment a new role is added.Parameters
| Name | Type | Description |
|---|---|---|
| options | RenderOptions | Axis labels and verbosity. Units are unused today. |
| annotation | Annotation | The annotation to label. |
Returns
stringA short label, safe to put in a legend or on an axis.
Example
renderAnnotation({})(curve); // "Linear fit"
renderAnnotation({ labels: { x: "hour" } })(marker); // "Vertex at hour = 3"
# AxisLabels interface
packages/forge/src/render.ts:9interface AxisLabels {
x?: string;
y?: string;
}Axis names, so a rendered fact reads in the reader’s domain rather than in
algebra. “As advertising spend increases, monthly sales tend to increase”
beats “As X increases, Y tends to increase” — especially as chart alt text.
# AxisUnits interface
packages/forge/src/render.ts:15interface AxisUnits {
x?: string;
y?: string;
}Units appended to quantities, e.g.
{ y: "£" } or { x: "days" }.# RenderOptions interface
packages/forge/src/render.ts:20interface RenderOptions {
labels?: AxisLabels;
units?: AxisUnits;
/**
* `"terse"` yields a single clause suitable for an `aria-label` or a tooltip.
* `"full"` yields one to three sentences for a `<desc>` or a body paragraph.
* @default "full"
*/
verbosity?: "terse" | "full";
}