[Bug-13309,13310] Making basic bar graph

I’m trying to make a super-simple bar graph using an embedded view. My embedded view has 5 parameters:

fillColour
backColour
min
max
value

The display has a single component; a rectangle (which is just a label with no text, since we don’t have actual primitives to play with yet) the same size as the view.
I bind the root container background colour to fillColour, and the rectangle background colour to backColour
(This might seem backward, but the math is simpler if I “fill” from the top down with the background colour, as opposed to filling from the bottom up with the fill colour)

I then use an expression binding to set the height of the rectangle:

1 - ({view.params.value} - {view.params.min}) / ({view.params.max} - {view.params.min})

(Obviously I’ll need out of range checking in there eventually, but, one step at a time)

This returns a value from 0.0 to 1.0, corresponding to my value parameter with respect to the min and max parameters. Since the view’s root container is set to Percent, I can now make the display as large or as small as I want, and the bar graph works exactly as I want it to.

However, when I embed the view into another view, it doesn’t work. Initially, the rectangle appears to have infinite dimensions - then, if I change the min/max/value properties I’m passing to the embedded view, the rectangle disappears altogether. I have added a label to the embedded display, bound to the height parameter of that rectangle, and it correctly updates between 0.0 and 1.0 - e.g. for min 0, max 100, value 50 it displays 0.5. But the height of the rectangle is not 50% of the height of the embedded view.

What am I missing here? Can what I’m trying to do be done?

Edit: interestingly, when I close and re-open the view (the one where I’m building the bar graph, not the one where I’m embedding it), the rectangle loses all of its position properties - x, y, width and height are all null. That’s presumably what’s happening to it when I embed it too - but why? If I remove the height binding, there is no such issue - all position properties are OK after closing and re-opening the view.

Everything logic-wise sounds good, and this is most likely a whole in the logic on our end, when it comes to how an Embedded View “scales” a Coordinate Container which is in percent mode. I’m off to open an internal ticket.

As for the edit regarding the position properties: I’m off to open another internal ticket…

1 Like

Just in case it’s helpful/relevant to the bug, I found similar behaviour on another display…

Using a coordinate view in percent mode, if a component has its X or Y position set to a negative value, it doesn’t display at runtime, and when the view is saved/closed/reopened, X/Y/Height/Width are all null.

In my specific case, I have an image which I want to position just slightly offscreen to the left (because there’s a lot of whitespace on that side of the image), but I can’t do that without the image losing all it’s size and position properties. Obviously, it’s an easy fix (crop the whitespace out of the image and position it at 0), but just figured I’d post in case the additional information helps with tracking down all the ways the bug manifests.

These issues should be fixed as of 4/10. Let us know if you are still seeing either of them.

Both of those issues have resolved, however my approach still isn’t working because of what appears to be another bug related to the Label object :slight_smile:

I have bound the backgroundColor of both the root container and the “fill” rectangle (which is actually a label) to view parameters, so that I can control the colour of the fill and the background. With the label object, the binding doesn’t hold - as soon as it’s embedded on another screen, the colour is just “transparent”, so my graph is always at 100%. If I close and re-open the view I’m embedding, when it’s re-opened, there is no backgroundColour property shown, it’s disappeared. As soon as I manually add it back in, it picks up the binding again, without me re-adding it. But close and open the view, and the property is gone again.

If I disable the binding, the property stays and the graph works (though without the ability to change the colour).

Bump - is the colour binding a bug, or am I doing something wrong?

I believe the latest thing you are seeing is remnants of an older bug we had where params would not stay persistent when they should. Try this, recreate the backgroundColor property so that it picks up the binding again and then right-click it and check the box for Persistent.
If that doesn’t fix it, would you mind sending me the JSON for your view so I can take a closer look at it?

1 Like

Thanks, that worked. Out of curiosity, are you able to explain why it worked? So I understand fully and know when I need to do it next time? :slight_smile:

When a property is persistent, this makes it’s current state save as part of the views json. When it is not, then the view is not aware of the existence of the property until it is created (for example via scripting or binding) unless it has a default value defined by the component itself. The docs has a decent explanation and video for this https://docs.inductiveautomation.com/display/DOC80/Perspective+Component+Properties

There was a bug previously that made it so that parameters weren’t persistent and would not be created when a view was opened. That has been fixed and setting the persistent flag manually fixes previously broken parameters.

1 Like