Working With Forms > The Form Objects > Graphics

Graphics
The Graphics () form object can plot the same thing as you can plot in the Graphics window in the COMSOL Desktop. Typically you choose a plot group under the Results branch of the model to plot. You can also plot a geometry or mesh, or dynamically let the plot type change. In addition, you can include the plot-while-solving functionality (including probe plots) in runnable applications. To do so, enable it in the study step settings and then ensure that the plot group you are plotting is set as the source to the Graphics form object.
The Graphics object includes a plot toolbar with buttons for zooming, transparency, lighting, printing, and more. You can extend or replace the standard plot toolbar with custom buttons.
Enter the name of the Graphics object in the Name field.
The Settings window contains the following sections:
Source for Initial Graphics Content
In this section you specify a node that represents a plot that becomes the initial contents of the graphics window. The section contains a tree with a filtered view of the trees in the Application Builder and Model Builder windows. The nodes represents some sort of plot or have children that do. The filtered view also includes Explicit selection nodes. You can extend the list of available data nodes by clicking the Switch to Model Builder and Activate Model Data Access button () in the Source for Initial Graphics Content section header, which takes you to the Model Builder, and then selecting a node in the Model Builder branch whose data you want to access. With this button active, the Settings window of the selected node displays a Select Data Source check box (a green square) next to the settings that you can include. Click to select the check box to include that data as an available source node for graphics objects.
When you select a node that represents data, the Use as source button () below the tree becomes enabled. You can also right-click the node and choose Use as source. After selecting a node as the source, the node appears as the selected source under Selected source. You can select from all of the plot groups under the Results branch and all geometry and mesh nodes. You can also select Explicit selection nodes, which makes it possible for users to select geometric entities to update that selection directly in the graphics. Alternatively, use a Selection Input object in the application for activating selections of geometric entities. Click the Edit Node toolbar button () below the tree to move to the corresponding node. If necessary, the program switches to the Model Builder. Click the Clear Source toolbar button () to remove a source that you have selected.
Furthermore, you can also select a string under the Declarations branch. The value of this string controls the plot to show, where the value represents a path to one of the nodes that you can select. For example, if the value is pg1, the plot shows the plot group with this tag. If the value is /GeomList/geom1, it plots the geometry with the tag geom1, and /MeshList/mesh1 plots the mesh with tag mesh1. You can also use the value /Results/ResultFeatureList/pg1 for the plot group, but that syntax is rather cumbersome.
The Zoom to extents on first plot check box is selected by default. This setting makes the first plot that appears in the graphics canvas zoom to its extents when the applications starts, if the graphics canvas is empty initially, or when something is plotted the first time. Clear this check box to disable the zoom to extents action.
Appearance
To add an icon to the upper-right corner (a logotype, for example), specify an image file to use from the Icon list, which includes all images in the Images library, or click the Add Image to Library and Use Here button () to locate an image to use on the file system. That image then becomes a part of the Images library and selected as the icon in this Graphics object. If you do not want to use an icon, select None from the Icon list. Click the Export button () to export the image to the file system (for use in another application, for example).
This section also contains settings for the background color.
Under Background for 2D plots, use the Color list to select the background color for 2D plots and 1D graphs.
The 3D background supports a gradient from top to bottom. Under Background for 3D plots, choose the top and bottom color in the Top color and Bottom color lists.
For all plot background colors, Use default is the default setting, which is a white background for 2D plots and 1D graphs, and a light blue gradient for 3D plots. In addition to a set of predefined colors, you can also choose Transparent and RGBA. For RGBA, enter values between 0 and 255 for the red, green, blue, and alpha (opacity, where 0 means full transparency, and 255 is fully opaque) components of the color as comma-separated values in the RGBA field.
Under State, you can control the initial state of the graphics object when users run the application. By default, the graphics object is visible and enabled. Clear the Visible or Enabled check box if you want to make the initial state so that the graphics object is hidden or unavailable. You can then make it visible or enable it using a method.
Toolbar
In this section, you can add items to a plot toolbar and activate the following table options:
From the Position list, choose where you want to position the toolbar relative to the table: Below, Above (the default), Left, or Right.
Clear the Include standard toolbar buttons check box if you do not want to display the standard plot toolbar buttons for zooming, changing the view, showing legends, adding scene light and transparency, and for creating image snapshots and printing the plot.
In the table below, you can add one or more buttons to form a plot toolbar:
Click the Add Item button () to open the Edit Custom Toolbar Button dialog box (see The Edit Custom Toolbar Button Dialog Box) and create and add a custom toolbar button to the plot toolbar.
Click the Add Separator button () to add a separator between groups of buttons in the toolbar.
Select a button in the table and click the Edit button () if you want to change the appearance or behavior of a custom toolbar button in the Edit Custom Toolbar Button dialog box. Click the Move Up and Move Down buttons ( and ) to move and rearrange the toolbar button order. Click the Delete button () to delete the selected button.
Position and Size
This section contains all layout settings for a graphics object in the grid of the parent form.
In the grid mode, you can control the horizontal and vertical alignment of the check box using the following lists:
From the Horizontal alignment list, choose Left, Center, Right, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
From the Vertical alignment list, choose Middle, Top, Bottom, or Fill, which automatically expands the form object to fill the cell in the horizontal or vertical direction (where applicable).
The need to specify the alignment is most obvious when working in the grid mode, as it controls how the form object is aligned in its grid cell. Aligning the form object can be useful in the sketch mode too, and you can then use the alignment tools on the Arrange menu in the Form toolbar’s Sketch section. When running the application in any client other than the Windows client, the form objects may not be positioned exactly as seen in the form windows. This is because the form objects may have a different size in other clients, giving them a slightly different positioning. Specifying the alignment ensures that the form objects are aligned as you want them to be in all clients.
You can also specify the width and height of the graphics object. Enter a width (in points) in the Width field and a height (in points) in the Height field. If you have chosen Fill from the Horizontal alignment list, you can instead specify a Minimum width. Choose Automatic to compute the minimum width automatically (typically this means a minimum size of 0), or choose Manual to specify a minimum width in the text field underneath. If you have chosen Fill from the Vertical alignment list, you can instead specify a Minimum height. Choose Automatic to compute the minimum height automatically (typically this means a minimum size of 0), or choose Manual to specify a minimum height in the text field underneath.
Additionally, in the sketch mode, you can specify the form object’s absolute position using the Position x and Position y fields. In the grid mode, you can position the object in the grid and see the grid position as the Row, Column, Row span, and Column span values.
Cell Margin
Under Cell margin (in grid mode only), you can control the margins around the form object. By default, the margins are taken from the parent form. From the Cell margin list, choose:
None, to use no margin around the form object.
From parent form (the default), to use the margins set for the parent form.
Custom, to specify the margins for the form object in the Horizontal and Vertical text fields.