Several if()s inside coalesce() for Vision - alternatives?

So, apparently I need to logically write out my question for this group to answer my own question. Who knew posting here would be so therapeutic?!

Original Q: I’m trying to make it more obvious for operators which asset(s) are contributing to an alarm by highlighting them on main screen that shows an overview of the process. I’ve used if()s nested inside a concat() before for handling strings, but I’m getting warnings with toColor() of the kind, “Cannot coerce string value ‘nullnullnullnull’ into a color”

This was the offending code:

// Expression to turn background of button depending on alarm severity
if ({Chiller_Is_Active},
  concat (
  	if ({Condition1},
	if ({Condition2},
	if (Condition3},
	if (Condition4},
  	toColor("White") // Default

Then I realized I was after the coalesce() function and I just needed to switch the colors names themselves

// Expression to turn background of button depending on alarm severity
        if ({Chiller_Is_Active},"White",NULL), // default, unless alarm
        if ({Condition1},"Orange",NULL), // bad
        if ({Condition2},"White",NULL), // okay for our purposes
        if (Condition3},"Yellow",NULL), // suspicious
        if (Condition4},"Red",NULL) // awful
    )//coalesce (not concat, you nincompoop!)

Are there better ways to do accomplish same effect?

I would wrap the conditions in a binEnc expression bound to a custom property (I usually use one called ‘state’, then use the Style Customizer to affect the look of the button.

Sorry, I should add that the Style customize can affect text as well. :wink:

Can you show me a short sample of what you mean? Doesn’t have to run. Thank you.

(I schedule ignition work once a week for force myself to maintain some basic proficiency…)

binEnc/binEnum take a sequence of booleans and turn them into an integer value. That integer is well suited for use with the Style Customizer

So binEnum(false, false, true, false, true) would evaluate to 3 - the third argument in sequence is true - while binEnc(false, false, true, false, true) constructs a binary number (00101) so the output is 5. (I may have gotten the order incorrect, but that’s the idea, regardless) binEnum is useful for mutually exclusive conditions, binEnc is useful for potentially complementary conditions.

So the idea is you create a custom property, add your conditions inside binEnc or binEnum, and then use the style customizer to drive the appearance off that custom property. That has the (in my opinion) advantage of separating the logic from the actual styles - and the customizer allows you to change multiple properties at once, as Jordan mentioned.

Doesn’t have to run?!? Where’s the fun in that? :crazy_face:

Here’s a window to illustrate.

JC_Style_Customizer_Example.proj (7.7 KB)

1 Like

But then, using a style customiser forces you to use magic colours…

Not if you cell update bind the styles dataset…

1 Like

Huh, I’d never thought of that! :thinking: