Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 2157 was 1964, checked in by mstoeger, 16 years ago

moved the canvas and the basic types of shapes to their own namespace. #498

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