Main Content

matlab.diagram.ClassViewer Class

Namespace: matlab.diagram

Create class diagrams in Class Diagram Viewer app

Since R2021a

Description

The matlab.diagram.ClassViewer class provides command-line access to the Class Diagram Viewer app. You can use the properties and methods of this class to populate a class diagram without using the graphical interface.

The matlab.diagram.ClassViewer class is a handle class.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

matlab.diagram.ClassViewer opens a Class Diagram Viewer instance with no classes loaded.

matlab.diagram.ClassViewer(Name,Value) adds the specified classes to both the Class Browser pane and the canvas. Use name-value arguments to determine what content to add.

viewer = matlab.diagram.ClassViewer(___) returns a handle for the Class Diagram Viewer instance. You can use any of the previous input argument syntaxes.

example

Input Arguments

expand all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Example: matlab.diagram.ClassViewer(Classes="matlab.net.http.RequestMessage")

Classes to add to the Class Browser and viewer, specified as a character vector, string scalar, or a vector of strings. You can also use class instances.

Example: matlab.diagram.ClassViewer(Classes="matlab.net.http.ResponseMessage")

Example: respMsg = matlab.net.http.RequestMessage; matlab.diagram.ClassViewer(Classes=respMsg)

Class folders to add to the Class Browser and viewer, specified as a character vector, string scalar, or a vector of strings.

Determines whether to include classes from subfolders, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 includes classes in subfolders of the Folders argument, and 0 omits them.

Namespaces to add to the Class Browser and canvas, specified as a character vector, string scalar, or a vector of strings.

Determines whether to include classes from inner namespaces, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 includes the classes in inner namespaces of the Namespaces argument, and 0 omits them.

Path of class diagram to load, specified as a character vector, string, or a vector of strings.

Since R2024b

Packages to add to the Class Browser and canvas, specified as a character vector, string scalar, or a vector of strings.

Determines whether the Class Diagram Viewer window is visible after creation, specified as a numeric or logical 0 (false) or 1 (true). A value of 1 makes the window visible, and 0 hides it.

Properties

expand all

The last file loaded or saved to the Class Diagram Viewer instance, returned as a string. This property can only be set by the load and save methods.

Attributes:

Dependent
true

The list of classes currently displayed in the diagram, returned as a vector of strings. The list includes classes displayed in the canvas, but it does not include classes that are only listed in the Class Browser.

Attributes:

Dependent
true

Since R2024a

Determines whether the Class Diagram Viewer displays associations, specified as a numeric or logical 0 (false) or 1 (true). A value of 0 excludes associations. Toggling between true and false immediately updates the diagram. For more information on associations, see Add Associations to Diagrams.

Determines whether the Class Diagram Viewer displays mixin classes, specified as a numeric or logical 0 (false) or 1 (true). A value of 0 excludes mixins and the handle class for a simpler diagram. A value of 1 enables adding mixins when adding superclasses, but it does not do so automatically.

Determines whether the Class Diagram Viewer displays the namespace names on the class cards, specified as a numeric or logical 1 (true) or 0 (false). A value of 1 displays the namespace names, and 0 hides them.

Determines whether the Class Diagram Viewer window is currently displayed, specified as a numeric or logical 0 (false) or 1 (true). A value of 1 makes the window visible, and 0 hides it.

Attributes:

Transient
true

Methods

expand all

Examples

collapse all

Construct a Class Diagram Viewer instance with one class preloaded. The class appears in both the Class Browser and the canvas.

httpViewer = matlab.diagram.ClassViewer(Classes="matlab.net.http.RequestMessage")

Class Diagram Viewer showing RequestMessage

Use the addClass method to add two classes to the diagram. Because matlab.net.http.Message is the superclass of the other two classes, the Class Diagram Viewer automatically connects them.

addClass(httpViewer,["matlab.net.http.Message",...
"matlab.net.http.ResponseMessage"])

Class Diagram Viewer showing three classes

Expand the class card for ResponseMessage.

expandClass(httpViewer,"matlab.net.http.ResponseMessage",1)

Class Diagram Viewer showing three classes, ResponseMessage expanded

Collapse the Properties section on the class card for ResponseMessage.

expandSection(httpViewer,"matlab.net.http.ResponseMessage","Properties",0)

Class Diagram Viewer showing three classes, ResponseMessage properties collapsed

Save the diagram as an MLDATX file.

save(httpViewer,"filepath/httpMessages.mldatx")

Version History

Introduced in R2021a

expand all