Free cookie consent management tool by TermsFeed Policy Generator

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

bugfixes in DataRow.RemoveValues (updating min/max-values). #498

File:
1 edited

Legend:

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

    r1983 r1984  
    113113
    114114    public override void RemoveValue(int index) {
    115       double remVal = dataRow[index];
    116       //check if index is valid
    117115      if (index >= 0 && index < dataRow.Count) {
     116        UpdateMinMaxValueForRemovedValue(index); // bad runtime but works
     117        double removedValue = dataRow[index];
    118118        dataRow.RemoveAt(index);
    119         OnValueChanged(remVal, index, Action.Deleted);
     119        OnValueChanged(removedValue, index, Action.Deleted);
    120120      } else {
    121121        throw new IndexOutOfRangeException();
     
    124124
    125125    public override void RemoveValues(int index, int count) {
    126       double[] remValues = new double[count]; //removed values
    127       int j = 0;
    128 
    129       //check if count is valid
    130126      if (count > 0) {
    131         //check if index is valid
    132127        if ((index >= 0) && (index + count <= dataRow.Count)) {
    133           for (int i = index; i < (index + count); i++) {
    134             remValues.SetValue(i, j);
    135             dataRow.RemoveAt(i);
    136             j++;
     128          double[] removedValues = new double[count];
     129          for (int i = 0; i < count; i++) {
     130            removedValues[i] = dataRow[index + i];
     131            UpdateMinMaxValueForRemovedValue(index); // bad runtime but works
     132            dataRow.RemoveAt(index);
    137133          }
    138           OnValuesChanged(remValues, index, Action.Deleted);
     134          OnValuesChanged(removedValues, index, Action.Deleted);
    139135        } else {
    140136          throw new IndexOutOfRangeException();
     
    165161    }
    166162
     163    private void UpdateMinMaxValueForRemovedValue(int removedValueIndex) {
     164      if (minValue == dataRow[removedValueIndex] || maxValue == dataRow[removedValueIndex]) {
     165        minValue = double.MaxValue;
     166        maxValue = double.MinValue;
     167
     168        for (int i = 0; i < dataRow.Count; i++) {
     169          if (i != removedValueIndex) {
     170            UpdateMinMaxValue(dataRow[i]);
     171          }
     172        }
     173      }
     174    }
     175
    167176    private void UpdateMinMaxValue(double newValue, int oldValueIndex) {
    168177      if (minValue != dataRow[oldValueIndex] && maxValue != dataRow[oldValueIndex])
Note: See TracChangeset for help on using the changeset viewer.