public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            T            start = range.Min;
            T            end   = range.Max;
            DifferenceIn diff  = Difference;

            start = RoundDown(start, end);
            end   = RoundUp(start, end);

            RoundingInfo bounds = RoundHelper.CreateRoundedRange(
                GetSpecificValue(start, start),
                GetSpecificValue(start, end));

            int delta = (int)(bounds.Max - bounds.Min);

            if (delta == 0)
            {
                return new TicksInfo <T> {
                           Ticks = new T[] { start }
                }
            }
            ;

            int step = delta / ticksCount;

            if (step == 0)
            {
                step = 1;
            }

            T    tick          = GetStart(start, (int)bounds.Min, step);
            bool isMinDateTime = IsMinDate(tick) && step != 1;

            if (isMinDateTime)
            {
                step--;
            }

            List <T> ticks      = new List <T>();
            T        finishTick = AddStep(range.Max, step);

            while (Continue(tick, finishTick))
            {
                ticks.Add(tick);
                tick = AddStep(tick, step);
                if (isMinDateTime)
                {
                    isMinDateTime = false;
                    step++;
                }
            }

            ticks = Trim(ticks, range);

            TicksInfo <T> res = new TicksInfo <T> {
                Ticks = ticks.ToArray(), Info = diff
            };

            return(res);
        }
Beispiel #2
0
        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  = RoundHelper.Round(start, rounding);
            double newFinish = RoundHelper.Round(finish, rounding);

            if (newStart == newFinish)
            {
                rounding--;
            }
        }
        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  = RoundHelper.Round(start, log);
            double newFinish = RoundHelper.Round(finish, log);

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

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

            if (step == 0)
            {
                stepLog--;
                step = RoundHelper.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);
        }
Beispiel #4
0
        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 - 2));
                res = RoundHelper.Round(tickInfo.Tick, round).ToString();
            }

            return(res);
        }