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)

treenode colorTable = Model.find("Tools/ColorPalettes/ColorPalette1>variables/colorNodes");
for(int i = 1; i <= colorTable.subnodes.length; i++) {     colorTable.subnodes[i].name = colorTable.subnodes[i].value; }
treenode colorTable = Model.find("Tools/ColorPalettes/ColorPalette1>variables/colorNodes");
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.

Sung K2 avatar image Sung K2 commented ·

Thank you, Felix.

I should have been more specific. I was looking for the node of State Pie Chart color.

I found the node of my State Pie Chart under "ChartTemplates" node. (I expected it would be under "Dashboard" node, but when I expanded the Dashboard node, it wouldn't allow me to expand and nothing there.) I thought there would be a node for colors or a link associated with the color so that I can change it on the fly as needed. Only node I can tell is "AdjustColorsForStateTable" node.

1695997286013.png

Anyway, your script works for changing the color of the color palette on the fly, middle of run, when a certain condition is met, but it still wouldn't update the color of my Pie Chart with the new color. I am sure I missed something to reflect the change to the State Pie Chart. Can you please make an example model to change color of the State Pie Chart middle of the run?

Thanks!

0 Likes 0 ·
1695997286013.png (34.6 KiB)
Felix Möhlmann avatar image Felix Möhlmann Sung K2 commented ·

Hm, turns out I didn't test my solution properly. I must've only tested changing the color manually. After updating the color values in code, you also have to refresh the palette. Sorry for that.

function_s(paletteNode, "refresh")

This then also works with the internal palette. The chart object can be found in the "Statistics" folder.

capture1.png

colorchange-while-running-fm.fsm

0 Likes 0 ·
Sung K2 avatar image Sung K2 Felix Möhlmann commented ·

Thank a million Felix for the Model and explanation!
Perfect! This is exactly what I was looking for.

Maybe not for you and other users, but for me, it is a fairly interesting place for the local palette color nodes! I would never know it is under "Statistics" node without your help. This is the node what I was looking for!

Also, "refreshing the palette" was a super "Ah Ha!" reminder for me.

Thank you very much again for your help!

0 Likes 0 ·