Expand description
Drawing persistence – JSON serialization and storage.
This module provides types for serializing drawings to and from JSON. The key
design decision is that anchors are stored as (timestamp, price) pairs
(StoredCoord) rather than bar indices or screen positions, so drawings
survive pan/zoom, resolution changes and history being prepended.
§Conversion flow
Drawing (in-memory) StoredDrawing (serializable)
───────────────── ────────────────────────────
chart_points: Vec<ChartPoint> ──────► points: Vec<StoredCoord>
(bar index + price) drawing_to_stored() (timestamp + price)
tool type and settings ──────► drawing: Drawing
chart_points: Vec<ChartPoint> ◄────── points: Vec<StoredCoord>
stored_to_drawing()Screen points are not stored: Drawing::update_screen_coords rebuilds
them from the anchors on the next frame.
A restored drawing keeps the id, creation time and notes of its record in
Drawing::stored_id, created_at and notes, and is saved back under
them. Restore drawings through
DrawingManager::add_synced_drawing,
which refuses a drawing that saving would refuse; the manager then gives a new drawing an
id that no restored drawing uses. Two managers restoring the same storage can still hand
out the same id: one storage per manager is the supported use.
§Storage format
Drawings are grouped by symbol into a DrawingStorage container that
includes a format version, metadata, and an optional timeframe filter.
Loading migrates versions 1 to 5, rejects versions it does not know and
skips any drawing it cannot read
(see from_json).
Structs§
- Drawing
Storage - Drawing storage for saving/loading drawings
- Skipped
Drawing - A drawing
DrawingStorage::from_jsonleft out because it could not be read or its id was already taken. - Storage
Metadata - Storage metadata
- Stored
Coord - A coordinate stored as a
(timestamp, price)pair for persistence. - Stored
Drawing - A fully serializable representation of a drawing with all its properties.
- Stored
Pane - A study pane identified by its studies rather than by a chart’s study ids.
Enums§
- Load
Error - Why drawings were not loaded, by
DrawingStorage::from_json,Chart::load_drawingsorChart::paste_drawings, before any drawing changed. - Save
Error - Why
DrawingStorage::to_jsondid not save. - Skip
Reason - Why
DrawingStorage::from_jsonleft a drawing out. - Storage
Error - A failed read or write of automatic drawing storage, from
Chart::take_storage_error.
Functions§
- drawing_
to_ stored - Convert a Drawing to StoredDrawing, its anchors mapped from bar index to timestamp, under the drawing’s stored id and creation time when it was restored from storage, and under its id and the current time otherwise.
- stored_
to_ drawing - Convert StoredDrawing back to a completed Drawing with id
next_id, its anchors mapped from timestamp to bar index and the record’s id, creation time and notes kept; the screen points follow on the nextDrawing::update_screen_coords.