Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1837: added prototype for sliding window GP

File size: 4.0 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.Yellow;
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      UpdateStripLine();
75    }
76
77    private void RedrawChart() {
78      chart.Series.Clear();
79      if (Content == null) return;
80
81      chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
82      chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
83      chart.Series[TARGETVARIABLE_SERIES_NAME].Points.AddY(Content.TargetValues);
84
85      UpdateStripLine();
86    }
87
88    private void UpdateStripLine() {
89      chart.ChartAreas[0].AxisX.StripLines[0].StripWidth = Content.SlidingWindowPosition.End - Content.SlidingWindowPosition.Start;
90      chart.ChartAreas[0].AxisX.StripLines[0].IntervalOffset = Content.SlidingWindowPosition.Start - 0.5;
91    }
92
93    private void UpdateCursorInterval() {
94      var targetValues = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
95      double targetValuesRange = targetValues.Max() - targetValues.Min();
96      double interestingValuesRange = Math.Max(targetValuesRange, 1.0);
97      double digits = (int)Math.Log10(interestingValuesRange) - 3;
98      double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
99      this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
100    }
101  }
102}
Note: See TracBrowser for help on using the repository browser.