Main Content

createDiagramTwoWayLink

Class: slreportgen.webview.EmbeddedWebViewDocument
Namespace: slreportgen.webview

Link and anchor in embedded web view report

Syntax

diag2link = createDiagramTwoWayLink(wvdoc,dhandle,domlabel)

Description

diag2link = createDiagramTwoWayLink(wvdoc,dhandle,domlabel) creates a two-way connection between a Simulink® web view diagram and a DOM object in an embedded web view document pane. The generated diag2link DOM object includes attributes that identify it as a link. The diag2link DOM object is of the same type as domlabel or, if domlabel is a string, the DOM object is an mlreportgen.DOM.Text object.

Input Arguments

expand all

Web view document, specified as an slreportgen.webview.WebViewDocument object.

Handle of web view diagram anchor, specified as a character vector of the path or as an object handle. You can use the getExportDiagrams method to obtain the diagram paths and handles.

Example: Character vector: 'slrgex_vdp'. Object handle: get_param('slrgex_vdp','handle')

DOM object from which to link, specified as a valid DOM object or as a character vector. If you enter a character vector, an mlreportgen.DOM.Text object is created.

Output Arguments

expand all

Examples

expand all

This example shows to create two-way links between second-level headings and block names in the document pane and the associated diagrams and blocks in the embedded web view.

Write a class called TwoWayLinkWebView that is a subclass of slreportgen.webview.EmbeddedWebViewDocument. In the fillContent method, use the createDiagramTwoWayLink and createElementTwoWayLink functions to create links to the embedded web view.

classdef TwoWayLinkWebView < slreportgen.webview.EmbeddedWebViewDocument

    methods
        function wvdoc = TwoWayLinkWebView(reportPath,modelName)
            % Invoke the EmbeddedWebViewDocument constructor, which
            % saves the report path and model name for use by the fill
            % methods of the report.
            wvdoc@slreportgen.webview.EmbeddedWebViewDocument( ...
                reportPath,modelName);
        end

        function fillContent(wvdoc)
            % Fill the Content hole in the report template with design
            % variable information. Use DOM or Report API methods to
            % create, format, add, and append content to this report.

            [~, handles] = getExportDiagrams(wvdoc);

            n = numel(handles);
            for i = 1:n
                diagHandle = handles{i};
                diagHeading = createDiagramTwoWayLink(wvdoc, ...
                    diagHandle, ...
                    mlreportgen.dom.Heading(2, ...
                        get_param(diagHandle,"Name")));
                append(wvdoc,diagHeading);

                blockFinder = slreportgen.finder.BlockFinder( ...
                    diagHandle);

                while hasNext(blockFinder)
                    r = next(blockFinder);
                    elemHandle = r.Object;
                    elemHeading = createElementTwoWayLink(wvdoc, ...
                        elemHandle, ...
                        mlreportgen.dom.Heading(3, ...
                            get_param(elemHandle,"Name")));
                    append(wvdoc,elemHeading);
                end

            end
        end
    end
end

Load the model.

model_name = "sf_car";
load_system(model_name);

Create an object of the TwoWayLinkWebView class.

wvdoc = TwoWayLinkWebView("myReport",model_name);

Use the methods in the class to generate the embedded web view report.

open(wvdoc);
fill(wvdoc);

Close the report and open the viewer.

close(wvdoc);
rptview(wvdoc);

For more information on how to use the links in the report, see Create Hyperlinks for Embedded Web View Reports.

More About

expand all

Version History

Introduced in R2017a