Free cookie consent management tool by TermsFeed Policy Generator

Changeset 861


Ignore:
Timestamp:
11/29/08 12:19:58 (15 years ago)
Author:
mstoeger
Message:

Adjustments on LineChart for new interface. #345

Location:
trunk/sources
Files:
6 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/HeuristicLab.Visualization.Test.csproj

    r858 r861  
    5252  </PropertyGroup>
    5353  <ItemGroup>
     54    <Reference Include="nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
     55      <SpecificVersion>False</SpecificVersion>
     56      <HintPath>NUnit-2.4.8-bin\nunit.framework.dll</HintPath>
     57    </Reference>
    5458    <Reference Include="System" />
    5559    <Reference Include="System.Core">
     
    7074    <Compile Include="HeuristicLabVisualizationTestApplication.cs" />
    7175    <Compile Include="HeuristicLabVisualizationTestPlugin.cs" />
     76    <Compile Include="LineChartTestForm.cs">
     77      <SubType>Form</SubType>
     78    </Compile>
     79    <Compile Include="LineChartTestForm.Designer.cs">
     80      <DependentUpon>LineChartTestForm.cs</DependentUpon>
     81    </Compile>
     82    <Compile Include="LineChartTests.cs" />
    7283    <Compile Include="MainForm.cs">
    7384      <SubType>Form</SubType>
     
    8394  </ItemGroup>
    8495  <ItemGroup>
     96    <ProjectReference Include="..\HeuristicLab.Core\HeuristicLab.Core.csproj">
     97      <Project>{F43B59AB-2B8C-4570-BC1E-15592086517C}</Project>
     98      <Name>HeuristicLab.Core</Name>
     99    </ProjectReference>
    85100    <ProjectReference Include="..\HeuristicLab.PluginInfrastructure\HeuristicLab.PluginInfrastructure.csproj">
    86101      <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project>
     
    93108  </ItemGroup>
    94109  <ItemGroup>
     110    <EmbeddedResource Include="LineChartTestForm.resx">
     111      <DependentUpon>LineChartTestForm.cs</DependentUpon>
     112    </EmbeddedResource>
    95113    <EmbeddedResource Include="MainForm.resx">
    96114      <DependentUpon>MainForm.cs</DependentUpon>
  • trunk/sources/HeuristicLab.Visualization/LineChart.cs

    r761 r861  
    11using System;
    2 using System.Drawing;
     2using System.Collections.Generic;
    33using HeuristicLab.Core;
    44
    5 namespace HeuristicLab.Visualization
    6 {
    7   public partial class LineChart : ViewBase
    8   {
     5namespace HeuristicLab.Visualization {
     6  public partial class LineChart : ViewBase {
    97    private readonly IChartDataRowsModel model;
    10     private Color[] lineColors;
    118
    129    /// <summary>
    1310    /// This constructor shouldn't be called. Only required for the designer.
    1411    /// </summary>
    15     public LineChart()
    16     {
     12    public LineChart() {
    1713      InitializeComponent();
    1814    }
     
    2218    /// </summary>
    2319    /// <param name="model">Referenz to the model, for data</param>
    24     public LineChart(IChartDataRowsModel model) : this()
    25     {
     20    public LineChart(IChartDataRowsModel model) : this() {
    2621      if (model == null)
    27       {
    2822        throw new NullReferenceException("Model cannot be null.");
    29       }
    3023
    3124      this.model = model;
     25      this.Item = (IItem)model;
    3226
    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      
    3927      //TODO: correct Rectangle to fit
    40       RectangleD clientRectangle = new RectangleD(ClientRectangle.Left, ClientRectangle.Top, ClientRectangle.Right,
    41                                                   ClientRectangle.Bottom);
     28      RectangleD clientRectangle = new RectangleD(-1, -1, 11, 11);
    4229      canvasUI1.MainCanvas.WorldShape = new WorldShape(clientRectangle, clientRectangle);
    43       Reset();
    44     }
    45 
    46     /// <summary>
    47     /// Resets the line chart by deleting all shapes and reloading all data from the model.
    48     /// </summary>
    49     private void Reset()
    50     {
    51       // TODO an neues model interface anpassen   
    52       throw new NotImplementedException();
    53      
    54 //      BeginUpdate();
    55 //
    56 //      // TODO clear existing shapes
    57 //
    58 //      WorldShape mainWorld = canvasUI1.MainCanvas.WorldShape;
    59 //
    60 //      double spacing = mainWorld.BoundingBox.Width/model.Columns.Count;
    61 //      double oldX = 0;
    62 //      double currentX = spacing;
    63 //      ChartDataRowsModelColumn oldColumn = null;
    64 //      // reload data from the model and create shapes
    65 //      foreach (ChartDataRowsModelColumn column in model.Columns)
    66 //      {
    67 //        if (oldColumn != null)
    68 //        {
    69 //          if (column.Values != null)
    70 //          {
    71 //            for (int i = 0; i < column.Values.Length; i++)
    72 //            {
    73 //              LineShape line = new LineShape(oldX, oldColumn.Values[i], currentX, column.Values[i], 0, lineColors[i]);
    74 //              mainWorld.AddShape(line);
    75 //            }
    76 //            oldX = currentX;
    77 //            currentX += spacing;
    78 //          }
    79 //          oldColumn = column;
    80 //        }
    81 //        else
    82 //        {
    83 //          oldColumn = column;
    84 //        }
    85 //
    86 //        canvasUI1.Invalidate();
    87 //
    88 //        //   AddColumn(column.ColumnId, column.Values);
    89 //      }
    90 //
    91 //      EndUpdate();
    92     }
    93 
    94     /// <summary>
    95     /// Event handler which gets called when data in the model changes.
    96     /// </summary>
    97     /// <param name="type">Type of change</param>
    98     /// <param name="columnId">Id of the changed column</param>
    99     /// <param name="values">Values contained within the changed column</param>
    100     private void OnDataChanged(ChangeType type, long columnId, double[] values)
    101     {
    102       switch (type)
    103       {
    104         case ChangeType.Add:
    105           AddColumn(columnId, values);
    106           break;
    107         case ChangeType.Modify:
    108           ModifyColumn(columnId, values);
    109           break;
    110         case ChangeType.Remove:
    111           RemoveColumn(columnId);
    112           break;
    113         default:
    114           throw new ArgumentOutOfRangeException("type");
    115       }
    116     }
    117 
    118     /// <summary>
    119     /// Adds a new column to the chart.
    120     /// </summary>
    121     /// <param name="columnId">Id of the column</param>
    122     /// <param name="values">Values of the column</param>
    123     private void AddColumn(long columnId, double[] values)
    124     {
    125       throw new NotImplementedException();
    126     }
    127 
    128     /// <summary>
    129     /// Modifies an existing column of the chart.
    130     /// </summary>
    131     /// <param name="columnId">Id of the column</param>
    132     /// <param name="values">Values of the column</param>
    133     private void ModifyColumn(long columnId, double[] values)
    134     {
    135       throw new NotImplementedException();
    136     }
    137 
    138     /// <summary>
    139     /// Removes a column from the chart.
    140     /// </summary>
    141     /// <param name="columnId">Id of the column</param>
    142     private void RemoveColumn(long columnId)
    143     {
    144       throw new NotImplementedException();
    14530    }
    14631
    14732    #region Add-/RemoveItemEvents
    14833
    149     protected override void AddItemEvents()
    150     {
    151       // TODO an neues model interface anpassen   
    152       throw new NotImplementedException();
    153 //      base.AddItemEvents();
    154 //      model.ColumnChanged += OnDataChanged;
     34    protected override void AddItemEvents() {
     35      base.AddItemEvents();
     36
     37      model.DataRowAdded += OnDataRowAdded;
     38      model.DataRowRemoved += OnDataRowRemoved;
     39      model.ModelChanged += OnModelChanged;
    15540    }
    15641
    157     protected override void RemoveItemEvents()
    158     {
    159       // TODO an neues model interface anpassen   
    160       throw new NotImplementedException();
     42    protected override void RemoveItemEvents() {
     43      base.RemoveItemEvents();
    16144
    162 //      base.RemoveItemEvents();
    163 //      model.ColumnChanged -= OnDataChanged;
     45      model.DataRowAdded -= OnDataRowAdded;
     46      model.DataRowRemoved -= OnDataRowRemoved;
     47      model.ModelChanged -= OnModelChanged;
     48    }
     49
     50    private void OnDataRowAdded(IDataRow row) {
     51      row.ValueChanged += OnRowValueChanged;
     52      row.ValuesChanged += OnRowValuesChanged;
     53
     54      InitShapes(row);
     55    }
     56
     57    private void InitShapes(IDataRow row) {
     58      List<LineShape> lineShapes = new List<LineShape>();
     59
     60      for (int i = 1; i < row.Count; i++) {
     61        LineShape lineShape = new LineShape(i - 1, row[i - 1], i, row[i], 0, row.Color);
     62        lineShapes.Add(lineShape);
     63        canvasUI1.MainCanvas.WorldShape.AddShape(lineShape);
     64      }
     65
     66      rowToLineShapes[row] = lineShapes;
     67
     68      canvasUI1.Invalidate();
     69    }
     70
     71    private void OnDataRowRemoved(IDataRow row) {
     72      row.ValueChanged -= OnRowValueChanged;
     73      row.ValuesChanged -= OnRowValuesChanged;
     74    }
     75
     76    private readonly IDictionary<IDataRow, List<LineShape>> rowToLineShapes = new Dictionary<IDataRow, List<LineShape>>();
     77
     78    private void OnRowValueChanged(IDataRow row, double value, int index) {
     79      List<LineShape> lineShapes = rowToLineShapes[row];
     80
     81      if (index > lineShapes.Count+1)
     82        throw new NotImplementedException();
     83
     84      // new value was added
     85      if (index > 0 && index == lineShapes.Count+1) {
     86        LineShape lineShape = new LineShape(index - 1, row[index - 1], index, row[index], 0, row.Color);
     87        lineShapes.Add(lineShape);
     88        canvasUI1.MainCanvas.WorldShape.AddShape(lineShape);
     89      }
     90
     91      // not the first value
     92      if (index > 0)
     93        lineShapes[index-1].Y2 = value;
     94
     95      // not the last value
     96      if (index > 0 && index < row.Count)
     97        lineShapes[index].Y1 = value;
     98
     99      canvasUI1.Invalidate();
     100    }
     101
     102    private void OnRowValuesChanged(IDataRow row, double[] values, int index) {
     103      foreach (double value in values) {
     104        OnRowValueChanged(row, value, index++);
     105      }
     106    }
     107
     108    private void OnModelChanged() {
    164109    }
    165110
     
    170115    private int beginUpdateCount = 0;
    171116
    172     public void BeginUpdate()
    173     {
     117    public void BeginUpdate() {
    174118      beginUpdateCount++;
    175119    }
    176120
    177     public void EndUpdate()
    178     {
     121    public void EndUpdate() {
    179122      if (beginUpdateCount == 0)
    180       {
    181123        throw new InvalidOperationException("Too many EndUpdates.");
    182       }
    183124
    184125      beginUpdateCount--;
    185126
    186127      if (beginUpdateCount == 0)
    187       {
    188128        Invalidate();
    189       }
    190129    }
    191130
  • trunk/sources/HeuristicLab.Visualization/LineShape.cs

    r754 r861  
    33namespace HeuristicLab.Visualization {
    44  public class LineShape : IShape {
    5     private RectangleD boundingRect;
     5    private RectangleD boundingBox;
    66    private double z;
    77    private Color color;
     
    1616    /// <param name="color">color for the LineShape</param>
    1717    public LineShape(double x1, double y1, double x2, double y2, double z, Color color) {
    18       this.boundingRect = new RectangleD(x1, y1, x2, y2);
     18      this.boundingBox = new RectangleD(x1, y1, x2, y2);
    1919      this.z = z;
    2020      this.color = color;
     
    2222
    2323    public RectangleD BoundingBox {
    24       get { return boundingRect; }
     24      get { return boundingBox; }
     25    }
     26
     27    public double Y1 {
     28      get { return boundingBox.Y1; }
     29      set { boundingBox.Y1 = value; }
     30    }
     31
     32    public double Y2 {
     33      get { return boundingBox.Y2; }
     34      set { boundingBox.Y2 = value; }
     35    }
     36
     37    public double X1 {
     38      get { return boundingBox.X1; }
     39      set { boundingBox.X1 = value; }
     40    }
     41
     42    public double X2 {
     43      get { return boundingBox.X2; }
     44      set { boundingBox.X2 = value; }
    2545    }
    2646
     
    3353    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    3454      using (Pen pen = new Pen(color, 3)){
    35         Rectangle screenRect = Transform.ToScreen(boundingRect, viewport, clippingArea);
     55        Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
    3656        graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
    3757      }
Note: See TracChangeset for help on using the changeset viewer.