1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 | using HeuristicLab.Visualization.LabelProvider;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.Visualization {
|
---|
7 | public class XAxis : WorldShape {
|
---|
8 | public const int PixelsPerInterval = 100;
|
---|
9 | private ILabelProvider labelProvider = new ContinuousLabelProvider("0.####");
|
---|
10 |
|
---|
11 | public ILabelProvider LabelProvider {
|
---|
12 | get { return labelProvider; }
|
---|
13 | set { labelProvider = value; }
|
---|
14 | }
|
---|
15 |
|
---|
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 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
|
---|
35 | shapes.Clear();
|
---|
36 |
|
---|
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;
|
---|
42 | shapes.Add(label);
|
---|
43 | }
|
---|
44 |
|
---|
45 | base.Draw(graphics, viewport, clippingArea);
|
---|
46 | }
|
---|
47 | }
|
---|
48 | } |
---|