JFLib

diagram_core/src/datagraphic.rs#

Source: lib/diagram_core/src/datagraphic.rs

datagraphic -- (JD19) data graphics: callouts, data bars, icon sets and colours that show a
shape's data (DA-07, DA-08, ST-08), stored as Visio stores them

  DataGraphic, Item, Kind, Pos, Opt, Rule, Op, Shade   the model of a data graphic: its name,
                                  its items (a text callout, a data bar, an icon set, a colour by
                                  value; the field expression "{Label}" or a formula of such
                                  fields, the callout master, the position or the graphic's
                                  default, the options, icon rules, colours), the default
                                  position, Shape-Text ausblenden, Rahmen
  is_graphic(doc, m) / graphics(doc)   a master is a data graphic: User.visUSEType = 1 in its
                                  page sheet
  read(doc, m) -> DataGraphic      the model of a data graphic master (Visio's or ours)
  create(tx, &g, src) -> MasterRef  a new data graphic master; the callout masters come from
                                  the document or from `src` (the app's stencil)
  update(tx, eng, m, &g, src)      the master written anew, every shape that uses it again
  rename / duplicate / delete      the gallery's menu (delete: from every shape first)
  applied(doc, shape) / shapes_with(doc, m) / callouts(doc, shape)
  apply(tx, eng, shapes, m, layer) the graphic on shapes (an earlier one goes first)
  remove(tx, eng, shapes)          the graphic off again, the old colours back
  fields(doc, shapes)              the shape data fields the shapes have (label, row name)
  resolve_field(doc, shape, expr)  "{Label}" -> the formula on the shape's Prop row
  icon_formula(&rules) / shade_formula(..)   the compiled formulas of icon rules and colours
  legend::*                        (ST-08, RD-07) the legend: a list of containers of lists

How Visio keeps a data graphic (Visio 2007 developer article "Building Custom Data Graphics",
the Visio Insights blog, ShapeSheets of files Visio saved; JD19 research):
* The graphic is a hidden master: its page sheet has User.visUSEType = 1, visDGVisible,
  visDGShowBorder, visDGHideText, visDGNextItemID, msvDGCalloutGap and the layer
  "Data Graphic"; its shape is a group with User.visDGDefaultPos = PNT(h,v) (the default
  position); every item is a subshape with User.msvCalloutType ("Text Callout", "Data Bar",
  "Icon Set", "Heading"), visDGDefaultPos (TRUE: the item takes the default position),
  visDGStackHeight, visDGCalloutItem, visDGField0 (the field expression), visDGItemID,
  visDGUseMaster = USE("<callout master>"), visDGCalloutField = User.visDGField0, and its
  options in Prop.msvCalloutProp* rows (Min, Max, Label, ValueFormat, ShowValue ...).
* Applied to a shape, the shape becomes a group and gets one instance of each item's callout
  master as a subshape: Prop.msvCalloutField's value is a formula on the shape's own Prop row
  (Sheet.5!Prop.Tasks, SortKey = the field's label), User.visDGDefaultPos follows the shape's
  control point Controls.msvDGPosition (seven snap points across, BOUND), the pin is a formula
  of the position and ThePage!User.msvDGCalloutGap, the callout lies on the layer "Data
  Graphic".  The shape itself gets User.visDGDisplayFormat = USE({UniqueID of the master}),
  visDGDefaultPos, msvLayoutIncludeSubshapes and Controls.msvDGPosition.
* Positions: PNT(h, v), h 0..6 = far left, left edge, left, centre, right, right edge, far
  right; v 0..6 = below, bottom edge, bottom, middle, top, top edge, above.  The instance
  rounds the control's place to -1..5 (= h - 1, "x * 4 / Width").
* Rendering comes from the callout masters' own cells: a data bar's fill width is a geometry
  formula of Prop.msvCalloutField and its Min/Max, an icon set shows the geometry section
  whose NoShow is false for User.msvCalloutIconNumber (-1: none), a text callout shows a text
  field with the value in Prop.msvCalloutPropValueFormat.

Checked in Visio 16 (JD19's Visio check, 2026-11-27: files of JFDiagrammer opened by Visio
through its automation, Visio's own graphics and callouts read, variants of them tried):
* Visio takes a subshape of the graphic as an item when it has User.visDGCalloutItem = 5,
  msvCalloutType ("Text Callout" -> text, "Data Bar" -> data bar ...), visDGItemID,
  visDGField0, visDGCalloutField and visDGUseMaster = USE("<an existing callout master>").
* A callout master counts when its shape has visDGCalloutItem = 5, visDGDefaultPos = 0,
  visDGStackHeight = 0 and the ID 5 (Visio's masters start at 5; Master::new does so now).
* Visio gives every master a UniqueID ending in -8E40-00608CF305B2 when it opens a file; a
  graphic written here has such an ID (visio_uid), so the shapes' USE({UniqueID}) keeps naming
  it.  USE takes the UniqueID bare, a master's name quoted.
* An instance on a shape names its item with visDGCalloutItem = DEPENDSON(the item's shape ID
  in the master), a Boolean 0; Visio's own pin formulas differ from ours but read the same
  cells.
* Value cells keep their type in the file (formula::Engine): a string U='STR', a colour
  U='COLOR', a point "PNT(h,v)" U='PNT' -- unmarked, Visio read them as numbers.
* Text and data bar items are Visio's items then (its dialogs list them, it applies the
  graphic itself); icon set and colour-by-value items are not: how Visio keeps their rules is
  its own and Visio's automation cannot make one to look at.  Visio draws and keeps them as
  written.  Visio's own legend (Page.DropLegend) builds nothing for these graphics.

Assumptions where nothing public says how Visio does it ([NF] in the research; read back by
JFDiagrammer, kept by Visio as ordinary cells):
* Icon rules: the instance gets Visio's one compiled formula User.msvCalloutIconNumber
  (IFERROR(IF(cond0,0,IF(cond1,1,...-1)),-1)); the rules themselves stay in the master item's
  User.JFD_IconRules ("op|a|b" per icon).  A Visio item without them keeps its own
  msvCalloutIconNumber formula as read (Item::icon_formula) and passes it on.
* Colour by value: the item is a subshape of the master group with msvCalloutType "Color By
  Value" (no callout master); its method and colours stay in User.JFD_CBVMethod (0 each
  value, 1 ranges) and User.JFD_CBVColors ("value|to|#fill|#text" per colour).  On a shape:
  User.visDGCBVFill = IF(match, RGB(..), ..., the old fill formula), FillForegnd =
  User.visDGCBVFill; a text colour goes through User.JFD_DGCBVText into Char.Color.
  User.visDGOldColors keeps what the shape had (our own text: "cell=I" inherited, "cell=F:..."
  an own formula, "cell=V:..." an own constant, for FillForegnd, Char.Color, HideText and the
  kind "Kind=Shape") and puts it back when the graphic goes.
* The shape, now a group, shows its own geometry behind the callouts (DisplayMode = 1, kept
  and put back like the colours).
* An item's own position: User.JFD_DGPos = PNT(h,v) with visDGDefaultPos FALSE; a Visio item
  without it gets the position its pin in the group is nearest to.
* An item of a master written here is an instance of its callout master (Visio writes a copy
  of the callout master's shape); instances on shapes are instances as in Visio.
* visDGUseMaster and visDGDisplayFormat: USE() is not computed by the engine, so the value
  written with it (254, as seen in Visio's files) stays.
* visDGStackHeight = the distance to the item's place (items at one position stack
  downwards, above the shape upwards).
* The helper cells User.JFD_DGH and User.JFD_DGV (the position 0..6 the instance's pin
  formulas read) are ours: Visio's own pin formulas are not known; ours give the same places.
* Shape-Text ausblenden: HideText = TRUE on the shape (the old value kept as above); the
  border (visDGShowBorder) is kept and written but not drawn.

Every edit runs inside the caller's transaction (one undo step) and computes what it wrote
(Engine::recalc of the sheets it touched).
/// the universal name of the layer data graphics lie on
LAYER_U: &str = "Data Graphic"
/// the gap between a shape and the callouts outside it (inches, on paper; Visio's 1/16 in)
GAP: f64 = 0.0625
/// User.visDGCalloutItem: Visio's mark of a data graphic callout (its callout masters, the items
/// of its graphics and their instances carry 5; an item without it is no item for Visio)
CALLOUT_ITEM: f64 = 5.0
  • enum Kind the kind of an item (Visio's GraphicItem.Type codes)
    • IconSet -- 2: one icon of a set chosen by rules
    • Text -- 3: the value as text
    • DataBar -- 4: a bar, stars, a thermometer ... between a minimum and a maximum
    • ColorByValue -- 5: the shape's fill by its value
    • Heading -- 6: a heading (Visio's; read and kept, not offered)

impl Kind

  • fn code(self) -> u32 Visio's GraphicItem.Type

  • fn callout_type(self) -> &'static str User.msvCalloutType as Visio writes it

  • fn parse(t: &str) -> Option<Kind> the kind of a msvCalloutType text (case and spaces ignored)

  • struct Pos a position at a shape: h 0..6 far left .. far right, v 0..6 below .. above

    • h: u8
    • v: u8

impl Pos

  • const DEFAULT: Pos = Pos { h: H_FAR_RIGHT, v: V_MIDDLE } far right, middle (Visio's default for new graphics)
  • fn pnt(self) -> String PNT(h,v)
  • fn parse(t: &str) -> Option<Pos> the position of a "PNT(h,v)" text (numbers clamped to 0..6)
/// horizontal positions
H_FAR_LEFT: u8 = 0
H_LEFT_EDGE: u8 = 1
H_LEFT: u8 = 2
H_CENTER: u8 = 3
H_RIGHT: u8 = 4
H_RIGHT_EDGE: u8 = 5
H_FAR_RIGHT: u8 = 6
/// vertical positions
V_BELOW: u8 = 0
V_BOTTOM_EDGE: u8 = 1
V_BOTTOM: u8 = 2
V_MIDDLE: u8 = 3
V_TOP: u8 = 4
V_TOP_EDGE: u8 = 5
V_ABOVE: u8 = 6
  • enum Opt an option of an item: the value of a Prop.msvCalloutProp* row
    • Num(f64)
    • Text(String)
    • Bool(bool)

impl Opt

  • fn num(&self) -> Option<f64> as a number (a Boolean 1 or 0, a text parsed)

  • fn text(&self) -> String as text

  • enum Op a rule's test of a value

    • NotUsed -- [nicht verwendet]: the icon is not used
    • Equal
    • NotEqual
    • Greater
    • GreaterEq
    • Less
    • LessEq
    • Between -- between a and b (both included)
    • Contains
    • NotContains

impl Op

  • const ALL: [Op; 10] = [Op::NotUsed, Op::Equal, Op::NotEqual, Op::Greater, Op::G ... every test in the dialog's order

  • fn code(self) -> &'static str the code in User.JFD_IconRules

  • fn parse(t: &str) -> Op

  • struct Rule an icon's rule: shown when the value passes the test

    • op: Op
    • a: String
    • b: String -- the upper bound of Between

impl Rule

  • fn new(op: Op, a: &str, b: &str) -> Rule

  • struct Shade a colour of a colour-by-value item: a value (or a range from value to to) and its fill and text colour (0xRRGGBB)

    • value: String
    • to: String -- the end of a range ("" for each value)
    • fill: u32
    • text: Option<u32>
  • struct Item an item of a data graphic

    • id: u32 -- visDGItemID
    • kind: Kind
    • field: String -- visDGField0: "{Label}" or a formula of such fields ("{Revenue}-{Expenses}")
    • callout: String -- the NameU of the callout master ("" for a colour by value)
    • pos: Option<Pos> -- None: the graphic's default position
    • options: Vec<(String, Opt)> -- Prop.msvCalloutProp* values: (row name, value)
    • rules: Vec<Rule> -- icon sets: the rule of each icon (index = icon number)
    • ranges: bool -- colour by value: ranges (else each value)
    • shades: Vec<Shade>
    • icon_formula: Option<String> -- an icon number formula read from a file whose rules are not known (kept)

impl Item

  • fn new(kind: Kind, field: &str, callout: &str) -> Item a new item of kind for field field ("{Label}") shown by callout master callout

  • fn opt(&self, name: &str) -> Option<&Opt> an option's value

  • fn set_opt(&mut self, name: &str, v: Opt) set an option

  • fn label(&self) -> Option<&str> the label of a field expression that is one field ("{Kosten}" -> "Kosten")

  • struct DataGraphic a data graphic

    • name: String -- the master's name
    • items: Vec<Item>
    • default_pos: Pos
    • hide_text: bool -- Shape-Text ausblenden (visDGHideText)
    • show_border: bool -- Rahmen um Elemente an der Standardposition (visDGShowBorder)
    • next_item: u32 -- visDGNextItemID

impl DataGraphic

  • fn new(name: &str) -> DataGraphic

  • fn push(&mut self, mut item: Item) -> usize add an item (its ID handed out) -> its index

  • fn item_of(&self, field: &str) -> Option<usize> the item of a field expression

  • fn parse_num(t: &str) -> Option<f64> a number typed by a user or kept as text ("1,5" and "1.5" alike)

  • fn hex(c: u32) -> String "#rrggbb" of 0xRRGGBB

  • fn parse_hex(t: &str) -> Option<u32> 0xRRGGBB of "#rrggbb"

  • fn user_text(doc: &Document, sheet: SheetRef, name: &str) -> Option<String> a User cell's value as text (a number as written)

  • fn unique_name(doc: &Document, base: &str) -> String a name no master of the document has (base, then "base (2)" ...)

  • fn is_graphic(doc: &Document, m: MasterRef) -> bool whether master m is a data graphic (User.visUSEType = 1 in its page sheet)

  • fn graphics(doc: &Document) -> Vec<MasterRef> the document's data graphics in master order

  • fn master_name(doc: &Document, m: MasterRef) -> String the name of a master (Name, else NameU)

  • fn read(doc: &Document, m: MasterRef) -> Option<DataGraphic> the model of data graphic master m (None: not a data graphic)

  • fn pin_formulas(gid: u32) -> (String, String) the pin formulas of a callout inside group gid (its ID): PinX, PinY (stacked by User.visDGStackHeight: down, up above the shape)

  • struct Field a shape data field: its label (as shown) and row name

    • label: String
    • row: String
  • fn fields(doc: &Document, shapes: &[ShapeRef]) -> Vec<Field> the shape data fields of the shapes, by row name, in the order they are met (the callouts' own msvCallout* rows left out)

  • fn field_expr(label: &str) -> String "{Label}" of a field

  • fn resolve_field(doc: &Document, shape: ShapeRef, expr: &str, sheet: Option<u32>) -> Option<(String, String)> a field expression on a shape -> (the formula, the label): every "{Label}" becomes the shape's Prop row (Sheet.N!Prop.Row with sheet Some(N), else Prop.Row); None when the shape lacks one of them

  • fn icon_formula(rules: &[Rule]) -> String User.msvCalloutIconNumber of icon rules: the number of the first icon whose rule the value passes, -1 for none (errors: -1)

  • fn shade_formula(shades: &[Shade], ranges: bool, value: &str, text: bool, otherwise: &str) -> String the colour of a value: IF(match, RGB(..), ...) with otherwise when none matches

  • fn find_master(doc: &Document, name_u: &str) -> Option<MasterRef> a master by NameU (else Name), ASCII case ignored

  • fn create(tx: &mut Transaction, eng: &mut Engine, g: &DataGraphic, src: Option<&Document>) -> Result<MasterRef, EditError> a new data graphic master (hidden) for g; the callout masters its items name come from the document or from src -> the master. The caller recalculates nothing: the master's cells are computed here.

  • fn update(tx: &mut Transaction, eng: &mut Engine, m: MasterRef, g: &DataGraphic, src: Option<&Document>, layer_name: &str) -> Result<Vec<ShapeRef>, EditError> write data graphic master m anew from g (its name, items, positions, options) and put it again on every shape that uses it -> those shapes

  • fn rename(tx: &mut Transaction, m: MasterRef, name: &str) -> Result<(), EditError> rename a data graphic (Name and NameU; shapes keep it by its UniqueID)

  • fn duplicate(tx: &mut Transaction, eng: &mut Engine, m: MasterRef, name: &str) -> Result<MasterRef, EditError> a copy of data graphic m under a new name ("name (2)" when taken) -> the copy

  • fn delete(tx: &mut Transaction, eng: &mut Engine, m: MasterRef) -> Result<(), EditError> delete data graphic m: off every shape first, then the master (its callout masters stay)

  • fn applied(doc: &Document, shape: ShapeRef) -> Option<MasterRef> the data graphic a shape shows (User.visDGDisplayFormat = USE("{UniqueID}" or name))

  • fn shapes_with(doc: &Document, m: MasterRef) -> Vec<ShapeRef> every shape of the document's pages that shows data graphic m

  • fn callouts(doc: &Document, shape: ShapeRef) -> Vec<ShapeRef> the data graphic callouts of a shape (subshapes with msvCalloutType and visDGCalloutItem)

  • fn page_layer(tx: &mut Transaction, page: PageRef, name: &str) -> Result<u32, EditError> the page's layer for data graphics (NameUniv "Data Graphic"), added with name when the page has none -> its index

  • fn apply(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef], m: MasterRef, layer_name: &str) -> Result<Vec<ShapeRef>, EditError> put data graphic m on shapes (an earlier graphic goes first; shapes on pages only) -> the shapes that show it now (a shape none of whose fields the graphic names is left out)

  • fn remove(tx: &mut Transaction, eng: &mut Engine, shapes: &[ShapeRef]) -> Result<(), EditError> take the data graphic off shapes: its callouts go, the shape's colours, text and kind come back, the graphic's rows go

  • fn describe(item: &Item, kinds: &[&str; 4]) -> String the text of a graphic's items for lists: "Kosten (Text)" ... (the caller's words)

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