Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/21/08 19:58:03 (16 years ago)
Author:
shofstad
Message:

Legend implementation finished (#407)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/LegendShape.cs

    r982 r1049  
    44namespace HeuristicLab.Visualization {
    55  public class LegendItem {
    6     public LegendItem(string label, Color color) {
     6    public LegendItem(string label, Color color, int thickness) {
    77      Label = label;
    88      Color = color;
     9      Thickness = thickness;
    910    }
    1011
    1112    public string Label { get; set; }
    1213    public Color Color { get; set; }
     14    public int Thickness { get; set; }
    1315  }
    1416
    1517
    16   public class LegendShape : IShape {
    17     private readonly Color color;
     18  public class LegendShape : CompositeShape {
     19    private RectangleD boundingBox;
     20    private Color color;
    1821
    1922    private readonly IList<LegendItem> legendItems = new List<LegendItem>();
    20     private readonly RectangleD rect;
    2123
    2224    public LegendShape(double x1, double y1, double x2, double y2, double z, Color color) {
    23       rect = new RectangleD(x1, y1, x2, y2);
     25      boundingBox = new RectangleD(x1, y1, x2, y2);
    2426      Z = z;
    2527      this.color = color;
     28      CreateLegend();
    2629    }
    2730
    2831    public double Z { get; set; }
    2932
    30     #region IShape Members
    31 
    3233    public RectangleD BoundingBox {
    33       get { return rect; }
     34      get { return boundingBox; }
     35      set { boundingBox = value; }
    3436    }
    3537
    36     public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    37       int startY = 10;
    38       foreach (LegendItem i in legendItems) {
    39         using (Pen pen = new Pen(i.Color, 5)) {
    40           graphics.DrawLine(pen, 10, startY+10, 30, startY+10);
    41         }
    42         using (Brush brush = new SolidBrush(Color.Black)) {
    43           graphics.DrawString(i.Label, new Font("Arial", 12), brush, 35, startY);
    44         }
    45         startY += 15;
     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;
    4644      }
    4745    }
    48 
    49     #endregion
    5046
    5147    public void AddLegendItem(LegendItem item) {
Note: See TracChangeset for help on using the changeset viewer.