// Method used to convert an input double in range [_minValue, _maxValue] // into corresponding rainbow-ordered Color public Color GetScaledColor(double input) { double hue = 0.667d * (maxValue - input) / (1.0d * (maxValue - minValue)); return(ColorScaler.HSL2RGB(hue, 1.0d, 0.5d)); }
/// <summary> /// Helper method to create FreqPlot markers (bmps) /// </summary> /// <param name="sendingChart"> Chart requiring new markers. </param> private void CreateMarkers(Chart sendingChart) { if (sendingChart.ChartAreas.Count == 0) { throw new Exception("CreateMarkers was called before chart area was initialized."); } // Determine correct Inner Plot Area size // If chart size has not yet been set up, initialize default values // default values are correct for _viewerWidth = 1050 and _viewerHeight = 800 int plottableWidth; int plottableHeight; if (sendingChart.ChartAreas[0].InnerPlotPosition.Width == 0 || sendingChart.ChartAreas[0].InnerPlotPosition.Height == 0 || sendingChart.ChartAreas[0].Position.Width == 0 || sendingChart.ChartAreas[0].Position.Height == 0) { plottableWidth = (int)(90.0f * (94.0f * sendingChart.ClientSize.Width / 100.0f) / 100.0f); plottableHeight = (int)(90.0f * (94.0f * sendingChart.ClientSize.Height / 100.0f) / 100.0f); } else { plottableWidth = (int)(sendingChart.ChartAreas[0].InnerPlotPosition.Width * (sendingChart.ChartAreas[0].Position.Width * sendingChart.ClientSize.Width / 100.0f) / 100.0f); plottableHeight = (int)(sendingChart.ChartAreas[0].InnerPlotPosition.Height * (sendingChart.ChartAreas[0].Position.Height * sendingChart.ClientSize.Height / 100.0f) / 100.0f); } // Determine color scaling parameters and generate ColorScaler double minFreqMag = Double.MaxValue; double maxFreqMag = Double.MinValue; foreach (List <PointD> pointList in freqTransVals) { foreach (PointD point in pointList) { if (point.Y < minFreqMag) { minFreqMag = point.Y; } if (point.Y > maxFreqMag) { maxFreqMag = point.Y; } } } ColorScaler scaler = new ColorScaler(minFreqMag, maxFreqMag); // Initialize marker images int markerWidth; int markerHeight = (int)Math.Max(1.0d, plottableHeight / freqTransVals.Count); int colorIndex = 0; foreach (NamedImage image in sendingChart.Images) { image.Dispose(); } sendingChart.Images.Clear(); foreach (List <PointD> freqValsList in freqTransVals) { markerWidth = (int)Math.Max(1.0d, plottableWidth / (double)freqValsList.Count); foreach (PointD freqVal in freqValsList) { Bitmap marker = new Bitmap(markerWidth, markerHeight); using (Graphics G = Graphics.FromImage(marker)) G.Clear(scaler.GetScaledColor(freqVal.Y)); sendingChart.Images.Add(new NamedImage("MarkerImage" + colorIndex.ToString(), marker)); colorIndex++; } } }