示例#1
0
        private static Dictionary <string, Color> GetGradientDictColor(BiColorGradientTheme gradientTheme)
        {
            var    result   = new Dictionary <string, Color>();
            double minValue = gradientTheme.MinValue;
            double maxValue = gradientTheme.MaxValue;

            double interval = (maxValue - minValue) / 5;
            double leftVal  = 0;
            double rightVal = 0;

            if (interval == 0)
            {
                interval = 1;
            }

            for (int index = 0; index <= 4; index++)
            {
                leftVal  = minValue + interval * index;
                rightVal = minValue + interval * (index + 1);
                string range = string.Format(" {0}~{1}", leftVal.ToString(), rightVal.ToString());

                result.Add(range, gradientTheme.GetColorByValue(minValue + index * interval));
            }

            return(result);
        }
示例#2
0
        public override Color GetColorByValue(double value)
        {
            double pos = (value - MinValue) / (MaxValue - MinValue);

            double[] posArr = _stops.Keys.ToArray();
            if (pos < posArr.First())
            {
                return(_stops.First().Value);
            }
            else
            {
                for (int i = 0; i < posArr.Length - 1; i++)
                {
                    double a = posArr[i];
                    double b = posArr[i + 1];
                    if (pos >= a && pos < b)
                    {
                        var bcgm = new BiColorGradientTheme {
                            MinValue = a, MaxValue = b, MinColor = _stops[a], MaxColor = _stops[b]
                        };
                        return(bcgm.GetColorByValue(pos));
                    }
                }
                return(_stops.Last().Value);
            }
        }