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.