Changeset 1038 for trunk/sources/HeuristicLab.Visualization/XAxis.cs
- Timestamp:
- 12/18/08 23:17:23 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Visualization/XAxis.cs
r987 r1038 5 5 // TODO move to own file 6 6 public class TextShape : IShape { 7 private readonlydouble x;8 private readonlydouble y;7 private double x; 8 private double y; 9 9 private string text; 10 10 11 private Font font = new Font("Arial", 8); 12 private Brush brush = new SolidBrush(Color.Blue); 11 private Font font; 12 private Color color; 13 private Brush brush; 13 14 14 public TextShape(double x, double y, string text) { 15 public TextShape(double x, double y, string text) : this(x, y, text, 8) {} 16 17 public TextShape(double x, double y, string text, int fontSize) { 15 18 this.x = x; 16 19 this.y = y; 17 20 this.text = text; 21 this.font = new Font("Arial", fontSize); 22 23 this.Color = Color.Blue; 18 24 } 19 25 … … 33 39 set { text = value; } 34 40 } 41 42 public double X { 43 get { return x; } 44 set { x = value; } 45 } 46 47 public double Y { 48 get { return y; } 49 set { y = value; } 50 } 51 52 public Color Color { 53 get { return color; } 54 set { 55 this.color = value; 56 this.brush = new SolidBrush(color); 57 } 58 } 35 59 } 36 60 37 public class XAxis : CompositeShape { 38 private readonly List<TextShape> labels = new List<TextShape>(); 39 private readonly LineShape axisLine = new LineShape(0, 0, 0, 0, 0, Color.Black, 1, DrawingStyle.Solid); 61 public class XAxis : WorldShape { 62 private readonly IDictionary<int, TextShape> labels = new Dictionary<int, TextShape>(); 63 64 public XAxis(RectangleD clippingArea, RectangleD boundingBox) 65 : base(clippingArea, boundingBox) {} 40 66 41 67 public void ClearLabels() { 42 shapes.Clear();43 68 labels.Clear(); 69 } 44 70 45 shapes.Add(axisLine); 71 public void SetLabel(int i, string text) { 72 labels[i] = new TextShape(i, 0, text); 46 73 } 47 74 48 75 public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) { 49 axisLine.X1 = Transform.ToWorldX(viewport.Left, viewport, clippingArea); 50 axisLine.X2 = Transform.ToWorldX(viewport.Right, viewport, clippingArea); 76 shapes.Clear(); 77 78 for (int i = (int)(ClippingArea.X1 - 1); i <= ClippingArea.X2 + 1; i++) { 79 TextShape label; 80 81 if (labels.ContainsKey(i)) { 82 label = labels[i]; 83 } else { 84 label = new TextShape(i, 0, i.ToString()); 85 } 86 87 label.Y = ClippingArea.Height - 3; 88 89 shapes.Add(label); 90 } 51 91 52 92 base.Draw(graphics, viewport, clippingArea); 53 93 } 54 55 public void SetLabel(int i, string text) {56 while (i >= labels.Count) {57 TextShape label = new TextShape(i, 0, i.ToString());58 labels.Add(label);59 AddShape(label);60 }61 labels[i].Text = text;62 }63 94 } 64 95 }
Note: See TracChangeset
for help on using the changeset viewer.