Example #1
0
 private double GetCoordinateFromTick(double tick, Size screenSize)
 {
     return(ValueToScreen(DataTransform.DataToPlot(tick), screenSize, Range));
 }
Example #2
0
        private void CreateTicks(Size axisSize)
        {
            Range range = new Range(
                DataTransform.PlotToData(Double.IsInfinity(Range.Min) || Double.IsNaN(Range.Min) ? 0 : Range.Min),
                DataTransform.PlotToData(Double.IsInfinity(Range.Max) || Double.IsNaN(Range.Max) ? 1 : Range.Max));

            // One tick if range is point
            if (range.IsPoint)
            {
                var t = new double[] { range.Min };
                Ticks  = t;
                labels = labelProvider.GetLabels(t);
                return;
            }

            // Do first pass of ticks arrangement
            ticksProvider.Range = range;
            double[] ticks = ticksProvider.GetTicks();
            labels = labelProvider.GetLabels(ticks);

            TickChange result;

            if (ticks.Length > MaxTicks)
            {
                result = TickChange.Decrease;
            }
            else if (ticks.Length < 2)
            {
                result = TickChange.Increase;
            }
            else
            {
                result = CheckLabelsArrangement(axisSize, labels, ticks);
            }

            int iterations = 0;
            int prevLength = ticks.Length;

            while (result != TickChange.OK && iterations++ < maxTickArrangeIterations)
            {
                if (result == TickChange.Increase)
                {
                    ticksProvider.IncreaseTickCount();
                }
                else
                {
                    ticksProvider.DecreaseTickCount();
                }
                double[] newTicks = ticksProvider.GetTicks();
                if (newTicks.Length > MaxTicks && result == TickChange.Increase)
                {
                    ticksProvider.DecreaseTickCount(); // Step back and stop to not get more than MaxTicks
                    break;
                }
                else if (newTicks.Length < 2 && result == TickChange.Decrease)
                {
                    ticksProvider.IncreaseTickCount(); // Step back and stop to not get less than 2
                    break;
                }
                var prevTicks = ticks;
                ticks = newTicks;
                var prevLabels = labels;
                labels = labelProvider.GetLabels(newTicks);
                var newResult = CheckLabelsArrangement(axisSize, labels, ticks);
                if (newResult == result) // Continue in the same direction
                {
                    prevLength = newTicks.Length;
                }
                else // Direction changed or layout OK - stop the loop
                {
                    if (newResult != TickChange.OK) // Direction changed - time to stop
                    {
                        if (result == TickChange.Decrease)
                        {
                            if (prevLength < MaxTicks)
                            {
                                ticks  = prevTicks;
                                labels = prevLabels;
                                ticksProvider.IncreaseTickCount();
                            }
                        }
                        else
                        {
                            if (prevLength >= 2)
                            {
                                ticks  = prevTicks;
                                labels = prevLabels;
                                ticksProvider.DecreaseTickCount();
                            }
                        }
                        break;
                    }
                    break;
                }
            }

            Ticks = ticks;
        }