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); }
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; }
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--; }