[1182] | 1 | using System;
|
---|
[987] | 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Drawing;
|
---|
[1194] | 4 | using HeuristicLab.Visualization.LabelProvider;
|
---|
[987] | 5 |
|
---|
[983] | 6 | namespace HeuristicLab.Visualization {
|
---|
[1038] | 7 | public class XAxis : WorldShape {
|
---|
[1182] | 8 | public const int PixelsPerInterval = 100;
|
---|
[1194] | 9 | private ILabelProvider labelProvider = new ContinuousLabelProvider("0.####");
|
---|
[983] | 10 |
|
---|
[1182] | 11 | public ILabelProvider LabelProvider {
|
---|
| 12 | get { return labelProvider; }
|
---|
| 13 | set { labelProvider = value; }
|
---|
[1038] | 14 | }
|
---|
[987] | 15 |
|
---|
[1182] | 16 | public static IEnumerable<double> GetTicks(int pixelsPerInterval, int screenSize, double worldSize, double worldStart) {
|
---|
| 17 | int intervals = screenSize/pixelsPerInterval;
|
---|
| 18 |
|
---|
| 19 | if (intervals > 0) {
|
---|
| 20 | double step = worldSize/intervals;
|
---|
| 21 | step = Math.Pow(10, Math.Floor(Math.Log10(step)));
|
---|
| 22 | if (worldSize/(step*5) > intervals)
|
---|
| 23 | step = step*5;
|
---|
| 24 | else if (worldSize/(step*2) > intervals)
|
---|
| 25 | step = step*2;
|
---|
| 26 |
|
---|
| 27 | for (double x = Math.Floor(worldStart/step)*step;
|
---|
| 28 | x <= worldStart + worldSize;
|
---|
| 29 | x += step)
|
---|
| 30 | yield return x;
|
---|
| 31 | }
|
---|
[987] | 32 | }
|
---|
| 33 |
|
---|
| 34 | public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
|
---|
[1038] | 35 | shapes.Clear();
|
---|
[987] | 36 |
|
---|
[1182] | 37 | foreach (double x in GetTicks(PixelsPerInterval, viewport.Width, ClippingArea.Width, ClippingArea.X1)) {
|
---|
| 38 | TextShape label = new TextShape(x, ClippingArea.Height - 3,
|
---|
| 39 | labelProvider.GetLabel(x));
|
---|
| 40 | label.AnchorPositionX = AnchorPositionX.Middle;
|
---|
| 41 | label.AnchorPositionY = AnchorPositionY.Top;
|
---|
[1038] | 42 | shapes.Add(label);
|
---|
[987] | 43 | }
|
---|
[1038] | 44 |
|
---|
| 45 | base.Draw(graphics, viewport, clippingArea);
|
---|
[987] | 46 | }
|
---|
[983] | 47 | }
|
---|
| 48 | } |
---|