Main Content

setWidths

Class: slmetric.dashboard.Group
Namespace: slmetric.dashboard

(To be removed) Specify multiple widths for Metrics Dashboard group

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.

Description

setWidths(groupName, widths) specifies possible widths for an slmetric.dashboard.Group object. You can specify up to four different widths. For the input argument widths, pass either one value or an array of four values. You can choose from these possible values:

  • slmetric.dashboard.Width.ExtraSmall — 2 columns wide

  • slmetric.dashboard.Width.Small — 4 columns wide

  • slmetric.dashboard.Width.Medium — 6 columns wide

  • slmetric.dashboard.Width.Large — 8 columns wide

  • slmetric.dashboard.Width.XLarge — 10 columns wide

  • slmetric.dashboard.Width.XXLarge — 12 columns wide

These values correspond to the different sizes that a group can have as the screen size changes. If you specify one value, the group always has that value regardless of the screen size. If you specify four different values, the group size can change four times as you maximize and minimize the screen.

Note

The Metrics Dashboard layout is divided into 12 columns of equal size. When you add a new group to an empty dashboard, the dashboard creates a new row with 12 columns. The dashboard adds groups or widgets to the same row until the width would exceed 12 columns. When the width would exceed 12 columns, the dashboard creates a new row. For example, if you have one group with a width of slmetric.dashboard.Width.XXLarge, that group uses all 12 columns in the row. If you have smaller group, the dashboard places those groups on the same row until the groups in the row reach the maximum width of 12.

Column 1Column 2Column 3Column 4Column 5Column 6Column 7Column 8Column 9Column 10Column 11Column 12
slmetric.dashboard.Width.XXLarge
slmetric.dashboard.Width.Mediumslmetric.dashboard.Width.Medium
slmetric.dashboard.Width.Mediumslmetric.dashboard.Width.Small(empty)
slmetric.dashboard.Width.Small(empty)

Input Arguments

expand all

slmetric.dashboard.Container object that is to have between one and four widths

Specify one or as many as four of these values:

  • slmetric.dashboard.Width.ExtraSmall — 2 columns wide

  • slmetric.dashboard.Width.Small — 4 columns wide

  • slmetric.dashboard.Width.Medium — 6 columns wide

  • slmetric.dashboard.Width.Large — 8 columns wide

  • slmetric.dashboard.Width.XLarge — 10 columns wide

  • slmetric.dashboard.Width.XXLarge — 12 columns wide

Examples

expand all

Create a custom metric that counts nonvirtual blocks. Specify a widget to display this metric on the Metrics Dashboard. Add it to the Size Group.

Open the model vdp by entering:

openExample('simulink_general/VanDerPolOscillatorExample')

Create a custom metric class.

className = 'nonvirtualblockcount';
slmetric.metric.createNewMetricClass(className);

Create the nonvirtual block count metric by adding this code to the nonvirtualblockcount.m file.

classdef nonvirtualblockcount < slmetric.metric.Metric
    %nonvirtualblockcount calculates number of nonvirtual blocks per level.
    % BusCreator, BusSelector and BusAssign are treated as nonvirtual.
    properties
        VirtualBlockTypes = {'Demux','From','Goto','Ground', ...
            'GotoTagVisibility','Mux','SignalSpecification', ...
            'Terminator','Inport'};
    end
    
    methods
    function this = nonvirtualblockcount()
        this.ID = 'nonvirtualblockcount';
        this.Name = 'Nonvirtual Block Count';
        this.Version = 1;
        this.CompileContext = 'None';
        this.Description = 'Algorithm that counts nonvirtual blocks per level.';
        this.AggregatedValueName = 'Nonvirtual Blocks (incl. Descendants)'
        this.ValueName = 'Nonvirtual Blocks'
        this.ComponentScope = [Advisor.component.Types.Model, ...
            Advisor.component.Types.SubSystem];
        this.AggregationMode = slmetric.AggregationMode.Sum;
        this.ResultChecksumCoverage = true;
        this.SupportsResultDetails = true;
            
    end

    function res = algorithm(this, component)
        % create a result object for this component
        res = slmetric.metric.Result();	

        % set the component and metric ID
        res.ComponentID = component.ID;
        res.MetricID = this.ID;
        
        % Practice
        D1=slmetric.metric.ResultDetail('identifier 1','Name 1');
        D1.Value=0;
        D1.setGroup('Group1','Group1Name');
        D2=slmetric.metric.ResultDetail('identifier 2','Name 2');
        D2.Value=1;
        D2.setGroup('Group1','Group1Name');
        
        

        % use find_system to get all blocks inside this component
        blocks = find_system(getPath(component), ...
            'SearchDepth', 1, ...
            'Type', 'Block');

        isNonVirtual = true(size(blocks));

        for n=1:length(blocks)
            blockType = get_param(blocks{n}, 'BlockType');

            if any(strcmp(this.VirtualBlockTypes, blockType))
                isNonVirtual(n) = false;
            else
                switch blockType
                    case 'SubSystem'
                        % Virtual unless the block is conditionally executed
                        % or the Treat as atomic unit check box is selected.
                        if strcmp(get_param(blocks{n}, 'IsSubSystemVirtual'), ...
                                'on')
                            isNonVirtual(n) = false;
                        end
                    case 'Outport'
                        % Outport: Virtual when the block resides within
                        % SubSystem block (conditional or not), and 
                        % does not reside in the root (top-level) Simulink window.
                        if component.Type ~= Advisor.component.Types.Model
                            isNonVirtual(n) = false;
                        end
                    case 'Selector'
                        % Virtual only when Number of input dimensions 
                        % specifies 1 and Index Option specifies Select 
                        % all, Index vector (dialog), or Starting index (dialog).
                        nod = get_param(blocks{n}, 'NumberOfDimensions');
                        ios = get_param(blocks{n}, 'IndexOptionArray');

                        ios_settings = {'Assign all', 'Index vector (dialog)', ...
                            'Starting index (dialog)'};

                        if nod == 1 && any(strcmp(ios_settings, ios))
                            isNonVirtual(n) = false;
                        end
                    case 'Trigger'
                        % Virtual when the output port is not present.
                        if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'off')
                            isNonVirtual(n) = false;
                        end
                    case 'Enable'
                        % Virtual unless connected directly to an Outport block.
                        isNonVirtual(n) = false;

                        if strcmp(get_param(blocks{n}, 'ShowOutputPort'), 'on')
                            pc = get_param(blocks{n}, 'PortConnectivity');

                            if ~isempty(pc.DstBlock) && ...
                                    strcmp(get_param(pc.DstBlock, 'BlockType'), ...
                                    'Outport')
                                isNonVirtual(n) = true;
                            end
                        end
                end
            end
        end

        blocks = blocks(isNonVirtual);

        res.Value = length(blocks);
    end
    end
end

Register the new metric in the metric repository.

[id_metric,err_msg] = slmetric.metric.registerMetric(className);

To begin, open the default configuration for the Metrics Dashboard layout.

conf = slmetric.dashboard.Configuration.open();

Obtain the slmetric.dashboard.Layout object from the slmetric.dashboard.Configuration object.

layout = getDashboardLayout(conf);

Obtain widget objects that are in the layout object.

layoutWidget = getWidgets(layout);

Remove the widget that represents the Simulink block count metric.

sizeGroup = layoutWidget(2); 
sizeGroupWidgets = sizeGroup.getWidgets(); 
sizeGroup.removeWidget(sizeGroupWidgets(1));

Add a widget that displays the nonvirtual block count metric. For custom widgets, the default visualization type is single value. If you want to use a different visualization technique, specify a different value for the VisualizationType property.

newWidget = sizeGroup.addWidget('Custom', 1);
newWidget.Title = ('Nonvirtual Block Count'); 
newWidget.setMetricIDs('nonvirtualblockcount');
newWidget.setWidths(slmetric.dashboard.Width.Medium);
newWidget.setHeight(70);

Specify whether there are lines separating the custom widget from other widgets in the group. These commands specify that there is a line to the right of the widget.

s.top = false;
s.bottom = false;
s.left = false;
s.right = true;
newWidget.setSeparators([s, s, s, s]);

Save the configuration object. This command serializes the API information to an XML file.

save(conf,'Filename','DashboardConfig.xml');

Set the active configuration.

slmetric.dashboard.setActiveConfiguration(fullfile(pwd,'DashboardConfig.xml'));

Open the Metrics Dashboard for the model vdp.

metricsdashboard vdp

Click the All Metrics button to run all metrics.

Version History

Introduced in R2018b

collapse all

R2022a: Metrics Dashboard will be removed

The Metrics Dashboard user interface, metricdashboard function, slmetric package API, and corresponding customizations will be removed in a future release. For more information, see Migrating from Metrics Dashboard to Model Maintainability Dashboard.