Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1038 for trunk


Ignore:
Timestamp:
12/18/08 23:17:23 (16 years ago)
Author:
mstoeger
Message:

Modified the XAxis labels so they are always visible at the bottom. (#433)
Added simple layout management to the line chart's root shape containing a title-, lines- and xaxis-area. (#345)

Location:
trunk/sources
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/LineChartTestForm.Designer.cs

    r986 r1038  
    2626      this.lineChartGroupBox = new System.Windows.Forms.GroupBox();
    2727      this.btnResetView = new System.Windows.Forms.Button();
     28      this.btnAddRandomValue = new System.Windows.Forms.Button();
    2829      this.SuspendLayout();
    2930      //
     
    3536      this.lineChartGroupBox.Location = new System.Drawing.Point(12, 12);
    3637      this.lineChartGroupBox.Name = "lineChartGroupBox";
    37       this.lineChartGroupBox.Size = new System.Drawing.Size(607, 318);
     38      this.lineChartGroupBox.Size = new System.Drawing.Size(673, 376);
    3839      this.lineChartGroupBox.TabIndex = 0;
    3940      this.lineChartGroupBox.TabStop = false;
     
    4344      //
    4445      this.btnResetView.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
    45       this.btnResetView.Location = new System.Drawing.Point(544, 346);
     46      this.btnResetView.Location = new System.Drawing.Point(610, 404);
    4647      this.btnResetView.Name = "btnResetView";
    4748      this.btnResetView.Size = new System.Drawing.Size(75, 23);
     
    5152      this.btnResetView.Click += new System.EventHandler(this.btnResetView_Click);
    5253      //
     54      // btnAddRandomValue
     55      //
     56      this.btnAddRandomValue.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     57      this.btnAddRandomValue.Location = new System.Drawing.Point(529, 404);
     58      this.btnAddRandomValue.Name = "btnAddRandomValue";
     59      this.btnAddRandomValue.Size = new System.Drawing.Size(75, 23);
     60      this.btnAddRandomValue.TabIndex = 2;
     61      this.btnAddRandomValue.Text = "Add Value";
     62      this.btnAddRandomValue.UseVisualStyleBackColor = true;
     63      this.btnAddRandomValue.Click += new System.EventHandler(this.btnAddRandomValue_Click);
     64      //
    5365      // LineChartTestForm
    5466      //
    5567      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    5668      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    57       this.ClientSize = new System.Drawing.Size(631, 395);
     69      this.ClientSize = new System.Drawing.Size(697, 453);
     70      this.Controls.Add(this.btnAddRandomValue);
    5871      this.Controls.Add(this.lineChartGroupBox);
    5972      this.Controls.Add(this.btnResetView);
     
    6881    private System.Windows.Forms.GroupBox lineChartGroupBox;
    6982    private System.Windows.Forms.Button btnResetView;
     83    private System.Windows.Forms.Button btnAddRandomValue;
    7084
    7185  }
  • trunk/sources/HeuristicLab.Visualization.Test/LineChartTestForm.cs

    r985 r1038  
    1 using System.Windows.Forms;
     1using System;
     2using System.Windows.Forms;
    23using HeuristicLab.Core;
    34
    45namespace HeuristicLab.Visualization.Test {
    56  public partial class LineChartTestForm : Form {
     7    private readonly IView view;
    68    private ChartDataRowsModel model;
    7     private IView view;
    89
    910    public LineChartTestForm() {
    1011      InitializeComponent();
     12    }
    1113
    12       model = new ChartDataRowsModel();
    13 
    14      
     14    public LineChartTestForm(ChartDataRowsModel model) : this() {
     15      this.model = model;
    1516      view = model.CreateView();
    1617
     
    2122    }
    2223
    23     public ChartDataRowsModel Model {
    24       get { return model; }
     24    private void btnResetView_Click(object sender, EventArgs e) {
     25      if (view != null) {
     26        LineChart lineChart = (LineChart)view;
     27        lineChart.ResetView();
     28      }
    2529    }
    2630
    27     private void btnResetView_Click(object sender, System.EventArgs e) {
    28       LineChart lineChart = (LineChart)view;
    29       lineChart.ResetView();
     31    private void btnAddRandomValue_Click(object sender, EventArgs e) {
     32      Random rand = new Random();
     33
     34      foreach (IDataRow row in model.Rows)
     35        row.AddValue(rand.NextDouble()*100);
    3036    }
    3137  }
  • trunk/sources/HeuristicLab.Visualization.Test/LineChartTests.cs

    r983 r1038  
    66  [TestFixture]
    77  public class LineChartTests {
     8    private ChartDataRowsModel model;
     9
     10    [SetUp]
     11    public void SetUp() {
     12      model = new ChartDataRowsModel();
     13    }
     14
    815    [Test]
    916    public void TestLineChart() {
    10       LineChartTestForm f = new LineChartTestForm();
     17      LineChartTestForm f = new LineChartTestForm(model);
    1118
    1219      IDataRow row1 = new DataRow();
     
    2734     
    2835
    29       f.Model.AddDataRow(row1);
    30       f.Model.AddDataRow(row2);
    31       f.Model.AddDataRow(row3);
     36      model.AddDataRow(row1);
     37      model.AddDataRow(row2);
     38      model.AddDataRow(row3);
    3239
    3340      row1.AddValue(10);
     
    5057      Random rand = new Random();
    5158
    52       for (int i = 0; i < 1000; i++) {
     59      for (int i = 0; i < 10000; i++) {
    5360        row1.AddValue(rand.NextDouble()*10);
    5461        row2.AddValue(rand.NextDouble()*10);
     
    6168    [Test]
    6269    public void TestAxes() {
    63       LineChartTestForm f = new LineChartTestForm();
     70      LineChartTestForm f = new LineChartTestForm(model);
    6471
    6572      IDataRow row1 = new DataRow();
     
    6976      row1.Style = DrawingStyle.Solid;
    7077
    71       f.Model.AddDataRow(row1);
     78      model.AddDataRow(row1);
    7279
    7380      row1.AddValue(10);
  • trunk/sources/HeuristicLab.Visualization.Test/MainForm.cs

    r865 r1038  
    3030      WorldShape mainWorld = canvasUI.MainCanvas.WorldShape;
    3131      // simple rectangle shape
    32       RectangleShape rect7 = new RectangleShape(5, 5, 50, 50, 0, Color.Black);
     32      RectangleShape rect7 = new RectangleShape(5, 5, 50, 50, Color.Black);
    3333      mainWorld.AddShape(rect7);
    3434    }
     
    4343
    4444      for (int i = 0; i < 10000; i++) {
    45         RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, 0, Color.Maroon);
     45        RectangleShape rect = new RectangleShape(x1, y1, x1 + 0.3, y1 + 0.3, Color.Maroon);
    4646        x1 += 0.4;
    4747        y1 += 0.4;
     
    5757      CompositeShape middleComp = new CompositeShape();
    5858
    59       RectangleShape rect5 = new RectangleShape(400, 10, 500, 300, 0, Color.Navy);
    60       RectangleShape rect6 = new RectangleShape(510, 310, 580, 590, 0, Color.Magenta);
     59      RectangleShape rect5 = new RectangleShape(400, 10, 500, 300, Color.Navy);
     60      RectangleShape rect6 = new RectangleShape(510, 310, 580, 590, Color.Magenta);
    6161
    6262      middleComp.AddShape(rect5);
     
    7171      WorldShape leftWorld = new WorldShape(new RectangleD(0, 0, 1000, 1000), new RectangleD(10, 10, 380, 590));
    7272
    73       RectangleShape fillRect = new RectangleShape(0, 0, 1000, 1000, 0, Color.LightBlue);
     73      RectangleShape fillRect = new RectangleShape(0, 0, 1000, 1000, Color.LightBlue);
    7474
    75       RectangleShape rect1 = new RectangleShape(100, 100, 500, 500, 0, Color.Red);
    76       RectangleShape rect2 = new RectangleShape(800, -200, 1200, 500, 0, Color.Green);
     75      RectangleShape rect1 = new RectangleShape(100, 100, 500, 500, Color.Red);
     76      RectangleShape rect2 = new RectangleShape(800, -200, 1200, 500, Color.Green);
    7777
    7878      CompositeShape comp1 = new CompositeShape();
    7979
    80       RectangleShape rect3 = new RectangleShape(510, 580, 590, 700, 0, Color.Blue);
    81       RectangleShape rect4 = new RectangleShape(600, 710, 800, 900, 0, Color.Orange);
     80      RectangleShape rect3 = new RectangleShape(510, 580, 590, 700, Color.Blue);
     81      RectangleShape rect4 = new RectangleShape(600, 710, 800, 900, Color.Orange);
    8282
    8383      comp1.AddShape(rect3);
  • trunk/sources/HeuristicLab.Visualization/Canvas.cs

    r635 r1038  
     1using System.Diagnostics;
    12using System.Drawing;
    23using System.Drawing.Drawing2D;
     
    1112    }
    1213
     14
    1315    public void Draw(Graphics graphics, Rectangle viewport) {
     16      Stopwatch sw = new Stopwatch();
     17      sw.Start();
     18
    1419      GraphicsState gstate = graphics.Save();
    1520
     
    1924
    2025      graphics.Restore(gstate);
     26
     27      sw.Stop();
     28      Trace.WriteLine(string.Format("Drawing time: {0:0.0}ms", sw.Elapsed.TotalMilliseconds));
    2129    }
    2230  }
  • trunk/sources/HeuristicLab.Visualization/CanvasUI.cs

    r958 r1038  
    3939        base.OnPaint(pe);
    4040      } catch (Exception e) {
    41        Debug.WriteLine(e);
     41       Trace.WriteLine(e);
    4242      }
    4343    }
  • trunk/sources/HeuristicLab.Visualization/LineChart.Designer.cs

    r928 r1038  
    2929        private void InitializeComponent()
    3030        {
    31           this.canvasUI1 = new HeuristicLab.Visualization.CanvasUI();
     31          this.canvas = new HeuristicLab.Visualization.CanvasUI();
    3232          this.SuspendLayout();
    3333          //
    34           // canvasUI1
     34          // canvas
    3535          //
    36           this.canvasUI1.Dock = System.Windows.Forms.DockStyle.Fill;
    37           this.canvasUI1.Location = new System.Drawing.Point(0, 0);
    38           this.canvasUI1.MouseEventListener = null;
    39           this.canvasUI1.Name = "canvasUI1";
    40           this.canvasUI1.Size = new System.Drawing.Size(552, 390);
    41           this.canvasUI1.TabIndex = 0;
    42           this.canvasUI1.Text = "canvasUI1";
    43           this.canvasUI1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown);
     36          this.canvas.Dock = System.Windows.Forms.DockStyle.Fill;
     37          this.canvas.Location = new System.Drawing.Point(0, 0);
     38          this.canvas.MouseEventListener = null;
     39          this.canvas.Name = "canvas";
     40          this.canvas.Size = new System.Drawing.Size(552, 390);
     41          this.canvas.TabIndex = 0;
     42          this.canvas.Text = "canvas";
     43          this.canvas.MouseDown += new System.Windows.Forms.MouseEventHandler(this.canvasUI1_MouseDown);
    4444          //
    4545          // LineChart
     
    4747          this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    4848          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    49           this.Controls.Add(this.canvasUI1);
     49          this.Controls.Add(this.canvas);
    5050          this.Name = "LineChart";
    5151          this.Size = new System.Drawing.Size(552, 390);
     
    5656        #endregion
    5757
    58         private CanvasUI canvasUI1;
     58        private CanvasUI canvas;
    5959    }
    6060}
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r996 r1038  
    66
    77namespace HeuristicLab.Visualization {
     8  public class LinesShape : WorldShape {
     9    private readonly RectangleShape background = new RectangleShape(0, 0, 1, 1, Color.FromArgb(240, 240, 240));
     10
     11    public LinesShape(RectangleD clippingArea, RectangleD boundingBox)
     12      : base(clippingArea, boundingBox) {
     13      AddShape(background);
     14    }
     15
     16    public override void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
     17      UpdateLayout();
     18      base.Draw(graphics, viewport, clippingArea);
     19    }
     20
     21    private void UpdateLayout() {
     22      background.Rectangle = ClippingArea;
     23    }
     24  }
     25
    826  public partial class LineChart : ViewBase {
    927    private readonly IChartDataRowsModel model;
     
    1432
    1533    private readonly WorldShape root;
     34    private readonly TextShape titleShape;
     35    private readonly LinesShape linesShape;
     36
    1637    private readonly XAxis xAxis;
    1738
     
    2849    /// <param name="model">Referenz to the model, for data</param>
    2950    public LineChart(IChartDataRowsModel model) : this() {
    30       if (model == null) {
     51      if (model == null)
    3152        throw new NullReferenceException("Model cannot be null.");
    32       }
    3353
    3454      //TODO: correct Rectangle to fit
    35       RectangleD clientRectangle = new RectangleD(-1, -1, 1, 1);
    36 
    37       root = new WorldShape(clientRectangle, clientRectangle);
    38 
    39       xAxis = new XAxis();
     55
     56      RectangleD dummy = new RectangleD(0, 0, 1, 1);
     57
     58      root = new WorldShape(dummy, dummy);
     59
     60      linesShape = new LinesShape(dummy, dummy);
     61      root.AddShape(linesShape);
     62
     63      xAxis = new XAxis(dummy, dummy);
    4064      root.AddShape(xAxis);
    4165
    42       canvasUI1.MainCanvas.WorldShape = root;
    43          
     66      titleShape = new TextShape(0, 0, "Title", 15);
     67      root.AddShape(titleShape);
     68
     69      canvas.MainCanvas.WorldShape = root;
     70      canvas.Resize += delegate { UpdateLayout(); };
     71
     72      UpdateLayout();
     73
    4474      CreateMouseEventListeners();
    45          
     75
    4676      this.model = model;
    4777      Item = model;
    48       maxDataRowCount = 0;
     78
     79      maxDataRowCount = 0;
    4980      //The whole data rows are shown per default
    5081      zoomFullView = true;
     
    5384    }
    5485
     86    /// <summary>
     87    /// Layout management - arranges the inner shapes.
     88    /// </summary>
     89    private void UpdateLayout() {
     90      root.ClippingArea = new RectangleD(0, 0, canvas.Width, canvas.Height);
     91
     92      titleShape.X = 10;
     93      titleShape.Y = canvas.Height - 10;
     94
     95      linesShape.BoundingBox = new RectangleD(0, 20, canvas.Width, canvas.Height);
     96
     97      xAxis.BoundingBox = new RectangleD(linesShape.BoundingBox.X1,
     98                                         0,
     99                                         linesShape.BoundingBox.X2,
     100                                         linesShape.BoundingBox.Y1);
     101    }
     102
    55103    public void ResetView() {
    56104      zoomFullView = true;
    57105      ZoomToFullView();
    58       canvasUI1.Invalidate();
     106
     107      canvas.Invalidate();
    59108    }
    60109
     
    68117      model.ModelChanged += OnModelChanged;
    69118
    70       foreach (IDataRow row in model.Rows) {
     119      foreach (IDataRow row in model.Rows)
    71120        OnDataRowAdded(row);
    72       }
    73121    }
    74122
     
    86134      if (row.Count > maxDataRowCount)
    87135        maxDataRowCount = row.Count;
    88      
     136
    89137      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       }
    105138    }
    106139
    107140    private void ZoomToFullView() {
    108       if(!zoomFullView)
     141      if (!zoomFullView)
    109142        return;
    110       RectangleD newClippingArea =  new RectangleD(-0.1,
    111         minDataValue-((maxDataValue-minDataValue)*0.05),
    112         maxDataRowCount-0.9,
    113         maxDataValue + ((maxDataValue - minDataValue) * 0.05));
    114       root.ClippingArea = newClippingArea;
     143      RectangleD newClippingArea = new RectangleD(-0.1,
     144                                                  minDataValue - ((maxDataValue - minDataValue)*0.05),
     145                                                  maxDataRowCount - 0.9,
     146                                                  maxDataValue + ((maxDataValue - minDataValue)*0.05));
     147
     148      SetLineClippingArea(newClippingArea);
     149    }
     150
     151    /// <summary>
     152    /// Sets the clipping area of the data to display.
     153    /// </summary>
     154    /// <param name="clippingArea"></param>
     155    private void SetLineClippingArea(RectangleD clippingArea) {
     156      linesShape.ClippingArea = clippingArea;
     157      xAxis.ClippingArea = new RectangleD(linesShape.ClippingArea.X1,
     158                                          xAxis.BoundingBox.Y1,
     159                                          linesShape.ClippingArea.X2,
     160                                          xAxis.BoundingBox.Y2);
    115161    }
    116162
     
    125171        lineShapes.Add(lineShape);
    126172        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    127         root.AddShape(lineShape);
     173        linesShape.AddShape(lineShape);
    128174        maxDataValue = Math.Max(row[i], maxDataValue);
    129175        minDataValue = Math.Min(row[i], minDataValue);
     
    132178      rowToLineShapes[row] = lineShapes;
    133179      ZoomToFullView();
    134       canvasUI1.Invalidate();
     180
     181      canvas.Invalidate();
    135182    }
    136183
     
    150197      minDataValue = Math.Min(value, minDataValue);
    151198
    152       if (index > lineShapes.Count + 1) {
     199      if (index > lineShapes.Count + 1)
    153200        throw new NotImplementedException();
    154       }
    155201
    156202      // new value was added
     
    161207        lineShapes.Add(lineShape);
    162208        // TODO each DataRow needs its own WorldShape so Y Axes can be zoomed independently.
    163         root.AddShape(lineShape);
     209        linesShape.AddShape(lineShape);
    164210      }
    165211
    166212      // not the first value
    167       if (index > 0) {
     213      if (index > 0)
    168214        lineShapes[index - 1].Y2 = value;
    169       }
    170215
    171216      // not the last value
    172       if (index > 0 && index < row.Count - 1) {
     217      if (index > 0 && index < row.Count - 1)
    173218        lineShapes[index].Y1 = value;
    174       }
    175219      ZoomToFullView();
    176       canvasUI1.Invalidate();
     220
     221      canvas.Invalidate();
    177222    }
    178223
    179224    // TODO use action parameter
    180225    private void OnRowValuesChanged(IDataRow row, double[] values, int index, Action action) {
    181       foreach (double value in values) {
     226      foreach (double value in values)
    182227        OnRowValueChanged(row, value, index++, action);
    183       }
    184     }
    185 
    186     private void OnModelChanged() {
    187       InitXAxis();
    188     }
     228    }
     229
     230    private void OnModelChanged() {}
    189231
    190232    #endregion
     
    199241
    200242    public void EndUpdate() {
    201       if (beginUpdateCount == 0) {
     243      if (beginUpdateCount == 0)
    202244        throw new InvalidOperationException("Too many EndUpdates.");
    203       }
    204245
    205246      beginUpdateCount--;
    206247
    207       if (beginUpdateCount == 0) {
    208         Invalidate();
    209       }
     248      if (beginUpdateCount == 0)
     249        canvas.Invalidate();
    210250    }
    211251
     
    230270      if (ModifierKeys == Keys.Control) {
    231271        zoomListener.StartPoint = e.Location;
    232         canvasUI1.MouseEventListener = zoomListener;
     272        canvas.MouseEventListener = zoomListener;
    233273
    234274        r = Rectangle.Empty;
    235         rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, 1000, Color.Blue);
     275        rectangleShape = new RectangleShape(e.X, e.Y, e.X, e.Y, Color.Blue);
    236276        rectangleShape.Opacity = 50;
    237277
    238         root.AddShape(rectangleShape);
     278        linesShape.AddShape(rectangleShape);
    239279      } else {
    240280        panListener.StartPoint = e.Location;
    241         canvasUI1.MouseEventListener = panListener;
    242 
    243         startClippingArea = root.ClippingArea;
     281        canvas.MouseEventListener = panListener;
     282
     283        startClippingArea = linesShape.ClippingArea;
    244284      }
    245285    }
    246286
    247287    private void Pan_OnMouseUp(Point startPoint, Point actualPoint) {
    248       canvasUI1.MouseEventListener = null;
     288      canvas.MouseEventListener = null;
    249289    }
    250290
    251291    private void Pan_OnMouseMove(Point startPoint, Point actualPoint) {
    252       Rectangle viewPort = canvasUI1.ClientRectangle;
     292      Rectangle viewPort = canvas.ClientRectangle;
    253293
    254294      PointD worldStartPoint = Transform.ToWorld(startPoint, viewPort, startClippingArea);
     
    264304      newClippingArea.Y2 = startClippingArea.Y2 - yDiff;
    265305
    266       root.ClippingArea = newClippingArea;
     306      SetLineClippingArea(newClippingArea);
    267307      panListener.StartPoint = startPoint;
    268308
    269309      zoomFullView = false; //user wants to pan => no full view
    270310
    271       canvasUI1.Invalidate();
     311      canvas.Invalidate();
    272312    }
    273313
    274314    private void Zoom_OnMouseUp(Point startPoint, Point actualPoint) {
    275       canvasUI1.MouseEventListener = null;
    276 
    277       RectangleD newClippingArea = Transform.ToWorld(r, canvasUI1.ClientRectangle, root.ClippingArea);
    278       root.ClippingArea = newClippingArea;
    279       root.RemoveShape(rectangleShape);
     315      canvas.MouseEventListener = null;
     316
     317      RectangleD newClippingArea = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea);
     318      SetLineClippingArea(newClippingArea);
     319      linesShape.RemoveShape(rectangleShape);
    280320
    281321      zoomFullView = false; //user wants to pan => no full view
    282322
    283       canvasUI1.Invalidate();
     323      canvas.Invalidate();
    284324    }
    285325
     
    306346      }
    307347
    308       rectangleShape.Rectangle = Transform.ToWorld(r, canvasUI1.ClientRectangle, root.ClippingArea);
    309       canvasUI1.Invalidate();
     348      rectangleShape.Rectangle = Transform.ToWorld(r, canvas.ClientRectangle, linesShape.ClippingArea);
     349     
     350      canvas.Invalidate();
    310351    }
    311352  }
  • trunk/sources/HeuristicLab.Visualization/RectangleShape.cs

    r996 r1038  
    44  public class RectangleShape : IShape {
    55    private RectangleD rectangle;
    6     private double z;
    76    private Color color;
    87    private int opacity = 255;
    98
    10     public RectangleShape(double x1, double y1, double x2, double y2, double z, Color color) {
     9    public RectangleShape(double x1, double y1, double x2, double y2, Color color) {
    1110      rectangle = new RectangleD(x1, y1, x2, y2);
    12       this.z = z;
    1311      this.color = color;
    1412    }
     
    3028    }
    3129
    32     public double Z {
    33       get { return z; }
    34       set { z = value; }
    35     }
    36 
    3730    public int Opacity {
    3831      get { return opacity; }
     
    4437      set { rectangle = value; }
    4538    }
     39
     40    public Color Color {
     41      get { return color; }
     42      set { color = value; }
     43    }
    4644  }
    4745}
  • trunk/sources/HeuristicLab.Visualization/WorldShape.cs

    r984 r1038  
    88    private RectangleD boundingBox;
    99
    10     private readonly List<IShape> shapes = new List<IShape>();
     10    protected readonly List<IShape> shapes = new List<IShape>();
    1111
    1212    public WorldShape(RectangleD clippingArea, RectangleD boundingBox) {
     
    1515    }
    1616
    17     public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
     17    public virtual void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    1818      GraphicsState gstate = graphics.Save();
    1919
     
    2929    }
    3030
    31     /// <summary>
    32     ///
    33     /// </summary>
    3431    public RectangleD BoundingBox {
    3532      get { return boundingBox; }
     33      set { boundingBox = value; }
    3634    }
    3735
     
    4139    }
    4240
    43     /// <summary>
    44     /// adds a shape to the WorldShape
    45     /// </summary>
    46     /// <param name="shape">shape to add</param>
    4741    public void AddShape(IShape shape) {
    4842      shapes.Add(shape);
  • trunk/sources/HeuristicLab.Visualization/XAxis.cs

    r987 r1038  
    55  // TODO move to own file
    66  public class TextShape : IShape {
    7     private readonly double x;
    8     private readonly double y;
     7    private double x;
     8    private double y;
    99    private string text;
    1010
    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;
    1314
    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) {
    1518      this.x = x;
    1619      this.y = y;
    1720      this.text = text;
     21      this.font = new Font("Arial", fontSize);
     22
     23      this.Color = Color.Blue;
    1824    }
    1925
     
    3339      set { text = value; }
    3440    }
     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    }
    3559  }
    3660
    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) {}
    4066
    4167    public void ClearLabels() {
    42       shapes.Clear();
    4368      labels.Clear();
     69    }
    4470
    45       shapes.Add(axisLine);
     71    public void SetLabel(int i, string text) {
     72      labels[i] = new TextShape(i, 0, text);
    4673    }
    4774
    4875    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      }
    5191
    5292      base.Draw(graphics, viewport, clippingArea);
    5393    }
    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     }
    6394  }
    6495}
Note: See TracChangeset for help on using the changeset viewer.