AxisLines: Allow them to be excluded from the legend#3612
AxisLines: Allow them to be excluded from the legend#3612swharden merged 5 commits intoScottPlot:mainfrom
Conversation
If an AxisLine (horizontal or vertical) has its Text property set it would always be included in anyt legend - both the automatic or manually built legends. The Text property is also used to display the text along the appropriate axis for the line so it is a valid use case to want the Text set but not add the line to the legend. This change adds an ExcludeFromLegend property to the AxisLine base class which defaults to false (no change to current default behavior). Setting this property to true keeps the line out of the legend regardless of the Text property being set or not.
Demonstrates how the AxisLine's Text and ExcludeFromLegend properties affects the legend.
|
I've realized there is a corollary use case that is not fixed by this change: if the Text/Label is only wanted in the legend and not at the end of the drawn line on the axis. That is currently impossible to do and still impossible with this change. A better, general solution to all of this may be:
This feels more consistent with (all?) other plottables that are added to the legend. AFAIK it is the Label property that controls legend visibility for all the rest. I think it would be clearer if the Text property is separate and only controls the along axis annotation. If you want both, you just set Text and Label to the same thing. I think it is very unlikely you would want both, but there is no harm in supporting all use cases. If you feel this proposed solution is better I'd be happy to close this PR and put a new one together that implements what I've described above. |
|
Hi @MCF, this looks great, thanks!
|
If an AxisLine (horizontal or vertical) has its Text property set it would always be included in any legend - both the automatic or manually built legends. The Text property is also used to display the text along the appropriate axis for the line so it is a valid use case to want the Text set but not add the line to the legend.
This change adds an ExcludeFromLegend property to the AxisLine base class which defaults to false (no change to current default behavior). Setting this property to true keeps the line out of the legend regardless of the Text property being set or not.
A cookbook recipe was added demonstrating how the AxisLines and legend work together. The recipe code and result is shown below.