Map Transform in Vision

I have a screen in Vision with a multi state indicator. I want to do a map transform like I would do on Perspective, using a numeric range of values from a property to output a specific color. Can I get a tip on how to do this simply in Vision? Thanks!

You’ll need to use a case statement

   ,0, 'Val 0'
   ,1, 'Val 1'
   , 'default' 

One of the few times I am ok with a runScript if your return values require some calculations/are more complicated than harcoded values.

You can do

def my_map(map_key):
    mapping = {
        return mapping[map_key]
    except KeyError:
        return "Default value here"

And then call it in the expression
runScript("someModule.myMap",0,{Root Container.someProperty})
where Root Container.someProperty becomes map_key in the function.

The real power starts when you assign functions to your mappings, but BEWARE these functions should be things that evaluate quickly. I’m am pretty @pturmel has written before about this, but never use a sendMessage inside a runScript. Having said that, you could do something like this -

Going back to the first example you can do

def square_it(num):
    return num ** 2

def cube_it(num):
    return num ** 3

def my_map(func_path, number):
    mapping = {
        "first_input": square_it
        "other_input": cube_it
        return mapping[func_path](number)
    except KeyError:
        return "Default value here"

Note that both case and the Python dict based method don’t really meet all the functionality of the map transform - you can’t (easily) define a range of possible values.

1 Like

If you need a range, I would use nested ifs:

if(cond1, 'val1', 
if(cond2, 'val2',