Free cookie consent management tool by TermsFeed Policy Generator

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

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

Legend implementation finished (#407)

File size: 1.5 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 : CompositeShape {
19    private RectangleD boundingBox;
20    private Color color;
21
22    private readonly IList<LegendItem> legendItems = new List<LegendItem>();
23
24    public LegendShape(double x1, double y1, double x2, double y2, double z, Color color) {
25      boundingBox = new RectangleD(x1, y1, x2, y2);
26      Z = z;
27      this.color = color;
28      CreateLegend();
29    }
30
31    public double Z { get; set; }
32
33    public RectangleD BoundingBox {
34      get { return boundingBox; }
35      set { boundingBox = value; }
36    }
37
38    public void CreateLegend() {
39      double y = boundingBox.Y2;
40      foreach (LegendItem item in legendItems) {
41        AddShape(new LineShape(10, y - 10, 30, y - 10, 0, item.Color, item.Thickness, DrawingStyle.Solid));
42        AddShape(new TextShape(35, y, item.Label));
43        y -= 15;
44      }
45    }
46
47    public void AddLegendItem(LegendItem item) {
48      legendItems.Add(item);
49    }
50
51    public void RemoveLegendItem(LegendItem item) {
52      legendItems.Remove(item);
53    }
54
55    public void ClearLegendItems() {
56      legendItems.Clear();
57    }
58  }
59}
Note: See TracBrowser for help on using the repository browser.