Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SlidingWindowDataView.cs @ 7850

Last change on this file since 7850 was 7850, checked in by mkommend, 12 years ago

#1837: Added view for sliding window GP and updated analyzer.

File size: 4.2 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.Drawing;
24using System.Linq;
25using System.Windows.Forms.DataVisualization.Charting;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
30  [View("Sliding Window View")]
31  [Content(typeof(SlidingWindowData), IsDefaultView = true)]
32  public partial class SlidingWindowDataView : ItemView {
33    private const string TARGETVARIABLE_SERIES_NAME = "Target Variable";
34
35    public new SlidingWindowData Content {
36      get { return (SlidingWindowData)base.Content; }
37      set { base.Content = value; }
38    }
39
40    public SlidingWindowDataView() {
41      InitializeComponent();
42      chart.CustomizeAllChartAreas();
43      chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
44      chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
45      chart.ChartAreas[0].AxisX.IsStartedFromZero = true;
46      chart.ChartAreas[0].CursorX.Interval = 1;
47
48      chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
49      chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
50      chart.ChartAreas[0].CursorY.Interval = 0;
51
52      StripLine stripLine = new StripLine();
53      stripLine.BackColor = Color.Gold;
54      stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
55      stripLine.Text = "Sliding Window";
56      chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
57    }
58
59    protected override void RegisterContentEvents() {
60      base.RegisterContentEvents();
61      Content.SlidingWindowPosition.ValueChanged += new System.EventHandler(SlidingWindowPosition_ValueChanged);
62    }
63    protected override void DeregisterContentEvents() {
64      Content.SlidingWindowPosition.ValueChanged -= new System.EventHandler(SlidingWindowPosition_ValueChanged);
65      base.DeregisterContentEvents();
66    }
67
68    protected override void OnContentChanged() {
69      base.OnContentChanged();
70      RedrawChart();
71    }
72
73    private void SlidingWindowPosition_ValueChanged(object sender, System.EventArgs e) {
74      if (InvokeRequired) Invoke((Action<object, EventArgs>)SlidingWindowPosition_ValueChanged, sender, e);
75      else UpdateStripLine();
76    }
77
78    private void RedrawChart() {
79      chart.Series.Clear();
80      if (Content == null) return;
81
82      chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
83      chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
84      chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.TargetValues.ToArray());
85
86      UpdateStripLine();
87      UpdateCursorInterval();
88    }
89
90    private void UpdateStripLine() {
91      chart.ChartAreas[0].AxisX.StripLines[0].StripWidth = Content.SlidingWindowPosition.End - Content.SlidingWindowPosition.Start;
92      chart.ChartAreas[0].AxisX.StripLines[0].IntervalOffset = Content.SlidingWindowPosition.Start - 0.5;
93    }
94
95    private void UpdateCursorInterval() {
96      var targetValues = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
97      double targetValuesRange = targetValues.Max() - targetValues.Min();
98      double interestingValuesRange = Math.Max(targetValuesRange, 1.0);
99      double digits = (int)Math.Log10(interestingValuesRange) - 3;
100      double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
101      this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.