Example #1
0
        /// <summary>
        /// Build a rule that includes the appropriate color and bar percentage for the supplied rule and column value
        /// </summary>
        /// <param name="v"></param>
        /// <param name="rule"></param>
        /// <returns></returns>

        public static CondFormatRule BuildPercentageRuleForDataBarValue(double v, CondFormatRule rule)
        {
            int pct = -1;

            CondFormatRule r2 = new CondFormatRule();
            double         v1 = rule.ValueNumber;
            double         v2 = rule.Value2Number;

            if (v1 <= v2)             // normal bar
            {
                pct = CalculatePercentageForDataBarValue(v, v1, v2);
            }

            else             // reverse bar (i.e. v2 < v1)
            {
                v   = v2 - (v - v1);
                pct = CalculatePercentageForDataBarValue(v, v2, v1);
            }

            Color[] colors = Bitmaps.GetColorSetByName(Bitmaps.DataBarsImageColors, rule.ImageName);             // get single color associated with image
            if (colors == null || colors.Length < 1)
            {
                return(r2);
            }

            Color c = colors[0];

            //Color c = rule.BackColor1; // get from back color (more general but not currently used)

            r2.BackColor1 = Color.FromArgb(pct, c);             // store pct in color alpha value
            return(r2);
        }
Example #2
0
        /// <summary>
        /// Create and return a new rule with the icon image index store in the back color alpha field
        /// </summary>
        /// <param name="rule"></param>
        /// <returns></returns>

        public static CondFormatRule BuildImageRuleForIconSetValue(CondFormatRule rule)
        {
            CondFormatRule r2 = new CondFormatRule();

            int ii = Bitmaps.GetImageIndexFromName(Bitmaps.I.IconSetImages, rule.ImageName);

            if (ii < 0)
            {
                ii = 0;                                      // shouldn't happen, but show error image if it does
            }
            Color c = Color.FromArgb(ii, Color.Transparent); // store icon image index in color alpha

            r2.BackColor1 = c;                               // store pct in color alpha value
            return(r2);
        }
Example #3
0
        /// <summary>
        /// Build a rule that provides the appropriate color for the supplied range limit values and colors (newer single-between-rule CF)
        /// </summary>
        /// <param name="v"></param>
        /// <param name="rule"></param>
        /// <returns></returns>

        public static CondFormatRule BuildColorRuleForColorScale(double v, CondFormatRule rule)
        {
            Color c = Color.Transparent;
            Color c0, c1, c2;

            double v1 = rule.ValueNumber;
            double v2 = rule.Value2Number;

            CondFormatRule r2 = new CondFormatRule();

            Color[] colors = Bitmaps.GetColorSetByName(Bitmaps.ColorScaleImageColors, rule.ImageName);
            if (colors == null)
            {
                return(r2);
            }

            if (colors.Length == 2)           // 2-Color gradient
            {
                if (v1 <= v2)                 // normal gradient
                {
                    c = CalculateColorForGradientValue(v, v1, v2, colors[0], colors[1]);
                }

                else                 // reverse gradient
                {
                    c = CalculateColorForGradientValue(v, v2, v1, colors[1], colors[0]);
                }
            }

            else if (colors.Length == 3)             // 3-color gradient
            {
                double midpoint = GeometryMx.Midpoint(v1, v2);



                if (v1 <= v2)                 // normal gradient
                {
                    if (v < midpoint)         // get color between first two colors
                    {
                        c = CalculateColorForGradientValue(v, v1, midpoint, colors[0], colors[1]);
                    }

                    else                     // get color between second two colors
                    {
                        c = CalculateColorForGradientValue(v, midpoint, v2, colors[1], colors[2]);
                    }
                }

                else                  // reverse gradient
                {
                    if (v < midpoint) // get color between first two colors
                    {
                        c = CalculateColorForGradientValue(v, v2, midpoint, colors[2], colors[1]);
                    }

                    else                     // get color between second two colors
                    {
                        c = CalculateColorForGradientValue(v, midpoint, v1, colors[1], colors[0]);
                    }
                }
            }

            else
            {
                return(r2);
            }

            r2.BackColor1 = c;
            return(r2);
        }