Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Problems.GrammaticalOptimization/DynamicDataDisplay/Common/Palettes/DiscretePalette.cs @ 12503

Last change on this file since 12503 was 12503, checked in by aballeit, 9 years ago

#2283 added GUI and charts; fixed MCTS

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Windows.Media;
6using System.Windows.Markup;
7using System.Collections.ObjectModel;
8using System.ComponentModel;
9
10namespace Microsoft.Research.DynamicDataDisplay.Common.Palettes
11{
12  [ContentProperty("Steps")]
13  public class DiscretePalette : IPalette
14  {
15    private readonly ObservableCollection<LinearPaletteColorStep> steps = new ObservableCollection<LinearPaletteColorStep>();
16    [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
17    public ObservableCollection<LinearPaletteColorStep> Steps
18    {
19      get { return steps; }
20    }
21
22    public DiscretePalette() { }
23    public DiscretePalette(params LinearPaletteColorStep[] steps)
24    {
25      this.steps.AddMany(steps);
26    }
27
28    public Color GetColor(double t)
29    {
30      if (t <= 0) return Steps[0].Color;
31      if (t >= Steps.Last().Offset) return steps.Last().Color;
32
33      int i = 0;
34      double x = 0;
35      while (x < t && i < steps.Count)
36      {
37        x = Steps[i].Offset;
38        i++;
39      }
40
41      Color result = Steps[i - 1].Color;
42      return result;
43    }
44
45    #region IPalette Members
46
47    public event EventHandler Changed;
48
49    #endregion
50  }
51}
Note: See TracBrowser for help on using the repository browser.