8.8 Defining Styles

It is possible to define a group of attributes as a style and later apply them collectively, see Styles.

Styles can be defined using the defstyle command, as below.

defstyle stylename, ... [ attribute=value | style, ... ], ... ;

First you list the name of the style(s) to define then the attributes and their intended values. Similar to color names, style names are case-sensitive and can only contain letters, numbers, underscores and dots, but can not start with a number or a dot and can not end with a dot. You do not have to specify all possible attributes, just those you want to modify with the style. The rest of the attributes will remain unspecified. When you apply the style to an element, attributes of the element that are unspecified in the syle are left unchanged.

You can also enlist styles among the attributes. In this case the newly defined style inherits all the attributes specified in that style. If you apply a style to an element, those attributes of the style, which not applicable to that particular element type are simply ignored. For example, applying a style including fill.color to an arrow will silently ignore the value of the fill.color attribute.

The same syntax above can be used to extend and modify styles. You can add new attributes to an existing style or modify existing attributes. This is when listing multiple styles comes in handy. You can set attributes to the same value in multiple styles in a signle command. Re-defining an existing style do not erase the attributes previously set in the style. Only the new attribute definition is added - changing the value of the attribute if already set in the style.

It is also possible to unset an attribute by specifying the attribute name, followed by the equal sign, but no value.

There are a number of default, built-in styles that govern the default appearance of elements. By modifying these you can impact, e.g., all the arrows in a chart or all edges in a graph. This is how chart designs operate: by modifying the built-in styles.

If you want to change a set of attributes for multiple elements (such as both for arrows and dividers) simply list these separated by commas before the attributes.

ex58_csh

It will apply to both.

In addition to default styles, most languages have a number of refinement styles. Such styles may contain some attributes set and are applied after and in addition to default styles. For example, after applying the default arrow style to a message in a signalling chart or an arrow of a block diagram, specified as a=>b;, an additional refinement style, named => is applied, making the arrow double-lined.

Redefining refinement enables you to quickly define, e.g., various arrow styles and use the various symbols as shorthand for these.

Thus, in summary the actual attributes of an element are set using the following logic. (There are minor variances for each language.)

  1. If you specify an attribute directly at the element (perhaps via applying a style), the specified value is used40.
  2. Otherwise, if the attribute is set in the refinement style (at the point and in the scope of where the element is defined), the value there is used.
  3. Otherwise, if the attribute is set in the default style of the element, the value there is used.
  4. Otherwise (if they exist in the language), the value of the applicable chart option is used, e.g., text.* for signalling charts. In order for these chart options to be effective default styles usually have no value specified for these attributes. You can set these attributes in styles, e.g., to set font type for empty boxes, which will take precedence over chart options.

Footnotes

(40)

If you specify the attribute several times, the last one is used.