Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1886 improved mutation analyzer

File size: 4.7 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 System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Optimization;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
30  [Item("ScatterPlotHelper", "Helper class for creating scatter plots.")]
31  [StorableClass]
32  public class ScatterPlotHelper : Item {
33
34    [Storable]
35    private ResultCollection resultsCol;
36    [Storable]
37    private string chartName;
38    [Storable]
39    private string xAxisTitle;
40    [Storable]
41    private string yAxisTitle;
42    [Storable]
43    public bool StoreHistory { get; set; }
44    [Storable]
45    public bool CreateDataTable { get; set; }
46    [Storable]
47    public DataTableHelper dataTableHelper;
48    [Storable]
49    private string lastRowName;
50
51    [Storable]
52    private ScatterPlot plot;
53    public ScatterPlot Plot {
54      get { return plot; }
55      private set { plot = value; }
56    }
57
58    [StorableConstructor]
59    private ScatterPlotHelper(bool deserializing) : base(deserializing) { }
60    private ScatterPlotHelper(ScatterPlotHelper original, Cloner cloner)
61      : base(original, cloner) {
62      StoreHistory = original.StoreHistory;
63      CreateDataTable = original.CreateDataTable;
64    }
65
66    public ScatterPlotHelper()
67      : base() {
68      StoreHistory = true;
69      CreateDataTable = false;
70    }
71
72    public ScatterPlotHelper(bool storeHistory, bool createDataTable)
73      : base() {
74      StoreHistory = storeHistory;
75      CreateDataTable = createDataTable;
76    }
77
78    public override IDeepCloneable Clone(Cloner cloner) {
79      return new ScatterPlotHelper(this, cloner);
80    }
81
82    public void InitializePlot(ResultCollection results, string chartName, string xAxisTitle, string yAxisTitle) {
83      if (CreateDataTable) {
84        if (dataTableHelper == null) {
85          dataTableHelper = new DataTableHelper();
86        }
87        dataTableHelper.InitializeChart(results, chartName + " Chart", new string[] { yAxisTitle });
88      }
89
90      if (!results.ContainsKey(chartName)) {
91        this.chartName = chartName;
92        this.resultsCol = results;
93        this.xAxisTitle = xAxisTitle;
94        this.yAxisTitle = yAxisTitle;
95
96        Initialize();
97        lastRowName = null;
98
99        results.Add(new Result(chartName, Plot));
100        if (StoreHistory)
101          results.Add(new Result(chartName + " History", new ScatterPlotHistory()));
102      }
103    }
104
105    public void AddPoint(string rowName, Point2D<double> point) {
106      if (!Plot.Rows.ContainsKey(rowName)) {
107        if (StoreHistory)
108          ((ScatterPlotHistory)resultsCol[chartName + " History"].Value).Add(Plot);
109
110        if (CreateDataTable && lastRowName != null && lastRowName != string.Empty) {
111          double avg = Plot.Rows[lastRowName].Points.Average(x => x.Y);
112          dataTableHelper.AddPoint(avg);
113        }
114
115        Initialize();
116        resultsCol[chartName].Value = Plot;
117
118        var points = new List<Point2D<double>>();
119        points.Add(point);
120        ScatterPlotDataRow row = new ScatterPlotDataRow(rowName, null, points);
121        row.VisualProperties.PointStyle = ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle;
122        row.VisualProperties.PointSize = 5;
123        Plot.Rows.Add(row);
124        lastRowName = rowName;
125      } else {
126        Plot.Rows[rowName].Points.Add(point);
127      }
128    }
129
130    private void Initialize() {
131      Plot = new ScatterPlot(chartName, null);
132      Plot.VisualProperties.XAxisTitle = xAxisTitle;
133      Plot.VisualProperties.YAxisTitle = yAxisTitle;
134    }
135
136    public void CleanUp() {
137      if (!StoreHistory && CreateDataTable) {
138        resultsCol[chartName].Value = null;
139        resultsCol.Remove(chartName);
140        plot = null;
141      }
142    }
143  }
144}
Note: See TracBrowser for help on using the repository browser.