Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1049


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

Legend implementation finished (#407)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs

    r1040 r1049  
    2828      row2.Thickness = 4;
    2929      row3.Thickness = 5;
     30
     31      row1.Label = "Simon";
     32      row2.Label = "Gertschi";
     33      row3.Label = "Maxi";
    3034
    3135      row1.Style = DrawingStyle.Solid;
  • 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) {
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r1045 r1049  
    3434    private readonly TextShape titleShape;
    3535    private readonly LinesShape linesShape;
     36    private readonly LegendShape legendShape;
    3637
    3738    private readonly XAxis xAxis;
     
    6263      root.AddShape(linesShape);
    6364
     65      legendShape = new LegendShape(0,0,0,0,0,Color.Black);
     66      //legendShape.AddLegendItem(new LegendItem("test", Color.Red, 5));
     67      //legendShape.AddLegendItem(new LegendItem("test1", Color.Blue, 5));
     68      //legendShape.AddLegendItem(new LegendItem("test2", Color.Pink, 5));
     69      root.AddShape(legendShape);
     70
    6471      xAxis = new XAxis(dummy, dummy);
    6572      root.AddShape(xAxis);
     
    6774      titleShape = new TextShape(0, 0, "Title", 15);
    6875      root.AddShape(titleShape);
     76
     77
    6978
    7079      canvas.MainCanvas.WorldShape = root;
     
    98107                                         linesShape.BoundingBox.X2,
    99108                                         linesShape.BoundingBox.Y1);
     109
     110      legendShape.BoundingBox = new RectangleD(10, 10, 110, canvas.Height - 50);
    100111    }
    101112
     
    136147      }
    137148
     149      legendShape.AddLegendItem(new LegendItem(row.Label, row.Color, row.Thickness));
     150      legendShape.CreateLegend();
    138151      InitLineShapes(row);
    139152    }
Note: See TracChangeset for help on using the changeset viewer.