Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views/3.4/VariableTrackbar.cs @ 8986

Last change on this file since 8986 was 8935, checked in by bburlacu, 12 years ago

#1763: Bugfixes and refactoring as suggested in the comments above.

File size: 3.1 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;
23using System.Collections.Generic;
24using System.Linq;
25using System.Windows.Forms;
26using System.Windows.Forms.DataVisualization.Charting;
27using HeuristicLab.Common;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression.Views {
30  public partial class VariableTrackbar : UserControl {
31    private readonly string variableName;
32    private const double FACTOR = 1000;
33
34    public double Value {
35      get { return trackBar.Value / FACTOR; }
36    }
37
38    public string VariableName {
39      get { return variableName; }
40    }
41
42    public VariableTrackbar(string variableName, IEnumerable<double> values) {
43      InitializeComponent();
44      this.variableName = variableName;
45      groupBox.Text = variableName;
46      var valuesArr = values.ToArray();
47      this.valueTextBox.Text = string.Format("{0:0.000e+00}", valuesArr.Median());
48      boxPlotChart.Series["DataSeries"].Points.Clear();
49      boxPlotChart.Series["DataSeries"].Points.DataBindY(valuesArr);
50      boxPlotChart.Series["BoxPlot"].ChartType = SeriesChartType.BoxPlot;
51      boxPlotChart.Series["BoxPlot"]["BoxPlotSeries"] = "DataSeries";
52      boxPlotChart.Series["BoxPlot"]["BoxPlotWhiskerPercentile"] = "5";
53      boxPlotChart.Series["BoxPlot"]["BoxPlotPercentile"] = "30";
54      boxPlotChart.Series["BoxPlot"]["BoxPlotShowAverage"] = "true";
55      boxPlotChart.Series["BoxPlot"]["BoxPlotShowMedian"] = "true";
56      boxPlotChart.Series["BoxPlot"]["BoxPlotShowUnusualValues"] = "true";
57      boxPlotChart.ChartAreas[0].AxisY.Minimum = valuesArr.Min();
58      boxPlotChart.ChartAreas[0].AxisY.Maximum = valuesArr.Max();
59
60
61      trackBar.Minimum = (int)Math.Round(valuesArr.Min() * FACTOR);
62      trackBar.Maximum = (int)Math.Round(valuesArr.Max() * FACTOR);
63      trackBar.Value = (int)Math.Round(valuesArr.Median() * FACTOR);
64      trackBar.TickStyle = TickStyle.None;
65      trackBar.Tag = variableName;
66    }
67
68    private void TrackBarValueChanged(object sender, EventArgs e) {
69      valueTextBox.Text = string.Format("{0:0.000e+00}", trackBar.Value / FACTOR);
70      RaiseValueChanged(EventArgs.Empty);
71    }
72
73    public event EventHandler ValueChanged;
74    private void RaiseValueChanged(EventArgs e) {
75      var handler = ValueChanged;
76      if (handler != null) handler(this, e);
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.