Added More Legend Flexibility to the BKBaseGraphApplet

comboGraph.png

The developer that has been doing a lot of work with the combo graph, and just graphs in general, came to me again today asking if it were possible to make the legend on a graph a fixed size. I didn't think so, but I didn't know for a fact. I knew that you could place the legend on the top of the graph, left, right (default), or bottom - as well as 'floating' it over the graph. I had put that into the base graph a while back, but failed to put it in the applet.

The problem is that if you are displaying graphs stacked on top of each other in a web page, you run the risk of having the legends different sizes (widths). If so, then the graphs themselves will be different sizes and the x-axes will not line up nicely one on top of the other. So the idea was to be able to set it to a fixed size large enough to hold all the legend entries on all the graphs, and then they would line up nicely.

What I found was that VantagePoint isn't as helpful here as it could be.

If you set the width of the legend you must also tell VantagePoint that you don't want it to sutomatically configure the size of the legend. This leads to the problem that if you don't set the height, then the default value is basically only one entry and it looks very bad. So when we set the width, we also have to set the height. Bummer there, folks. But thankfully, it looks like the scale is approximately 20 pixels for each entry in the legend.

Thankfully, I have the ability to see what's supposed to be on the graph, take that number, multiply it by 20 and use that as the height. It's not perfect, but it's pretty good. There might be problems if you change the font size, or even the font. Or if there is meant to be a scrolling list of legend entries and that's going to mess things up something fierce. But for a first cut, and because I've spent hours trying to figure this out with no luck, let's go with this for now.

If it turns out to be a bad guess, then I'll send an email to VantagePoint and ask them how to do a better job of estimation. I'm sure they have to have something that calculates the default height, all I need to do is to tap into that. May not be easy, but it's certainly an avenue if this doesn't work out.