goat1000/SVGGraph

Make legend_reverse an official option.

AbcAeffchen opened this issue · 7 comments

Hi,

I found that there are some graphs like StackedBarGraph where the legend seems to be reversed. Turns out that there is already an option for this but it is set as a fixed option, overwriting what ever one would set. I see no reason why the reverse legend should be forced but I see that one may want to have a different default dependent on the graph class used.

I would suggest, merge this settings into the settings handed over by the user such that the user settings overwrite the default. If it has to exist in the ini file and so is always set and thus the class default gets always overwritten by the global default, just set the global default to null and check on this.

Let me know what way you prefer. I think I can take care about this.

Best,
Alex

This one isn't an option at the moment because it is a bit of a kludge. The reason for it is that someone pointed out the legend entries were going in the opposite direction to the bar styles on stacked graphs.

Reversing the legend entries solves that for stacked graphs, but it doesn't help with stacked and grouped graphs, or other shaped graphs, or even some stacked graphs when negative values are involved.

I really need to have a long look at how legends work now and how they should work, and ideally legend_reverse would go away to be replaced by something more useful.

I saw such an option in e.g. jpgraph. I think this option can be useful. The order of the legend depends a little bit if you like to have it associated with the order of appearance or ordered by name of the items or something like that. But this depends on the use case so I think this should be an option.

At the moment I fix this by reversing data, color and legend arrays.

Are there any updates on this? Let me know if I should make some changes in one or the other direction.

No, I haven't had a chance to look at it yet. I'll see if I can come up with a decent solution in the next couple of days.

I've just committed 9efbc6a, which replaces legend_reverse with a new option called legend_order.

The default for the option is "auto" for each graph to choose its own ordering, plus it supports "normal" for displaying the entries in the order they are supplied, "sort" for alphabetic sort, "reverse" for reverse normal order and "reverse sort" (or "sort reverse") for reverse alphabetic sort. It also supports supplying an array of integer keys for listing the entries in a specific order.

Wow. Thanks a lot.
I will test it as soon as possible.

I just tested the changes and they look good. Thanks again.

While checking if everything works fine I noticed that for StackedBarStackedBarGraphs with only two value sets, the legend seems to have a random order, even though the legend is hard coded for the whole set of plots I generate. This seems already an issue in version 3.1.0. I will try to find out more about this and open a new issue if I find something. The new option seems to have nothing to do with this, but also no effect on the order.

Best,
Alex