5.9.9. Customizing Gravis

Many aspects of how Gravis operates can be adapted and enhanced via the Gravis configuration. You can find the Gravis rule with various options in the Tools aspect in the graphical configuration interface.

Note

Configuration changes only take effect after quitting and restarting Gravis.

5.9.9.1. Visualization options

The way Gravis displays graphical diagrams is controlled by the graph_style option in the Gravis rule. For instance, you can set the background color of graph windows (default: white) via the option graph_style.background_color. By default, node and edge labels are shown in black, but this can be changed via the option graph_style.default_label_color. You can define the colors and shapes of nodes via graph_style.node_types and the color, thickness, dash pattern, and arrow types/sizes of edges via graph_style.edge_types. Both are dictionaries that map node/edge type names to a hierarchy of structured settings. You can leave any of the child settings at None (unspecified), which makes the given type inherit this property from its parent in the type hierarchy as shown in the Gravis Node/Edge Type panels.

By default, most settings of most types are None (unspecified). This allows you to set properties for whole subtrees of the type hierarchy. For instance, if you set Source_Dependency.width to 2.0 in graph_style.edge_types, then all edge types in the subtree of Source_Dependency, e.g., Static_Call and Variable_Use, are shown 2 pixels wide. You can still override the width of individual types by setting a specific value there.

Custom Node and Edge Types

The graph_style.node_types and graph_style.edge_types dictionaries contain entries for all predefined node and edge types. In addition to editing these entries, you can add new entries for any custom node and edge types you want to use by clicking on the New entry... button in the node_types/edge_types edit dialog and entering the name of your custom type. After restarting Gravis, if a loaded graph contains a node/edge type with the given name, or a type of that name is created in the graph, the settings of this entry are used to visualize it.

If a graph contains node/edge types that are not mentioned in the graph_style.node_types/edge_types dictionaries, their visualization settings are inherited from their parents in the type hierarchy and the __default__ entry as the implicit parent of all top-level types.

Adding SVG Icons

Gravis provides a set of predefined node shapes. In addition, you can use any SVG graphic as a node shape for existing node types or custom node types. The shape sub-option of the entries in the graph_style.node_types dictionary accepts either the name of a predefined node shape or the filename of an SVG file (as an absolute path or relative to the directory containing the configuration file).

Configuring an SVG shape in the GUI.

Using the graphical configuration interface to configure a custom node type to use an SVG icon.

The size and position of the icon in the SVG file are not important; Gravis scales it to match the size of the predefined node shapes.

Adding custom icons without configuration changes (legacy mechanism)

Gravis has a legacy mechanism to look for custom icons for node types that lack a shape configuration in node_types, either because they do not appear in the dictionary or because their shape option is set to None. It looks for files with a .svg extension in the directory custom_icons inside any configuration layer, i. e., inside any directory listed in BAUHAUS_CONFIG or inside the directory .bauhaus in the user’s home directory. Found files are associated with node types by name; for example, the file $(HOME)/.bauhaus/custom_icons/MyType.svg is used for nodes of type MyType (and its subtypes in the type hierarchy, provided they have no explicit shape configuration). This mechanism is deprecated and may be removed in a future version of Gravis.

Node and Edge Labels

Gravis can display labels at the top, center, and bottom of nodes, as well as in six different positions around edges: at the top and bottom near the source node, at the top and bottom in the middle of the edge, and at the top and bottom near the target node. For each node or edge type, each of these positions can display nothing, a fixed string, or a string based on the presence and content of an attribute. For instance, the label_top option in the Routine entry of graph_style.node_types controls the label displayed at the top of Routine nodes (or any subtypes of Routine for which this key is not explicitly overridden). The label_middle option controls the label in the center of the node, which is wrapped to the width of the node and shown as rich text if it resembles HTML. The label_middle_top option in the UML Relation entry in graph_style.edge_types controls the label shown above UML Relation edges, centered between the start and end nodes.

The value of these label options is a label specification, which is either the key of an attribute to display or a list of comma-separated key=value pairs that define various aspects of the label, including its display style. Comma and backslash characters within a value must be escaped with a backslash character. Available label specification keys are:

  • attr=name

    Specifies the key of an attribute to display. If the attribute is not present, the value specified by the default key is shown; otherwise, no label is shown. For attributes other than boolean flags, the attribute value is shown, optionally enclosed by a prefix and suffix. If the attribute is a boolean flag, the redundant value true is never shown; instead, only the prefix is displayed. In this case, the prefix must be specified, otherwise nothing is shown at all.

  • bold=flag

    Specifies whether the label should be displayed in a bold font.

  • default=string

    Specifies a string to be displayed if the specified attribute is not set. If no attr key is specified, the default string is always shown.

  • italic=flag

    Specifies whether the label should be displayed in an italic font.

  • size=+/-number

    Specifies the relative font size to be used. A positive value makes the label appear larger than the default label font size, while a negative value makes it appear smaller. The increment/decrement is measured in points.

  • prefix=string

    Specifies a string to be displayed before the attribute value. This is only shown if the attribute is set. This key is optional, unless attr refers to a boolean flag attribute, in which case it is required.

  • suffix=string

    Specifies a string to be displayed after the attribute value. This is only shown if the attribute is set. This is not shown for boolean flag attributes.

Either attr or default must be present for a label setting to take effect.

Example label specifications:

  • attr=UML.Stereotypes,bold=true,size=-1

    displays the contents of the attribute UML.Stereotypes in a bold font and 1pt smaller than the normal label font size, or nothing if the attribute is not set.

  • attr=Metric.Lines.LOC,prefix=LOC=,default=(no LOC)

    displays the contents of the integer attribute Metric.Lines.LOC prefixed by LOC=, or (no LOC) if the attribute is not set.

  • default=Association,italic=true

    displays the label Association in an italic font unconditionally for every node or edge type for which this label is configured.

  • attr=Element.Is_Optional,prefix=optional

    displays optional if Element.Is_Optional is set; otherwise, nothing is shown.

  • attr=Element.Is_Optional,prefix=optional,default=mandatory

    displays optional if Element.Is_Optional is set; otherwise, it displays mandatory.

Variable edge widths

Gravis can be configured to display different edge widths based on applied attribute values. For instance, this can be used to show thicker edges for architecture violations caused by numerous unwanted source code dependencies.

To enable this feature for an edge type, configure the width_multiplier field in its entry in the graph_style.edge_types dictionary. This field takes a multiplier specification, which is a semicolon-separated sequence of multiplier expressions. The first applicable multiplier expression computes the multiplier – the value by which the configured width of the given edge is multiplied. Expressions that use an incorrect format or reference an attribute that is not applied to the edge are skipped. If all expressions are skipped, the edge width remains unchanged. This sequencing allows the multiplier to be computed based on several attributes with a priority ordering.

A multiplier expression follows the format func(param1, param2, ..., paramN), where each parameter is either a float value or the name of a numeric attribute (i.e., an attribute of type int or float).

Currently, the only available function is map_range(attr_name, vmin, vmax, rmin, rmax), which retrieves the attribute attr_name and maps attribute values between vmin and vmax to the result range rmin to rmax. Attribute values below vmin are mapped to rmin, and attribute values larger than vmax are mapped to rmax.

Example multiplier expression:

Architecture analysis result edges (i.e., edge-divergence Divergence and edge-convergence Convergence edges) have an integer attribute Analysis.Causing_Edge_Count that specifies the number of source code dependencies contributing to that result edge.

If you set the following width_multiplier for the Architecture_Check_Result edge type:

map_range(Analysis.Causing_Edge_Count,1,21,1.0,6.0)

then result edges caused by one source code dependency are shown at the original edge width, whereas edges caused by 21 or more source code dependencies are shown at six times the configured edge width. An edge caused by five source code dependencies (20% of the way from 1 to 21) would be shown at 2.0 times the configured width (also 20% of the way from 1.0 to 6.0).

To apply different widths only to divergence edges, apply this setting to the Divergence edge type instead of its supertype Architecture_Check_Result.

5.9.9.2. Keyboard shortcuts

Gravis offers keyboard shortcuts for many menu entries. If there is a shortcut for a menu entry, it is shown next to it. Existing shortcuts can be changed, and shortcuts can be assigned to most menu operations that do not yet offer one.

To add or change keyboard shortcuts, add a file named gravis_shortcuts.txt to any configuration layer, i. e., either a directory listed in BAUHAUS_CONFIG or the directory .bauhaus in the user’s home directory. If there is more than one such file, standard layering rules apply, so changes made in more local layers override those made in more global layers. The .bauhaus directory in the user’s home directory is considered the most local layer.

The gravis_shortcuts.txt file associates operation names with keyboard shortcuts, e. g.:

# my personal shortcuts
Graph.LayoutStorage.SaveAsPNG      Ctrl+F2
Graph.LayoutStorage.SaveAsPDF      Ctrl+F3     # next to "SaveAsPNG" on the keyboard
Diagram.Edit.DeleteSelection       # clear shortcut to avoid accidents

You can find the operation names in the menu reference section above. The most global gravis_shortcuts.txt file, which is part of the Axivion Suite installation, lists all operations that can be bound to keyboard shortcuts. Files in more local layers can only use the operation names listed there. Lines with other operation names are ignored with a warning.

Use any number of whitespace characters to separate the operation name from the shortcut. Shortcuts are specified using English key names (Ctrl, Shift, etc.), independent of the computer’s locale settings. Leaving out the shortcut definition clears any existing shortcut for the given operation. Comments are introduced by a hash character and extend to the end of the current line.

Instead of a key combination, you can specify one of the following names, which stand for the standard shortcut of the respective action on the current platform: :HelpContents, :WhatsThis, :Open, :Close, :Save, :New, :Delete, :Cut, :Copy, :Paste, :Undo, :Redo, :Back, :Forward, :Refresh, :ZoomIn, :ZoomOut, :Print, :AddTab, :NextChild, :PreviousChild, :Find, :FindNext, :FindPrevious, :Replace, :SelectAll, :SaveAs, :Preferences, :Quit, :FullScreen, :Deselect and :Cancel. If the current platform has no standard shortcut for the action, the line has no effect and results in a warning.

If the same operation occurs more than once in a file, the last change in the file wins.

The command clear() on its own line clears all shortcuts assigned so far, allowing you to start setting up all shortcuts from scratch. This can be useful to avoid conflicts between newly assigned shortcuts and predefined shortcuts.

Conditional blocks

It is possible to define platform-specific shortcuts using ifeq/else/endif constructs similar to GNU make:

ifeq ($(PLATFORM),Windows)
   File.Reload                            F12
else
   File.Reload                            Ctrl+R
endif

The else branch is optional. Use ifneq instead to test for inequality. Conditional constructs can be nested.

$(PLATFORM) is a pseudo-variable that resolves to Windows, Linux, or macOS depending on the current platform. Any other variable name is looked up as an environment variable. Non-existent environment variables expand to the empty string.

Conflict resolution

Each operation can only have a single shortcut, and each possible shortcut can only be assigned to a single operation. The first requirement is always satisfied: as described above, later changes override earlier ones, so if the same operation appears more than once in a shortcuts file, the last change in the most local layer wins.

Similar logic applies to shortcuts appearing more than once on the right-hand side: if a shortcut that was already mentioned is assigned to a different operation, the association with the earlier operation is removed. Again, the last use in the most local layer wins. Because these conflicts are not obvious, they result in a warning.

Conflict resolution also accounts for menu scripts bound to keyboard shortcuts (see Adding Scripts to Menus, Shortcuts and Events). Menu scripts are considered more local than shortcuts files, so if the same shortcut is assigned in both a shortcuts file and a menu script, the menu script wins, regardless of the layers. This kind of conflict also results in a warning.

The standard shortcuts for :Close close the active window tab and cannot be reassigned. If a shortcuts file assigns one of them to an operation, the assignment is ignored with a warning.

Additional operations

In addition to the operation names shown next to menu entries in this chapter, there are the following non-menu operations that can be bound to keyboard shortcuts:

  • Diagram.RenameNode to rename the node under the pointer (default: F2)

  • Tools.Navigate (default: F3), Tools.Select (default: F4), Tools.Mark (default: F5), Tools.Node (default: F6), Tools.Edge (default: F7), Tools.Hierarchy (default: F8), Tools.Zoom (default: F9), Tools.Scroll (default: F10), Tools.Mapping (default: F11) to select a tool

  • Visualization.ToggleEdgeBundling to toggle the edge bundling visualization option (default: Ctrl+Shift+B)

5.9.10. Command-line parameters

Usage:

gravis [options] <input file(s)>

The first input file is opened as it would be with Open... in the File menu: an RFG file is loaded, a GXL file is imported into a new empty graph, and an architecture project file (extension .gaproj) loads its graph. Every subsequent input file must have the extension .gxl and is imported into that graph. Any other file type will cause loading to stop with an error message.

Options:

--script <script filename>

Runs the given Python script at startup (after loading input files).

--script-param <parameter>

Adds a parameter to be passed to the Python script (only useful in conjunction with --script).

--noscript

Disables Python scripting.

--quit

Causes Gravis to quit after startup (mainly useful in conjunction with --script), enabling non-interactive mode.

--font <font name>

Specifies the font to be used in the user interface.

--font-size <font size>

Specifies the font size in pt to be used in the user interface (in conjunction with --font). 0 for system default.

--ignore_geometry

Prevents window position and size information stored during the previous session from being loaded. Useful if the information has become corrupted and causes the window to be opened off-screen.

--basepath <path>

Specifies the base path used for source code lookup.

--no_platform_override

Does not override the platform to offscreen for non-interactive Linux/macOS use.

--no_translate

Prevents translation files from being loaded and forces the English UI to be shown.

--translate <locale>

Overrides the system locale for finding translation files. If this option is not specified, the locale name is read from the environment variable AXIVION_UI_LANGUAGE, and if that variable is not set, the system locale is used to determine the preferred UI language.

--style <style>

Overrides the Qt platform style, e.g., fusion.

In addition to these options, common options for Axivion Suite tools are supported (see Tool Reference).