Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using System.Windows.Media;
|
---|
6 | using System.Windows.Markup;
|
---|
7 | using System.Collections.ObjectModel;
|
---|
8 | using System.ComponentModel;
|
---|
9 |
|
---|
10 | namespace 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.