public sealed override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount) { DateTime start = range.Min; DateTime end = range.Max; TimeSpan length = end - start; bool isPositive = length.Ticks > 0; DifferenceIn diff = difference; DateTime newStart = isPositive ? RoundDown(start, diff) : SafelyRoundUp(start); DateTime newEnd = isPositive ? SafelyRoundUp(end) : RoundDown(end, diff); RoundingInfo bounds = RoundHelper.CreateRoundedRange(GetSpecificValue(newStart, newStart), GetSpecificValue(newStart, newEnd)); int delta = (int)(bounds.Max - bounds.Min); if (delta == 0) { return new TicksInfo <DateTime> { Ticks = new DateTime[] { newStart } } } ; int step = delta / ticksCount; if (step == 0) { step = 1; } DateTime tick = GetStart(newStart, (int)bounds.Min, step); bool isMinDateTime = IsMinDate(tick) && step != 1; if (isMinDateTime) { step--; } List <DateTime> ticks = new List <DateTime>(); DateTime finishTick = AddStep(range.Max, step); while (tick < finishTick) { ticks.Add(tick); tick = AddStep(tick, step); if (isMinDateTime) { isMinDateTime = false; step++; } } TicksInfo <DateTime> res = new TicksInfo <DateTime> { Ticks = ticks.ToArray(), Info = diff }; return(res); }
/// <summary> /// Gets the ticks. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public override ITicksInfo <DateTime> GetTicks(Range <DateTime> range, int ticksCount) { Verify.Is(ticksCount > 0); DateTime start = range.Min; DateTime end = range.Max; TimeSpan length = end - start; diff = GetDifference(length); TicksInfo <DateTime> res = new TicksInfo <DateTime> { Info = diff }; if (providers.ContainsKey(diff)) { ITicksInfo <DateTime> result = providers[diff].GetTicks(range, ticksCount); DateTime[] mayorTicks = result.Ticks; res.Ticks = mayorTicks; DifferenceIn lowerDiff = DifferenceIn.Year; // todo разобраться с minor ticks bool lowerDiffExists = TryGetLowerDiff(diff, out lowerDiff); if (lowerDiffExists && providers.ContainsKey(lowerDiff)) { var minorTicks = result.Ticks.GetPairs().Select(r => ((IMinorTicksProvider <DateTime>)providers[lowerDiff]).CreateTicks(r)). SelectMany(m => m).ToArray(); res.MinorTicks = minorTicks; } return(res); } DateTime newStart = RoundDown(start, diff); DateTime newEnd = RoundUp(end, diff); DebugVerify.Is(newStart <= start); List <DateTime> resultTicks = new List <DateTime>(); DateTime dt = newStart; do { resultTicks.Add(dt); dt = Shift(dt, diff); } while (dt <= newEnd); while (resultTicks.Count > ticksCount) { var res2 = resultTicks; resultTicks = res2.Where((date, i) => i % 2 == 0).ToList(); } res.Ticks = resultTicks.ToArray(); return(res); }
/// <summary> /// Generates ticks for given range and preferred ticks count. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public ITicksInfo <int> GetTicks(Range <int> 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 int step = (int)RoundingHelper.Round(unroundedStep, stepLog); if (step == 0) { stepLog--; step = (int)RoundingHelper.Round(unroundedStep, stepLog); if (step == 0) { // step will not be rounded if attempts to be rounded to zero. step = (int)unroundedStep; } } if (step < minStep) { step = minStep; } if (step > maxStep) { step = maxStep; } if (step <= 0) { step = 1; } int[] ticks = CreateTicks(start, finish, step); TicksInfo <int> res = new TicksInfo <int> { Info = log, Ticks = ticks }; return(res); }
public ITicksInfo <double> GetTicks(Range <double> range, int ticksCount) { // Tried using a subset, but using the whole lot gives consistent shading on the axis grid, otherwise it jumps around var ticks = _ticks; int log = 0; TicksInfo <double> result = new TicksInfo <double> { Ticks = ticks, TickSizes = ArrayExtensions.CreateArray(ticks.Length, 1.0), Info = log }; return(result); }
public ITicksInfo <double> GetTicks(Range <double> range, int ticksCount) { double min = LogByBase(range.Min); double max = LogByBase(range.Max); double minDown = Math.Floor(min); double maxUp = Math.Ceiling(max); double logLength = LogByBase(range.GetLength()); ticks = CreateTicks(range); int log = RoundingHelper.GetDifferenceLog(range.Min, range.Max); TicksInfo <double> result = new TicksInfo <double> { Ticks = ticks, TickSizes = ArrayExtensions.CreateArray(ticks.Length, 1.0), Info = log }; return(result); }
public ITicksInfo <double> GetTicks(Range <double> range, int ticksCount) { double min = LogByBase(range.Min); double max = LogByBase(range.Max); double minDown = Math.Floor(min); double maxUp = Math.Ceiling(max); double logLength = LogByBase(range.GetLength()); // JCS TODO Create a range that hold the number of tick counts. The range created is always // powers of logBase,could pad it out ticks = CreateTicks(range); //.Concat(new double[] { 0.02, 0.04, 0.06, 0.08, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9 }).OrderBy(x => x).ToArray(); int log = RoundingHelper.GetDifferenceLog(range.Min, range.Max); TicksInfo <double> result = new TicksInfo <double> { Ticks = ticks, TickSizes = ArrayExtensions.CreateArray(ticks.Length, 1.0), Info = log }; return(result); }
/// <summary> /// Generates ticks for given range and preferred ticks count. /// </summary> /// <param name="range">The range.</param> /// <param name="ticksCount">The ticks count.</param> /// <returns></returns> public ITicksInfo <TAxis> GetTicks(Range <TAxis> range, int ticksCount) { EnsureSearcher(); //minResult = searcher.SearchBetween(range.Min, minResult); //maxResult = searcher.SearchBetween(range.Max, maxResult); minResult = searcher.SearchFirstLess(range.Min); maxResult = searcher.SearchGreater(range.Max); if (!(minResult.IsEmpty && maxResult.IsEmpty)) { int startIndex = !minResult.IsEmpty ? minResult.Index : 0; int endIndex = !maxResult.IsEmpty ? maxResult.Index : collection.Count - 1; int count = endIndex - startIndex + 1; TAxis[] ticks = new TAxis[count]; for (int i = startIndex; i <= endIndex; i++) { ticks[i - startIndex] = axisMapping(collection[i]); } TicksInfo <TAxis> result = new TicksInfo <TAxis> { Info = startIndex, TickSizes = ArrayExtensions.CreateArray(count, 1.0), Ticks = ticks }; return(result); } else { return(TicksInfo <TAxis> .Empty); } }