Skip to content

Axis span: ensure rendered rectangle is at least 1px wide#4017

Merged
swharden merged 4 commits intoScottPlot:mainfrom
CoderPM2011:AxisSpan1px
Jun 29, 2024
Merged

Axis span: ensure rendered rectangle is at least 1px wide#4017
swharden merged 4 commits intoScottPlot:mainfrom
CoderPM2011:AxisSpan1px

Conversation

@CoderPM2011
Copy link
Contributor

@CoderPM2011 CoderPM2011 commented Jun 28, 2024

Just a simple patch.

When the axis span is less than 1, force the mean value ±0.5 as the new range values.
like this

if (vert.Span < 1)
{
    float middle = (vert.Top + vert.Bottom) / 2;
    vert = new(middle - 0.5F, middle + 0.5F);
}

Are there other aspects to consider?

#3968

@swharden swharden linked an issue Jun 29, 2024 that may be closed by this pull request
@swharden swharden enabled auto-merge (squash) June 29, 2024 10:46
@swharden
Copy link
Member

This looks great @CoderPM2011, thanks!

[Test]
public void Test_AxisSpan_ExtremelyNarrow()
{
    ScottPlot.Plot plot = new();

    for (int i = 0; i < 10; i++)
    {
        double width = 1e-10;
        plot.Add.VerticalSpan(i, i + width);
        plot.Add.HorizontalSpan(i, i + width);
    }

    plot.HideGrid();
    plot.SaveTestImage();
}

Before

image

After

image

@swharden swharden merged commit 4be2126 into ScottPlot:main Jun 29, 2024
@CoderPM2011 CoderPM2011 deleted the AxisSpan1px branch June 29, 2024 11:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Axis span: ensure rendered rectangle is at least 1px wide

2 participants