Skip to content

Legend: add option to disable column-based wrapping #3758

@MCF

Description

@MCF

When using a horizontal legend with labels of significantly different widths, it would be nice to have an option to have tight spacing across the legend. Right now the labels are padded so that all labels are the same width (to match the longest label).

I know the legend is doing a lot of hard work to space and align items automatically, but horizontal legends look a bit odd if the labels are different widths.

Here is an example of the current behaviour, a screen capture of the result, followed by a mock up of the proposed behaviour.

ScottPlot.Plot myPlot = new();

var sp1 = myPlot.Add.Signal(Generate.RandomSample(50, -1, 1));
sp1.LineWidth = 2;
sp1.LegendText = "Random";

var sp2 = myPlot.Add.Signal(Generate.Sin());
sp2.LegendText = "One Cycle of A Sine Wave";
sp2.LineWidth = 4;

var sp3 = myPlot.Add.Signal(Generate.Consecutive(count: 50, delta: 0.03, first: -1));
sp3.LegendText = "Ramp";
sp3.LineWidth = 2;
sp3.LinePattern = LinePattern.Dotted;

myPlot.Legend.Orientation = Orientation.Horizontal;
myPlot.Legend.Alignment = Alignment.UpperLeft;

myPlot.SavePng("bug.png");

Current behaviour:

horizontal-legend-example

Proposed behaviour:

horizontal-legend-example-new

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions