Free cookie consent management tool by TermsFeed Policy Generator

Changeset 1983


Ignore:
Timestamp:
05/31/09 21:26:27 (15 years ago)
Author:
mstoeger
Message:

bugfixes in DataRow.Add/ModifyValues (checking indexes, updating min/max-values). #498

Location:
trunk/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.Test/3.2/LineChartTests.cs

    r1982 r1983  
    219219
    220220    [Test]
    221     public void TestInsertValuesInDataRow() {
     221    public void TestAddValueToDataRow() {
     222      LineChartTestForm f = new LineChartTestForm(model);
     223
     224      IDataRow row = new DataRow();
     225      row.AddValue(0);
     226      row.AddValue(10);
     227      row.AddValue(-5);
     228
     229      model.AddDataRow(row);
     230
     231      f.ShowDialog();
     232    }
     233
     234    [Test]
     235    public void TestAddValuesToDataRow() {
     236      LineChartTestForm f = new LineChartTestForm(model);
     237
     238      IDataRow row = new DataRow();
     239      row.AddValues(new double[] {0, 10, -5});
     240
     241      model.AddDataRow(row);
     242
     243      f.ShowDialog();
     244    }
     245
     246    [Test]
     247    public void TestInsertValueInDataRow() {
    222248      LineChartTestForm f = new LineChartTestForm(model);
    223249
     
    228254      row.AddValue(10, 1);
    229255      row.AddValue(10, 2);
     256
     257      model.AddDataRow(row);
     258
     259      f.ShowDialog();
     260    }
     261
     262    [Test]
     263    public void TestInsertValuesInDataRow() {
     264      LineChartTestForm f = new LineChartTestForm(model);
     265
     266      IDataRow row = new DataRow();
     267      row.AddValue(0);
     268      row.AddValue(5);
     269
     270      row.AddValues(new double[] {10, 10}, 1);
     271
     272      model.AddDataRow(row);
     273
     274      f.ShowDialog();
     275    }
     276
     277    [Test]
     278    public void TestModifyValueInDataRow() {
     279      LineChartTestForm f = new LineChartTestForm(model);
     280
     281      IDataRow row = new DataRow();
     282      row.AddValue(0);
     283      row.AddValue(100);
     284      row.AddValue(0);
     285
     286      row.ModifyValue(5, 1);
     287
     288      model.AddDataRow(row);
     289
     290      f.ShowDialog();
     291    }
     292
     293    [Test]
     294    public void TestModifyValuesInDataRow() {
     295      LineChartTestForm f = new LineChartTestForm(model);
     296
     297      IDataRow row = new DataRow();
     298      row.AddValue(0);
     299      row.AddValue(100);
     300      row.AddValue(100);
     301      row.AddValue(0);
     302
     303      row.ModifyValues(new double[] {5, 5}, 1);
    230304
    231305      model.AddDataRow(row);
  • trunk/sources/HeuristicLab.Visualization/3.2/DataRow.cs

    r1982 r1983  
    22using System.Drawing;
    33using System.Collections.Generic;
    4 using HeuristicLab.Visualization.LabelProvider;
    54
    65namespace HeuristicLab.Visualization {
     
    7675
    7776    public override void AddValues(double[] values, int index) {
    78       int j = index;
    79 
    80       //check if index to start changes is valid
    81       if (index >=0 && (index + values.Length) < dataRow.Count) {
    82         foreach (double d in values) {
    83           dataRow.Insert(j, d);
    84           j++;
     77      if (index >= 0 && index < dataRow.Count) {
     78        for (int i = 0; i < values.Length; i++) {
     79          double value = values[i];
     80          UpdateMinMaxValue(value);
     81          dataRow.Insert(index + i, value);
    8582        }
    8683        OnValuesChanged(values, index, Action.Added);
     
    9390      //check if index is valid
    9491      if (index >= 0 && index < dataRow.Count) {
     92        UpdateMinMaxValue(value, index); // bad runtime but works
    9593        dataRow[index] = value;
    9694        OnValueChanged(value, index, Action.Modified);
     
    10199
    102100    public override void ModifyValues(double[] values, int index) {
    103       int startInd = index;
    104       int modInd = index;
    105 
    106101      //check if index to start modification is valid
    107       if (startInd >=0 && startInd + values.Length < dataRow.Count) {
    108         foreach (double d in values) {
    109           dataRow[modInd] = d;
    110           modInd++;
     102      if (index >= 0 && index + values.Length < dataRow.Count) {
     103        for (int i = 0; i < values.Length; i++) {
     104          double value = values[i];
     105          UpdateMinMaxValue(value, index + i); // bad runtime but works
     106          dataRow[index+i] = value;
    111107        }
    112         OnValuesChanged(values, startInd, Action.Modified);
     108        OnValuesChanged(values, index, Action.Modified);
    113109      } else {
    114110        throw new IndexOutOfRangeException();
     
    169165    }
    170166
     167    private void UpdateMinMaxValue(double newValue, int oldValueIndex) {
     168      if (minValue != dataRow[oldValueIndex] && maxValue != dataRow[oldValueIndex])
     169        UpdateMinMaxValue(newValue);
     170      else {
     171        minValue = double.MaxValue;
     172        maxValue = double.MinValue;
     173
     174        for (int i = 0; i < dataRow.Count; i++) {
     175          double value = oldValueIndex != i ? dataRow[i] : newValue;
     176          UpdateMinMaxValue(value);
     177        }
     178      }
     179    }
     180
    171181    private void UpdateMinMaxValue(double value) {
    172182      maxValue = Math.Max(value, maxValue);
Note: See TracChangeset for help on using the changeset viewer.