Perspective Indirect formatting on a label

I am working on putting together a generic label to use with any of my analog values. On my tags, I always use the numeric properties and fill in the units and format string. I want to use this in a embedded view in perspective similar to the way I use it in Vision on a template. Is there a way to have the format bound to a parameter?

I’m sure there’s probably a better way to manage this, but this solution here works (but obviously update the path as needed for you project). This is an Expression binding on Label.props.text against a Tag in my project. It obtains the tag’s value, formatString, and engUnit and uses those pieces to build a String.

numberFormat(tag("[default]Experimentation/IntRepl"), tag("[default]Experimentation/IntRepl.formatString")) + tag("[default]Experimentation/IntRepl.engUnit")

Result:
8.00psi

If you want the format bound to a parameter instead of the format used on the Tag, you should store the format as a string in a property somewhere, and instead of using the Expression above you would replace the format portion with a reference to your custom property:

numberFormat(tag("[default]Experimentation/IntRepl"), {self.custom.formatString}) + tag("[default]Experimentation/IntRepl.engUnit")

Thank you cmallonee! That worked.

1 Like

For the sake of performance you should replace the tag() calls with indirect tag bindings - that is, make a structure in view.custom something like:

{
  "tagPath": "${some String}",
  "formatString": <indirect binding to formatString>,
  "engUnit": <indirect binding to engUnit>,
}

For best results, make these properties private (right click menu) so that the intermediate values aren’t synchronized to the front-end. Then mash them together in a numberFormat expression as Cody did above.

1 Like

Thank you PGriffith. I had already put it in the meta properties. I didn’t know about making it private, though. I will do that.

The custom category is where we recommend you put it. There are some properties present in meta that we do not expose for public use. If you happen to provide a key in meta which matches one of the properties we’ve put in place there you could overwrite important values, or ignore security on that property and expose it in the web browser.

Is there a clean solution for this in 2022?

Why isn’t there a tickbox to enable the EngUnit in Label, Text, …?