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