JFLib

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 DataSets the document's external data: Visio's DataConnections and DataRecordSets

    • connections: Vec<Connection> -- the connections (an Excel workbook, a text file ...)
    • next_connection: u32 -- NextID of DataConnections
    • recordsets: Vec<Recordset> -- the recordsets in file order (the External Data pane's tabs)
    • next_recordset: u32 -- NextID of DataRecordSets
    • active: Option<u32> -- ActiveRecordsetID: the tab shown
    • window_order: Option<String> -- DataWindowOrder as written
    • connections_attrs: Vec<(String, String)> -- unknown attributes of DataConnections
    • recordsets_attrs: Vec<(String, String)> -- unknown attributes of DataRecordSets
  • struct Connection a data connection (DataConnection)

    • id: u32 -- ID, unique among the connections
    • file_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 query
    • friendly_name: Option<String> -- FriendlyName
    • timeout: Option<u32> -- Timeout
    • always_use_file: Option<bool> -- AlwaysUseConnectionFile
    • attrs: Vec<(String, String)> -- unknown attributes as read
  • struct Column a column of a recordset (DataColumn)

    • id: String -- ColumnNameID: the column's name in the source, unique in the recordset
    • name: String -- Name: the name of the shape data rows (Prop.<Name>) the column maps to, unique
    • label: String -- Label: what the user sees (the shape data label; renaming a column changes it)
    • orig_label: Option<String> -- OrigLabel
    • lang: Option<String> -- LangID as written: Visio writes a culture name ("de-DE"), not the number [MS-VSDX]'s schema names
    • calendar: Option<u16> -- Calendar
    • data_type: u16 -- DataType (kind::*)
    • unit_type: Option<String> -- UnitType
    • currency: Option<u16> -- Currency
    • degree: Option<u32> -- Degree
    • display_width: Option<u32> -- DisplayWidth
    • display_order: Option<u32> -- DisplayOrder
    • mapped: Option<bool> -- Mapped
    • hyperlink: Option<bool> -- Hyperlink
    • attrs: Vec<(String, String)> -- unknown attributes as read
  • enum DataValue a cell of a recordset's row

    • Empty -- no value
    • Text(String) -- text
    • Num(f64) -- a number
    • Bool(bool) -- a truth value
    • Date(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) -> String the 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 / FALSE

  • fn kind(&self) -> u16 the data type a value of this kind has (kind::*)

  • struct DataRow a row of a recordset with its Visio row ID

    • id: 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 Key a key column with the key value of every row (PrimaryKey with its RowKeyValue elements)

    • column: String -- ColumnNameID of the key column
    • values: Arc<Vec<(u32, String)>> -- (RowID, value) per row
  • struct Recordset a recordset (DataRecordSet): what a source delivered and how its rows are bound to shapes

    • id: u32 -- ID, unique among the recordsets
    • connection: Option<u32> -- ConnectionID (None: data without connection, e.g. pasted XML)
    • command: Option<String> -- Command: the query
    • options: 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 ID
    • name: String -- Name: the tab's name in the External Data pane
    • row_order: bool -- RowOrder: without key columns the position identifies a row
    • overwrite_all: bool -- RefreshOverwriteAll: a refresh overwrites values the user changed too
    • no_reconcile_ui: Option<bool> -- RefreshNoReconciliationUI
    • refresh_interval: u32 -- RefreshInterval in minutes (0: none)
    • replace_links: Option<u32> -- ReplaceLinks
    • checksum: Option<u32> -- Checksum
    • columns: Vec<Column> -- DataColumns: the columns
    • sort_column: Option<String> -- SortColumn of DataColumns
    • sort_asc: Option<bool> -- SortAsc of DataColumns
    • key: Vec<Key> -- the key columns with their values (empty: the row order identifies rows)
    • links: Vec<RowLink> -- RowMap: rows bound to shapes
    • conflicts: Vec<RowLink> -- RefreshConflict: bound shapes whose row was not found at the last refresh
    • auto_link: Vec<AutoLink> -- AutoLinkComparison as read
    • rows: Arc<Vec<DataRow>> -- the cached rows (the recordset part); shared so that an undo step is cheap
    • raw: Option<Arc<Vec<u8>>> -- the recordset part as read when it could not be understood: written back unchanged
    • attrs: Vec<(String, String)> -- unknown attributes as read

impl Recordset

  • fn from_table(name: &str, headers: &[String], rows: Vec<Vec<DataValue>>, key: &[String]) -> Recordset a 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 ID
  • fn 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 to
  • fn no_refresh(&self) -> bool whether refreshing is switched off for it (Options bit 1)
  • fn key_of(&self, row: &DataRow) -> String a 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>) -> u16 the data type of a column from its values: number, date, Boolean or currency when every non-empty value is one, else text

  • enum ExcelTable what 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) -> String the provider's table name: "Tabelle1$", "Tabelle1$A1:C9", "Geräte"

  • fn parse(table: &str) -> ExcelTable a provider's table name back (quotes around a sheet name removed)

  • enum Source what a connection reads, as far as JFDiagrammer can read it itself

    • Excel { path: String, table: ExcelTable, header: bool } -- an Excel workbook: its path, the sheet, range or named range, whether the first row holds the column names
    • Text { path: String, header: bool } -- a text file (CSV): its path, whether the first row holds the column names
    • Other -- 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 table

  • fn source_of(data: &DataSets, rs: &Recordset) -> Source what 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 ID

  • fn recordset(&self, id: u32) -> Option<&Recordset> a recordset by ID

  • type 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 it

  • fn 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 user_edited(tx: &mut Transaction, sheet: SheetRef, name: &str) -> Result<(), EditError> a user changed the value of shape data field name (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 instead

  • enum ShapeField the shape field a column is compared with by auto_link

    • Text -- the shape's text
    • Name -- 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)

  • enum Conflict a conflict a refresh found

    • RowGone { 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 taken
    • UserValue { 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 Refreshed what refresh did

    • added: usize -- rows that are new
    • changed: usize -- rows whose values changed
    • removed: usize -- rows that are gone
    • shapes: usize -- shapes whose data was updated
    • conflicts: Vec<Conflict> -- what needs the user
    • written: Vec<Written> -- the Value cells written
  • fn missing_key(doc: &Document, rs: u32, headers: &[String]) -> Vec<String> the key columns of recordset rs (their source names) that the source's headers lack: 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 recordset rs (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). now is 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 word

  • fn 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)

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

Source: docs/API.md in the JFLib repository.