[7845] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using System.Drawing;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
| 26 | using HeuristicLab.Core.Views;
|
---|
| 27 | using HeuristicLab.MainForm;
|
---|
| 28 |
|
---|
| 29 | namespace 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";
|
---|
[9162] | 34 | private const string ESTIMATEDVAlUES_SERIES_NAME = "Estimated Values";
|
---|
[7845] | 35 |
|
---|
| 36 | public new SlidingWindowData Content {
|
---|
| 37 | get { return (SlidingWindowData)base.Content; }
|
---|
| 38 | set { base.Content = value; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public SlidingWindowDataView() {
|
---|
| 42 | InitializeComponent();
|
---|
| 43 | chart.CustomizeAllChartAreas();
|
---|
| 44 | chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 45 | chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
|
---|
| 46 | chart.ChartAreas[0].AxisX.IsStartedFromZero = true;
|
---|
| 47 | chart.ChartAreas[0].CursorX.Interval = 1;
|
---|
| 48 |
|
---|
| 49 | chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
| 50 | chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
|
---|
| 51 | chart.ChartAreas[0].CursorY.Interval = 0;
|
---|
| 52 |
|
---|
| 53 | StripLine stripLine = new StripLine();
|
---|
[7850] | 54 | stripLine.BackColor = Color.Gold;
|
---|
[7845] | 55 | stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
|
---|
| 56 | stripLine.Text = "Sliding Window";
|
---|
| 57 | chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | protected override void RegisterContentEvents() {
|
---|
| 61 | base.RegisterContentEvents();
|
---|
[9162] | 62 | Content.SlidingWindowPosition.ValueChanged += new EventHandler(SlidingWindowPosition_ValueChanged);
|
---|
| 63 | Content.EstimatedValuesChanged += new EventHandler(EstimatedValuesChanged);
|
---|
[7845] | 64 | }
|
---|
| 65 | protected override void DeregisterContentEvents() {
|
---|
[9162] | 66 | Content.SlidingWindowPosition.ValueChanged -= new EventHandler(SlidingWindowPosition_ValueChanged);
|
---|
| 67 | Content.EstimatedValuesChanged -= new EventHandler(EstimatedValuesChanged);
|
---|
[7845] | 68 | base.DeregisterContentEvents();
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | protected override void OnContentChanged() {
|
---|
| 72 | base.OnContentChanged();
|
---|
| 73 | RedrawChart();
|
---|
| 74 | }
|
---|
| 75 |
|
---|
[9162] | 76 | private void SlidingWindowPosition_ValueChanged(object sender, EventArgs e) {
|
---|
[7850] | 77 | if (InvokeRequired) Invoke((Action<object, EventArgs>)SlidingWindowPosition_ValueChanged, sender, e);
|
---|
| 78 | else UpdateStripLine();
|
---|
[7845] | 79 | }
|
---|
[9162] | 80 | private void EstimatedValuesChanged(object sender, EventArgs e) {
|
---|
| 81 | if (InvokeRequired) Invoke((Action<object, EventArgs>)EstimatedValuesChanged, sender, e);
|
---|
| 82 | else RedrawChart();
|
---|
| 83 | }
|
---|
[7845] | 84 |
|
---|
| 85 | private void RedrawChart() {
|
---|
| 86 | chart.Series.Clear();
|
---|
| 87 | if (Content == null) return;
|
---|
| 88 |
|
---|
| 89 | chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
|
---|
| 90 | chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
[9870] | 91 | var xValues = Enumerable.Range(Content.TrainingPartitionStart + 1, Content.TrainingPartitionEnd - Content.TrainingPartitionStart).ToArray();
|
---|
| 92 | chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindXY(xValues, Content.TargetValues.ToArray());
|
---|
[7845] | 93 |
|
---|
[9162] | 94 | if (Content.EstimatedValues.Any()) {
|
---|
| 95 | chart.Series.Add(ESTIMATEDVAlUES_SERIES_NAME);
|
---|
| 96 | chart.Series[ESTIMATEDVAlUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
[9870] | 97 | var yValues = Content.EstimatedValues.ToArray();
|
---|
| 98 | chart.Series[ESTIMATEDVAlUES_SERIES_NAME].Points.DataBindXY(xValues, yValues);
|
---|
[9162] | 99 | }
|
---|
| 100 |
|
---|
[7845] | 101 | UpdateStripLine();
|
---|
[7850] | 102 | UpdateCursorInterval();
|
---|
[7845] | 103 | }
|
---|
| 104 |
|
---|
| 105 | private void UpdateStripLine() {
|
---|
| 106 | chart.ChartAreas[0].AxisX.StripLines[0].StripWidth = Content.SlidingWindowPosition.End - Content.SlidingWindowPosition.Start;
|
---|
| 107 | chart.ChartAreas[0].AxisX.StripLines[0].IntervalOffset = Content.SlidingWindowPosition.Start - 0.5;
|
---|
| 108 | }
|
---|
| 109 |
|
---|
| 110 | private void UpdateCursorInterval() {
|
---|
| 111 | var targetValues = this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.Select(x => x.YValues[0]).DefaultIfEmpty(1.0);
|
---|
| 112 | double targetValuesRange = targetValues.Max() - targetValues.Min();
|
---|
| 113 | double interestingValuesRange = Math.Max(targetValuesRange, 1.0);
|
---|
| 114 | double digits = (int)Math.Log10(interestingValuesRange) - 3;
|
---|
| 115 | double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
|
---|
| 116 | this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
| 119 | }
|
---|