Exemplo n.º 1
0
        public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            Verify.IsTrue(ticksCount > 0);

            T        start  = range.Min;
            T        end    = range.Max;
            TimeSpan length = GetDifference(start, end);

            diff = strategy.GetDifference(length);

            TicksInfo <T> res = new TicksInfo <T> {
                Info = diff
            };

            if (providers.ContainsKey(diff))
            {
                ITicksInfo <T> result     = providers[diff].GetTicks(range, ticksCount);
                T[]            mayorTicks = result.Ticks;

                res.Ticks   = mayorTicks;
                this.result = res;
                return(res);
            }

            throw new InvalidOperationException(Properties.Resources.UnsupportedRangeInAxis);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        private void DoDrawMayorLabels()
        {
            additionalLabelsCanvas.Children.Clear();
            ITicksProvider <T> mayorTicksProvider = ticksProvider.MayorProvider;

            if (mayorTicksProvider != null && MayorLabelProvider != null)
            {
                Size renderSize = RenderSize;
                var  mayorTicks = mayorTicksProvider.GetTicks(range, DefaultTicksProvider.DefaultTicksCount);

                double[] screenCoords = mayorTicks.Ticks.Select(tick => createDataPoint(convertToDouble(tick))).
                                        Select(p => p.DataToScreen(transform)).Select(p => getCoordinate(p)).ToArray();

                // todo this is not the best decision - when displaying, for example,
                // milliseconds, it causes to create hundreds and thousands of textBlocks.
                double rangesRatio = GetRangesRatio(mayorTicks.Ticks.GetPairs().ToArray()[0], range);

                object          info    = mayorTicks.Info;
                MayorLabelsInfo newInfo = new MayorLabelsInfo
                {
                    Info             = info,
                    MayorLabelsCount = (int)Math.Ceiling(rangesRatio)
                };

                var newMayorTicks = new TicksInfo <T>
                {
                    Info      = newInfo,
                    Ticks     = mayorTicks.Ticks,
                    TickSizes = mayorTicks.TickSizes
                };

                UIElement[] additionalLabels = MayorLabelProvider.CreateLabels(newMayorTicks);

                for (int i = 0; i < additionalLabels.Length; i++)
                {
                    if (screenCoords[i].IsNaN())
                    {
                        continue;
                    }

                    UIElement tickLabel = additionalLabels[i];

                    tickLabel.Measure(renderSize);

                    StackCanvas.SetCoordinate(tickLabel, screenCoords[i]);
                    StackCanvas.SetEndCoordinate(tickLabel, screenCoords[i + 1]);

                    if (tickLabel is FrameworkElement)
                    {
                        ((FrameworkElement)tickLabel).LayoutTransform = additionalLabelTransform;
                    }

                    additionalLabelsCanvas.Children.Add(tickLabel);
                }
            }
        }
Exemplo n.º 4
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  = 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);
        }
Exemplo n.º 5
0
        public ITicksInfo <double> GetTicks(Range <double> range, int ticksCount)
        {
            if (Coeffs.Length == 0)
            {
                return(new TicksInfo <double>());
            }

            var minorTicks = ranges.Select(r => CreateTicks(r)).SelectMany(m => m);
            var res        = new TicksInfo <double>();

            res.TickSizes = minorTicks.Select(m => m.Value).ToArray();
            res.Ticks     = minorTicks.Select(m => m.Tick).ToArray();

            return(res);
        }
Exemplo n.º 6
0
        public ITicksInfo <T> GetTicks(Range <T> range, int ticksCount)
        {
            if (mayorTicks.Length == 0)
            {
                return(new TicksInfo <T>());
            }

            ticksCount /= mayorTicks.Length;
            if (ticksCount == 0)
            {
                ticksCount = 2;
            }

            var ticks = mayorTicks.GetPairs().Select(r => Clip(provider.GetTicks(r, ticksCount), r)).
                        SelectMany(t => t.Ticks).ToArray();

            var res = new TicksInfo <T>
            {
                Ticks     = ticks,
                TickSizes = ArrayExtensions.CreateArray(ticks.Length, ticksSize)
            };

            return(res);
        }