Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/DensityTrackbar.cs @ 13853

Last change on this file since 13853 was 13853, checked in by pfleck, 8 years ago

#2597

  • Added GradientChartConfigurationDialog to allow setup x/y axis and drawing steps.
  • Added "calculating pending"-icon only after 100ms to avoid flickering.
  • Fixed some small issues.
File size: 4.5 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;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Globalization;
26using System.Windows.Forms;
27using HeuristicLab.Problems.DataAnalysis;
28
29namespace HeuristicLab.Algorithms.DataAnalysis.Views {
30  public partial class DensityTrackbar : UserControl {
31
32    public decimal Value {
33      get { return TickToValue(trackBar.Value); }
34      set { trackBar.Value = ValueToTick(value); }
35    }
36    public event EventHandler ValueChanged;
37
38    public bool Checked {
39      get { return radioButton.Checked; }
40      set { radioButton.Checked = value; }
41    }
42    public event EventHandler CheckedChanged;
43
44    public DoubleLimit Limits {
45      get { return doubleLimitView.Content; }
46    }
47    public event EventHandler LimitsChanged;
48
49    private IList<double> trainingValues;
50
51    // For VisualStudio Designer
52    internal DensityTrackbar() {
53      InitializeComponent();
54    }
55
56    public DensityTrackbar(string name, DoubleLimit limit, IList<double> trainingValues) {
57      InitializeComponent();
58
59      this.trainingValues = trainingValues;
60
61      doubleLimitView.Content = limit;
62      doubleLimitView.Content.ValueChanged += doubleLimit_ValueChanged;
63
64      textBox.Text = Value.ToString(CultureInfo.InvariantCulture);
65      radioButton.Text = name;
66
67      UpdateDensityChart();
68    }
69
70    public void UpdateTrainingValues(IList<double> trainingValues) {
71      this.trainingValues = trainingValues;
72      UpdateDensityChart();
73    }
74
75    private void UpdateDensityChart() {
76      chart.UpdateChart(trainingValues, Limits.Lower, Limits.Upper,
77        numBuckets: trackBar.Maximum - trackBar.Minimum, minimumHeight: 0.1);
78    }
79
80    #region Event Handlers
81    private void trackBar_ValueChanged(object sender, EventArgs e) {
82      textBox.Text = Value.ToString(CultureInfo.InvariantCulture);
83      OnValueChanged();
84    }
85    private void doubleLimit_ValueChanged(object sender, EventArgs e) {
86      UpdateDensityChart();
87      OnLimitsChanged();
88      OnValueChanged();
89    }
90    private void radioButton_CheckedChanged(object sender, EventArgs e) {
91      Checked = radioButton.Checked;
92      trackBar.Enabled = !Checked;
93      textBox.Text = Checked ? "Plotted" : Value.ToString(CultureInfo.InvariantCulture);
94      radioButton.BackColor = Checked ? SystemColors.ActiveCaption : SystemColors.Control;
95      OnCheckedChanged();
96    }
97    protected override void OnTextChanged(EventArgs e) {
98      base.OnTextChanged(e);
99      radioButton.Text = Text;
100    }
101    #endregion
102
103    protected virtual void OnValueChanged() {
104      if (ValueChanged != null)
105        ValueChanged(this, EventArgs.Empty);
106    }
107    protected virtual void OnCheckedChanged() {
108      if (CheckedChanged != null)
109        CheckedChanged(this, EventArgs.Empty);
110    }
111    protected virtual void OnLimitsChanged() {
112      if (LimitsChanged != null)
113        LimitsChanged(this, EventArgs.Empty);
114    }
115    #region Hepers
116
117    private decimal TickToValue(int tick) {
118      return TickToValue(tick, trackBar.Maximum - trackBar.Minimum, (decimal)Limits.Lower, (decimal)Limits.Upper);
119    }
120    private int ValueToTick(decimal value) {
121      return ValueToTick(value, trackBar.Maximum - trackBar.Minimum, (decimal)Limits.Lower, (decimal)Limits.Upper);
122    }
123    private static decimal TickToValue(int tick, int numberOfTicks, decimal lower, decimal upper) {
124      return lower + (upper - lower) * tick / numberOfTicks;
125    }
126    private static int ValueToTick(decimal value, int numberOfTicks, decimal lower, decimal upper) {
127      return (int)((value - lower) / ((upper - lower) / numberOfTicks));
128    }
129    #endregion
130  }
131}
Note: See TracBrowser for help on using the repository browser.