Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/YAxis.cs @ 1591

Last change on this file since 1591 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

File size: 2.7 KB
Line 
1using System;
2using System.Drawing;
3using HeuristicLab.Visualization.LabelProvider;
4using HeuristicLab.Visualization.Test;
5
6namespace HeuristicLab.Visualization {
7  public class YAxis : WorldShape {
8    public const int PixelsPerInterval = 75;
9
10    private ILabelProvider labelProvider = new ContinuousLabelProvider("e4");
11    private AxisPosition position = AxisPosition.Left;
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 AxisPosition Position {
21      get { return position; }
22      set { position = value; }
23    }
24
25    public bool ShowLabel {
26      get { return showLabel; }
27      set { showLabel = value; }
28    }
29
30    public string Label {
31      get { return label; }
32      set { label = value; }
33    }
34
35    public override void Draw(Graphics graphics) {
36      ClearShapes();
37
38      foreach (double y in AxisTicks.GetTicks(PixelsPerInterval, Parent.Viewport.Height,
39                                              ClippingArea.Height,
40                                              ClippingArea.Y1)) {
41        double x;
42        AnchorPositionX anchorPositionX;
43
44        switch (position) {
45          case AxisPosition.Left:
46            x = ClippingArea.X2 - 3;
47            anchorPositionX = AnchorPositionX.Right;
48            break;
49          case AxisPosition.Right:
50            x = ClippingArea.X1 + 3;
51            anchorPositionX = AnchorPositionX.Left;
52            break;
53          default:
54            throw new NotImplementedException();
55        }
56       
57        TextShape tickLabel = new TextShape(x, y, labelProvider.GetLabel(y));
58        tickLabel.AnchorPositionX = anchorPositionX;
59        tickLabel.AnchorPositionY = AnchorPositionY.Middle;
60        AddShape(tickLabel);
61      }
62
63      if (showLabel) {
64        double x;
65        AnchorPositionY anchorPositionY;
66
67        switch (position) {
68          case AxisPosition.Left:
69            x = ClippingArea.X1 + 3;
70            anchorPositionY = AnchorPositionY.Top;
71            break;
72          case AxisPosition.Right:
73            x = ClippingArea.X2 - 3;
74            anchorPositionY = AnchorPositionY.Bottom;
75            break;
76          default:
77            throw new NotImplementedException();
78        }
79
80        TextShape label = new TextShape(x,
81                                        ClippingArea.Y1 + ClippingArea.Height/2,
82                                        this.label);
83        label.AnchorPositionX = AnchorPositionX.Middle;
84        label.AnchorPositionY = anchorPositionY;
85        label.Rotation = -90;
86        AddShape(label);
87      }
88
89      base.Draw(graphics);
90    }
91  }
92}
Note: See TracBrowser for help on using the repository browser.