JFLib

diagram_core/src/report.rs#

Source: lib/diagram_core/src/report.rs

report -- (JD19) shape reports (DA-09, DA-13, AS-05, EX-12): Visio's report definitions as a
model, run against a drawing into a table, put on a page as a table shape

  ReportDef                     a definition as Visio's VisioReportDefinition describes it:
                                name, title, description, which shapes (Scope), the criteria
                                (Filter), the columns (Field: built-in fields, shape data,
                                user cells; display names and order; summaries), grouping
                                with subtotals, grand summary and duplicates (Grouping),
                                up to three sort keys (Sort), precision, units, case; what a
                                file had and the model does not know stays as data (attrs,
                                extra) for the writer
  run(doc, &def, &Ctx) -> Table   the result: title, columns, item rows, group headers,
                                subtotal rows, the grand total; every cell as text (in the
                                definition's precision, with units when it says so) and
                                typed (for CSV and XLSX)
  place(tx, eng, owner, at, &table, &Place) -> ShapeRef   the table shape: a group of cell
                                shapes (title, header, grid, group and summary rows) on its
                                own layer, marked with User.JFD_Report* (report/shape.rs)
  report_shape(doc, shape) / refresh(tx, eng, shape, &table) / report_layer(..)   find a table
                                shape (a cell of it too), build it anew in place (DA-13)

The XML (VisioReportDefinition, .vrd files) and the definitions kept in the document sheet
(User.visPropRptN, U="STR") are diagram_io::report: this crate holds no file format.  The
codes below (Scope::code, Condition::code, Func::bit, Property::tag, Builtin::key) are the
numbers and names that XML carries.

Assumptions where no source says (Annahmen; the user's own Visio file will settle them):
* SelectDrawingDataMethod: 1 every page, 2 the current page (both seen), 3 the selected
  shapes (not seen); another number reads as Scope::Other and runs over every page.
* Condition, checked in Visio 16 (a definition per code run through Visio's report add-on,
  Auslastung against 60): 1 =, 2 <>, 3 >, 4 <, 5 >=, 6 <=, 8 exists; Visio's own definitions
  (INVENTRY.VRD) write "exists" as 8 with Value 1 and PropertyDataType 3 (a Boolean), so "does
  not exist" is written as 8 with Value 0 (diagram_io::report; 7 is read as it too, earlier
  JFDiagrammer files wrote it, Visio gives no report for 7).
* AdvancedFilter: Visio's own definitions write 0; with 1 Visio leaves the criteria out (every
  code gave every shape), so they count only without it (run.rs, as Visio).
* SummaryTypes is a bit mask, checked in Visio 16 (JD19's Visio check: a definition with each
  bit alone run through Visio's report add-on): 1 count, 2 total, 4 average, 8 minimum,
  16 maximum, 32 median (Func::bit); Visio's grand total row shows the total alone.
* Tag 1 a built-in field, 2 shape data, 3 a user cell (seen); Type and PropertyDataType are
  the shape data types of diagram_core::data::kind (0 text, 2 number, 3 Boolean seen).
* ItemDisplay 1 shows the shapes' rows with the summaries, 0 only the summaries (one row per
  group); GroupingField 0 groups nothing; a Boolean attribute is 1 or 0 (true / -1 read too).
* A shape data field is named by its row name (Prop.<Name>); a shape that has no row of that
  name but one with that label counts too (Visio's dialog lists the fields by label).
* NAMEINFO is the shape's name as shown (Name), NAMEIDINFO its NameID ("Sheet.5"); lengths
  (PINXINFO ...) in the unit of their cell, else the page's.
* Visio's output "Visio-Shape" is an embedded Excel object (NO-22: not here), an instance of
  its hidden master "Report shape" that names the definition only in RUNADDONWARGS formulas
  (EventDrop, the actions "Bericht aktualisieren" and "Bericht erstellen"; seen in JD19's
  check).  The table shape here is JFDiagrammer's own: User.JFD_Report = 1,
  JFD_ReportName, JFD_ReportDef (a copy of the definition) or JFD_ReportLink (the
  definition's name in the drawing or a .vrd path), on the layer the app names ("Bericht").

The columns are in DisplayOrder with the grouping field first, as Visio's report shows them.

Which shapes a report sees (run.rs): the top-level shapes of the pages of its scope (the
foreground pages for "every page") or the selected shapes; a group without master and without
shape data of its own stands for its members (a user's group of devices counts its devices),
every other shape counts as one -- an instance's subshapes never.  Table shapes of reports
are left out.  Summaries: Count counts the rows of the group, the others take the numbers.
  • enum Scope which shapes a report takes (SelectDrawingDataMethod)
    • AllPages -- the shapes of every (foreground) page: 1
    • Page -- the shapes of the current page: 2
    • Selection -- the selected shapes: 3 (assumed)
    • Other(u32) -- a number not known here (runs like AllPages, written back as read)

impl Scope

  • fn code(self) -> u32 the code of SelectDrawingDataMethod

  • fn of(code: u32) -> Scope the scope of a code

  • enum Builtin a built-in field (Tag 1): its name in the definition

    • Text -- TEXTINFO: the shape's text as shown (fields included)
    • Master -- MASTERINFO: the name of the shape's master
    • Name -- NAMEINFO: the shape's name
    • NameId -- NAMEIDINFO: the shape's NameID ("Sheet.5")
    • PinX -- PINXINFO
    • PinY -- PINYINFO
    • Width -- WIDTHINFO
    • Height -- HEIGHTINFO
    • Other(String) -- a name not known here (kept; it shows nothing)
/// the built-in fields in the order the wizard offers them
BUILTINS: [Builtin; 8] = [Builtin::Text, Builtin::Master, Builtin::Name, Builtin:: ...

impl Builtin

  • fn key(&self) -> &str the name in the definition (TEXTINFO ...)

  • fn of(key: &str) -> Builtin the field of a name

  • fn is_length(&self) -> bool whether its values are lengths

  • enum Property what a column or a criterion reads from a shape

    • Builtin(Builtin) -- a built-in field (Tag / PropertyType 1)
    • Data(String) -- a shape data field by its row name (Prop.<name>; Tag 2)
    • User(String) -- a user cell by its row name (User.<name>; Tag 3)

impl Property

  • fn tag(&self) -> u32 Tag / PropertyType

  • fn key(&self) -> &str the name the definition writes (TEXTINFO, the row name)

  • fn of(tag: u32, key: &str) -> Property the property of a tag and a name (an unknown tag reads as shape data)

  • enum Func a summary function of a column (SummaryTypes, a bit each; Visio's bits, checked in Visio 16)

    • Total -- the sum: bit 2
    • Average -- the mean: bit 4
    • Median -- the middle value: bit 32
    • Count -- the number of rows: bit 1
    • Min -- the smallest number: bit 8
    • Max -- the largest number: bit 16
/// the functions in the order of the dialog (and of the summary rows)
FUNCS: [Func; 6] = [Func::Total, Func::Average, Func::Median, Func::Count, F ...

impl Func

  • fn bit(self) -> u32 its bit in SummaryTypes

  • fn of_mask(mask: u32) -> Vec<Func> the functions of a SummaryTypes mask, in order

  • struct Field a column of the report (VisioRptDefField)

    • id: u32 -- ID (groups and sort keys name it)
    • property: Property -- what it shows (Tag with Name)
    • display_name: String -- DisplayName: the column's heading ("" -- the property's name)
    • display: bool -- Display: shown as a column
    • order: u32 -- DisplayOrder: the column's place (smaller first)
    • data_type: u16 -- Type: the data type (data::kind: 0 text, 2 number ...)
    • summary: u32 -- SummaryTypes (Func::bit)
    • attrs: Vec<(String, String)> -- attributes not known here, kept

impl Field

  • fn new(id: u32, property: Property, display_name: &str) -> Field a shown column of a property with a heading

  • fn heading(&self) -> &str the heading: DisplayName, else the property's name

  • enum Condition a condition of a criterion (Condition; codes assumed, see the file head)

    • Eq -- =
    • Ne -- <>
    • Gt -- >
    • Ge -- >=
    • Lt -- <
    • Le -- <=
    • Exists -- the shape has the property
    • NotExists -- the shape does not have it
    • Other(u32) -- a code not known here (the criterion holds for no shape)
/// the conditions with their codes (one table: the assumption lives here)
CONDITIONS: [(Condition, u32); 8] = [ (Condition::Eq, 1), (Condition::Ne, 2), (Condition::Gt, ...

impl Condition

  • fn code(self) -> u32 the code of Condition

  • fn of(code: u32) -> Condition the condition of a code

  • fn has_value(self) -> bool whether it compares with a value (Exists and NotExists do not)

  • struct Filter a criterion: which shapes the report takes (VisioRptDefFilter)

    • id: u32 -- ID
    • property: Property -- the property compared (PropertyType with Property)
    • condition: Condition -- Condition
    • value: String -- Value: what it compares with
    • unit: String -- Unit: the value's unit code ("MM"; "" none)
    • data_type: u16 -- PropertyDataType (data::kind)
    • and: bool -- AndOr: 1 and (Visio's criteria are all "and"), 0 or with the ones before
    • attrs: Vec<(String, String)> -- attributes not known here, kept

impl Filter

  • fn new(id: u32, property: Property, condition: Condition, value: &str) -> Filter a criterion "property condition value"

  • struct Grouping grouping and the summaries of the whole (VisioRptDefGroup)

    • id: u32 -- ID
    • field: u32 -- GroupingField: the ID of the field the rows are grouped by (0: none)
    • show_items: bool -- ItemDisplay: the shapes' rows are shown (else only the summaries)
    • grand_summary: bool -- GrandSummary: summaries over every row at the end
    • exclude_duplicates: bool -- ExcludeDuplicates: a row the same as one before is left out
    • attrs: Vec<(String, String)> -- attributes not known here, kept
  • struct Sort a sort key (VisioRptDefSort)

    • id: u32 -- ID
    • field: u32 -- SortField: the field's ID
    • ascending: bool -- Ascending
    • case_sensitive: bool -- CaseSensitive
    • attrs: Vec<(String, String)> -- attributes not known here, kept

impl Sort

  • fn new(id: u32, field: u32, ascending: bool) -> Sort a sort key on a field

  • struct ReportDef a report definition (VisioReportDefinition; a .vrd file holds the same)

    • name: String -- Name: what the list of reports shows
    • title: String -- Title: the heading of the result ("" -- the name)
    • description: String -- Description
    • scope: Scope -- SelectDrawingDataMethod
    • precision: u32 -- Precision: decimals of numbers
    • show_units: bool -- ShowUnits: lengths, angles and durations with their unit
    • case_sensitive: bool -- CaseSensitive: criteria compare texts with case
    • user_cells: bool -- UserCells: the wizard offers user cells (Visio's "Show all properties")
    • hidden_properties: bool -- HiddenProperties: the wizard offers hidden shape data
    • advanced_filter: bool -- AdvancedFilter: criteria were given (Visio's dialog Erweitert)
    • filter_expression: String -- FilterExpression as read (written back unchanged)
    • exists: bool -- ReportExists
    • version: String -- Version ("3")
    • fields: Vec<Field> -- the columns in file order
    • filters: Vec<Filter> -- the criteria
    • grouping: Option<Grouping> -- grouping and summaries (None: the file has no group element)
    • sorts: Vec<Sort> -- the sort keys, the first one first
    • attrs: Vec<(String, String)> -- root attributes not known here, kept
    • extra: Vec<String> -- child elements not known here, as XML text, written back after the known ones

impl ReportDef

  • fn new(name: &str) -> ReportDef an empty definition named name (every page, two decimals, units shown)
  • fn field(&self, id: u32) -> Option<&Field> a field by ID
  • fn columns(&self) -> Vec<&Field> the shown fields in their display order (DisplayOrder, then file order)
  • fn heading(&self) -> &str the title shown: Title, else Name
  • fn next_field_id(&self) -> u32 the next free field ID

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