Main Content

slreportgen.report.Diagram Class

Namespace: slreportgen.report
Superclasses: slreportgen.report.Reporter

Create diagram reporter

Description

Create a diagram reporter, including a diagram snapshot and caption, for a Simulink® or Stateflow® diagram.

Note

To use a Diagram reporter in a report, you must create the report using the slreportgen.report.Report class.

The slreportgen.report.Diagram class is a handle class.

Creation

Description

diagram = Diagram() creates an empty diagram reporter. Set its properties to capture a Simulink or Stateflow diagram.

example

diagram = Diagram(source) creates a diagram reporter for the Simulink or Stateflow diagram specified by source. Adding this reporter to a report creates a snapshot of the diagram. Then, the snapshot displays in the report as an image with a caption. The snapshot image is stored in the temporary folder of the report. When the report is closed, the snapshot image is copied into the report and then, the image is deleted from the temporary folder. To prevent the snapshot image file from being deleted, use the Debug property of the report. See slreportgen.report.Report

diagram = Diagram(Name=Value) sets properties using name-value pairs. You can specify multiple name-value pair arguments in any order.

Input Arguments

expand all

See the Source property.

Properties

expand all

Diagram snapshot image source, specified as one of these values.

  • Name of an open or loaded Simulink model

  • Path of a Simulink subsystem block that contains the Simulink diagram or Stateflow chart

  • slreportgen.finder.DiagramResult object

  • Handle to a subsystem block containing a Simulink diagram or Stateflow chart

  • Stateflow.Chart or Stateflow subchart object. Subcharts are graphical objects that can contain the same objects as a top-level chart, including other subcharts. Subcharts are commonly specified by a Stateflow.State, Stateflow.Function, or Stateflow.Box object.

Snapshot reporter, set by default to an object of the mlreportgen.report.FormalImage class. You do not need to set this property yourself. The FormalImage object adds the diagram snapshot to a report. To control the size of the snapshot, set the mlreportgen.report.FormalImage properties.

Diagram area to capture in the snapshot, specified as a 1-by-4 array of doubles. The first two values of the array are the x and y coordinates, in pixels, of the top left corner of the diagram area in the Simulink Editor coordinate space. The last two values are the width and height, in pixels. An empty array specifies the entire diagram.

You can set up the view that you want to capture in the Simulink Editor and then set the SnapshotArea property to the output of the slreportgen.utils.getCurrentEditorView function. For an example, see Take Snapshot of Part of a Diagram.

Snapshot image format, specified as a character vector or string scalar. Supported formats are:

  • 'bmp' — Bitmap image.

  • 'gif' — Graphics Interchange format.

  • 'jpg' — JPEG image.

  • 'png' — PNG image.

  • 'emf' — Enhanced metafile, supported only in DOCX output on Windows® platforms.

  • 'svg' — Scalable Vector Graphics.

  • 'tiff' — Tag Image File format, not supported in HTML output.

  • 'pdf' — PDF image.

See Version History.

Choice to include a hyperlink of each diagram element, specified as a logical. If this property is true, each element becomes a hyperlink to an object in the report that describes it. This property applies only to PDF and HTML reports. Hyperlinks allow you to navigate the report using Simulink and Stateflow charts.

The Diagram, SimulinkObjectProperties, and StateflowObjectProperties reporters work together to enable navigation using hyperlinks. Each reporter prefaces the report object it creates with a hyperlink target. The ID of that target is based on the path of the reported element in the model. The Diagram reporter also overlays elements of a diagram snapshot with hyperlinks to the corresponding element-based target ID. The report object to which a diagram element links depends on the element type.

  • A diagram-based block (subsystem, chart, model) links to the diagram of the block.

  • Other blocks link to textual block descriptions, typically block property tables.

  • Masked subsystem blocks that have mask parameters link to the textual description of the block, such as the mask parameter tables. This linking to the textual descriptions is true only if the MaskedSystemLinkPolicy property of the Diagram reporter is set to 'block' or 'default'. Otherwise, the masked system block links to its diagram.

  • Masked subsystem blocks that do not have mask parameters link to the diagram of the block.

To customize diagram-based navigation, create custom link targets based on target IDs generated by the slreportgen.utils.getObjectID utility function.

Policy to determine the targets for the hyperlinks of masked system blocks, specified as one of these values.

  • 'default' — Masked system blocks that have parameters link to textual descriptions, such as mask parameter tables. Masked system blocks that do not have parameters link to the corresponding block diagram in the report.

  • 'system' — Masked system blocks link to their block diagram in the report.

  • 'block' — Masked system blocks link to their textual description, such as a table of masked parameters or subsystem parameters.

Scaling options for diagram snapshot image, specified as the string, auto, custom, or zoom. Scaling controls size of the diagram snapshot image in the image file.

  • auto — For PDF or Word (docx) output, auto scales the diagram snapshot image to fit in the current page layout while maintaining its aspect ratio. First, the diagram snapshot image is scaled to the page width. If the image height exceeds the page height, then the image is again scaled down. This additional scaling assures that the image fits in the current page with an extra 1" spacing. The extra spacing allows for extra text, such as a caption. Scaling does not apply to HTML output.

  • custom — Scales the diagram snapshot image based on the values of the Height and Width properties

  • zoom — Enlarges or reduces the snapshot image size to the percent value specified by the Zoom property. To specify the maximum image height and maximum image width, use the MaxHeight and MaxWidth properties, respectively.

Note

A java.lang.OutOfMemoryError can occur when either of these combinations of property settings occur:

  • Scaling set to zoom, and Zoom, MaxHeight, and MaxWidth properties set to large values

  • Scaling set to custom, and Height and Width properties set to large values

To avoid this error, for zoom Scaling, use smaller Zoom, MaxHeight, and MaxWidth property values. For custom Scaling, use smaller Height and Width property values. Using smaller values ensures that the diagram fits on the page.

Height of snapshot image, specified as a character vector or string scalar that consists of a number followed by an abbreviation for a unit of measurement. For example, '2in' specifies two inches. Valid abbreviations are:

  • px — pixels (default)

  • cm — centimeters

  • in — inches

  • mm — millimeters

  • pc — picas

  • pt — points

Example: '2in'

Width of snapshot image, specified as a character vector or string scalar that consists of a number followed by an abbreviation for a unit of measurement. For example, '2in' specifies two inches. Valid abbreviations are:

  • px — pixels (default)

  • cm — centimeters

  • in — inches

  • mm — millimeters

  • pc — picas

  • pt — points

Example: '3in'

Amount to zoom the diagram snapshot image, specified as a string. The Zoom format is value%, where value is the percentage by which the diagram snapshot image is enlarged or reduced.

Maximum height for zoom scaling, specified as a string. This property applies only if Scaling is set to zoom.

The MaxHeight format is valueUnits, where Units is an abbreviation for the height units and value is the number of units. See the Height property for a table of valid Units abbreviations.

Maximum width for zoom scaling, specified as a string. This property applies only if Scaling is set to zoom.

The MaxWidth format is valueUnits, where Units is an abbreviation for the height units and value is the number of units. See the Height property for a table of valid Units abbreviations.

Source of the template for this reporter, specified as one of these options:

  • Character vector or string scalar that specifies the path of the file that contains the template for this reporter

  • Reporter or report whose template is used for this reporter or whose template library contains the template for this reporter

  • DOM document or document part whose template is used for this reporter or whose template library contains the template for this reporter

The specified template must be the same type as the report to which this reporter is appended. For example, for a Microsoft® Word report, TemplateSrc must be a Word reporter template. If the TemplateSrc property is empty, this reporter uses the default reporter template for the output type of the report.

Name of template for this reporter, specified as a character vector or string scalar. The template for this reporter must be in the template library of the template source (TemplateSrc) for this reporter.

Hyperlink target for this reporter, specified as a character vector or string scalar that specifies the link target ID or as an mlreportgen.dom.LinkTarget object. A character vector or string scalar value is converted to a LinkTarget object. The link target immediately precedes the content of this reporter in the output report.

Methods

expand all

Examples

collapse all

Add a snapshot of the top level of the slrgex_vdp model to a report.

load_system("slrgex_vdp")
import slreportgen.report.*
import mlreportgen.report.*
rpt = slreportgen.report.Report("output","pdf");
 
chapter = Chapter();
chapter.Title = "Diagram Reporter Example";
 
diagram = Diagram("slrgex_vdp");
diagram.Snapshot.Caption = "The van der Pol Equation";
diagram.SnapshotFormat = "svg";
diagram.Snapshot.Height = "4in";

add(chapter,diagram);
add(rpt,chapter);
rptview(rpt);

reporters_diagram_ex1.png

Create a PDF report and add diagram snapshots of the root system and a subsystem from the sf_car model to it. Add a hyperlink to the transmission subsystem and add a paragraph as the target for that link.

import mlreportgen.report.*
import slreportgen.report.*
import slreportgen.utils.*
import mlreportgen.dom.*
rpt = slreportgen.report.Report("output","pdf");
chapter = Chapter("sf_car");

load_system("sf_car");
diag1 = Diagram("sf_car");
diag1.Snapshot.Caption = "Root System: sf_car";
add(chapter,diag1);
add(chapter,PageBreak);

diag2 = Diagram("sf_car/Engine");
diag2.Snapshot.Caption = "Subsystem: sf_car/Engine";
add(chapter,diag2);
add(chapter, PageBreak);

para = Paragraph("Custom target for sf_car/transmission");
id = getObjectID("sf_car/transmission");
append(para,mlreportgen.dom.LinkTarget(id));
add(chapter,para);
add(chapter,PageBreak);

add(rpt,chapter);
close(rpt);
rptview(rpt);

Use the SnapshotArea property to specify the area of the diagram to capture in the snapshot. This example sets up the view in the Simulink Editor and then sets the SnapshotArea property to that view by calling slreportgen.utils.getCurrentEditorView.

Open the model.

openExample('f14')

In the Simulink Editor, display the part of the diagram that you want to capture in the snapshot. Get the current Simulink Editor view area by calling slreportgen.utils.getCurrentEditorView.

editorViewArea = getCurrentEditorView();

Create the report and diagram reporter. Set the diagram snapshot area to the current editor viewing area. Add the diagram reporter to the report.

import slreportgen.report.*
import Slreportgen.utils.*
rpt = Report('output','pdf');

diag = Diagram('f14');
diag.SnapshotArea = editorViewArea;
add(rpt, diag);

close(rpt);
rptview(rpt);

Version History

Introduced in R2017b

expand all