Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/LegendShape.cs @ 1195

Last change on this file since 1195 was 1195, checked in by shofstad, 15 years ago

Legend implementation changed (#407)

File size: 1.2 KB
Line 
1using System.Collections.Generic;
2using System.Drawing;
3
4namespace HeuristicLab.Visualization {
5  public class LegendItem {
6    public LegendItem(string label, Color color, int thickness) {
7      Label = label;
8      Color = color;
9      Thickness = thickness;
10    }
11
12    public string Label { get; set; }
13    public Color Color { get; set; }
14    public int Thickness { get; set; }
15  }
16
17
18  public class LegendShape : WorldShape {
19    private readonly IList<LegendItem> legendItems = new List<LegendItem>();
20   
21    public LegendShape() {
22      CreateLegend();
23    }
24
25    public void CreateLegend() {
26      shapes.Clear();
27      double y = BoundingBox.Y2;
28      foreach (LegendItem item in legendItems) {
29        AddShape(new LineShape(10, y - 10, 30, y - 10, 0, item.Color, item.Thickness, DrawingStyle.Solid));
30        AddShape(new TextShape(35, y, item.Label));
31        y -= 15;
32      }
33    }
34
35    public void AddLegendItem(LegendItem item) {
36      legendItems.Add(item);
37    }
38
39    public void RemoveLegendItem(LegendItem item) {
40      legendItems.Remove(item);
41    }
42
43    public void ClearLegendItems() {
44      legendItems.Clear();
45    }
46  }
47}
Note: See TracBrowser for help on using the repository browser.