Control Sets on Web Page

I am trying to create a web application that shows a graph in a WebCanvas. I am trying to label the graph’s x axis using a control set of labels. But the number of labels depends on the size of the canvas. So in a resize event for the page, I have to change the number of labels. Following the “Control Arrays” example, I do this (where LAXAxis is the name of the control set) in the page’s resize event:

[code] for i as integer = XLUBound DownTo 1
LAXAxis(i).Close
next

XLUBound = (CVGraph.width-30)\100 \\ number of labels - 1
dim newLabel as LAXAxis \\ variable for the new label
dim xstart as integer = LAXAxis(0).Left \\ find out where the left-most label is
for i as integer = 1 to XLUBound
newLabel = New LAXAxis \\ create the new label
newLabel.Left = xstart + i*100 \\ set the left position of the new label
newLabel.Visible = True \\ make it visible.
next[/code]

This all compiles and executes without error, but none of the new labels show on the display: I only see the single LAXAxis(0) label. To make things even more confusing, if I try to debug the program, the control set does not appear in the debugger’s list of window properties at all (not even the LAXAxis(0) member), even though all the other controls in the window appear in the variable list. So I can’t seem to check whether the new members of the set ever got created.

Is there something special I need to do with Web apps to make the controls appear? Why don’t they show up in the debugger?

Why not draw the labels directly on the canvas?

Well, I thought about that, but I thought that the latency issues would be less of a problem if I were using label controls. The controls would remain in place between resizings (which would likely happen only once or twice a session) and only the captions would need updating even as the contents, scale, and origin of the graph would change. But I admit that I was unsure about how the canvas works. Does the server side only send instructions to the client side (e.g. draw a line here, draw text here) or does it send a rasterized PNG for the rectangular areas that need updating? I know that there is some way that the server side decides to send the “differences” to the client, but I don’t have a clear enough understanding to design something that is going to be as fast as possible.

[quote=165684:@Thomas Moore]I am trying to create a web application that shows a graph in a WebCanvas. I am trying to label the graph’s x axis using a control set of labels. But the number of labels depends on the size of the canvas. So in a resize event for the page, I have to change the number of labels. Following the “Control Arrays” example, I do this (where LAXAxis is the name of the control set) in the page’s resize event:

[code] for i as integer = XLUBound DownTo 1
LAXAxis(i).Close
next

XLUBound = (CVGraph.width-30)\100 \\ number of labels - 1
dim newLabel as LAXAxis \\ variable for the new label
dim xstart as integer = LAXAxis(0).Left \\ find out where the left-most label is
for i as integer = 1 to XLUBound
newLabel = New LAXAxis \\ create the new label
newLabel.Left = xstart + i*100 \\ set the left position of the new label
newLabel.Visible = True \\ make it visible.
next[/code]

This all compiles and executes without error, but none of the new labels show on the display: I only see the single LAXAxis(0) label. To make things even more confusing, if I try to debug the program, the control set does not appear in the debugger’s list of window properties at all (not even the LAXAxis(0) member), even though all the other controls in the window appear in the variable list. So I can’t seem to check whether the new members of the set ever got created.

Is there something special I need to do with Web apps to make the controls appear? Why don’t they show up in the debugger?[/quote]

If I am not mistaken, the dynamic creation of new control members is not available in WE. The prefered method for dynamic addition of controls is through a webcontainer. See bottom of the page http://documentation.xojo.com/index.php/WebContainer

Alternatively, you could create a bunch of labels in advance and keep them out of the page area, at something like left=-200, them move them in place and back away as needed. Of course that means keeping track of those used and not.

That would explain what I am seeing. But I couldn’t find any statement to that effect in the documentation (and I think I looked pretty hard).

Thank you very much for this idea. I never would have thought about it.

I did think about doing this (or keeping the controls on the page but invisible). I was a bit worried that putting controls off-page would lead to bad behavior, but perhaps this is the way to go.

Try the labels directly on the canvas. With the diff algorithm we use, it should be plenty fast.

[quote=165815:@Thomas Moore]If I am not mistaken, the dynamic creation of new control members is not available in WE.
That would explain what I am seeing. But I couldn’t find any statement to that effect in the documentation (and I think I looked pretty hard).[/quote]

There was a thread a while ago where Greg suggested using the Container Control was preferable.

Thanks, Michel and Greg, for your suggestions. I appreciate it.

It sends the instructions, and only sends what is new/different.

Thanks, Tim, that is very helpful information.