Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }