示例#1
0
        public static Dictionary <string, Brush> CreateValueDependentBrushes(this HistoGrapher hg, double minValue, double maxValue, Func <double, Color> colorMapper)
        {
            Contract.Requires <ArgumentNullException>(hg != null, "hg");
            Contract.Requires <ArgumentNullException>(colorMapper != null, "colorMapper");
            Contract.Requires <ArgumentException>(minValue < maxValue, "The minimum value should be less than the maximum value.");
            Contract.Requires <ArgumentException>(hg.MinValue >= minValue && hg.MaxValue <= maxValue, "HistoGrapher's values should not exceed the explicitly specified bounds of colour.");

            return(hg.CreateValueDependentBrushes(minValue, maxValue, (x => new SolidBrush(colorMapper(x)))));
        }
示例#2
0
        public static Dictionary <string, Brush> CreateValueDependentBrushes(this HistoGrapher hg, double minValue, double maxValue, Color minColor, Color maxColor)
        {
            Contract.Requires <ArgumentNullException>(hg != null, "hg");
            Contract.Requires <ArgumentException>(minValue < maxValue, "The minimum value should be less than the maximum value.");
            Contract.Requires <ArgumentException>(hg.MinValue >= minValue && hg.MaxValue <= maxValue, "HistoGrapher's values should not exceed the explicitly specified bounds of colour.");

            double rDiff = maxColor.R - minColor.R;
            double gDiff = maxColor.G - minColor.G;
            double bDiff = maxColor.B - minColor.B;
            double aDiff = maxColor.A - minColor.A;

            Func <double, Color> colorMapper = delegate(double k)
            {
                int rNew = minColor.R + (int)(k * rDiff);
                int gNew = minColor.G + (int)(k * gDiff);
                int bNew = minColor.B + (int)(k * bDiff);
                int aNew = minColor.A + (int)(k * aDiff);

                return(Color.FromArgb(aNew, rNew, gNew, bNew));
            };

            return(hg.CreateValueDependentBrushes(minValue, maxValue, colorMapper));
        }