protected void Init(double[] ticks)
        {
            if (ticks.Length == 0)
            {
                return;
            }

            double start  = ticks[0];
            double finish = ticks[ticks.Length - 1];

            if (start == finish)
            {
                shouldRound = false;
                return;
            }

            double delta = finish - start;

            rounding = (int)Math.Round(Math.Log10(delta));

            double newStart  = RoundingHelper.Round(start, rounding);
            double newFinish = RoundingHelper.Round(finish, rounding);

            if (newStart == newFinish)
            {
                rounding--;
            }
        }
Пример #2
0
        public ITicksInfo <double> GetTicks(Range <double> range, int ticksCount)
        {
            double start  = range.Min;
            double finish = range.Max;

            double delta = finish - start;

            int log = (int)Math.Round(Math.Log10(delta));

            double newStart  = RoundingHelper.Round(start, log);
            double newFinish = RoundingHelper.Round(finish, log);

            if (newStart == newFinish)
            {
                log--;
                newStart  = RoundingHelper.Round(start, log);
                newFinish = RoundingHelper.Round(finish, log);
            }

            // calculating step between ticks
            double unroundedStep = (newFinish - newStart) / ticksCount;
            int    stepLog       = log;
            // trying to round step
            double step = RoundingHelper.Round(unroundedStep, stepLog);

            if (step == 0)
            {
                stepLog--;
                step = RoundingHelper.Round(unroundedStep, stepLog);
                if (step == 0)
                {
                    // step will not be rounded if attempts to be rounded to zero.
                    step = unroundedStep;
                }
            }

            if (step < minStep)
            {
                step = minStep;
            }

            if (step != 0.0)
            {
                ticks = CreateTicks(start, finish, step);
            }
            else
            {
                ticks = new double[] { };
            }

            TicksInfo <double> res = new TicksInfo <double> {
                Info = log, Ticks = ticks
            };

            return(res);
        }
        protected override string GetStringCore(LabelTickInfo <double> tickInfo)
        {
            string res;

            if (!shouldRound)
            {
                res = tickInfo.Tick.ToString();
            }
            else
            {
                int round = Math.Min(15, Math.Max(-15, rounding - 3));                 // was rounding - 2
                res = RoundingHelper.Round(tickInfo.Tick, round).ToString();
            }

            return(res);
        }