Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/XAxis.cs @ 987

Last change on this file since 987 was 987, checked in by mstoeger, 15 years ago

Implemented simple XAxis (#433)

File size: 1.8 KB
Line 
1using System.Collections.Generic;
2using System.Drawing;
3
4namespace HeuristicLab.Visualization {
5  // TODO move to own file
6  public class TextShape : IShape {
7    private readonly double x;
8    private readonly double y;
9    private string text;
10
11    private Font font = new Font("Arial", 8);
12    private Brush brush = new SolidBrush(Color.Blue);
13
14    public TextShape(double x, double y, string text) {
15      this.x = x;
16      this.y = y;
17      this.text = text;
18    }
19
20    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
21      int screenX = Transform.ToScreenX(x, viewport, clippingArea);
22      int screenY = Transform.ToScreenY(y, viewport, clippingArea);
23
24      graphics.DrawString(text, font, brush, screenX, screenY);
25    }
26
27    public RectangleD BoundingBox {
28      get { return RectangleD.Empty; }
29    }
30
31    public string Text {
32      get { return text; }
33      set { text = value; }
34    }
35  }
36
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);
40
41    public void ClearLabels() {
42      shapes.Clear();
43      labels.Clear();
44
45      shapes.Add(axisLine);
46    }
47
48    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);
51
52      base.Draw(graphics, viewport, clippingArea);
53    }
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    }
63  }
64}
Note: See TracBrowser for help on using the repository browser.