LiveCharts.Charts.CartesianChartCore.PrepareAxes C# (CSharp) Method

PrepareAxes() public method

Prepares Chart Axes
public PrepareAxes ( ) : void
return void
        public override void PrepareAxes()
        {
            base.PrepareAxes();

            if (View.ActualSeries.Any(x => !(x.Model is ICartesianSeries)))
                throw new LiveChartsException(
                    "There is a invalid series in the series collection, " +
                    "verify that all the series implement ICartesianSeries.");

            var cartesianSeries = View.ActualSeries.Select(x => x.Model).Cast<ICartesianSeries>().ToArray();

            for (var index = 0; index < AxisX.Count; index++)
            {
                var xi = AxisX[index];

                xi.CalculateSeparator(this, AxisOrientation.X);
                xi.BotLimit = double.IsNaN(xi.MinValue) ? cartesianSeries.Where(x => x.View.ScalesXAt == index)
                    .Select(x => x.GetMinX(xi))
                    .DefaultIfEmpty(0).Min() : xi.MinValue;
                xi.TopLimit = double.IsNaN(xi.MaxValue) ? cartesianSeries.Where(x => x.View.ScalesXAt == index)
                    .Select(x => x.GetMaxX(xi))
                    .DefaultIfEmpty(0).Max() : xi.MaxValue;

                if (Math.Abs(xi.BotLimit - xi.TopLimit) < xi.S * .01)
                {
                    if (Math.Abs(xi.PreviousBot - xi.PreviousTop) < xi.S * .01)
                    {
                        if (double.IsNaN(xi.MinValue)) xi.BotLimit -= xi.S;
                        else xi.BotLimit = xi.MinValue;

                        if (double.IsNaN(xi.MaxValue)) xi.TopLimit += xi.S;
                        else xi.TopLimit = xi.MaxValue;

                        if (Math.Abs(xi.BotLimit - xi.TopLimit) < xi.S * .01 && !View.IsInDesignMode)
                            throw new LiveChartsException("One axis has an invalid range, it is or is really " +
                                                          "close to zero, please ensure your axis has a valid " +
                                                          "range");
                    }
                    else
                    {
                        xi.BotLimit = xi.PreviousBot;
                        xi.TopLimit = xi.PreviousTop;
                    }
                }
                xi.PreviousBot = xi.BotLimit;
                xi.PreviousTop = xi.TopLimit;
            }

            for (var index = 0; index < AxisY.Count; index++)
            {
                var yi = AxisY[index];

                yi.CalculateSeparator(this, AxisOrientation.Y);
                yi.BotLimit = double.IsNaN(yi.MinValue) ? cartesianSeries.Where(x => x.View.ScalesYAt == index)
                    .Select(x => x.GetMinY(yi))
                    .DefaultIfEmpty(0).Min() : yi.MinValue;
                yi.TopLimit = double.IsNaN(yi.MaxValue) ? cartesianSeries.Where(x => x.View.ScalesYAt == index)
                    .Select(x => x.GetMaxY(yi))
                    .DefaultIfEmpty(0).Max() : yi.MaxValue;

                if (Math.Abs(yi.BotLimit - yi.TopLimit) < yi.S * .01)
                {
                    if (Math.Abs(yi.PreviousBot - yi.PreviousTop) < yi.S * .01)
                    {
                        if (double.IsNaN(yi.MinValue)) yi.BotLimit -= yi.S;
                        else yi.BotLimit = yi.MinValue;

                        if (double.IsNaN(yi.MaxValue)) yi.TopLimit += yi.S;
                        else yi.TopLimit = yi.MaxValue;

                        if (Math.Abs(yi.BotLimit - yi.TopLimit) < yi.S * .01)
                            throw new LiveChartsException("One axis has an invalid range, it is or is really " +
                                                          "close to zero, please ensure your axis has a valid " +
                                                          "range");
                    }
                    else
                    {
                        yi.BotLimit = yi.PreviousBot;
                        yi.TopLimit = yi.PreviousTop;
                    }
                }
                yi.PreviousBot = yi.BotLimit;
                yi.PreviousTop = yi.TopLimit;
            }

            PrepareSeries();
            CalculateComponentsAndMargin();
            DrawOrUpdateSections();

            AreComponentsLoaded = true;
        }