Free cookie consent management tool by TermsFeed Policy Generator

Changeset 987 for trunk


Ignore:
Timestamp:
12/14/08 18:48:35 (16 years ago)
Author:
mstoeger
Message:

Implemented simple XAxis (#433)

Location:
trunk/sources/HeuristicLab.Visualization
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/CompositeShape.cs

    r635 r987  
    2424    }
    2525
     26    public void ClearShapes() {
     27      shapes.Clear();
     28      boundingBox = RectangleD.Empty;
     29    }
     30
    2631    public void AddShape(IShape shape) {
    2732      if (shapes.Count == 0) {
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r985 r987  
    5151      minDataValue = Double.PositiveInfinity;
    5252      maxDataValue = Double.NegativeInfinity;
    53 
    5453    }
    5554
     
    8887        maxDataRowCount = row.Count;
    8988     
    90       InitShapes(row);
     89      InitLineShapes(row);
     90      InitXAxis();
     91    }
     92
     93    private void InitXAxis() {
     94      int numLabels = 0;
     95
     96      foreach (IDataRow row in model.Rows) {
     97        numLabels = Math.Max(numLabels, row.Count);
     98      }
     99
     100      xAxis.ClearLabels();
     101
     102      for (int i = 0; i < numLabels; i++) {
     103        xAxis.SetLabel(i, i.ToString());
     104      }
    91105    }
    92106
     
    101115    }
    102116
    103     private void InitShapes(IDataRow row) {
    104      
    105        
     117    private void InitLineShapes(IDataRow row) {
    106118      List<LineShape> lineShapes = new List<LineShape>();
    107119      if (row.Count > 0) {
     
    132144    // TODO use action parameter
    133145    private void OnRowValueChanged(IDataRow row, double value, int index, Action action) {
     146      xAxis.SetLabel(index, index.ToString());
     147
    134148      List<LineShape> lineShapes = rowToLineShapes[row];
    135149      maxDataValue = Math.Max(value, maxDataValue);
     
    142156      // new value was added
    143157      if (index > 0 && index == lineShapes.Count + 1) {
    144        
    145158        if (maxDataRowCount < row.Count)
    146159          maxDataRowCount = row.Count;
     
    148161        lineShapes.Add(lineShape);
    149162        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    150         canvasUI1.MainCanvas.WorldShape.AddShape(lineShape);
     163        root.AddShape(lineShape);
    151164      }
    152165
     
    171184    }
    172185
    173     private void OnModelChanged() {}
     186    private void OnModelChanged() {
     187      InitXAxis();
     188    }
    174189
    175190    #endregion
  • trunk/sources/HeuristicLab.Visualization/XAxis.cs

    r983 r987  
     1using System.Collections.Generic;
     2using System.Drawing;
     3
    14namespace HeuristicLab.Visualization {
     5  // TODO move to own file
     6  public class TextShape : IShape {
     7    private readonly double x;
     8    private readonly double y;
     9    private string text;
     10
     11    private Font font = new Font("Arial", 8);
     12    private Brush brush = new SolidBrush(Color.Blue);
     13
     14    public TextShape(double x, double y, string text) {
     15      this.x = x;
     16      this.y = y;
     17      this.text = text;
     18    }
     19
     20    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
     21      int screenX = Transform.ToScreenX(x, viewport, clippingArea);
     22      int screenY = Transform.ToScreenY(y, viewport, clippingArea);
     23
     24      graphics.DrawString(text, font, brush, screenX, screenY);
     25    }
     26
     27    public RectangleD BoundingBox {
     28      get { return RectangleD.Empty; }
     29    }
     30
     31    public string Text {
     32      get { return text; }
     33      set { text = value; }
     34    }
     35  }
     36
    237  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);
    340
     41    public void ClearLabels() {
     42      shapes.Clear();
     43      labels.Clear();
     44
     45      shapes.Add(axisLine);
     46    }
     47
     48    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);
     51
     52      base.Draw(graphics, viewport, clippingArea);
     53    }
     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    }
    463  }
    564}
Note: See TracChangeset for help on using the changeset viewer.