Free cookie consent management tool by TermsFeed Policy Generator

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

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

Display of X- and Y-Axis-Labels (#556)

File size: 1.9 KB
Line 
1using System.Drawing;
2using HeuristicLab.Visualization.LabelProvider;
3
4namespace HeuristicLab.Visualization {
5  public class XAxis : WorldShape {
6    public const int PixelsPerInterval = 100;
7   
8    private ILabelProvider labelProvider = new ContinuousLabelProvider("0.####");
9
10    private Color color = Color.Blue;
11    private Font font = new Font("Arial", 8);
12    private bool showLabel = true;
13    private string label = "";
14
15    public ILabelProvider LabelProvider {
16      get { return labelProvider; }
17      set { labelProvider = value; }
18    }
19
20    public override void Draw(Graphics graphics) {
21      ClearShapes();
22
23      foreach (double x in AxisTicks.GetTicks(PixelsPerInterval, Parent.Viewport.Width,
24                                              ClippingArea.Width,
25                                              ClippingArea.X1)) {
26        TextShape tickLabel = new TextShape(x, ClippingArea.Height - 3,
27                                        labelProvider.GetLabel(x), Font, Color);
28        tickLabel.AnchorPositionX = AnchorPositionX.Middle;
29        tickLabel.AnchorPositionY = AnchorPositionY.Top;
30        AddShape(tickLabel);
31      }
32
33      if (showLabel) {
34        TextShape label = new TextShape(ClippingArea.X1 + ClippingArea.Width/2,
35                                        ClippingArea.Y1 + 3,
36                                        this.label);
37        label.AnchorPositionX = AnchorPositionX.Middle;
38        label.AnchorPositionY = AnchorPositionY.Bottom;
39
40        AddShape(label);
41      }
42
43      base.Draw(graphics);
44    }
45
46    public Color Color {
47      get { return color; }
48      set { color = value; }
49    }
50
51    public Font Font {
52      get { return font; }
53      set { font = value; }
54    }
55
56    public bool ShowLabel {
57      get { return showLabel; }
58      set { showLabel = value; }
59    }
60
61    public string Label {
62      get { return label; }
63      set { label = value; }
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.