Skip to content
Snippets Groups Projects
Commit c0079c75 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

update VisB manual

parent cea4acaf
No related branches found
No related tags found
No related merge requests found
Pipeline #117215 passed
%% Cell type:markdown id:5b53d563 tags:
%% Cell type:markdown id:5850e2ad tags:
# VisB
Initially VisB was developed for [[ProB2-UI]], the new user interface of ProB based on JavaFX and the ProB2-Java-API.
It is included in ProB2-UI version 1.1.0 and later, which [[Download#ProB2-UI using Java FX|can be downloaded here]].
Users of ProB2-UI version 1.0.0 can [[#Installing the VisB plugin for older ProB2-UI versions|install VisB as a plugin]].
[[File:ProB2UI_VisB_View.png|center|550px]]
ProB Tcl/Tk and probcli version 1.11.0 and later also support VisB visualisations:
* with <tt>probcli File.mch ... -visb VISBJSONFILE HTMLFILE</tt> you can export the animator's history to a self-contained HTML file including a visualisation of the states in the history
* in ProB Tcl/Tk you can visualise the current state or the history using a VisB visualisation file (it is shown in an external browser) by right clicking in the "State Properties" or the "History" pane.
Hovers work in both cases, but unlike in ProB2-UI, you cannot click to perform events.
An article about VisB has been [https://rdcu.be/b4rqh published in the ABZ'2020 proceedings].
%% Cell type:markdown id:6942b823 tags:
%% Cell type:markdown id:53b80314 tags:
As of version 1.12 you can also provide many of the VisB annotations via B DEFINITIONS.
This can be done in addition to a VisB JSON file or completely replacing the JSON file.
By adding this definition to your B machine you specify that you wish to use an empty
SVG file as base:
<pre>
VISB_JSON_FILE == "";
</pre>
### VISB_SVG_BOX
With a VISB_SVG_BOX definition you can set the size of the generated empty SVG file:
<pre>
VISB_SVG_BOX == rec(height:formula, width:1800);
</pre>
Note: you can also provide an optional <tt>viewBox</tt> attribute as a B string.
### VISB_SVG_OBJECTS
You can populate the empty SVG file with your own new objects using DEFINITIONS that start with <pre>VISB_SVG_OBJECTS</pre>.
Here is an example where we create one red circle:
%% Cell type:code id:22657ef0 tags:
%% Cell type:code id:629b2052 tags:
``` prob
::load
MACHINE test1
DEFINITIONS
VISB_JSON_FILE == "";
VISB_SVG_BOX == rec(height:100, width:400);
VISB_SVG_OBJECTS == rec(`id`:"button", svg_class:"circle",
cx:200,cy:50, r:30, fill: "red",
stroke:"black", `stroke-width`:2);
END
```
%% Output
Loaded machine: test1
%% Cell type:code id:9cf27405 tags:
%% Cell type:code id:ed27217b tags:
``` prob
:init
```
%% Output
Executed operation: INITIALISATION()
%% Cell type:code id:5fd0cbbe tags:
%% Cell type:code id:9e2e4225 tags:
``` prob
:show
```
%% Output
<VisB visualization>
%% Cell type:markdown id:41725617 tags:
%% Cell type:markdown id:b8d00549 tags:
A VISB_SVG_OBJECT definition should either define a record or a set of records. The fields of the record specify the kind of object created and its initial attributes:
* usually all created object should have an id (so that you can later modify the attributes)
* you have to provide an <tt>svg_class</tt> attribute: circle, ellipse, line, path, polygon, polyline, rect, text
* you then can (and probably) should provide necessary attributes and initial values for your object
Note: <tt>id</tt> is a keyword in B and hence you have to use backquotes around it. Similarly, B does not allow identifiers with hyphens, hence you need surround such attributes (like <tt>stroke-width</tt>) with backquotes as well.
%% Cell type:code id:764ca933 tags:
%% Cell type:code id:669da81c tags:
``` prob
::load
MACHINE test2
DEFINITIONS
N == 5; WID==400.0;
VISB_JSON_FILE == "";
VISB_SVG_BOX == rec(height:100, width:WID+30.0);
VISB_SVG_OBJECTS == UNION(i).(i:1..N|
{rec(`id`:("circ",i), svg_class:"circle",
cx:real(i)*WID/real(N),cy:50, r:(30-i), fill: "red",
stroke:"black", `stroke-width`:2)});
END
```
%% Output
Loaded machine: test2
%% Cell type:code id:f9945f44 tags:
%% Cell type:code id:5846d13f tags:
``` prob
:init
```
%% Output
Executed operation: INITIALISATION()
%% Cell type:code id:5b769d49 tags:
%% Cell type:code id:64d5cc55 tags:
``` prob
:show
```
%% Output
<VisB visualization>
%% Cell type:code id:00c70a05 tags:
%% Cell type:code id:1cddf7f4 tags:
``` prob
:table VISB_SVG_OBJECTS
```
%% Output
|cx|cy|fill|id|r|stroke|stroke-width|svg_class|
|---|---|---|---|---|---|---|---|
|80.0|50|"red"|("circ"↦1)|29|"black"|2|"circle"|
|160.0|50|"red"|("circ"↦2)|28|"black"|2|"circle"|
|240.0|50|"red"|("circ"↦3)|27|"black"|2|"circle"|
|320.0|50|"red"|("circ"↦4)|26|"black"|2|"circle"|
|400.0|50|"red"|("circ"↦5)|25|"black"|2|"circle"|
cx cy fill id r stroke stroke-width svg_class
80.0 50 "red" ("circ"|->1) 29 "black" 2 "circle"
160.0 50 "red" ("circ"|->2) 28 "black" 2 "circle"
240.0 50 "red" ("circ"|->3) 27 "black" 2 "circle"
320.0 50 "red" ("circ"|->4) 26 "black" 2 "circle"
400.0 50 "red" ("circ"|->5) 25 "black" 2 "circle"
%% Cell type:code id:2222fff4 tags:
%% Cell type:markdown id:7c892901 tags:
### VISB_SVG_UPDATES
To dynamically update the SVG objects based on a B model's state you can specify <tt>VISB_SVG_UPDATES</tt> DEFINITIONS. They have the same form as <tt>VISB_SVG_OBJECTS</tt> DEFINITIONS, except you should not specify the <tt>svg_class</tt> attribute. In addition, the attribute values can depend on B variables.
Here is a small example:
%% Cell type:code id:7d8491f0 tags:
``` prob
::load
MACHINE test3
VARIABLES x
INVARIANT x:1..N
INITIALISATION x:=1
OPERATIONS inc = BEGIN x:= (x mod N)+1 END
DEFINITIONS
N == 5; WID==400.0;
VISB_JSON_FILE == "";
VISB_SVG_BOX == rec(height:100, width:WID+30.0);
VISB_SVG_OBJECTS == UNION(i).(i:1..N|
{rec(`id`:("circ",i), svg_class:"circle",
cx:real(i)*WID/real(N),cy:50, r:(30-i),
stroke:"black")});
VISB_SVG_UPDATES == UNION(i).(i:1..N|
{rec(`id`:("circ",i),
fill: IF i=x THEN "red" ELSE "gray" END,
`stroke-width`:IF i=x THEN 2.0 ELSE 0.5 END)});
END
```
%% Output
Loaded machine: test3
%% Cell type:code id:ea98b025 tags:
``` prob
:init
```
%% Output
Executed operation: INITIALISATION()
%% Cell type:code id:bb265467 tags:
``` prob
:show
```
%% Output
<VisB visualization>
%% Cell type:code id:d8d09a69 tags:
``` prob
:exec inc
```
%% Output
Executed operation: inc()
%% Cell type:code id:61d5ca71 tags:
``` prob
:show
```
%% Output
<VisB visualization>
%% Cell type:code id:2993ed34 tags:
``` prob
:table VISB_SVG_UPDATES
```
%% Output
|fill|id|stroke-width|
|---|---|---|
|"gray"|("circ"↦1)|0.5|
|"gray"|("circ"↦3)|0.5|
|"gray"|("circ"↦4)|0.5|
|"gray"|("circ"↦5)|0.5|
|"red"|("circ"↦2)|2.0|
fill id stroke-width
"gray" ("circ"|->1) 0.5
"gray" ("circ"|->3) 0.5
"gray" ("circ"|->4) 0.5
"gray" ("circ"|->5) 0.5
"red" ("circ"|->2) 2.0
%% Cell type:markdown id:7818407b tags:
### VISB_SVG_CONTENTS
With <tt>VISB_SVG_CONTENTS</tt> DEFINITIONS you can add additional static content to your SVG file. This is useful for CSS styles or arrow markers, for example.
Here is an example:
%% Cell type:code id:5bdcf602 tags:
``` prob
::load
MACHINE test4
VARIABLES x
INVARIANT x:1..N
INITIALISATION x:=1
OPERATIONS inc = BEGIN x:= (x mod N)+1 END
DEFINITIONS
N == 5; WID==400.0;
VISB_JSON_FILE == "";
VISB_SVG_BOX == rec(height:100, width:WID+30.0);
VISB_SVG_OBJECTS == UNION(i).(i:1..N|
{rec(`id`:("circ",i), svg_class:"circle",
cx:real(i)*WID/real(N),cy:50, r:(30-i))});
VISB_SVG_UPDATES == UNION(i).(i:1..N|
{rec(`id`:("circ",i),
class: IF i=x THEN "selected" ELSE "normal" END)});
VISB_SVG_CONTENTS == '''
<style>
.selected {
fill: red;
stroke : black;
stroke-width: 2.0
}
.normal {
fill : gray;
stroke : none
}
</style>
''';
END
```
%% Output
Loaded machine: test4
%% Cell type:code id:366c7bfc tags:
``` prob
:init
```
%% Output
Executed operation: INITIALISATION()
%% Cell type:code id:569344f3 tags:
``` prob
:show
```
%% Output
<VisB visualization>
%% Cell type:code id:caeb65b3 tags:
``` prob
:table VISB_SVG_UPDATES
```
%% Output
|class|id|
|---|---|
|"normal"|("circ"↦2)|
|"normal"|("circ"↦3)|
|"normal"|("circ"↦4)|
|"normal"|("circ"↦5)|
|"selected"|("circ"↦1)|
class id
"normal" ("circ"|->2)
"normal" ("circ"|->3)
"normal" ("circ"|->4)
"normal" ("circ"|->5)
"selected" ("circ"|->1)
%% Cell type:code id:09c42864 tags:
``` prob
:table VISB_SVG_OBJECTS
```
%% Output
|cx|cy|id|r|svg_class|
|---|---|---|---|---|
|80.0|50|("circ"↦1)|29|"circle"|
|160.0|50|("circ"↦2)|28|"circle"|
|240.0|50|("circ"↦3)|27|"circle"|
|320.0|50|("circ"↦4)|26|"circle"|
|400.0|50|("circ"↦5)|25|"circle"|
cx cy id r svg_class
80.0 50 ("circ"|->1) 29 "circle"
160.0 50 ("circ"|->2) 28 "circle"
240.0 50 ("circ"|->3) 27 "circle"
320.0 50 ("circ"|->4) 26 "circle"
400.0 50 ("circ"|->5) 25 "circle"
%% Cell type:code id:a215c22b tags:
``` prob
```
%% Cell type:code id:caffd470 tags:
``` prob
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment