Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/11/14 14:23:19 (10 years ago)
Author:
aesterer
Message:

Refactored scatter plot

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ScatterPlotContent.cs

    r10967 r10987  
    2020#endregion
    2121
     22using System.Collections.Generic;
    2223using System.Drawing;
     24using HeuristicLab.Analysis;
    2325using HeuristicLab.Common;
    2426using HeuristicLab.Core;
     
    2729
    2830  [Item("ScatterPlot", "Represents a scatter plot.")]
    29   public class ScatterPlotContent : PreprocessingChartContent {
     31  public class ScatterPlotContent : Item, IViewChartShortcut {
     32    public static new Image StaticItemImage {
     33      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
     34    }
    3035
    3136    public string SelectedXVariable { get; set; }
    32 
    3337    public string SelectedYVariable { get; set; }
    3438
    35     public ScatterPlotContent(IChartLogic chartlogic)
    36       : base(chartlogic) {
     39    public IPreprocessingContext Context {
     40      get;
     41      private set;
     42    }
     43    public ITransactionalPreprocessingData PreprocessingData {
     44      get { return Context.Data; }
     45    }
     46
     47    public ScatterPlotContent(IPreprocessingContext context)
     48      : base() {
     49      this.Context = context;
    3750    }
    3851
    3952    public ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
    4053      : base(content, cloner) {
    41         this.SelectedXVariable = content.SelectedXVariable;
    42         this.SelectedYVariable = content.SelectedYVariable;
     54      this.Context = content.Context;
     55      this.SelectedXVariable = content.SelectedXVariable;
     56      this.SelectedYVariable = content.SelectedYVariable;
    4357    }
    44 
    45     public static new Image StaticItemImage {
    46       get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
    47     }
    48 
    4958    public override IDeepCloneable Clone(Cloner cloner) {
    5059      return new ScatterPlotContent(this, cloner);
    5160    }
    5261
     62    public DataRow CreateDataRow(string variableName, DataRowVisualProperties.DataRowChartType chartType) {
     63      int columnIndex = PreprocessingData.GetColumnIndex(variableName);
     64      IList<double> values = PreprocessingData.GetValues<double>(columnIndex);
     65      DataRow row = new DataRow(variableName, "", values);
     66      row.VisualProperties.ChartType = chartType;
     67      return row;
     68    }
     69
     70    public IEnumerable<string> GetVariableNames() {
     71      List<string> doubleVariableNames = new List<string>();
     72
     73      //only return variable names from type double
     74      foreach (string variableName in PreprocessingData.VariableNames) {
     75        if (PreprocessingData.IsType<double>(PreprocessingData.GetColumnIndex(variableName)))
     76          doubleVariableNames.Add(variableName);
     77      }
     78
     79      return doubleVariableNames;
     80    }
     81
     82    public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY) {
     83      ScatterPlot scatterPlot = new ScatterPlot();
     84
     85      int xColumnIndex = PreprocessingData.GetColumnIndex(variableNameX);
     86      int yColumnIndex = PreprocessingData.GetColumnIndex(variableNameY);
     87
     88      IList<double> xValues = PreprocessingData.GetValues<double>(xColumnIndex);
     89      IList<double> yValues = PreprocessingData.GetValues<double>(yColumnIndex);
     90
     91      List<Point2D<double>> points = new List<Point2D<double>>();
     92
     93      for (int i = 0; i < xValues.Count; i++) {
     94        Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
     95        points.Add(point);
     96      }
     97
     98      ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
     99      scatterPlot.Rows.Add(scdr);
     100      return scatterPlot;
     101    }
     102
    53103  }
    54104}
Note: See TracChangeset for help on using the changeset viewer.