Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/15/11 14:54:43 (13 years ago)
Author:
abeham
Message:

#1465

  • updated branch with changes from trunk
  • fixed some bugs
  • introduced secondary x-axis option
Location:
branches/histogram
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/histogram

  • branches/histogram/HeuristicLab.Analysis.Views/3.3/DataTableView.cs

    r6010 r6011  
    142142      }
    143143      series.YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
     144      series.XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
    144145      if (row.VisualProperties.Color != Color.Empty) series.Color = row.VisualProperties.Color;
    145146      series.ToolTip = row.Name + " X = #INDEX, Y = #VAL";
     
    305306            chart.Series[row.Name].ChartType = SeriesChartType.Column;
    306307            chart.Series[row.Name]["PointWidth"] = "1";
     308            CalculateHistogram(chart.Series[row.Name], row);
    307309            break;
    308310          default:
     
    311313        }
    312314        chart.Series[row.Name].YAxisType = row.VisualProperties.SecondYAxis ? AxisType.Secondary : AxisType.Primary;
     315        chart.Series[row.Name].XAxisType = row.VisualProperties.SecondXAxis ? AxisType.Secondary : AxisType.Primary;
    313316        if (row.VisualProperties.Color != Color.Empty) chart.Series[row.Name].Color = row.VisualProperties.Color;
    314317        chart.ChartAreas[0].RecalculateAxesScale();
     
    444447
    445448    private void FillSeriesWithRowValues(Series series, DataRow row) {
    446       if (row.VisualProperties.ChartType == DataRowVisualProperties.DataRowChartType.Histogram) {
    447         series.Points.Clear();
    448         if (!row.Values.Any()) return;
    449         int bins = row.VisualProperties.Bins;
    450 
    451         double minValue = row.Values.Min();
    452         double maxValue = row.Values.Max();
    453         double intervalWidth = (maxValue - minValue) / bins;
    454         if (intervalWidth <= 0) return;
    455 
    456         if (!row.VisualProperties.ExactBins) {
    457           intervalWidth = HumanRoundRange(intervalWidth);
    458           minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
    459           maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
    460         }
    461 
    462         double current = minValue, intervalCenter = intervalWidth / 2.0;
    463         int frequency = 0;
    464         foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
    465           while (v > current + intervalWidth) {
    466             series.Points.AddXY(current + intervalCenter, frequency);
    467             current += intervalWidth;
    468             frequency = 0;
    469           }
    470           frequency++;
    471         }
    472         series.Points.AddXY(current + intervalCenter, frequency);
    473       } else {
    474         for (int i = 0; i < row.Values.Count; i++) {
    475           var value = row.Values[i];
    476           DataPoint point = new DataPoint();
    477           point.XValue = row.VisualProperties.StartIndexZero ? i : i + 1;
    478           if (IsInvalidValue(value))
    479             point.IsEmpty = true;
    480           else
    481             point.YValues = new double[] { value };
    482           series.Points.Add(point);
    483         }
    484       }
     449      switch (row.VisualProperties.ChartType) {
     450        case DataRowVisualProperties.DataRowChartType.Histogram:
     451          CalculateHistogram(series, row);
     452          break;
     453        default: {
     454            for (int i = 0; i < row.Values.Count; i++) {
     455              var value = row.Values[i];
     456              DataPoint point = new DataPoint();
     457              point.XValue = row.VisualProperties.StartIndexZero ? i : i + 1;
     458              if (IsInvalidValue(value))
     459                point.IsEmpty = true;
     460              else
     461                point.YValues = new double[] { value };
     462              series.Points.Add(point);
     463            }
     464          }
     465          break;
     466      }
     467    }
     468
     469    private void CalculateHistogram(Series series, DataRow row) {
     470      series.Points.Clear();
     471      if (!row.Values.Any()) return;
     472      int bins = row.VisualProperties.Bins;
     473
     474      double minValue = row.Values.Min();
     475      double maxValue = row.Values.Max();
     476      double intervalWidth = (maxValue - minValue) / bins;
     477      if (intervalWidth <= 0) return;
     478
     479      if (!row.VisualProperties.ExactBins) {
     480        intervalWidth = HumanRoundRange(intervalWidth);
     481        minValue = Math.Floor(minValue / intervalWidth) * intervalWidth;
     482        maxValue = Math.Ceiling(maxValue / intervalWidth) * intervalWidth;
     483      }
     484
     485      double current = minValue, intervalCenter = intervalWidth / 2.0;
     486      int frequency = 0;
     487      foreach (double v in row.Values.Where(x => !IsInvalidValue(x)).OrderBy(x => x)) {
     488        while (v > current + intervalWidth) {
     489          series.Points.AddXY(current + intervalCenter, frequency);
     490          current += intervalWidth;
     491          frequency = 0;
     492        }
     493        frequency++;
     494      }
     495      series.Points.AddXY(current + intervalCenter, frequency);
    485496    }
    486497
Note: See TracChangeset for help on using the changeset viewer.