コード例 #1
0
ファイル: Category.cs プロジェクト: CGX-GROUP/DotSpatial
 /// <summary>
 /// Tests to see if the specified value falls in the range specified by this ColorCategory
 /// </summary>
 /// <param name="value">The value of type int to test</param>
 /// <returns>Boolean, true if the value was found in the range</returns>
 public bool Contains(double value)
 {
     return(Range == null || Range.Contains(value));
 }
コード例 #2
0
ファイル: ColorCategory.cs プロジェクト: CGX-GROUP/DotSpatial
        /// <summary>
        /// This is primarily used in the BiValue situation where a color needs to be generated
        /// somewhere between the start value and the end value.
        /// </summary>
        /// <param name="value">The value to be converted into a color from the range on this color break</param>
        /// <returns>A color that is selected from the range values.</returns>
        public virtual Color CalculateColor(double value)
        {
            if (!Range.Contains(value))
            {
                return(Color.Transparent);
            }
            if (Minimum == null || Maximum == null)
            {
                return(Range.Minimum == null ? HighColor : LowColor);
            }

            // From here on we have a double that falls in the range somewhere
            double lowVal = Minimum.Value;
            double range  = Math.Abs(Maximum.Value - lowVal);
            double p      = 0; // the portion of the range, where 0 is LowValue & 1 is HighValue
            double ht;

            switch (GradientModel)
            {
            case GradientModel.Linear:
                p = (value - lowVal) / range;
                break;

            case GradientModel.Exponential:
                ht = value;
                if (ht < 1)
                {
                    ht = 1.0;
                }
                if (range > 1)
                {
                    p = Math.Pow(ht - lowVal, 2) / Math.Pow(range, 2);
                }
                else
                {
                    return(LowColor);
                }

                break;

            case GradientModel.Logarithmic:
                ht = value;
                if (ht < 1)
                {
                    ht = 1.0;
                }
                if (range > 1.0 && ht - lowVal > 1.0)
                {
                    p = Math.Log(ht - lowVal) / Math.Log(range);
                }
                else
                {
                    return(LowColor);
                }

                break;
            }

            int alpha = Utils.ByteRange(LowColor.A + Math.Round((HighColor.A - LowColor.A) * p));
            int red   = Utils.ByteRange(LowColor.R + Math.Round((HighColor.R - LowColor.R) * p));
            int green = Utils.ByteRange(LowColor.G + Math.Round((HighColor.G - LowColor.G) * p));
            int blue  = Utils.ByteRange(LowColor.B + Math.Round((HighColor.B - LowColor.B) * p));

            return(Color.FromArgb(alpha, red, green, blue));
        }