JFLib

diagram_core/src/report/run.rs#

Source: lib/diagram_core/src/report/run.rs

run -- a report definition run against a drawing: the shapes it takes, their values, the
table with groups, summaries and the grand total

  run(doc, &def, &Ctx) -> Table
  Ctx { page, selection, labels }    the page shown, the selected shapes, the words of the
                                     summary rows (the app's language; English by default)
  Table { title, columns, rows, shapes }   rows of RowKind Item, Group (a group's heading),
                                     Summary(f) (a group's subtotal), Grand(f) (over all);
                                     None instead of a function: a row with several

The layouts:
* no grouping: the shapes' rows (sorted, duplicates left out when the definition says so),
  then one row per summary function any column has (Grand), the function's name in the first
  empty cell
* grouping with the rows shown: per group a heading row (the group's value in its column),
  its rows, one subtotal row per function; with GrandSummary the summaries over all at the end
* grouping, summaries only (ItemDisplay 0): one row per group -- the group's value, then a
  column per (field, function): "Anzahl" for the grouping field itself, else
  "<field> (<function>)" -- and with GrandSummary a last row over all (Visio's inventory:
  Master-Name and the count of each)

Summaries take the numbers of a column, also numbers kept as text ("450" in a text field).
Values: a number in the definition's precision with the drawing's decimal sign
(Document::fields), with the unit's abbreviation when ShowUnits is on and the unit has one
(lengths in the unit of their cell, per cent, angles, durations); dates in the general date
format; Booleans as Labels::yes / no; texts as they are.  Each cell also carries its value
typed (Val): the number in the shown unit, rounded to the precision, for CSV and XLSX.
Sorting compares numbers as numbers and texts by their characters (case as the sort key
says); an empty or missing value comes first.  Criteria: =, <>, <, <=, >, >= compare numbers
when both sides are numbers (the criterion's value in its Unit, else in the shape's unit),
else texts (case as the definition says); exists / does not exist ask whether the shape has
the field.  Every criterion must hold, one with AndOr 0 is an "or" with the ones before.
  • struct Labels the words of the summary rows and of truth values (the app's language)
    • total: String -- Func::Total
    • average: String -- Func::Average
    • count: String -- Func::Count
    • min: String -- Func::Min
    • max: String -- Func::Max
    • median: String -- Func::Median
    • grand: String -- the rows over all groups
    • yes: String -- a true value
    • no: String -- a false value

impl Labels

  • fn func(&self, f: Func) -> &str the word of a function

  • struct Ctx<'a> where a report runs

    • page: Option<PageRef> -- the page shown (Scope::Page)
    • selection: &'a [ShapeRef] -- the selected shapes (Scope::Selection)
    • labels: Labels -- the words of the summary rows
  • enum Val a cell's value, typed

    • Empty -- nothing
    • Num(f64) -- a number in the unit shown
    • Text(String) -- a text
    • Bool(bool) -- a truth value
    • Date(f64) -- a date (days since 30 December 1899)
  • struct Cell a cell of the table: its text and its value

    • text: String -- as shown
    • value: Val -- typed
  • enum RowKind what a row of the table is

    • Item -- a shape's row (summaries only: a group's row)
    • Group -- a group's heading
    • Summary(Option<Func>) -- a group's subtotal (None: several functions in one row)
    • Grand(Option<Func>) -- the summary over all (None: several functions in one row)
  • struct Row a row of the table

    • kind: RowKind -- what it is
    • cells: Vec<Cell> -- a cell per column
  • struct Column a column of the table

    • name: String -- its heading
    • numeric: bool -- its values are numbers (right-aligned)
  • struct Table a report's result

    • title: String -- the title (the definition's Title, else its Name)
    • columns: Vec<Column> -- the columns
    • rows: Vec<Row> -- the rows
    • shapes: usize -- how many shapes the report took
  • fn run(doc: &Document, def: &ReportDef, ctx: &Ctx) -> Table run a definition against a drawing

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