public Color GetColor(double value, ColorScaleInterpolation interpolation = ColorScaleInterpolation.HSV) { if (interpolation == ColorScaleInterpolation.HSV) { return(GetColorHsv(value)); } if (interpolation == ColorScaleInterpolation.RGB) { return(GetColorRgb(value)); } throw new NotSupportedException(string.Concat("Unsupported interpolation type '", interpolation, "'.")); }
/// <summary> /// Initializes a new instance of the <see cref="ColorScale" /> class. /// </summary> /// <param name="name">The name.</param> /// <param name="invalidColor">Color of the invalid.</param> /// <param name="entries">The entries.</param> /// <param name="interpolation">The interpolation mode.</param> /// <exception cref="ArgumentException">Error creating color scale: Duplicate color entries (values) are not allowed.</exception> /// <exception cref="System.ArgumentException">Error creating color scale: Duplicate color entries (values) are not allowed.</exception> public ColorScale(string name, Color invalidColor, IEnumerable <ColorScaleEntry> entries = null, ColorScaleInterpolation interpolation = ColorScaleInterpolation.HSV) { Name = name; InvalidColor = invalidColor; Interpolation = interpolation; Precision = 1; Entries = entries?.OrderBy(entry => entry.Value).ToArray() ?? new ColorScaleEntry[0]; _OrderedValueList = Entries.Select(entry => entry.Value).ToArray(); if (_OrderedValueList.Distinct().Count() != _OrderedValueList.Length) { throw new ArgumentException("Error creating color scale: Duplicate color entries (values) are not allowed."); //Prevents division by zero in color interpolation. } _ColorSpans = new ColorSpan[_OrderedValueList.Length - 1]; _HasConstantColors = true; for (var i = 0; i < _OrderedValueList.Length - 1; i++) { _ColorSpans[i] = new ColorSpan(_OrderedValueList[i], _OrderedValueList[i + 1], Entries[i].RightColor, Entries[i + 1].LeftColor); if (i > 0 && Entries[i - 1].RightColor != Entries[i].LeftColor) { _HasConstantColors = false; } Precision = Math.Max(Precision, CalculatePrecision(_OrderedValueList[i])); } if (_OrderedValueList.Length > 0) { MinValue = Entries[0].Value; MaxValue = Entries[Entries.Length - 1].Value; } else { MinValue = float.MaxValue; MaxValue = float.MinValue; } }