LineSeries not visible when y-axis reversed

Jan 11, 2011 at 2:29 PM

I've been using OxyPlot for a few hours, and I've been very happy with how intuitive it is.  Looking at the example projects, I see there is a plot which has its axes reversed.  I have tried to plot LineSeries data such that the y-axis starts at 0 and proceeds downward to 700.  When I do this, the y-axis is shown as intended, but the LineSeries doesn't get rendered.  The method below renders the LineSeries fine when the StartPosition and EndPosistion are not specified.  When they are specified, no lines are drawn.  Is there something I'm missing?

 

private PlotModel GetPlot(Reel reel)
{
    var plotModel = new PlotModel();
    var offset = 1.0F;
    for (int i = 0; i < reel.TraceDataBlocks.Count; i += 3)
    {
        var series = new LineSeries("Trace " + i)
            {
                Color = OxyColors.Black,
                Title = i.ToString(),
                StrokeThickness = 0.5,
            };

        var y = 0F;
        var samples = reel.TraceDataBlocks[i].Samples.Take(750);
        var minX = samples.Min(s => s);
        var maxX = samples.Max(s => s);
        foreach (var sample in samples)
        {
            var normX = ((sample - minX) / (maxX - minX)) + offset;
            series.Points.Add(new DataPoint(normX, y++));
        }

        offset += 1F;
        plotModel.Series.Add(series);
    }

    plotModel.Axes.Add(new LinearAxis
    {
        Minimum =0,
        Maximum = 700,
        Position = AxisPosition.Left,
        StartPosition = 1,
        EndPosition = 0
    });
    plotModel.Axes.Add(new LinearAxis
    {
        Minimum = 0,
        Maximum = 50,
        Position = AxisPosition.Bottom,
    });
    return plotModel;
}

 

 

Jan 11, 2011 at 10:00 PM
Edited Jan 11, 2011 at 10:03 PM

I had another look at the problem I'm having.  I found that in OxyPlot.LineSeries.Render(...) where the clipping object is newed up there is no check to see if screen min/max values are reversed (as is the case when StartPosision = 1 and EndPosition = 0).

var clipping = new CohenSutherlandClipping(
    XAxis.ScreenMin.X, XAxis.ScreenMax.X,
    YAxis.ScreenMin.Y, YAxis.ScreenMax.Y);

Adding in a check and swapping the min/max values around fixed the issue.  Is this the appropriate way to make this go?  The modification:

 

double yMin, yMax, xMin, xMax;
if (YAxis.ScreenMax.Y > YAxis.ScreenMin.Y)
{
    yMin = YAxis.ScreenMin.Y;
    yMax = YAxis.ScreenMax.Y;
}
else
{
    yMin = YAxis.ScreenMax.Y;
    yMax = YAxis.ScreenMin.Y;
}
if (XAxis.ScreenMax.X > XAxis.ScreenMin.X)
{
    xMin = XAxis.ScreenMin.X;
    xMax = XAxis.ScreenMax.X;
}
else
{
    xMin = XAxis.ScreenMax.X;
    xMax = XAxis.ScreenMin.X;
}

var clipping = new CohenSutherlandClipping(xMin, xMax, yMin, yMax);

 

 

 

Jan 11, 2011 at 11:09 PM

thanks for reporting the bug. Yes, your solution is right - the clipping rectangle was not defined properly.

The bug is corrected in changelist 62017.

Jan 27, 2011 at 5:49 AM

Looks like changeset 62484 reintroduced this bug.  Change beginning on line 139 below fixes it:

var minX = Math.Min(XAxis.ScreenMin.X, XAxis.ScreenMax.X);
var minY = Math.Min(YAxis.ScreenMin.Y, YAxis.ScreenMax.Y);
var maxX = Math.Max(XAxis.ScreenMin.X, XAxis.ScreenMax.X);
var maxY = Math.Max(YAxis.ScreenMin.Y, YAxis.ScreenMax.Y);

var clippingRect = new OxyRect(
    minX,
    minY,
    maxX - minX, 
    maxY - minY);

Jan 27, 2011 at 6:16 AM

thanks! not sure how that happened... I have checked in the fix!