import { Grid } from '@hanzo/ui/grid' import { SizableText, XStack, YStack } from '@hanzo/gui' import { paint } from '../material/paint' /** * The handful of figures a surface opens with, in a row across the top. * * A person arriving at a venue, a treasury or a proposal wants to know the size * of the thing before they read anything in it, and four figures answer that * faster than two drawings do. * * The point of the component is the fourth state. An entry has a figure, or is * still being read, or the reading failed, or the answer is genuinely nothing — * and only the last of those is a zero. One dash drawn for all four is the same * surface that reports an empty venue when its indexer is down. */ /** * What is known about one figure. * * The same three constructors a table's rows have, for the same reason: a read * that failed and a read that came back with nothing are one value in any * client that keeps a string and a flag. `it: null` is the answer that is * genuinely nothing, and `failed` carries a reason and cannot be spelled as an * empty string — which is what puts the flatten-to-zero mistake out of reach. */ export type Figure = | { at: 'reading' } | { at: 'failed'; why: string } | { at: 'read'; it: string | null } export interface Stat { /** What the figure is, in the fewest words that stay unambiguous. */ name: string of: Figure /** What changed, as a proportion, where a change is a thing this figure * has. The sign picks the mark and the hue; `say.percent` writes it. */ change?: number | null } /** * What a tally says that it cannot work out. * * Three words and one formatter. A figure is written by whoever read it and * arrives as text; these are the rest of the line, and they belong to a * language rather than to a component — `today` is `сегодня`, and the sign of a * percentage goes where the reader's own rules put it. */ export interface Said { /** What a change is measured over, set mid-line — "today". */ since: string /** Where a reading failed. Not the same mark as a figure of nothing. */ missing: string /** Where the answer is genuinely nothing. */ none: string /** A proportion, as this reader's percentage. `figures().percent` is one. */ percent(of: number): string } /** * Which way a figure moved, as the mark that sits beside it. * * A triangle rather than a chevron. A chevron says a control opens something, * or that one name follows another, and a direction of travel is a third * statement; drawn with the same glyph they read as a disclosure nobody can * open. Hidden from a reader who is being read to — the sign is in the * percentage, and `Intl` puts it where the language puts it. * * Three marks, because there are three things a figure can have done. A day * that did not move drew the rising triangle, since anything not negative * pointed up, and a mark is read before the digits beside it are: the row said * a treasury had grown on the day it held still. A level rule is what held * still looks like, and it keeps the room the other two stand in, so a row of * five settles at one width whatever the readings were. */ const MARK = 12 const WAY = { up: 'M6 3.5 L10 8.5 L2 8.5 Z', down: 'M6 8.5 L10 3.5 L2 3.5 Z', flat: 'M2 5.5 L10 5.5 L10 6.5 L2 6.5 Z', } as const function Moved({ of, colour }: { of: number; colour: string }) { return ( ) } /** * What the figure did, and over what. * * The period is part of the line rather than a heading over the row: five * entries reading five different quantities all move over the same day, and the * word is what says which day. * * Zero is achromatic. Green because it is not negative reports a flat day as a * good one — but quiet under a plain figure reads as a figure that failed, so * it takes the plain weight and says nothing with hue. */ export function Change({ of, say }: { of: number; say: Said }) { const hue = of === 0 ? paint.plain : of > 0 ? paint.good : paint.bad return ( {/* One element, so the line is one string wherever it is read from. */} {say.percent(of)} {say.since} ) } /** * What an entry puts where the figure goes. * * Four states and four different words. A dash for a reading that failed would * be the same mark as a figure of nothing, which is the substitution this * component exists to avoid. * * The ellipsis stays a mark. It says the same thing in every language, and a * catalog entry holding one character is an entry a translator can only get * wrong. */ export const said = (of: Figure, say: Said): string => of.at === 'reading' ? '…' : of.at === 'failed' ? say.missing : (of.it ?? say.none) /** * The gutter one entry keeps between its rule and its own words, and the room * the change line holds whether or not there is a change to put in it. * * The second is the point. A figure with a change and one without are the same * entry at two heights, so the row settles at a different depth on every read * and whatever is under it moves with the data. Reserved, the row has one * bottom edge in every state, which is what the rest of the page is measured * against. */ const GUTTER = 25 const CHANGE = 'var(--leading-sm)' /** One figure, its name, and what it did. */ function Entry({ of, say }: { of: Stat; say: Said }) { return ( // The rule between two figures, and not around them. A border on all four // sides is a card, and five cards across the top of a page is a dashboard; // one hairline in the gutter is the same separation without the frames. // // Every entry draws one and it stands in the gutter BEFORE it. The entry // reaches back across the gutter to carry it and gives the width straight // back as inset, so the words do not move, and the rule of whichever entry // opens a row falls outside the strip where the wrapper cuts it away. That // is what makes it right at any number of columns: a hairline at the row's // own edge is a line with nothing on the other side of it, and neither an // opening nor a closing edge can be told from one without knowing where the // row breaks. {of.name} {/* The figure carries no weight of its own. Size and colour are the whole of what raises it above its label, and only an entry holding a figure takes the plain colour — so which of the four states it is in is visible before the words are read. Marked, a row of five reads as five buttons. */} {said(of.of, say)} {/* Under the figure rather than beside it: a percentage set on the same baseline as a twenty-point number reads as part of it, and the two are different measurements of different things. */} {of.of.at === 'read' && of.change !== null && of.change !== undefined ? ( ) : null} ) } /** * The reasons, each said once. * * Four entries that all failed because one request went unanswered, each saying * so under itself, is the same sentence four times across the top of a screen — * louder than the figures it replaced, and no more informative than one of * them. Where the reasons genuinely differ, each is still stated. */ export const reasons = (of: readonly Stat[]): string[] => [ ...new Set(of.flatMap((s) => (s.of.at === 'failed' ? [s.of.why] : []))), ] export function Tally({ of, say, columns, }: { of: readonly Stat[] say: Said /** * How many across. * * A fact about the screen rather than about the figures, so a screen that has * measured its own says so. A row over a venue is one row and its count IS * the figures in it; six figures about one asset stand three across two rows, * which is an arrangement six figures do not imply and nothing here could * derive. Unsaid, the count is still the figures. */ columns?: number }) { return ( {/* The wrapper is what cuts away the rule of the entry that opens each row. */} {of.map((s) => ( ))} {reasons(of).map((line) => ( {line} ))} ) }