-
Notifications
You must be signed in to change notification settings - Fork 981
Closed
Description
Suggestion: Would you consider making the Plot.Legend property settable and the Legend class inheritable, by making some methods virtual (e.g. GetItems method)? I am trying to create a custom "LegendWithOrderControl" class that can sort the legends with any logic I want, but Plot.Legend is not mutable.
public class LegendWithOrderControl : Legend
{
private Func<LegendItem[], LegendItem[]>? _orderingFunction;
public LegendWithOrderControl(Plot plot) : base(plot)
{
}
/// <summary>
/// Sets the function used to determine the order of legend items
/// </summary>
/// <param name="orderingFunction">A function that takes an array of LegendItems and returns them in the desired order</param>
public void SetOrderingFunction(Func<LegendItem[], LegendItem[]> orderingFunction)
{
_orderingFunction = orderingFunction;
}
/// <summary>
/// Clears the custom ordering function, reverting to default ordering
/// </summary>
public void ClearOrderingFunction()
{
_orderingFunction = null;
}
/// <summary>
/// Override of the base GetItems method to apply custom ordering if specified
/// </summary>
public override LegendItem[] GetItems()
{
// Get items from base implementation
LegendItem[] items = base.GetItems();
// Apply custom ordering if a function is set
if (_orderingFunction != null)
{
return _orderingFunction(items);
}
return items;
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels