Exemple #1
0
 /// <summary>
 /// Returns the parameters to attach to the BaseHRef for each bucket.
 /// </summary>
 /// <param name="b"></param>
 /// <returns></returns>
 public virtual IDictionary <string, string> ParametersForBucket(Bucket b)
 {
     return(new Dictionary <string, string>());
 }
Exemple #2
0
        /// <summary>
        /// Generates the buckets for the range of Histogrammable.  WILL THROW AN EXCEPTION IF THE ORDINAL IS NOT AN INTEGER!
        /// </summary>
        /// <param name="items"></param>
        /// <returns></returns>
        protected override IDictionary <IComparable, Bucket> BucketsForData(IEnumerable <IHistogramable> items, IEnumerable <HistogramableValue> columns)
        {
            Dictionary <IComparable, Bucket> dict = new Dictionary <IComparable, Bucket>();

            if (items == null)
            {
                throw new ArgumentNullException(nameof(items));
            }

            if (!items.Any())
            {
                return(dict);
            }

            if (BucketWidth == 0)
            {
                throw new InvalidOperationException("Buckets cannot have 0 width!");
            }

            int min = Int32.MaxValue, max = Int32.MinValue;

            // Find the range.
            foreach (IHistogramable h in items)
            {
                int i = (int)h.BucketSelector(BucketSelectorName);
                if (i < min)
                {
                    min = i;
                }
                if (i > max)
                {
                    max = i;
                }
            }

            if (min > 0 && BucketForZero)
            {
                min = 0;
            }

            // Align to bucket width
            min = (int)KeyForValue(min);

            // Now create the buckets
            do
            {
                if (min == 0 && BucketForZero)
                {
                    dict[KeyForValue(min)] = new Bucket((int)KeyForValue(min), min.ToString(CultureInfo.CurrentCulture), columns);                                   // zero bucket
                    ++min;
                    dict[KeyForValue(min)] = new Bucket((int)KeyForValue(min), String.Format(CultureInfo.CurrentCulture, "{0}-{1}", min, BucketWidth - 1), columns); // 1-(Bucketwidth-1) bucket
                    min = BucketWidth + 1;                                                                                                                           // go to the "101" bucket.
                }
                else
                {
                    dict[KeyForValue(min)] = new Bucket((int)KeyForValue(min), String.Format(CultureInfo.CurrentCulture, "{0}-{1}", min, min + BucketWidth - 1), columns);
                    min += BucketWidth;
                }
            } while (min <= max);

            return(dict);
        }