Gauge color slow to change

Perhaps this isn’t the best way to handle this. I have a gauge, I pass in the bounds and colors into a script

def UpdateGauge(gauge, Bound1, Bound2, Color1, Color2, Color3):
if gauge.props.value > Bound2:
gauge.props.arc.color = Color3
elif gauge.props.value > Bound1:
gauge.props.arc.color = Color2
else:
gauge.props.arc.color = Color1

This function runs whenever the value, maxValue or any of the 2 bounds change with with a change script. Any thoughts on this? It can be anywhere from instant to like 30 seconds.
Sometimes the color is black, which is never even an option.Thx, jake

This sounds like an ideal use for a map transform:
https://docs.inductiveautomation.com/display/DOC81/Map+Transform#MapTransform-ExpressiontoColor

1 Like

Looks interesting, I’ll check it out.

So I have another place this will work, but not in this case. There’s 3 values that will change the color. The value, bounds1 and bounds2, I didn’t see a away to map one prop to another.Thx, jake

Oh, I see - you’re passing in dynamic bounds as well. I would say, in general, avoiding the change script is probably going to be better for performance. Could you maybe do an expression transform on gauge.props.arc.color directly? There’s a lot of ways to skin this cat, but one way would be something like:
binEnum({gauge.props.value} > {Bound2}, {gauge.props.value} > {Bound1}) - that will return a 0, 1, or 2 that you could feed into a map transform. The referenced properties should be automatically wired up, so no need for a change script to re-run the binding, and the logic is also separated from the colors.

I’ll try that.Thx, jake

Works like a charm now, I used the if(exp, true, false) function and just imbedded if’s to mimic my original function, mapped that 2 a sudo color index that’s mapped to the rgb. Thanks for the help.

2 Likes