Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Visualize the Simulation State with an SVG Image


The Data Pool View shows all variables present in the simulation. However it can be difficult for humans to interpret the state of a model when having only a load of numbers and variables. The former KIELER Environment Visualization (KEV) had been developed to display the simulation state in a more pleasant way. Therefore KEV loaded an SVG image and could manipulate it to reflect the state of the simulation.

This approach has been developed further in KIELER Visualization (KiVis) to integrate with the new simulation. Furthermore a DSL for kivis files has been created to configure how the SVG image will be manipulated.

Besides displaying the state of the simulation, KiVis is also able to interact with the simulation, e.g., when an element in the simulation is clicked. Thus buttons in the SVG image can be created to set variables in the simulation, or to step, stop, play and pause the simulation.

Creating an SVG Image

In this section the open-source vector graphics program Inkscape is used to illustrate how to create an SVG image that can be used with KiVis.

It is advisable to first set the document size. In Inkscape this is done under File > Document Settings. In the image below the size is set to 512x512 px. This setting defines the coordinate system of the file, which is useful when animating, e.g., movement later. Anyhow, SVG images can be scaled to any size.

Inkscape Document Settings

Afterwards three circles and a rectangle have to be created. The circles will simulate the red, green and yellow lights of a traffic light, and thus are colored accordingly. The rectangle will show the same information, but using different animations.

Traffic lights

After the elements of the image have been created, it is necessary to give elements that should be animated a unique name. This can be done in Inkscape by selecting the object and using Right click > Object properties. In the window that opens, an id can be set in the first field (the value without leading hash, labelled "Kennung" in german). Name the circles according to their color, theRedOne, theYellowOne and theGreenOne. The rectangle gets the id theRect.

Note that a new id has to be applied using the button in the object properties window!

Finally, save the result as Inkscape-SVG (recommended) or Normal-SVG and name it Lights.svg.

Groups and Layers

SVG is an XML format. Elements can be grouped and layers can be created which forms a hierarchy. When working with groups and layers in Inkscape, it can be useful to work with the XML-Editor (Ctlr+Shift+X).

Flowed Text

In Inkscape it is possible to create a flowed text element, which is text that wraps its content inside a user defined area. However this is not a fully specified feature in SVG and thus not supported by many SVG viewers. For instance Gimp displays these elements as black box and Firefox does not display them at all.
KEV and the newer KiVis uses Apache Batik for SVG rendering, which also does not support flowed text. If you encounter issues with text object, try to convert them to simple text in Inkscape, via Text > Convert to normal text.

For more information see also the Inkscape FAQ for this topic:

Creating a Configuration File

The configuration depends on the model to be simulated. In the following a simple kivis file is shown for the example model below.

Example KiVis File
image: "Lights.svg"

animate theRect {
  apply color using showLight {
    fillColor: 0 is "red", 1 is "yellow", 2 is "green"

animate theRedOne {
  apply color using showLight {
    opacity: 0 is 1, 1-2 is 0

animate theYellowOne {
  apply color using showLight {
    opacity: 0 is 0, 1 is 1, 2 is 0

animate theGreenOne {
  apply color using showLight {
    opacity: 0-1 is 0, 2 is 1

This configuration will animate the svg element with the id theRect. The value of the variable showLight is used to determine the attributes of the color animation, in this case the fillColor attribute is set. The value 0 of showLight is mapped to the value "red" for the attribute, 1 is mapped to "yellow" and 2 is mapped to "green".

The animations of theRedOne / theYellowOne / theGreenOne is used to show this element (opacity is 1) when the showLight variable is 0 / 1 / 2 and to hide them otherwise (opacity is 0). This represents a very simple traffic light.

When writing a visualiation configuration, code completion can be used to show the available attributes of an animation. In the following the available animations are explained.

Color Animation

It is used to change the appearance of elements. The fill color, stroke color and with as well as opacity can be changed.

fillColorString, either a color name of predefined colors,
or a hexadecimal rgb color
Sets the fill color
fillOpacityFloat, ranges from 0 (fully transparent) to 1 (fully visible)Sets the opacity of the filling
strokeColorSame as fillColorSets the color of the outline / stroke
strokeOpacitySame as fillOpacitySets the opacity of the outline / stroke
opacitySame as fillOpacitySets the overall transparency

Text Animation

This animation can be used for text objects in the SVG to set the font and text.

textStringSets the text of the element
fontSizeIntegerSets the size of the text element
fontFamilyString, name of an installed font (e.g. "Arial Black" or "serif")Sets the font family

Move Animation

This animation changes the position of an SVG element relative to its original position.

xFloatThe x coordinate relative to the original position
yFloatThe y coordinate relative to the original position

Rotate Animation

This animation changes the rotation of elements.

angleIntegerThe angle in degrees that the object should be rotated
anchorXFloat, 0 to 1

Relative position inside the SVG element where the anchor point of the rotation will be.

0 is at the left side, 1 is at the right side. Default is 0.5, which is the middle.

anchorYFloat, 0 to 1

Relative position inside the SVG element where the anchor point of the rotation will be.

0 is at the top side, 1 is at the bottom side. Default is 0.5, which is the middle.

Walk Path Animation

This animation is used to position SVG elements on SVG paths. Therefore the start value of the path and the end value of the path have to be defined. The position is then interpolated linearly between start and end.

This is a powerful animation to position SVG elements, because the position can be drawn as path in the svg itself.

nameStringThe id of the path in the SVG image

The start position of the path.

When the position value is the same as the value of this attribute, the object will be position at the beginning of the path.


The end position of the path.

When the position value is the same as the value of this, the object will be position at the end of the path.


The length of the path.

Can be used instead the absolute end position. In this case the end position is calculated as
end = start+length


Used to set a fixed position on the path. Normally the position is taken from a variable in the simulation data pool, but it can also be set to a fixed value with this attribute.

The value should be between start and end of the path

autoOrientationBoolean, true / falseDetermines if the object should also align its rotation to the path

When autoOrientation is true, this offset in degrees is added to the calculated rotation on the path.

For example if the element is facing with in the wrong direction when it is walking the path, an offset of 180 can be used to turn it.

anglesee rotate animationsee rotate animation
anchorXsee rotate animation

see rotate animation

anchorYsee rotate animationsee rotate animation

Interaction with the Simulation

It is also possible to interact with the visualization. For the image that has been created above, a simple interaction could be configured as follows:

Interaction example
image: "Lights.svg"

animate theRect {
  apply color using showLight {
    fillColor: 0 is "red", 1 is "yellow", 2 is "green"
  } when showLight >= 1

perform on click from theRect {
  showLight = 1
  step simulation
} when showLight != 1

This illustrates that animations and interactions can be used with the same SVG element, which is theRect in this case.

The interaction that is setup in this example is a click listener for theRect. If the element with this id is clicked, the variable showLight will be set to 1 and the simulation will perform a macro tick. However this is only done when the condition holds. Thus the simulation will not be stepped, if the showLight variable already has a value of 1.

Example Model

Create an empty SCChart and fill it with the following content:

scchart TrafficLight {
    output int showLight
    initial state init
      go to init do showLight += 1; showLight = showLight % 3

This model will set the variable showLight successively to 0, 1 and 2.

see rotate animation

  • No labels