Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        internal override CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
        {
            if (!(Math.Abs(TopLimit - BotLimit) > S * .01) || !ShowLabels)
            {
                return(new CoreMargin());
            }

            var currentMargin = new CoreMargin();
            var tolerance     = S / 10;

            InitializeGarbageCollector();

            // Determine which magnitude and unit to use
            var m = (!double.IsNaN(View.Unit) ? View.Unit : Magnitude);
            var u = (!double.IsNaN(View.Unit) ? View.Unit : 1);

            // Calculate the separator indices
            var indices = CalculateSeparatorIndices(chart, source, u);

            // Draw the separators
            foreach (var index in indices)
            {
                DrawSeparator(index, tolerance, currentMargin, source);
            }

            return(currentMargin);
        }
Exemplo n.º 2
0
        private void DrawSeparator(double i, double tolerance, CoreMargin currentMargin, Func <double, string> f, AxisOrientation source)
        {
            if (i < BotLimit)
            {
                return;
            }

            SeparatorElementCore asc;

            var key = Math.Round(i / tolerance) * tolerance;

            if (!Cache.TryGetValue(key, out asc))
            {
                asc = new SeparatorElementCore {
                    IsNew = true
                };
                Cache[key] = asc;
            }
            else
            {
                asc.IsNew = false;
            }

            View.RenderSeparator(asc, Chart);

            asc.Key   = key;
            asc.Value = i;
            asc.GarbageCollectorIndex = GarbageCollectorIndex;

            var labelsMargin = asc.View.UpdateLabel(f(i), this, source);

            currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width
                ? labelsMargin.TakenWidth
                : currentMargin.Width;
            currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height
                ? labelsMargin.TakenHeight
                : currentMargin.Height;

            currentMargin.Left = labelsMargin.Left > currentMargin.Left
                ? labelsMargin.Left
                : currentMargin.Left;
            currentMargin.Right = labelsMargin.Right > currentMargin.Right
                ? labelsMargin.Right
                : currentMargin.Right;

            currentMargin.Top = labelsMargin.Top > currentMargin.Top
                ? labelsMargin.Top
                : currentMargin.Top;
            currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom
                ? labelsMargin.Bottom
                : currentMargin.Bottom;

            if (LastAxisMax == null)
            {
                asc.State = SeparationState.InitialAdd;
                return;
            }

            asc.State = SeparationState.Keep;
        }
Exemplo n.º 3
0
        private void DrawSeparator(double x, double tolerance, CoreMargin currentMargin, AxisOrientation source)
        {
            SeparatorElementCore elementCore;

            var key = Math.Round(x / tolerance) * tolerance;

            if (!Cache.TryGetValue(key, out elementCore))
            {
                elementCore = new DateSeparatorElementCore {
                    IsNew = true
                };
                Cache[key] = elementCore;
            }
            else
            {
                elementCore.IsNew = false;
            }

            // Determine whether this separator is a header now
            ((DateSeparatorElementCore)elementCore).IsHeader = SelectedWindow.IsHeader(x);

            View.RenderSeparator(elementCore, Chart);

            elementCore.Key   = key;
            elementCore.Value = x;
            elementCore.GarbageCollectorIndex = GarbageCollectorIndex;

            var labelsMargin = elementCore.View.UpdateLabel(SelectedWindow.FormatAxisLabel(x), this, source);

            currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width
                ? labelsMargin.TakenWidth
                : currentMargin.Width;
            currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height
                ? labelsMargin.TakenHeight
                : currentMargin.Height;

            currentMargin.Left = labelsMargin.Left > currentMargin.Left
                ? labelsMargin.Left
                : currentMargin.Left;
            currentMargin.Right = labelsMargin.Right > currentMargin.Right
                ? labelsMargin.Right
                : currentMargin.Right;

            currentMargin.Top = labelsMargin.Top > currentMargin.Top
                ? labelsMargin.Top
                : currentMargin.Top;
            currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom
                ? labelsMargin.Bottom
                : currentMargin.Bottom;

            if (LastAxisMax == null)
            {
                elementCore.State = SeparationState.InitialAdd;
                return;
            }

            elementCore.State = SeparationState.Keep;
        }
Exemplo n.º 4
0
        internal virtual CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
        {
            if (!(Math.Abs(TopLimit - BotLimit) > S * .01) || !ShowLabels)
            {
                return(new CoreMargin());
            }

            CalculateSeparator(chart, source);

            var f = GetFormatter();

            var currentMargin = new CoreMargin();
            var tolerance     = S / 10;

            InitializeGarbageCollector();

            var m = !double.IsNaN(View.BarUnit)
                ? View.BarUnit
                : (!double.IsNaN(View.Unit)
                    ? View.Unit
                    : Magnitude);

            var u = !double.IsNaN(View.BarUnit)
                ? View.BarUnit
                : (!double.IsNaN(View.Unit)
                    ? View.Unit
                    : 1);

            if (TopLimit <= 0 && BotLimit < 0)
            {
                var l = TopLimit - (EvaluatesUnitWidth ? u : 0);
                LastSeparator = l;
                for (var i = l; i >= Math.Truncate(BotLimit / m) * m; i -= S)
                {
                    FirstSeparator = i;
                    DrawSeparator(i, tolerance, currentMargin, f, source);
                }
            }
            else
            {
                var l = Math.Truncate(BotLimit / m) * m;
                FirstSeparator = l;
                for (var i = l; i <= TopLimit - (EvaluatesUnitWidth ? u : 0); i += S)
                {
                    LastSeparator = i;
                    DrawSeparator(i, tolerance, currentMargin, f, source);
                }
            }

            return(currentMargin);
        }
Exemplo n.º 5
0
        internal override CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
        {
            if (!(Math.Abs(TopLimit - BotLimit) > S * .01) || !ShowLabels)
            {
                return(new CoreMargin());
            }

            CalculateSeparator(chart, source);

            var f = GetFormatter();

            var currentMargin = new CoreMargin();

            if (S < 1)
            {
                S = 1;
            }
            var tolerance = S / 10;

            InitializeGarbageCollector();

            var bl    = Math.Ceiling(BotLimit / Magnitude) * Magnitude;
            var @base = ((ILogarithmicAxisView)View).Base;

            for (var i = bl; i <= TopLimit - (EvaluatesUnitWidth ? 1 : 0); i += S)
            {
                var minTolerance = tolerance / 10;
                if (Math.Abs(i - bl) > tolerance)
                {
                    var step = Math.Pow(@base, i - 1);
                    for (var j = Math.Pow(@base, i - 1) + step;
                         j < Math.Pow(@base, i);
                         j += step)
                    {
                        SeparatorElementCore minorAsc;
                        var scaledJ = Math.Log(j, @base);

                        var minorKey = Math.Round(scaledJ / minTolerance) * minTolerance;
                        if (!Cache.TryGetValue(minorKey, out minorAsc))
                        {
                            minorAsc = new SeparatorElementCore {
                                IsNew = true
                            };
                            Cache[minorKey] = minorAsc;
                        }
                        else
                        {
                            minorAsc.IsNew = false;
                        }

                        View.RenderSeparator(minorAsc, Chart);

                        minorAsc.Key   = minorKey;
                        minorAsc.Value = scaledJ;
                        minorAsc.GarbageCollectorIndex = GarbageCollectorIndex;

                        minorAsc.View.UpdateLabel(string.Empty, this, source);

                        if (LastAxisMax == null)
                        {
                            minorAsc.State = SeparationState.InitialAdd;
                            continue;
                        }

                        minorAsc.State = SeparationState.Keep;
                    }
                }

                SeparatorElementCore asc;

                var key = Math.Round(i / tolerance) * tolerance;
                if (!Cache.TryGetValue(key, out asc))
                {
                    asc = new SeparatorElementCore {
                        IsNew = true
                    };
                    Cache[key] = asc;
                }
                else
                {
                    asc.IsNew = false;
                }

                View.RenderSeparator(asc, Chart);

                asc.Key   = key;
                asc.Value = i;
                asc.GarbageCollectorIndex = GarbageCollectorIndex;

                var labelsMargin = asc.View.UpdateLabel(f(i), this, source);

                currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width
                    ? labelsMargin.TakenWidth
                    : currentMargin.Width;
                currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height
                    ? labelsMargin.TakenHeight
                    : currentMargin.Height;

                currentMargin.Left = labelsMargin.Left > currentMargin.Left
                    ? labelsMargin.Left
                    : currentMargin.Left;
                currentMargin.Right = labelsMargin.Right > currentMargin.Right
                    ? labelsMargin.Right
                    : currentMargin.Right;

                currentMargin.Top = labelsMargin.Top > currentMargin.Top
                    ? labelsMargin.Top
                    : currentMargin.Top;
                currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom
                    ? labelsMargin.Bottom
                    : currentMargin.Bottom;

                if (LastAxisMax == null)
                {
                    asc.State = SeparationState.InitialAdd;
                    continue;
                }

                asc.State = SeparationState.Keep;
            }
            return(currentMargin);
        }
Exemplo n.º 6
0
        internal CoreMargin PrepareChart(AxisOrientation source, ChartCore chart)
        {
            if (!(Math.Abs(TopLimit - BotLimit) > S*.01) || !ShowLabels) return new CoreMargin();

            CalculateSeparator(chart, source);

            var f = GetFormatter();

            var currentMargin = new CoreMargin();
            var tolerance = S/10;

            InitializeGarbageCollector();

            var bl = Math.Ceiling(BotLimit/Magnitude)*Magnitude;

            for (var i = bl; i <= TopLimit - (EvaluatesUnitWidth ? 1 : 0); i += S)
            {
                SeparatorElementCore asc;

                var key = Math.Round(i/tolerance)*tolerance;
                if (!Cache.TryGetValue(key, out asc))
                {
                    asc = new SeparatorElementCore {IsNew = true};
                    Cache[key] = asc;
                }
                else
                {
                    asc.IsNew = false;
                }

                View.RenderSeparator(asc, Chart);

                asc.Key = key;
                asc.Value = i;
                asc.GarbageCollectorIndex = GarbageCollectorIndex;

                var labelsMargin = asc.View.UpdateLabel(f(i), this, source);

                currentMargin.Width = labelsMargin.TakenWidth > currentMargin.Width
                    ? labelsMargin.TakenWidth
                    : currentMargin.Width;
                currentMargin.Height = labelsMargin.TakenHeight > currentMargin.Height
                    ? labelsMargin.TakenHeight
                    : currentMargin.Height;

                currentMargin.Left = labelsMargin.Left > currentMargin.Left
                    ? labelsMargin.Left
                    : currentMargin.Left;
                currentMargin.Right = labelsMargin.Right > currentMargin.Right
                    ? labelsMargin.Right
                    : currentMargin.Right;

                currentMargin.Top = labelsMargin.Top > currentMargin.Top
                    ? labelsMargin.Top
                    : currentMargin.Top;
                currentMargin.Bottom = labelsMargin.Bottom > currentMargin.Bottom
                    ? labelsMargin.Bottom
                    : currentMargin.Bottom;

                if (LastAxisMax == null)
                {
                    asc.State = SeparationState.InitialAdd;
                    continue;
                }

                asc.State = SeparationState.Keep;
            }
            return currentMargin;
        }