#578 Measures: presentation and parsing per measure, and editor fields (#573)
–
- github
- github/openchronology/timeline-app
- github/openchronology/timeline-app#578
- pull request
- state:merged
Closes #573, part 2 of #570. Stacked on #577: until that merges, this diff includes its commit too. Each measure gets its own **printer and parser**, the counterpart of the time display. The editor gets a **Measures** dialog and a field per measure. ## Presentation (`src/measure-presentation.ts`) ```json "cost": { "type": "mpz", "label": "Cost", "presentation": { "mode": "fixed", "scale": "1/100", "decimals": 2, "prefix": "$" } } ``` - **Modes:** - `exact`, the default; - `fixed` decimals, for money: `123456` cents shows as `$1,234.56`; - `decimal` (significant digits); - `scientific`; - `si` (`1500` with unit `Wh` shows as `1.5 kWh`). Each mode takes a scale (shown = stored × scale), a prefix, a unit and thousands separators. - **Purposes:** - **Value and total:** as shown. - **Input:** exact, so text you don't change keeps its exact value. - **Tooltip:** adds the exact value where the label rounds, e.g. `0.33 (exactly 1/3)`. - **Axis:** abbreviated, e.g. `$1.23M`. - **Parsing:** - It accepts the prefix, the unit and commas. - It refuses text it would have to round: `$12.345` for a 2-decimal measure, or half a cent for a whole-number measure in cents. - It never uses floating point. ## Editor (`src/measure-ui.ts`) - **Measures dialog** (toolbar, or Tools on a phone): - **Fields per measure:** label, name (filled in from the label), whole numbers or fractions, and how it's shown. - **Feedback:** a live example, and a summary of what saving does to values ("Cost becomes Price", "the values of X are deleted"). - **Settings changes** (adding, restyling, widening) are recorded as settings edits and undone like others. - **Rewrites:** renaming, removing or narrowing rewrites values, in one of three places: - in the page, as one Undo; - in a large desktop file's store (undo restores the baseline); - on the server, through `POST /measures` with progress. This needs your other changes saved first. - **Forms:** moment and duration details get a field per measure, typed as shown and stored exactly. When the parser refuses a value, its reason is shown. - **Reader:** lists an event's values as each measure shows them. Not here: - **Hover cards, and the reader on server timelines:** values there need overview projections to carry `measures`, which goes with the overviews work in #575. - **Custom printers from plugins:** these go with the plugin API in #575. ## Tests - `test/measure-presentation.test.mjs` (unit). - `test/measures-browser.mjs`, in the browser suite: it declares a currency measure, types `$1,234.56`, refuses `12.345`, renames the measure with one Undo, and checks the reader in View mode. I ran it locally in Chromium. - OpenAPI gains `MeasurePresentation`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_011fFY8eruEi1xAkkMBni13B https://github.com/circagraph/timeline-app/pull/578
Related
- #570 Measures: typed quantities on moments and durations, totalled in every summary
- #573 Measures 2: presentation and parsing per measure, with editor fields
- #575 Measures 4: totals in overviews, cluster labels, the plugin API and the background chart
- #577 Measures: declarations, exact values, validation and formats (#572)
- #579 Measures: totals in the editor's index and its overview groups (#574)
- #580 Measures: totals in the PostgreSQL moment tree and its overviews (#574)
- #582 Measures: totals on summaries, values on hover cards, and plugins (#575)
Open #578 Measures: presentation and parsing per measure, and editor fields (#573) in the timeline