Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/ScatterPlotHelper.cs @ 8505

Last change on this file since 8505 was 8505, checked in by ascheibe, 12 years ago

#1886 fixed cloning and storing

File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Optimization;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
29  [Item("ScatterPlotHelper", "Helper class for creating scatter plots.")]
30  [StorableClass]
31  public class ScatterPlotHelper : Item {
32
33    [Storable]
34    private ResultCollection resultsCol;
35    [Storable]
36    private string chartName;
37    [Storable]
38    private string xAxisTitle;
39    [Storable]
40    private string yAxisTitle;
41
42    [Storable]
43    private ScatterPlot plot;
44    public ScatterPlot Plot {
45      get { return plot; }
46      private set { plot = value; }
47    }
48
49    [StorableConstructor]
50    private ScatterPlotHelper(bool deserializing) : base(deserializing) { }
51    private ScatterPlotHelper(ScatterPlotHelper original, Cloner cloner)
52      : base(original, cloner) {
53      resultsCol = original.resultsCol;
54      chartName = original.chartName;
55      xAxisTitle = original.xAxisTitle;
56      yAxisTitle = original.yAxisTitle;
57      plot = (ScatterPlot)original.plot.Clone(cloner);
58    }
59    public ScatterPlotHelper() : base() { }
60
61    public override IDeepCloneable Clone(Cloner cloner) {
62      return new ScatterPlotHelper(this, cloner);
63    }
64
65    public void InitializePlot(ResultCollection results, string chartName, string xAxisTitle, string yAxisTitle) {
66      if (!results.ContainsKey(chartName)) {
67        this.chartName = chartName;
68        this.resultsCol = results;
69        this.xAxisTitle = xAxisTitle;
70        this.yAxisTitle = yAxisTitle;
71
72        Initialize();
73
74        results.Add(new Result(chartName, Plot));
75        results.Add(new Result(chartName + " History", new ScatterPlotHistory()));
76      }
77    }
78
79    public void AddPoint(string rowName, Point2D<double> point) {
80      if (!Plot.Rows.ContainsKey(rowName)) {
81        ((ScatterPlotHistory)resultsCol[chartName + " History"].Value).Add(Plot);
82        Initialize();
83        resultsCol[chartName].Value = Plot;
84
85        var points = new List<Point2D<double>>();
86        points.Add(point);
87        ScatterPlotDataRow row = new ScatterPlotDataRow(rowName, null, points);
88        row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
89        row.VisualProperties.PointSize = 5;
90        Plot.Rows.Add(row);
91      } else {
92        Plot.Rows[rowName].Points.Add(point);
93      }
94    }
95
96    private void Initialize() {
97      Plot = new ScatterPlot(chartName, null);
98      Plot.VisualProperties.XAxisTitle = xAxisTitle;
99      Plot.VisualProperties.YAxisTitle = yAxisTitle;
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.