diagram_core/src/data.rs#
Source: lib/diagram_core/src/data.rs
data -- (JD18) external data in a document: connections, recordsets with their rows, rows
linked to shapes (DA-04, DA-05, DF-12)
doc.data: DataSets connections, recordsets (Document::data; diagram_io reads and
writes them as Visio's connections.xml, recordsets.xml and one
recordset part per recordset)
Recordset columns, the key (or the row order), the cached rows (shown
without file or network access), the links row -> shape,
refresh settings and conflicts as Visio keeps them
Recordset::from_table(..) a new recordset from columns and rows (types guessed per column)
doc.data_link(shape, rs) the row a shape is linked to; doc.data_links(shape) all of them
rs.shapes_of(row) the shapes linked to a row (page ID, shape ID)
Transactions (undo like every edit; they return the Value cells written, for the formula
engine's recalc_cells):
add_recordset(tx, conn, rs) -> the recordset's ID (IDs and a unique name handed out)
remove_recordset(tx, id) the recordset, its links, its connection when no other uses it
set_recordset(tx, rs) replace one (column settings, refresh interval, name ...)
link(tx, shape, rs, row) bind a row to a shape: one Property row per column (Label,
Type, Value, DataLinked = 1); a shape has at most one row of
a recordset, an earlier one is replaced
unlink(tx, shape, rs) the binding goes, the shape data stays with its last values
auto_link(tx, shapes, rs, pairs, replace) AS-04: a column against a shape field (text,
name or a shape data field) -> the rows bound where they match
refresh(tx, rs, columns, rows, now) DA-05: new data for a recordset: rows matched by key
(or by order), linked shapes updated, conflicts reported;
missing_key(doc, rs, columns): key columns the source lacks
(refresh refuses those)
user_edited(tx, sheet, name) a user's change of a linked value: DataLinked = 0, so a
refresh keeps it (unless the recordset overwrites all)
resolve_* what the user decides about a conflict
Visio's rules (MS-VSDX 2.2.10.2, 2.3.4.2.39): a column maps to the shape data rows whose name
(N) equals the column's Name; a RowMap binds a row (RowID) to a shape (PageID, ShapeID);
with PrimaryKey elements the key columns identify a row across refreshes, without them
(RowOrder = 1) its position does; RefreshOverwriteAll = 0 updates only the Value cells whose
row has DataLinked = 1. Row IDs start at 1 in the order of the source (Visio's DataAsXML).
Visio's codes stay as they are in the model: Type and DataType 0 text, 1 fixed list,
2 number, 3 Boolean, 4 variable list, 5 date, 6 duration, 7 currency. New columns get Visio's
row names ("_VisDM_" and the source name's letters and digits, ROW_PREFIX).
struct DataSetsthe document's external data: Visio's DataConnections and DataRecordSetsconnections: Vec<Connection>-- the connections (an Excel workbook, a text file ...)next_connection: u32-- NextID of DataConnectionsrecordsets: Vec<Recordset>-- the recordsets in file order (the External Data pane's tabs)next_recordset: u32-- NextID of DataRecordSetsactive: Option<u32>-- ActiveRecordsetID: the tab shownwindow_order: Option<String>-- DataWindowOrder as writtenconnections_attrs: Vec<(String, String)>-- unknown attributes of DataConnectionsrecordsets_attrs: Vec<(String, String)>-- unknown attributes of DataRecordSets
struct Connectiona data connection (DataConnection)id: u32-- ID, unique among the connectionsfile_name: String-- FileName: an .odc or data source file ("" when the connection string says it all)connection_string: Option<String>-- ConnectionString (an OLE DB / ODBC string; see excel_connection, text_connection)command: Option<String>-- Command: the queryfriendly_name: Option<String>-- FriendlyNametimeout: Option<u32>-- Timeoutalways_use_file: Option<bool>-- AlwaysUseConnectionFileattrs: Vec<(String, String)>-- unknown attributes as read
struct Columna column of a recordset (DataColumn)id: String-- ColumnNameID: the column's name in the source, unique in the recordsetname: String-- Name: the name of the shape data rows (Prop.<Name>) the column maps to, uniquelabel: String-- Label: what the user sees (the shape data label; renaming a column changes it)orig_label: Option<String>-- OrigLabellang: Option<String>-- LangID as written: Visio writes a culture name ("de-DE"), not the number [MS-VSDX]'s schema namescalendar: Option<u16>-- Calendardata_type: u16-- DataType (kind::*)unit_type: Option<String>-- UnitTypecurrency: Option<u16>-- Currencydegree: Option<u32>-- Degreedisplay_width: Option<u32>-- DisplayWidthdisplay_order: Option<u32>-- DisplayOrdermapped: Option<bool>-- Mappedhyperlink: Option<bool>-- Hyperlinkattrs: Vec<(String, String)>-- unknown attributes as read
enum DataValuea cell of a recordset's rowEmpty-- no valueText(String)-- textNum(f64)-- a numberBool(bool)-- a truth valueDate(f64)-- a date: days since 30 December 1899 (the fraction is the time of day)Currency(f64)-- an amount of money
impl DataValue
fn text(&self) -> Stringthe value as the External Data pane shows it and as keys and matching compare it: numbers in their shortest form, dates "2026-11-23" (with " 14:05:00" when there is a time), TRUE / FALSEfn kind(&self) -> u16the data type a value of this kind has (kind::*)struct DataRowa row of a recordset with its Visio row IDid: u32-- the row ID (from 1; stays the same across refreshes while the key matches)values: Vec<DataValue>-- one value per column, in the order of Recordset::columns
struct RowLinka row bound to a shape (RowMap; RefreshConflict has the same three numbers)row: u32-- RowIDpage: u32-- PageID: the ID of the shape's pageshape: u32-- ShapeID: the shape's ID on that page
struct Keya key column with the key value of every row (PrimaryKey with its RowKeyValue elements)column: String-- ColumnNameID of the key columnvalues: Arc<Vec<(u32, String)>>-- (RowID, value) per row
struct AutoLinkAutoLinkComparison as read (which column was compared with which shape field)column: String-- ColumnNamecontext: u32-- ContextTypelabel: Option<String>-- ContextTypeLabel
struct Recordseta recordset (DataRecordSet): what a source delivered and how its rows are bound to shapesid: u32-- ID, unique among the recordsetsconnection: Option<u32>-- ConnectionID (None: data without connection, e.g. pasted XML)command: Option<String>-- Command: the queryoptions: Option<u32>-- Options (bit 1: no refresh)time_refreshed: Option<String>-- TimeRefreshed as written ("2026-11-23T14:05:00")next_row: u32-- NextRowID: the next free row IDname: String-- Name: the tab's name in the External Data panerow_order: bool-- RowOrder: without key columns the position identifies a rowoverwrite_all: bool-- RefreshOverwriteAll: a refresh overwrites values the user changed toono_reconcile_ui: Option<bool>-- RefreshNoReconciliationUIrefresh_interval: u32-- RefreshInterval in minutes (0: none)replace_links: Option<u32>-- ReplaceLinkschecksum: Option<u32>-- Checksumcolumns: Vec<Column>-- DataColumns: the columnssort_column: Option<String>-- SortColumn of DataColumnssort_asc: Option<bool>-- SortAsc of DataColumnskey: Vec<Key>-- the key columns with their values (empty: the row order identifies rows)links: Vec<RowLink>-- RowMap: rows bound to shapesconflicts: Vec<RowLink>-- RefreshConflict: bound shapes whose row was not found at the last refreshauto_link: Vec<AutoLink>-- AutoLinkComparison as readrows: Arc<Vec<DataRow>>-- the cached rows (the recordset part); shared so that an undo step is cheapraw: Option<Arc<Vec<u8>>>-- the recordset part as read when it could not be understood: written back unchangedattrs: Vec<(String, String)>-- unknown attributes as read
impl Recordset
fn from_table(name: &str, headers: &[String], rows: Vec<Vec<DataValue>>, key: &[String]) -> Recordseta new recordset from a table: one column per header (types guessed from the values), row IDs from 1;key: the source names of the key columns (empty: the row order). IDs and the name are handed out by add_recordset.fn column_by_id(&self, id: &str) -> Option<usize>the column with this source name (ColumnNameID)fn column_by_name(&self, name: &str) -> Option<usize>the column with this shape data name (Name)fn row(&self, id: u32) -> Option<&DataRow>a row by IDfn shapes_of(&self, row: u32) -> impl Iterator<Item = (u32, u32)> + '_the shapes a row is bound to: (page ID, shape ID)fn row_of(&self, page: u32, shape: u32) -> Option<u32>the row a shape is bound tofn no_refresh(&self) -> boolwhether refreshing is switched off for it (Options bit 1)fn key_of(&self, row: &DataRow) -> Stringa row's key as text (the key columns' values joined by TAB; the row ID without key)fn update_key_values(&mut self)recompute the RowKeyValue lists from the rows (after a change of rows or key columns)
/// the prefix of the shape data rows Visio makes for a linked column ("Prop._VisDM_Ports")
ROW_PREFIX: &str = "_VisDM_"
fn guess_kind<'a>(values: impl Iterator<Item = &'a DataValue>) -> u16the data type of a column from its values: number, date, Boolean or currency when every non-empty value is one, else textenum ExcelTablewhat an Excel connection reads: the table name of the OLE DB provider ("Tabelle1$" a sheet, "Tabelle1$A1:C9" a range of a sheet, "Geräte" a named range)Sheet(String)-- a whole sheet (its used range)Range(String, String)-- a range of a sheet ("A1:C9")Name(String)-- a named range of the workbook
impl ExcelTable
fn ole(&self) -> Stringthe provider's table name: "Tabelle1$", "Tabelle1$A1:C9", "Geräte"fn parse(table: &str) -> ExcelTablea provider's table name back (quotes around a sheet name removed)enum Sourcewhat a connection reads, as far as JFDiagrammer can read it itselfExcel { path: String, table: ExcelTable, header: bool }-- an Excel workbook: its path, the sheet, range or named range, whether the first row holds the column namesText { path: String, header: bool }-- a text file (CSV): its path, whether the first row holds the column namesOther-- anything else (a database, a SharePoint list): shown from the cache, not refreshed
fn excel_connection(path: &str, table: &ExcelTable, header: bool) -> (String, String)the connection string and command Visio writes for an Excel workbook (the ACE OLE DB provider, as Visio's data selector does; Visio refreshes through it)fn text_connection(path: &str, header: bool) -> (String, String)the connection string and command for a text file (the ACE text driver; Visio's "Other OLE DB" path): the folder is the data source, the file the tablefn source_of(data: &DataSets, rs: &Recordset) -> Sourcewhat a recordset's connection reads (Source::Other when it is not a workbook or text file JFDiagrammer can open)
impl Document
fn data_ids(&self, shape: ShapeRef) -> Option<(u32, u32)>the page ID and shape ID of a shape on a page (None for master shapes)fn data_shape(&self, page: u32, shape: u32) -> Option<ShapeRef>the shape with this page ID and shape IDfn data_link(&self, shape: ShapeRef, rs: u32) -> Option<u32>the row of recordsetrsa shape is bound tofn data_links(&self, shape: ShapeRef) -> Vec<(u32, u32)>every binding of a shape: (recordset ID, row ID)fn recordset(&self, id: u32) -> Option<&Recordset>a recordset by IDtype Written = (SheetRef, CellAddr)a Value cell a data edit wrote (for Engine::recalc_cells)fn add_recordset(tx: &mut Transaction, conn: Option<Connection>, mut rs: Recordset) -> Result<u32, EditError>add a recordset (and its connection, if any) -> the recordset's ID. The connection gets the next connection ID, the recordset the next recordset ID and a name no other has ("Daten", "Daten (2)" ...); it becomes the active one.fn remove_recordset(tx: &mut Transaction, id: u32) -> Result<(), EditError>remove a recordset with its links (the shape data stays); its connection goes too when no other recordset uses itfn set_recordset(tx: &mut Transaction, rs: Recordset) -> Result<(), EditError>replace a recordset (same ID): its name, columns' labels and types, refresh settings ...fn set_connection(tx: &mut Transaction, conn: Connection) -> Result<(), EditError>replace a connection (same ID)fn set_active(tx: &mut Transaction, id: u32) -> Result<(), EditError>make a recordset the active one (the tab the External Data pane shows)
/// the Property cell that says a value comes from linked data (1) or was changed by the user (0)
DATA_LINKED: &str = "DataLinked"
fn link(tx: &mut Transaction, shape: ShapeRef, rs: u32, row: u32) -> Result<Vec<Written>, EditError>bind a row to a shape on a page: the shape's earlier row of this recordset is replaced, one shape data row per column gets the row's value -> the Value cells writtenfn unlink(tx: &mut Transaction, shape: ShapeRef, rs: Option<u32>) -> Result<(), EditError>remove a shape's binding to recordsetrs(None: to every recordset); the shape data stays with its last values, marked as no longer linkedfn user_edited(tx: &mut Transaction, sheet: SheetRef, name: &str) -> Result<(), EditError>a user changed the value of shape data fieldname(the Shape Data pane, a dialog): when it came from linked data, it is marked as the user's (DataLinked = 0), so that a refresh keeps it and reports it as a conflict insteadenum ShapeFieldthe shape field a column is compared with by auto_linkText-- the shape's textName-- the shape's name (Name, else NameU)Data(String)-- a shape data field by row name (Prop.<name>)
fn shape_field(doc: &Document, shape: ShapeRef, field: &ShapeField) -> Option<String>what a shape shows for a field (None: the shape has no such field)fn auto_link(tx: &mut Transaction, shapes: &[ShapeRef], rs: u32, pairs: &[(usize, ShapeField)], replace: bool) -> Result<(Vec<(ShapeRef, u32)>, Vec<Written>), EditError>AS-04: bind rows to shapes where a column's value equals a shape field (all pairs must match; compared as text, trimmed, ignoring case); shapes already bound to the recordset keep their row unlessreplace-> the bindings made (shape, row) and the Value cellsenum Conflicta conflict a refresh foundRowGone { row: u32, shape: ShapeRef }-- the row a shape is bound to is gone from the source (the binding stays until the user decides: resolve_unlink or delete the shape)DuplicateKey { key: String, rows: u32 }-- several new rows have the key of one bound row; the first one was takenUserValue { shape: ShapeRef, column: String, user: String, data: DataValue }-- the user changed a linked value and the source changed it too; the user's value stayed
struct Refreshedwhat refresh didadded: usize-- rows that are newchanged: usize-- rows whose values changedremoved: usize-- rows that are goneshapes: usize-- shapes whose data was updatedconflicts: Vec<Conflict>-- what needs the userwritten: Vec<Written>-- the Value cells written
fn missing_key(doc: &Document, rs: u32, headers: &[String]) -> Vec<String>the key columns of recordsetrs(their source names) that the source'sheaderslack: refresh refuses such data (ask the user to choose the key again)fn refresh(tx: &mut Transaction, rs: u32, headers: &[String], rows: Vec<Vec<DataValue>>, now: &str) -> Result<Refreshed, EditError>DA-05: new data for recordsetrs(the source's columns by name and its rows in source order). Rows keep their IDs while their key matches (without key: their position); new rows get new IDs; columns keep their Name, label and type when the source still has them, new ones are added. Every bound shape gets the new values -- a value the user changed (DataLinked = 0) only when the recordset overwrites all, else it stays and is reported. Shapes whose row is gone stay bound and are reported (and kept as RefreshConflict).nowis the time to note ("2026-11-23T14:05:00"). Invalid, with nothing changed, when the source lacks a key column (missing_key): matched by position instead, each bound shape got another row's data without a wordfn resolve_take_data(tx: &mut Transaction, shape: ShapeRef, rs: u32, column: &str) -> Result<Vec<Written>, EditError>a conflict resolved by taking the source's value over the user's (DataLinked = 1 again)fn resolve_unlink(tx: &mut Transaction, shape: ShapeRef, rs: u32) -> Result<(), EditError>a conflict resolved by keeping the shape without its row: the binding goes
mod kind
Visio's data type codes (a column's DataType, a shape data row's Type)
/// text (string)
TEXT: u16 = 0
/// fixed list
FIXED_LIST: u16 = 1
/// number
NUMBER: u16 = 2
/// Boolean
BOOL: u16 = 3
/// variable list
VAR_LIST: u16 = 4
/// date and time
DATE: u16 = 5
/// duration
DURATION: u16 = 6
/// currency
CURRENCY: u16 = 7