question

Sung K2 avatar image
1 Like"
Sung K2 asked Sung K2 commented

Changing color in State Pie Chart Based on Condition on the fly?

Is it possible to change the color of the State Pie Chart when a condition is met during a run? For example, when a processor has the "processing" state over 80%, the color of the processing state in the pie chart turns to RED from GREEN (Green is the initial color for the Processing state.)

I tried to assign a different color palette when the condition was detected, but it didn't work. maybe the color palette is only set once at reset?

I also tried to find a node for the color of the particular "processing" state, so that I could try to change color directly to the node, but I couldn't find where the color node is.

Anyone knows how?

Thanks.

FlexSim 23.2.0
color changeflexsim scriptcolor palettestatepie
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

Felix Möhlmann avatar image
0 Likes"
Felix Möhlmann answered Sung K2 commented

The color nodes can be found in the tree as seen below.

capture1.png

If you run the following script once, changing the names of the color nodes to be equal to the state name, you can afterwards cast the "colorNodes" node as a table and change the color component value of a given state relatively easily. (When using the code, obviously adjust the name of the palette to what you are using)

  1. treenode colorTable = Model.find("Tools/ColorPalettes/ColorPalette1>variables/colorNodes");
  2. for(int i = 1; i <= colorTable.subnodes.length; i++)
  3. {
  4.     colorTable.subnodes[i].name = colorTable.subnodes[i].value;
  5. }
  1. treenode colorTable = Model.find("Tools/ColorPalettes/ColorPalette1>variables/colorNodes");
  2. colorTable.as(Table)["Processing"]["r"] = 0.83;

When a chart is assigned to a color palette, the colors will update the next time the chart is drawn (so not while the simulation is stopped). This does not work with the internal palette of chart. Those seem to only update on reset.


capture1.png (5.6 KiB)
· 3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.