source: branches/DataPreprocessing Enhancements/HeuristicLab.DataPreprocessing/3.4/Content/ScatterPlotContent.cs @ 14467

Last change on this file since 14467 was 14467, checked in by pfleck, 4 years ago

#2709

  • Removed some groupboxes in ViewShortcutListView.
  • Removed unnecessary IViewChartShortcut
  • Split ScatterPlot Multi and Single in to separate contents.
  • Renamed Color-combo box in Scatterplot to "Group".
File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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.Linq;
24using HeuristicLab.Analysis;
25using HeuristicLab.Common;
26
27namespace HeuristicLab.DataPreprocessing {
28
29  public abstract class ScatterPlotContent : PreprocessingChartContent {
30    protected ScatterPlotContent(IFilteredPreprocessingData preprocessingData)
31      : base(preprocessingData) {
32    }
33
34    protected ScatterPlotContent(ScatterPlotContent content, Cloner cloner)
35      : base(content, cloner) {
36    }
37
38    public ScatterPlot CreateScatterPlot(string variableNameX, string variableNameY, string variableNameColor = "-") {
39      ScatterPlot scatterPlot = new ScatterPlot();
40
41      IList<double> xValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameX));
42      IList<double> yValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameY));
43      if (variableNameColor == null || variableNameColor == "-") {
44        List<Point2D<double>> points = new List<Point2D<double>>();
45
46        for (int i = 0; i < xValues.Count; i++) {
47          Point2D<double> point = new Point2D<double>(xValues[i], yValues[i]);
48          points.Add(point);
49        }
50
51        ScatterPlotDataRow scdr = new ScatterPlotDataRow(variableNameX + " - " + variableNameY, "", points);
52        scdr.VisualProperties.IsVisibleInLegend = false;
53        scatterPlot.Rows.Add(scdr);
54
55      } else {
56        var colorValues = PreprocessingData.GetValues<double>(PreprocessingData.GetColumnIndex(variableNameColor));
57        var data = xValues.Zip(yValues, (x, y) => new { x, y }).Zip(colorValues, (v, c) => new { v.x, v.y, c }).ToList();
58        var gradients = ColorGradient.Colors;
59        int curGradient = 0;
60        int numColors = colorValues.Distinct().Count();
61        foreach (var colorValue in colorValues.Distinct()) {
62          var values = data.Where(x => x.c == colorValue);
63          var row = new ScatterPlotDataRow(
64            variableNameX + " - " + variableNameY + " (" + colorValue + ")",
65            "",
66            values.Select(v => new Point2D<double>(v.x, v.y)),
67            new ScatterPlotDataRowVisualProperties() { Color = gradients[curGradient] });
68          curGradient += gradients.Count / numColors;
69          scatterPlot.Rows.Add(row);
70        }
71      }
72      return scatterPlot;
73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.