I want to dynamize a display (for example color) based on two variables, how can I do that?
- Armin Beck
I want to dynamize a display (for example color) based on two variables, how can I do that?
Nearly all default displays of atvise's library taking actions based on a single variable only. So any dynamization based on two or more variables needs to be programmed by yourself.
As a good starter we should first look what happens when a "Simple dynamic" on a simple box is used when "change color" action is selected.
Draw a box and use "Add Simple Dynamic" on it.
Under "Single Node" enter the source variable delivering the value that decides on the dynamization
Then choose "Color" as action, a "source value" with any fill color as shown.
You can now look to the source code using the script button that was created for this action.
Â
Below find the resulting scripting code automatically created. It makes a data subscription to the selected variable and whenever the value is changed the functio(e) will be called:
Â
webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_1", function(e) {
var id = "id_0";
var value = e.value;
if (value == 0) webMI.gfx.setFill(id, "#ff2b8a");
});
If we now modify this source code by duplicating it manually you can get easily a dynamization depending on two differnet variables. In this case you have to work with global variables in order record values of the past from previous function calls.
Â
var value_Signal_1;
var value_Signal_2;
Â
webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_1", function(e) {
var id = "id_0";
var value_Signal_1 = e.value;
Â
if (value_Signal_1 == 0 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff2b8a");
if (value_Signal_1 == 0 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#002b8a");
if (value_Signal_1 == 1 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff008a");
if (value_Signal_1 == 1 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#333333");
Â
});
Â
webMI.data.subscribe("Server1/Device_1.Signal Group_1.Signal_2", function(e) {
var id = "id_0";
var value_Signal_2 = e.value;
Â
if (value_Signal_1 == 0 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff2b8a");
if (value_Signal_1 == 0 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#002b8a");
if (value_Signal_1 == 1 && value_Signal_2 == 0) webMI.gfx.setFill(id, "#ff008a");
if (value_Signal_1 == 1 && value_Signal_2 == 1) webMI.gfx.setFill(id, "#333333");
Â
});
Since atvise detects that the original source code has been modifed and is no standard dynamic any more it removes the possibility to click on the simple dynamics list.
Â
Â
Â
Â