[1457] | 1 | using System;
|
---|
[1182] | 2 | using System.Drawing;
|
---|
[1194] | 3 | using HeuristicLab.Visualization.LabelProvider;
|
---|
[1457] | 4 | using HeuristicLab.Visualization.Test;
|
---|
[1182] | 5 |
|
---|
| 6 | namespace HeuristicLab.Visualization {
|
---|
| 7 | public class YAxis : WorldShape {
|
---|
| 8 | public const int PixelsPerInterval = 75;
|
---|
| 9 |
|
---|
[1194] | 10 | private ILabelProvider labelProvider = new ContinuousLabelProvider("e4");
|
---|
[1457] | 11 | private AxisPosition position = AxisPosition.Left;
|
---|
[1462] | 12 | private bool showLabel = true;
|
---|
| 13 | private string label = "";
|
---|
[1182] | 14 |
|
---|
| 15 | public ILabelProvider LabelProvider {
|
---|
| 16 | get { return labelProvider; }
|
---|
| 17 | set { labelProvider = value; }
|
---|
| 18 | }
|
---|
| 19 |
|
---|
[1457] | 20 | public AxisPosition Position {
|
---|
| 21 | get { return position; }
|
---|
| 22 | set { position = value; }
|
---|
| 23 | }
|
---|
| 24 |
|
---|
[1462] | 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 |
|
---|
[1240] | 35 | public override void Draw(Graphics graphics) {
|
---|
| 36 | ClearShapes();
|
---|
[1182] | 37 |
|
---|
[1343] | 38 | foreach (double y in AxisTicks.GetTicks(PixelsPerInterval, Parent.Viewport.Height,
|
---|
| 39 | ClippingArea.Height,
|
---|
| 40 | ClippingArea.Y1)) {
|
---|
[1457] | 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 |
|
---|
[1462] | 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;
|
---|
[1343] | 86 | AddShape(label);
|
---|
[1182] | 87 | }
|
---|
| 88 |
|
---|
[1240] | 89 | base.Draw(graphics);
|
---|
[1182] | 90 | }
|
---|
| 91 | }
|
---|
| 92 | } |
---|