Skip to content

SPARKLINE: implement the Google Sheets in-cell chart function #766

Description

@hhimanshu

What

Implement SPARKLINE, a Google Sheets function TrueCalc does not currently have. Confirmed absent: no match for sparkline anywhere under crates/.

Why

SPARKLINE is a real conformance gap. It is one of the few Sheets functions whose result is a miniature chart rather than a scalar, and it is widely used for trend columns inside tables. Any consumer rendering a Sheets-compatible grid needs the engine to accept and validate it, even if that consumer draws the pixels itself.

Signature

SPARKLINE(data, [options])
  • data — a range or array. For most chart types a single row or column; for bar mode, two values.
  • options — an optional 2-column range or inline array of key/value pairs, e.g. {"charttype","column"; "color","red"}.

Google Sheets' documented option keys include charttype (line | bar | column | winloss), color, lowcolor, highcolor, firstcolor, lastcolor, negcolor, axis, axiscolor, ymin, ymax, linewidth, max, min, empty, nan, rtl. Do not take that list as ground truth — verify against the live oracle before implementing (see below).

The design question this raises

SPARKLINE returns something that is not a number, string, bool, date or error — it is a render spec. That does not fit the existing Value shape, so this needs a deliberate decision before code:

  1. A new Value variant carrying the parsed spec, which every consumer must then handle; or
  2. A distinct typed value that renders as a spec and coerces predictably elsewhere (what does =SPARKLINE(A1:A5)+1 do? what does LEN() of it do? what does it export as?)

Whatever is chosen, the cross-surface determinism guarantee still applies: the same workbook must produce the same result everywhere. Decide and record this before implementing — it is the load-bearing part, not the option parsing.

Ground truth first — do not self-confirm

Per the repo's rules, expected values come from the Google Sheets conformance fixtures, never from reasoning about what Sheets probably does. Before implementing:

  • Confirm the accepted option keys, their casing/synonyms, and their defaults.
  • Confirm the error behaviour: what happens with a non-range data, an odd-shaped options, an unknown option key, a bar sparkline given three values, empty/blank cells inside the range, text inside the range.
  • Confirm what charttype defaults to when omitted.

Fixtures are immutable ground truth; add rows through the fixtures pipeline rather than hand-writing expected values.

Acceptance criteria

  • A recorded decision on how a non-scalar render spec fits the value model, including coercion and export behaviour
  • SPARKLINE parses data + options and validates them, with Sheets-matching errors for malformed input
  • Conformance fixture rows covering: each charttype, omitted charttype, colour options, ymin/ymax, blanks inside the range, text inside the range, wrong-arity bar, unknown option key, malformed options shape
  • Tests live in separate test files (not inline #[cfg(test)] blocks), per the repo convention
  • The function is listed by the function-registry surfaces and documented
  • CI green

Notes

Renderers already exist on the consumer side, so the engine work here is parsing, validation and the value-model decision — not drawing. Scope this issue to the engine.

Metadata

Metadata

Assignees

Labels

functionsFormula function implementations

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions