Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.DataPreprocessing/3.4/Implementations/ScatterPlotContent.cs @ 10987

Last change on this file since 10987 was 10987, checked in by aesterer, 10 years ago

Refactored scatter plot

File size: 3.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Drawing;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27
28namespace HeuristicLab.DataPreprocessing {
29
30  [Item("ScatterPlot", "Represents a scatter plot.")]
31  public class ScatterPlotContent : Item, IViewChartShortcut {
32    public static new Image StaticItemImage {
33      get { return HeuristicLab.Common.Resources.VSImageLibrary.Performance; }
34    }
35
36    public string SelectedXVariable { get; set; }
37    public string SelectedYVariable { get; set; }
38
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;
50    }
51
52    public ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
53      : base(content, cloner) {
54      this.Context = content.Context;
55      this.SelectedXVariable = content.SelectedXVariable;
56      this.SelectedYVariable = content.SelectedYVariable;
57    }
58    public override IDeepCloneable Clone(Cloner cloner) {
59      return new ScatterPlotContent(this, cloner);
60    }
61
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
103  }
104}
Note: See TracBrowser for help on using the repository browser.