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--; } }
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 = RoundingHelper.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); }
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); }