This lesson is part of the Perspective Components and Bindings course. You can browse the rest of the lessons below.


Autoplay Off


This lesson introduces the Map Transform. This simple transform takes the results of a component binding, and returns a different value, based on what the binding returned. Useful when mixing data types, such as retrieving a numerical value from a binding, and then using the Map Transform to return a matching string value.

Video recorded using: Ignition 8.0


(open in window)

[00:00] In this lesson, we'll look at the map transform. A map transform allows you to take in an input value and then return one of several possible output values instead. So to start with I have this label and I have a memory tag. I would like to take the value on this memory tag, which is an integer, and then show some text here on the label depending on what the value is. We'll start with just a normal tag binding. On the text property, I'll click the binding icon. I want to use the value on my memory tag. So we'll use a normal direct tag binding to the memory tag. Now we see in the preview that this returns the value of the tag. I want to replace this with text. An easy way to do that would be to add a map transform. So I can hit the add transform button here and we'll see a little popup window up here. We'll stick with the map transform for now and talk about the others in later videos. So a map transform allows you to take some inputs or a range of inputs and turn them into an output. I'll hit the add transform button and whenever you're using a map transform, we always start or at least give you a fallback value. So if our input happens to be something you didn't define, we'll use the fallback. I'll add a couple of rows to this table by pressing the plus button over here a couple of times. So the way this works is whatever value's on the tag, we're going to go ahead and push down to this transform as an input. And then we'll try to find a matching output. So for the input type column, I can define some values. We'll type zero and one respectively. And then I can come over to the output type column and then specify what I want to return from the transform based on what the bindings bringing in. So if the tag bindings returning was zero, we can return the string off and if it returns a one, we can return the string on. Let's also define a fallback value. So if our tag binding returns anything other than a zero or one, the transform will return the string error. If I hit okay, we can see the value in my tag as one. So it's showing on, if I change the value of my tag and can see that it's off, when I said it to zero, if I change it to something else, you can see that it gives us an error. So we're taking the numerical value on the tag here and we're turning it into a string. Now if I go back into the interface here and take a look at our transform, notice that I can add more transforms. So if I were to add another map, you can see that it adds another map down below as well as showing it on this little path down here. So it shows us what the value is ultimately going to end with as well as everything along the way. So the takeaway from this is that one transform can lead into another transform. Be careful with chaining too many of these. In some cases it might be easier to try a different binding all together or maybe take a different approach instead of making four or five transforms. Now let's close this window and look at my led display. The value on this component is currently bound to my memory tag. I'll select this component and I would like to change the value of the diode on color property based on the value of the tag. Just like last time, we'll start by creating a binding. I'll click the icon, we'll select a tag binding and for the tag path, I'll grab my memory tag once again. We hit okay and when we add the transform this time while I'm selecting map again, we can actually change the input and the output. So there's actually some dropdowns over here. So instead of just looking at each individual value, I can click up here and select a numeric range of values. And with the output type we can actually do something very similar. I'll click where it says value and you'll see that there's a dropdown. I'm going to use color, but you can see that there's a bunch of options. We'll talk about them in later videos. So I'll pick color for right now. And then how about for the fall back color here, we'll just specify maybe a blue color. I'll add a couple of rows here. And how about when we were in range? Maybe we could just stick with our green color and then when we're a little too high maybe how about we jump to a red color? Then we need to define the ranges. So if I double click in this cell over here, we can see that it actually shows me an example of what it wants for the format. So square brackets, a minimum and a maximum value. So if I start typing, I can place one to 10 in here. So if the value on the tag is between one and 10 and that's inclusive, so it's including those numbers, then we'll return the green color. So I'll hit enter to commit here. And then how about for the red? We can state 11 as the minimum value and then choose to not include a maximum in this case. So if I close this off here, we're saying that the value, if it's 11 or higher, use red. I'll hit apply right now and if we move this out of the way, you can see that I'm well above 10 so we're showing the red color. If I were to type in five, we can see that we fall back within range and if I go to a negative number, which we really didn't define, you can see that we're using the blue color. Now one last thing, I'll bring the binding window back. You can also omit a minimum instead. So maybe up above here, instead of setting it to one as the minimum, I can remove the one, hit enter and now I'm basically saying if it's 10 or lower we're green. If it's 11 or higher, we're red. If we somehow get something else, we'll use the blue color. Hit okay again, and you can see we were blue before, but now with negative 50, we're showing green. So hopefully that gives you a good idea about what these map transforms can do. Again, they're fantastic when you're taking the value of a tag or a property and you need to convert that value into a different data type.

You are editing this transcript.

Make any corrections to improve this transcript. We'll review any changes before posting them.