Bruno DelorenceBruno
Appearance
Appearance

Choose your reading theme.

Contact

Insight thread

New

An analytics assistant’s thread: the queries it ran, sources with previews, an annotated chart of what dropped and when, and a composer with @table mentions.

insight-thread/insight-thread.tsx
Live · interactive

Activation drop, last 14 days

Why did activation drop last week?

Activation fell from 41% to 33%. Nearly all of the loss is at email verification, and it is all in Android sign-ups since the 2.14 release.

Email verified, by platform

Line chart of the share of sign-ups who verified their email, by day from October 6 to 19. Web holds near 90% and iOS near 85%. Android holds near 79% until release 2.14 ships on October 13, then falls to 44% by October 19, 35 points under its expected level.

Daily, Oct 6 – 19 · dashed = expectedActivated 33% · was 41%

Since 2.14, Android opens the verification link in an in-app browser that drops the session, and a third of those users never return to the app. Sending the link back to the system browser, as 2.13 did, should win back most of the drop.

The live component, numbered part by part. Every measurement is read from it as it is drawn. Point at a row to outline its part, or at a part to find its row.

The choices it offers, each value drawn live and the default marked, with how to pick one.

When to use

  • An assistant that answers questions about a team’s data, where each answer has to show its work: the queries it ran and the tables and docs it read.
  • A finding worth explaining in one place: the answer in a sentence, a chart annotated with what changed and when, and what to do next.
  • Follow-up questions about the same data, where naming a table with @ keeps the assistant on the right source.
  • Answers whose form the asker chooses: a sentence, a small chart or a table, over a range and against last week.

When not to use

  • A general chat assistant with no data behind it. The sources, queries and charts would stay empty; use a plain message list.
  • A dashboard someone checks every day. Pin the chart to a dashboard; a thread is for one question and its follow-ups.
  • Running or editing SQL by hand. Use a query editor with results; the thread shows queries, it does not let you change them.
  • Long reports with many charts. Write a doc; past two or three charts, a thread is hard to scan.

Placement and size

  • A panel or page of its own, one thread at a time. The window grows to 760 px wide and centres itself in what is left.
  • Its layout answers to its container, not the screen: at 560 px and under, the range shows its icon only and the gap label drops “vs expected”; at 400 px and under, the title gets a row of its own, with the picker and Share under it.
  • maxHeight (560 px by default) is how tall the thread gets before it scrolls inside its own box, keeping its end in view. Set it to the room the panel has.

Shaping an answer

  • answer comes first: what changed, by how much and where, in a sentence or two.
  • Then chart or table, never both: the table takes the chart’s place. Past one chart, a thread is hard to scan.
  • Mark the change on the chart: anomaly turns a series red from the day it left its expected level and hatches the gap; marker names what happened that day.
  • followUp goes under the chart with the why and what to do; suggestion is the next question, asked when pressed.
  • List in sources every table or doc the answer read, and in thought the queries it ran, so the answer can be checked.

New questions

  • onAsk hears every question sent, with the tables it mentions and the format, range, comparison and model it was sent with. Run the question from there.
  • The answers the thread writes back to new questions come from its own sample tables. Wire it to your data before it shows real figures.
  • tables lists what “@” offers, with row counts; models fills the picker, the first one chosen.

Each one drawn with the component itself, used well or badly.

Every piece of a thread is written to be read in order: the finding, the proof, then what to do.

  • The title: the finding as a noun phrase, sentence case, no full stop: Refund spike on Tuesday.
  • The question: as someone would ask it, with the metric and the time: Why did activation drop last week?
  • The answer: the figures first, with the before and after: Activation fell from 41% to 33%.
  • The chart: a title naming what is measured and how it is split (Email verified, by platform), a caption with the range, and a headline with the figure.
  • The marker: what happened, in two or three words (2.14 shipped), with its date under it.
  • describe: the chart in sentences for screen readers, with the figures a sighted reader would take from it.
  • The suggestion: the next question, short enough for a chip: Compare 2.13 vs 2.14.
  • Sources: the table or doc names as they are in your warehouse, so people can find them.

You can add this component with the shadcn CLI or by hand:

Into components/insight-thread of any React project, with no setup:

Terminal
npx shadcn@latest add https://brunodelorence.com/r/insight-thread.json

Either way it needs React 19 and a bundler that supports CSS Modules, such as Next.js or Vite. It has a dark colour scheme: it follows your page’s color-scheme, light unless the page sets one, or its colorScheme prop, with nothing to configure. Browsers without light-dark() show it light.

Usage

ask-page.tsx
import { InsightThread } from './insight-thread';export function AskPage() {  return (    <InsightThread      assistant="Wren"      defaultFormat="chart"      defaultRange="30d"      onAsk={(question, options) => runQuestion(question, options)}      autoplay={false}    />  );}

Each state below is a live instance, locked so you can study it.

The pieces it is built from, each with its measurements read live.

Below are variations of this component, each live, with its code.

Table answer

A thread about churn answered with a table instead of a chart, and the composer set to answer new questions with tables too.

Still streaming

A breakdown by @signups channel asked a moment ago: the queries running, the answer halfway written, and Send turned into Stop.

Refund spike

A different anomaly: card refunds jump eighteen points over their expected level after a gateway timeout, so the gap and its label sit above the line.

Composer only

No thread yet: the composer alone, answering in text. The first question grows a thread above it.

One question about the data and its answer, laid out so the work shows. “Thought for 12 s · ran 3 queries” opens to the queries; the sources are chips that preview their columns; the chart draws each platform, the one that fell in red from the day a release shipped, its expected level dashed and the gap hatched with its size. The composer turns “@” into a menu of tables and the one picked into a token, picks the answer’s format, range and comparison, and streams the answer back with a small chart or table. Light and dark.

  • The chart is SVG drawn in real px: a ResizeObserver reads its box, so the text never stretches and the labels are HTML over it. Each line is a run of cubic curves whose handles follow the neighbouring days. A series with an anomaly turns red from its first day off, a dashed line holds its expected level, and the gap between them is filled with a hatch pattern and labelled with its size in points.
  • The values at the right end are sorted by height and pushed apart so none overlap. The release marker’s label goes under the lines, or over them when the lines run low, as in the refund spike.
  • The crosshair follows the pointer (or the arrow keys, Home and End) to the nearest day: a dot on each series and a tooltip with the values, highest first, that flips to the left past the middle. The legend’s buttons turn series off, and the gap goes with its series.
  • The composer is a line of parts: text, @table tokens, and the field being typed. A space or the start followed by “@” and letters opens the Tables menu, filtered by those letters; Enter or a press turns the match into a token. Backspace in the empty field takes back the last part whole.
  • A question is answered from its words and the tables it mentions: a breakdown by channel, a comparison of versions, or activation by platform. The format picks bars, a table or text alone; the range dilutes the drop over a longer window; the comparison adds last week as ticks on the bars or a change column.
  • The answer thinks for a moment, then streams two words at a time; Send turns into Stop meanwhile. Under reduced motion it comes all at once. The thread scrolls inside its own box and keeps its end in view.
  • The model picker sets how long the next answer thinks and how many queries it runs. Share and Copy write to the clipboard; the thumbs up is a toggle.
  • While on screen and untouched, a demo pointer opens the queries, reads the chart a day at a time, types “Break it down by @”, picks signups, types “channel” and sends. Any real input hands it over; it comes back after 9 s of quiet.
PropTypeDefaultDescription
threadThread | nullACTIVATIONThe conversation it opens on: title, question, the queries behind it, the answer, sources, a line chart or a table, the follow-up and a suggestion. null opens on the composer alone. ACTIVATION, REFUNDS and CHURN are exported.
assistantstring'Wren'The assistant’s name, in the composer’s placeholder and what it announces.
modelsModel[]threeThe header’s model picker: name, a note and how long it thinks. The first is chosen.
tables{ name: string; rows: string }[]fourThe tables “@” lists, with their row counts.
defaultFormat'text' | 'chart' | 'table''chart'How new answers come back at first.
defaultRange'7d' | '30d' | '90d''30d'The range new answers cover at first.
onAsk(question: string, options) => void—Called with each question sent, its mentioned tables, and the format, range, comparison and model it was sent with.
maxHeightnumber560The thread’s height before it scrolls on its own, in px.
autoplaybooleantrueWhile on screen and untouched, a demo pointer shows the main interactions. Any real input stops it.
defaultStateInsightThreadState—Opens held in a moment (queries open, a day read, a menu open, a question half answered), with the demo off.
colorScheme'light' | 'dark' | 'system'—Light or dark colours, or the reader’s; without it, the page’s color-scheme.
classNamestring—Classes for the stage.

Screen readers

  • The thread is a section named by its title; each question and answer is an article named by its question, marked busy while its answer streams.
  • A polite live region announces the answer once it is complete, not word by word, and says when a table is added to the question.

The chart

  • The chart says in words what it shows: its describe text is tied to the plot by aria-describedby.
  • The plot takes the focus: the Left and Right arrows, Home and End read a day at a time into a live region, and Escape clears it. The legend’s buttons are aria-pressed.
  • Colour is never the only sign of the change: the expected level is dashed, the gap is hatched and labelled with its size in points (WCAG 1.4.1, A).
  • Every word, figure and end label is at least 4.5:1 against its surface in both schemes (WCAG 1.4.3, AA), and the lines, marks and switch track at least 3:1 (WCAG 1.4.11, AA).

Keyboard

The composer’s field is a combobox: “@” opens a listbox of tables, the arrows move through it, Enter or Tab picks and Escape closes. Enter sends; Backspace in an empty field takes back the last part whole. The model and range menus move with the arrows, Home and End, and Escape closes them with the focus back on their button. The format is a radiogroup moved with the arrows; the comparison is a switch.

Motion

Under reduced motion nothing slides, blinks or streams: an answer comes all at once, and the demo never plays. Otherwise the pointer over it holds the demo, and the first press, key or wheel stops it for good (WCAG 2.2.2, A).

In this build

  • The thread is a section named by its title; each question and answer is an article named by its question, busy while its answer streams. The answer is announced in a polite live region once it is complete, not word by word.
  • The chart says in words what it shows. Its plot takes the focus: the arrow keys, Home and End read a day at a time into a live region, and Escape clears it. The legend’s buttons are aria-pressed.
  • The source chips are buttons whose preview is a tooltip linked by aria-describedby, shown on hover and on focus and closed by Escape.
  • The composer’s field is a combobox: “@” opens a listbox of tables, the arrows move aria-activedescendant, Enter or Tab picks and Escape closes. The model and range are menu buttons whose menus move with the arrows and close on Escape with the focus back on their button.
  • The format is a radiogroup moved with the arrow keys; the comparison is a switch; dictation is a toggle button. Send is aria-disabled until there is a question, and becomes Stop while an answer streams.
  • Under reduced motion nothing slides, blinks or streams and the demo never plays. The demo pointer is decorative.

The complete source behind this demo. Open source under the MIT license, © 2026 Bruno Delorence: copy it, change it, ship it.

insight-thread.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import {  useEffect,  useEffectEvent,  useId,  useLayoutEffect,  useRef,  useState,  type CSSProperties,  type KeyboardEvent as ReactKeyboardEvent,} from 'react';import { AnswerBars, AnswerTable, LineChart, chartX } from './charts';import {  ACTIVATION,  MODELS,  RANGES,  TABLES,  answerFor,  type Answer,  type Format,  type Model,
charts.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import {  useEffect,  useId,  useRef,  useState,  type CSSProperties,  type KeyboardEvent as ReactKeyboardEvent,  type PointerEvent as ReactPointerEvent,} from 'react';import type { BarSpec, LineChartSpec, TableSpec } from './data';import styles from './insight-thread.module.css';/* * The charts in the thread, hand-drawn: * * - LineChart, the annotated one: a line per series, the dropping (or jumping) one red from the *   day it leaves its expected level, a dashed line where it was expected and the gap hatched *   between them with its size, a marker on the day something shipped, values at the ends, and a *   crosshair with the day's values under the pointer or the arrow keys. It is drawn in real px *   (its width read by a ResizeObserver), so the text never stretches; labels and the tooltip are
insight-thread.module.css
/* Insight thread (insight-thread.tsx): an analytics assistant's window on a grey stage, near-black   by night and white by day. The header, the thread in an inset panel that scrolls on its own,   and the composer with its tools under it. The charts (charts.tsx) use the same tokens.   Colours are the tokens below, light-dark(light, dark) where the two differ: the component takes   the color-scheme it inherits from the page, or the one its colorScheme prop sets   (data-color-scheme). */.root {  --stage: #e9e9ec;  --window: #ffffff;  --panel: #f7f7f8;  --line: #e7e7ea;  --line-2: #dcdce1;  --ink: #18181b;  --ink-2: #66666e;  --ink-3: #6d6d73;  --bubble: #ededf0;  --chip: #ffffff;  --hover: #f1f1f3;  --card: #ffffff;  --grid: #d9d9de;  --menu: #ffffff;  --menu-active: #f0f0f3;
data.ts
// Copyright (c) 2026 Bruno Delorence. MIT License./* * The insight thread's content: the thread it opens on (a question, the queries the assistant * ran, its answer, the sources and an annotated chart), the tables the composer can mention, and * the answers it writes for new questions. Answers are read from the question's words, the * tables it mentions, the format, the range and the comparison, so every option changes them. */export type Tone = 'green' | 'violet' | 'amber' | 'red' | 'blue';/** One line of the annotated chart. */export type Series = {  id: string;  name: string;  tone: Tone;  /** One value a day, in percent. */  values: number[];  /** From this day on the line runs off the level it was expected at: drawn red, the gap hatched. */  anomaly?: { from: number; expected: number };};export type LineChartSpec = {  title: string;
menu.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import {  useEffect,  useLayoutEffect,  useRef,  useState,  type KeyboardEvent as ReactKeyboardEvent,  type ReactNode,} from 'react';import { Icon } from './glyphs';import styles from './insight-thread.module.css';/* * The menus: placed on the stage under their trigger (over it when there is no room below), in * the stage's own px, since a gallery card may scale the whole stage. The arrows, Home and End * move between items; Escape closes and gives the focus back; a press elsewhere closes. */const ITEMS = '[role="menuitem"], [role="menuitemradio"]';export function Menu({
glyphs.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License./* * The thread's line icons: a 24-unit box, drawn with currentColor. The sparkle is filled. */const PATHS = {  chevronDown: 'M7 10l5 5 5-5',  chevronRight: 'M10 7l5 5-5 5',  share: 'M12 15V4M7.5 8.5 12 4l4.5 4.5M5 13v6.5h14V13',  table: 'M4 5h16v14H4zM4 10h16M10 10v9',  doc: 'M7 3.5h7l4 4V20.5H7zM14 3.5V8h4',  copy: 'M9 9h11v11H9zM5 15V4h11',  thumb:    'M7.5 10.5v9M7.5 10.5l3.6-6.3c1.2 0 2.2 1 2.1 2.3l-.4 3.2h5c1.1 0 1.9 1 1.7 2.1l-1.2 6.2c-.2.9-1 1.5-1.9 1.5H7.5M7.5 10.5H4v9h3.5',  plus: 'M12 5v14M5 12h14',  lines: 'M5 7h14M5 12h14M5 17h9',  bars: 'M5 4v15.5h15M9 16v-5M13 16V8M17 16v-7',  calendar: 'M4.5 6h15v14h-15zM4.5 10h15M8.5 3.5v4M15.5 3.5v4',  mic: 'M12 3.5a3 3 0 0 0-3 3v5a3 3 0 0 0 6 0v-5a3 3 0 0 0-3-3zM6 11.5a6 6 0 0 0 12 0M12 17.5v3',  arrowUp: 'M12 19V5M6.5 10.5 12 5l5.5 5.5',  enter: 'M19 6v5a3 3 0 0 1-3 3H6M9.5 10.5 6 14l3.5 3.5',  check: 'M5 12.5l4.5 4.5L19 7.5',  query:
demo-pointer.tsx
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import type { CSSProperties, Ref } from 'react';/* * The demo's pointer, and the steps that move it. A demo is a script of awaited steps: wait, or * glide the pointer somewhere. Stopping the demo (the reader takes over, or it scrolls away) ends * the step in progress at once: its promise rejects, which ends the script right there, and the * pointer fades out. * * Each glide is a curved flight played by the Web Animations API, so nothing runs frame by frame. * The points of the flight are handed to whoever wants to move along with it. The arrow and the * hand are HTML boxes * that swap by their visibility: a change of style inside an SVG would lay the SVG out again. */export type Point = { x: number; y: number };/** A glide's path and timing, for an animation that plays along with it. */export type Flight = { points: Point[]; timing: KeyframeAnimationOptions };export type Demo = {
use-autoplay.ts
// Copyright (c) 2026 Bruno Delorence. MIT License.'use client';import { useCallback, useEffect, useRef, useState } from 'react';/* * When a demo may play on its own: while part of it is on screen and the tab is visible, never * under reduced motion, and never again once the reader has used it. `take()` (a press, a key or * the wheel) hands it to the reader for good, until the component remounts. `pause()` (the * pointer moving over it) only holds it, and it carries on `idle` ms after the pointer stops. */export function useAutoplay<T extends HTMLElement>(idle = 6000) {  const ref = useRef<T>(null);  const [visible, setVisible] = useState(false);  const [reduced, setReduced] = useState(true);  const [taken, setTaken] = useState(false);  const [paused, setPaused] = useState(false);  const timer = useRef(0);  useEffect(() => {    const element = ref.current;    if (!element) return;    let onScreen = false;