Some services only report a value as it is now, like a net worth or a battery level. A sparkline's points can be a history rule instead: the Mac records the rule's number each time the source answers and draws the readings it has kept.
{ "id": "trend", "type": "sparkline", "label": "Net worth, 60 days", "unit": "USD",
"source": { "ref": "money", "map": { "points": { "history": "net", "every": "1d", "keep": 60 } } } }| Setting | ||
|---|---|---|
history | required | A rule giving a number, here the derived net. |
every | optional | One reading per period, 1d by default, at least 1m. A later reading in the same period replaces the earlier one, so with 1d the day's last answer is its point. Days start at midnight on the Mac. |
keep | optional | How many readings to keep, the newest, from 2 to 60. Default 60. |
Until there are two readings, the card says it's collecting them. Only a sparkline's points take a history rule. The card's labels, start_label and end_label come from the readings' times unless the page sets them, each point labelled the way the ends are: with 1d or longer, the first reading's date ("Oct 28") and "Today" (or the last reading's date when it wasn't today); more often, the first reading's time and "Now" while the last reading is at most one and a half periods old, each with its date when it isn't today's. They stay true on their own: at midnight, and when "Now" runs out, the card is drawn again from the readings kept, without asking the service. A lowered keep drops the oldest readings, and their labels, at once.
Another page's readings
A home page can show readings another page keeps, as they are, without recording them again: { "history_of": "net-worth#trend.points" } names the page id, the card and its points. The chart opens with every reading that card has, and the other page goes on recording them. every (default 1d) says how far apart they are, for the labels, and keep (2–60) how many of the newest to show. The card says it's collecting readings until that history has two.
{ "id": "worth", "type": "sparkline", "label": "Net worth", "unit": "USD",
"source": { "ref": "money", "map": { "points": { "history_of": "net-worth#trend.points", "keep": 30 } } } }The readings are kept on the Mac, not in the page file, so rewriting the page keeps them, and each Mac has its own. They're kept in History's database, listed in Settings → History under "Sparkline readings" by page, with Export… and Delete… for each page, and included in Export history…. They're removed five minutes after their page leaves the Pages folder. They start when the rule is added: there's nothing to backfill from, and the Mac records only while Legato is running and the source answers.
Use history_of to show a sparkline's numbers on another page. To collect and query whole rows across pages, use a dataset. See History.