Skip to content

Radial Gauge Plot: Poor rendering with <4 gauges #2448

@swharden

Description

@swharden

Thanks daddydavid from the Discord (#1966) for pointing this out!

Reproducing

for (int i = 1; i < 6; i++)
    MakeGaugePlot(i);
void MakeGaugePlot(int gaugeCount)
{
    double[] data = Enumerable.Range(0, gaugeCount)
        .Select(x => (double)Random.Shared.Next(10, 100))
        .ToArray();

    ScottPlot.Plot myPlot = new(200, 200);
    myPlot.AddRadialGauge(data);
    myPlot.SaveFig($"test-{gaugeCount}.png");
}

test-5test-4test-3test-2test-1

Relevant Code

I think the problem could be improved by adding some custom logic here to shrink radiusPx for cases with 1, 2, or 3 gauges.

int index;
int position;
for (int i = 0; i < GaugeCount; i++)
{
if (GaugeMode == RadialGaugeMode.SingleGauge)
{
index = GaugeCount - i - 1;
position = GaugeCount;
}
else
{
index = i;
position = OrderInsideOut ? i + 1 : (GaugeCount - i);
}
RadialGauge gauge = new()
{
MaximumSizeAngle = MaximumAngle,
StartAngle = startAngles[index],
SweepAngle = sweepAngles[index],
Color = Colors[index],
BackgroundColor = Color.FromArgb(backgroundAlpha, Colors[index]),
Width = gaugeWidthPx,
CircularBackground = CircularBackground,
Clockwise = Clockwise,
BackStartAngle = StartingAngleBackGauges,
StartCap = StartCap,
EndCap = EndCap,
Mode = GaugeMode,
Font = Font,
FontSizeFraction = FontSizeFraction,
Label = Levels[index].ToString(LevelTextFormat),
LabelPositionFraction = LabelPositionFraction,
ShowLabels = ShowLevels,
};
float radiusPx = position * radiusPixels;
gauge.Render(gfx, dims, centerPixel, radiusPx);

Metadata

Metadata

Assignees

No one assigned

    Labels

    Help WantedScott won't do this soon, but PRs from the community are welcome!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions