Free cookie consent management tool by TermsFeed Policy Generator

Changeset 4808


Ignore:
Timestamp:
11/16/10 13:51:54 (14 years ago)
Author:
mkommend
Message:

Extracted ColorGradient in a separate class (ticket #1261).

Location:
trunk/sources
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Analysis.Views/3.3/HeatMapView.cs

    r4748 r4808  
    2121
    2222using System;
     23using System.Collections.Generic;
    2324using System.Drawing;
    2425using System.Windows.Forms;
    2526using System.Windows.Forms.DataVisualization.Charting;
     27using HeuristicLab.Common;
    2628using HeuristicLab.Core.Views;
    2729using HeuristicLab.MainForm;
     
    3234  public partial class HeatMapView : ItemView {
    3335    protected static Color[] colors = new Color[256];
    34     protected static Color[] grayscaleColors = new Color[256];
    35 
    36     #region Initialize Colors
    37     static HeatMapView() {
    38       int stepWidth = (256 * 4) / colors.Length;
    39       int currentValue;
    40       int currentClass;
    41       for (int i = 0; i < colors.Length; i++) {
    42         currentValue = (i * stepWidth) % 256;
    43         currentClass = (i * stepWidth) / 256;
    44         switch (currentClass) {
    45           case 0: { colors[i] = Color.FromArgb(0, currentValue, 255); break; }        // blue -> cyan
    46           case 1: { colors[i] = Color.FromArgb(0, 255, 255 - currentValue); break; }  // cyan -> green
    47           case 2: { colors[i] = Color.FromArgb(currentValue, 255, 0); break; }        // green -> yellow
    48           case 3: { colors[i] = Color.FromArgb(255, 255 - currentValue, 0); break; }  // yellow -> red
    49         }
    50       }
    51       for (int i = 0; i < 256; i++)
    52         grayscaleColors[i] = Color.FromArgb(255 - i, 255 - i, 255 - i);  // white -> black
    53     }
    54     #endregion
    55 
    5636    public new HeatMap Content {
    5737      get { return (HeatMap)base.Content; }
     
    123103
    124104    protected virtual Color GetDataPointColor(double value, double min, double max, bool grayscale) {
    125       int count = grayscale ? grayscaleColors.Length : colors.Length;
    126       int index = (int)((count - 1) * (value - min) / (max - min));
    127       if (index >= count) index = count - 1;
     105      IList<Color> colors = grayscale ? ColorGradient.GrayscaledColors : ColorGradient.Colors;
     106      int index = (int)((colors.Count - 1) * (value - min) / (max - min));
     107      if (index >= colors.Count) index = colors.Count - 1;
    128108      if (index < 0) index = 0;
    129       return grayscale ? grayscaleColors[index] : colors[index];
     109      return colors[index];
    130110    }
    131111
  • trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj

    r4419 r4808  
    9898      <RequiredTargetFramework>3.5</RequiredTargetFramework>
    9999    </Reference>
     100    <Reference Include="System.Drawing" />
    100101    <Reference Include="System.Xml.Linq">
    101102      <RequiredTargetFramework>3.5</RequiredTargetFramework>
     
    113114    <Compile Include="CancelEventArgs.cs" />
    114115    <None Include="HeuristicLabCommonPlugin.cs.frame" />
     116    <Compile Include="ColorGradient.cs" />
    115117    <Compile Include="Cloner.cs" />
    116118    <Compile Include="Content\ContentManager.cs" />
  • trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs

    r4799 r4808  
    580580
    581581    #region automatic coloring
    582     private static Color[] colors;
    583     protected static Color[] Colors {
    584       get {
    585         if (colors == null) InitializeColors();
    586         return colors;
    587       }
    588     }
    589     private static void InitializeColors() {
    590       colors = new Color[256];
    591       int stepWidth = (256 * 4) / colors.Length;
    592       int currentValue;
    593       int currentClass;
    594       for (int i = 0; i < colors.Length; i++) {
    595         currentValue = (i * stepWidth) % 256;
    596         currentClass = (i * stepWidth) / 256;
    597         switch (currentClass) {
    598           case 0: { colors[i] = Color.FromArgb(0, currentValue, 255); break; }        // blue -> cyan
    599           case 1: { colors[i] = Color.FromArgb(0, 255, 255 - currentValue); break; }  // cyan -> green
    600           case 2: { colors[i] = Color.FromArgb(currentValue, 255, 0); break; }        // green -> yellow
    601           case 3: { colors[i] = Color.FromArgb(255, 255 - currentValue, 0); break; }  // yellow -> red
    602         }
    603       }
    604     }
    605 
    606582    private void colorXAxisButton_Click(object sender, EventArgs e) {
    607583      double minValue = chart.Series[0].Points.Min(p => p.XValue);
    608584      double maxValue = chart.Series[0].Points.Max(p => p.XValue);
    609585      foreach (DataPoint point in chart.Series[0].Points) {
    610         int colorIndex = (int)((Colors.Length - 1) * (point.XValue - minValue) / (maxValue - minValue));
     586        int colorIndex = (int)((ColorGradient.Colors.Count - 1) * (point.XValue - minValue) / (maxValue - minValue));
    611587        IRun run = point.Tag as IRun;
    612         if (run != null)
    613           run.Color = Colors[colorIndex];
     588        if (run != null) run.Color = ColorGradient.Colors[colorIndex];
    614589      }
    615590    }
     
    619594      double maxValue = chart.Series[0].Points.Max(p => p.YValues[0]);
    620595      foreach (DataPoint point in chart.Series[0].Points) {
    621         int colorIndex = (int)((Colors.Length - 1) * (point.YValues[0] - minValue) / (maxValue - minValue));
     596        int colorIndex = (int)((ColorGradient.Colors.Count - 1) * (point.YValues[0] - minValue) / (maxValue - minValue));
    622597        IRun run = point.Tag as IRun;
    623         if (run != null)
    624           run.Color = Colors[colorIndex];
     598        if (run != null) run.Color = ColorGradient.Colors[colorIndex];
    625599      }
    626600    }
Note: See TracChangeset for help on using the changeset viewer.