Search code examples
c#wpfoxyplot

Can I remove clipping from a oxyplot chart with multiple axes?


I have a chart with multiple y-axes created with the oxyplot library.When I zoom one y-axis out I noticed that the line gets clipped. arrows indicate where the line gets clipped

Can I expand the clipping area to the size of the area of the whole chart. Charts with multiple axes that can use the whole area of the chart are used a lot with medical data.

An EEG recording


Solution

  • I pulled the latest develop branch from github and changed the code in the GetClippingRect() method in the XYAxisSeries.cs source file:

    protected OxyRect GetClippingRect()
        {
            double minX,minY,maxX,maxY;
            if (this.PlotModel.AxisSizeIsClippingArea)
            {
                minX = Math.Min(this.XAxis.ScreenMin.X, this.XAxis.ScreenMax.X);
                minY = Math.Min(this.YAxis.ScreenMin.Y, this.YAxis.ScreenMax.Y);
                maxX = Math.Max(this.XAxis.ScreenMin.X, this.XAxis.ScreenMax.X);
                maxY = Math.Max(this.YAxis.ScreenMin.Y, this.YAxis.ScreenMax.Y);
            }
            else
            {
                var yAxes = this.PlotModel.Axes.Where(ax => ax.Position == AxisPosition.Left || ax.Position == AxisPosition.Right);
                var xAxes = this.PlotModel.Axes.Where(ax => ax.Position == AxisPosition.Bottom || ax.Position == AxisPosition.Top);
                maxY = yAxes.Max(ax => Math.Max(ax.ScreenMin.Y, ax.ScreenMax.Y));
                minY = yAxes.Min(ax => Math.Min(ax.ScreenMin.Y, ax.ScreenMax.Y));
                maxX = xAxes.Max(ax => Math.Max(ax.ScreenMax.X, ax.ScreenMax.X));
                minX = xAxes.Min(ax => Math.Min(ax.ScreenMin.X, ax.ScreenMin.X));
            }
            return new OxyRect(minX, minY, maxX - minX, maxY - minY);
        }
    

    I Added a property AxisSizeIsClippingArea to the PlotModel that is true by default. When it's false, instead of getting the minima and maxima of the current axis, the minima and maxima of all axes combined are calculated. Now when AxisSizeIsClippingArea is false there is no more clipping.