Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/18/08 23:17:23 (16 years ago)
Author:
mstoeger
Message:

Modified the XAxis labels so they are always visible at the bottom. (#433)
Added simple layout management to the line chart's root shape containing a title-, lines- and xaxis-area. (#345)

File:
1 edited

Legend:

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

    r987 r1038  
    55  // TODO move to own file
    66  public class TextShape : IShape {
    7     private readonly double x;
    8     private readonly double y;
     7    private double x;
     8    private double y;
    99    private string text;
    1010
    11     private Font font = new Font("Arial", 8);
    12     private Brush brush = new SolidBrush(Color.Blue);
     11    private Font font;
     12    private Color color;
     13    private Brush brush;
    1314
    14     public TextShape(double x, double y, string text) {
     15    public TextShape(double x, double y, string text) : this(x, y, text, 8) {}
     16
     17    public TextShape(double x, double y, string text, int fontSize) {
    1518      this.x = x;
    1619      this.y = y;
    1720      this.text = text;
     21      this.font = new Font("Arial", fontSize);
     22
     23      this.Color = Color.Blue;
    1824    }
    1925
     
    3339      set { text = value; }
    3440    }
     41
     42    public double X {
     43      get { return x; }
     44      set { x = value; }
     45    }
     46
     47    public double Y {
     48      get { return y; }
     49      set { y = value; }
     50    }
     51
     52    public Color Color {
     53      get { return color; }
     54      set {
     55        this.color = value;
     56        this.brush = new SolidBrush(color);
     57      }
     58    }
    3559  }
    3660
    37   public class XAxis : CompositeShape {
    38     private readonly List<TextShape> labels = new List<TextShape>();
    39     private readonly LineShape axisLine = new LineShape(0, 0, 0, 0, 0, Color.Black, 1, DrawingStyle.Solid);
     61  public class XAxis : WorldShape {
     62    private readonly IDictionary<int, TextShape> labels = new Dictionary<int, TextShape>();
     63
     64    public XAxis(RectangleD clippingArea, RectangleD boundingBox)
     65      : base(clippingArea, boundingBox) {}
    4066
    4167    public void ClearLabels() {
    42       shapes.Clear();
    4368      labels.Clear();
     69    }
    4470
    45       shapes.Add(axisLine);
     71    public void SetLabel(int i, string text) {
     72      labels[i] = new TextShape(i, 0, text);
    4673    }
    4774
    4875    public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    49       axisLine.X1 = Transform.ToWorldX(viewport.Left, viewport, clippingArea);
    50       axisLine.X2 = Transform.ToWorldX(viewport.Right, viewport, clippingArea);
     76      shapes.Clear();
     77
     78      for (int i = (int)(ClippingArea.X1 - 1); i <= ClippingArea.X2 + 1; i++) {
     79        TextShape label;
     80
     81        if (labels.ContainsKey(i)) {
     82          label = labels[i];
     83        } else {
     84          label = new TextShape(i, 0, i.ToString());
     85        }
     86
     87        label.Y = ClippingArea.Height - 3;
     88
     89        shapes.Add(label);
     90      }
    5191
    5292      base.Draw(graphics, viewport, clippingArea);
    5393    }
    54 
    55     public void SetLabel(int i, string text) {
    56       while (i >= labels.Count) {
    57         TextShape label = new TextShape(i, 0, i.ToString());
    58         labels.Add(label);
    59         AddShape(label);
    60       }
    61       labels[i].Text = text;
    62     }
    6394  }
    6495}
Note: See TracChangeset for help on using the changeset viewer.