public void TestTruncateList()
 {
     var limits = new Limits {Min = 1.111111111, Max = 8.8888888888};
     Truncate(limits);
     Assert.AreEqual(1.1111, limits.Min);
     Assert.AreEqual(8.8889, limits.Max);
 }
        public void TestTimePeriodsAreFormatted()
        {
            GroupRoot groupRoot = new GroupRoot();
            groupRoot.Grouping.Add(new Grouping { DataPointYear = 2005, YearRange = 1, DataPointQuarter = -1 });
            IndicatorMetadata metadata = new IndicatorMetadata { YearTypeId = 1 };

            Limits limits = new Limits { Min = 0, Max = 50 };
            var formatter = NumericFormatterFactory.NewWithLimits(metadata, limits);
            new GroupRootFormatter().Format(groupRoot, metadata, new DataPointTimePeriodFormatter(), formatter);

            Assert.AreEqual("2005", groupRoot.Grouping[0].TimePeriodText);
        }
        public LimitsWithStep(Limits limits, double? step)
        {
            if (limits != null)
            {
                Min = limits.Min;
                Max = limits.Max;
            }

            if (step.HasValue)
            {
                Step = step;
            }
        }
        public ChartAxisIntervalCalculator(Limits limits)
        {
            difference = limits.Max - limits.Min;

            for (int i = 1000000; i >= 10; i /= 10)
            {
                TryStep(i);
            }

            TryToFindStepDivisibleBy10();

            if (Step == null)
            {
                Step = difference / 5;
            }
        }
        /// <summary>
        /// New numeric formatter instance.
        /// </summary>
        /// <param name="metadata">Indicator metadata of data to be formatted.</param>
        /// <param name="limits">May be null if fixed decimal place is specified in metadata.</param>
        public static NumericFormatter NewWithLimits(IndicatorMetadata metadata, Limits limits)
        {
            int? decimalPlacesDisplayed = metadata.DecimalPlacesDisplayed;
            if (decimalPlacesDisplayed.HasValue && decimalPlacesDisplayed.Value >= 0)
            {
                return new FixedDecimalPlaceFormatter(decimalPlacesDisplayed.Value);
            }

            switch (metadata.ValueTypeId)
            {
                case 5:
                    return new ProportionFormatter(metadata, limits);
                default:
                    return new DefaultFormatter(metadata, limits);
            }
        }
        public MinMaxRounder(double min, double max)
        {
            // Perhaps add some padding with max *= 0.05
            double diff = Math.Abs(max - min);

            int order = 0;

            if (diff == 0)
            {
                // Skip
            }
            else if (diff >= 1)
            {
                while (diff >= 1)
                {
                    diff /= 10;
                    order++;
                }
            }
            else
            {
                while (diff <= 0.1)
                {
                    diff *= 10;
                    order--;
                }
            }

            double step = GetStep(diff);
            double bit = Math.Pow(10, order - 2);
            step *= Convert.ToDouble(bit);

            Limits = new Limits
            {
                Min = FloorNearest(min, step),
                Max = CeilNearest(max, step)
            };
        }
 internal NumericFormatter(IndicatorMetadata metadata, Limits limits)
 {
     this.metadata = metadata;
     this.limits = limits;
     SetFormatMethod();
 }
 public DefaultFormatter(IndicatorMetadata metadata, Limits limits)
     : base(metadata, limits)
 {
 }
 internal ProportionFormatter(IndicatorMetadata metadata, Limits limits)
     : base(metadata, limits)
 {
 }
 private static void Truncate(Limits limits)
 {
     new LimitsProcessor().TruncateList(new List<Limits> { limits });
 }