Free cookie consent management tool by TermsFeed Policy Generator

Changeset 754 for trunk/sources


Ignore:
Timestamp:
11/13/08 22:44:22 (15 years ago)
Author:
dwagner
Message:

#345 First implementation of LineChart

Location:
trunk/sources/HeuristicLab.Visualization
Files:
1 added
5 edited

Legend:

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

    r736 r754  
    4949
    5050    public override IView CreateView() {
    51       //return new LineChart(this); when LineChart is implemented
     51      return new LineChart(this); //when LineChart is implemented
    5252      return new IntDataView(test);
    5353    }
  • trunk/sources/HeuristicLab.Visualization/ChartDataRowsModelDummy.cs

    r727 r754  
    44using System.Text;
    55
    6 namespace HeuristicLab.Visualization {
    7   public class ChartDataRowsModelDummy : ChartDataRowsModel {
     6namespace HeuristicLab.Visualization{
     7  public class ChartDataRowsModelDummy : ChartDataRowsModel  {
     8    public ChartDataRowsModelDummy(){
     9      Random rand = new Random();
    810
    9      public ChartDataRowsModelDummy(){
    10 
    11         // test rows
    12         AddDataRow(1);
    13         AddDataRow(2);
    14         AddDataRow(3);
    15         AddDataRow(4);
    16 
    17        PushData(1, 1.2);
    18        PushData(1, 2.0);
    19        PushData(1, 4.5);
    20        PushData(1, 8.4);
    21        PushData(1, 5.0);
    22        PushData(1, 6.0);
    23        PushData(2, 2.0);
    24        PushData(3, 8.3);
    25        PushData(3, 7.3);
    26        PushData(3, 9.7);
    27        PushData(3, 2.3);
    28        PushData(3, 1.7);
    29        PushData(3, 0.3);
    30        PushData(3, 0.1);
    31        PushData(3, 2.0);
    32        PushData(3, 8.8);
    33        PushData(3, 9.9);
    34 
    35      }
    36    
     11   
     12      // test rows
     13      for (int i = 0; i < 10; i++){
     14        AddDataRow(i);
     15        PushData(i, rand.NextDouble() * 1000);
     16        PushData(i, rand.NextDouble() * 1000);
     17        PushData(i, rand.NextDouble() * 1000);
     18      }
     19    }
    3720  }
    3821}
  • trunk/sources/HeuristicLab.Visualization/HeuristicLab.Visualization.csproj

    r726 r754  
    44    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    55    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    6     <ProductVersion>9.0.21022</ProductVersion>
     6    <ProductVersion>9.0.30729</ProductVersion>
    77    <SchemaVersion>2.0</SchemaVersion>
    88    <ProjectGuid>{E392A1E2-DC95-4E33-B82E-8ED690EDA1AB}</ProjectGuid>
     
    7676      <DependentUpon>LineChart.cs</DependentUpon>
    7777    </Compile>
     78    <Compile Include="LineShape.cs" />
    7879    <Compile Include="MouseEventListener.cs" />
    7980    <Compile Include="Offset.cs" />
  • trunk/sources/HeuristicLab.Visualization/LineChart.Designer.cs

    r684 r754  
    2929        private void InitializeComponent()
    3030        {
    31             this.SuspendLayout();
    32             //
    33             // LineChart
    34             //
    35             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    36             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    37             this.Name = "LineChart";
    38             this.Size = new System.Drawing.Size(552, 390);
    39             this.ResumeLayout(false);
     31          this.canvasUI1 = new HeuristicLab.Visualization.CanvasUI();
     32          this.SuspendLayout();
     33          //
     34          // canvasUI1
     35          //
     36          this.canvasUI1.Location = new System.Drawing.Point(3, 3);
     37          this.canvasUI1.MouseEventListener = null;
     38          this.canvasUI1.Name = "canvasUI1";
     39          this.canvasUI1.Size = new System.Drawing.Size(546, 384);
     40          this.canvasUI1.TabIndex = 0;
     41          this.canvasUI1.Text = "canvasUI1";
     42          //
     43          // LineChart
     44          //
     45          this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     46          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
     47          this.Controls.Add(this.canvasUI1);
     48          this.Name = "LineChart";
     49          this.Size = new System.Drawing.Size(552, 390);
     50          this.ResumeLayout(false);
    4051
    4152        }
    4253
    4354        #endregion
     55
     56        private CanvasUI canvasUI1;
    4457    }
    4558}
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r697 r754  
    11using System;
     2using System.Drawing;
    23using HeuristicLab.Core;
    34
    4 namespace HeuristicLab.Visualization {
    5   public partial class LineChart : ViewBase {
     5namespace HeuristicLab.Visualization
     6{
     7  public partial class LineChart : ViewBase
     8  {
    69    private readonly IChartDataRowsModel model;
     10    private Color[] lineColors;
    711
    812    /// <summary>
    913    /// This constructor shouldn't be called. Only required for the designer.
    1014    /// </summary>
    11     public LineChart() {
     15    public LineChart()
     16    {
    1217      InitializeComponent();
    1318    }
     
    1621    /// Initializes the chart.
    1722    /// </summary>
    18     /// <param name="model"></param>
    19     public LineChart(IChartDataRowsModel model) : this() {
    20       if (model == null) {
     23    /// <param name="model">Referenz to the model, for data</param>
     24    public LineChart(IChartDataRowsModel model) : this()
     25    {
     26      if (model == null)
     27      {
    2128        throw new NullReferenceException("Model cannot be null.");
    2229      }
     
    2431      this.model = model;
    2532
     33      //TODO: read line colors instead of static ones
     34      lineColors = new Color[3];
     35      lineColors[0] = Color.Red;
     36      lineColors[1] = Color.Green;
     37      lineColors[2] = Color.Blue;
     38     
     39      //TODO: correct Rectangle to fit
     40      RectangleD clientRectangle = new RectangleD(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right,
     41                                                  ClientRectangle.Bottom);
     42      canvasUI1.MainCanvas.WorldShape = new WorldShape(clientRectangle, clientRectangle);
    2643      Reset();
    2744    }
     
    3047    /// Resets the line chart by deleting all shapes and reloading all data from the model.
    3148    /// </summary>
    32     private void Reset() {
     49    private void Reset()
     50    {
    3351      BeginUpdate();
    3452
    3553      // TODO clear existing shapes
    3654
     55      WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape;
     56
     57      double spacing = mainWorld.BoundingBox.Width/model.Columns.Count;
     58      double oldX = 0;
     59      double currentX = spacing;
     60      ChartDataRowsModelColumn oldColumn = null;
    3761      // reload data from the model and create shapes
    38       foreach (ChartDataRowsModelColumn column in model.Columns) {
    39         AddColumn(column.ColumnId, column.Values);
     62      foreach (ChartDataRowsModelColumn column in model.Columns)
     63      {
     64        if (oldColumn != null)
     65        {
     66          if (column.Values != null)
     67          {
     68            for (int i = 0; i < column.Values.Length; i++)
     69            {
     70              LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]);
     71              mainWorld.AddShape(line);
     72            }
     73            oldX = currentX;
     74            currentX += spacing;
     75          }
     76          oldColumn = column;
     77        }
     78        else
     79        {
     80          oldColumn = column;
     81        }
     82
     83        canvasUI1.Invalidate();
     84
     85        //   AddColumn(column.ColumnId, column.Values);
    4086      }
    4187
     
    4995    /// <param name="columnId">Id of the changed column</param>
    5096    /// <param name="values">Values contained within the changed column</param>
    51     private void OnDataChanged(ChangeType type, long columnId, double[] values) {
    52       switch (type) {
     97    private void OnDataChanged(ChangeType type, long columnId, double[] values)
     98    {
     99      switch (type)
     100      {
    53101        case ChangeType.Add:
    54102          AddColumn(columnId, values);
     
    70118    /// <param name="columnId">Id of the column</param>
    71119    /// <param name="values">Values of the column</param>
    72     private void AddColumn(long columnId, double[] values) {
     120    private void AddColumn(long columnId, double[] values)
     121    {
    73122      throw new NotImplementedException();
    74123    }
     
    79128    /// <param name="columnId">Id of the column</param>
    80129    /// <param name="values">Values of the column</param>
    81     private void ModifyColumn(long columnId, double[] values) {
     130    private void ModifyColumn(long columnId, double[] values)
     131    {
    82132      throw new NotImplementedException();
    83133    }
     
    87137    /// </summary>
    88138    /// <param name="columnId">Id of the column</param>
    89     private void RemoveColumn(long columnId) {
     139    private void RemoveColumn(long columnId)
     140    {
    90141      throw new NotImplementedException();
    91142    }
     
    93144    #region Add-/RemoveItemEvents
    94145
    95     protected override void AddItemEvents() {
     146    protected override void AddItemEvents()
     147    {
    96148      base.AddItemEvents();
    97149      model.ColumnChanged += OnDataChanged;
    98150    }
    99151
    100     protected override void RemoveItemEvents() {
     152    protected override void RemoveItemEvents()
     153    {
    101154      base.RemoveItemEvents();
    102155      model.ColumnChanged -= OnDataChanged;
     
    109162    private int beginUpdateCount = 0;
    110163
    111     public void BeginUpdate() {
     164    public void BeginUpdate()
     165    {
    112166      beginUpdateCount++;
    113167    }
    114168
    115     public void EndUpdate() {
    116       if (beginUpdateCount == 0) {
     169    public void EndUpdate()
     170    {
     171      if (beginUpdateCount == 0)
     172      {
    117173        throw new InvalidOperationException("Too many EndUpdates.");
    118174      }
     
    120176      beginUpdateCount--;
    121177
    122       if (beginUpdateCount == 0) {
     178      if (beginUpdateCount == 0)
     179      {
    123180        Invalidate();
    124181      }
Note: See TracChangeset for help on using the changeset viewer.