[3408] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2010 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 | using System;
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Collections.Specialized;
|
---|
| 24 | using System.ComponentModel;
|
---|
| 25 | using System.Data;
|
---|
| 26 | using System.Drawing;
|
---|
| 27 | using System.Linq;
|
---|
| 28 | using System.Text;
|
---|
| 29 | using System.Windows.Forms;
|
---|
| 30 | using HeuristicLab.Common;
|
---|
| 31 | using HeuristicLab.MainForm;
|
---|
| 32 | using HeuristicLab.Problems.DataAnalysis;
|
---|
| 33 | using HeuristicLab.MainForm.WindowsForms;
|
---|
[3442] | 34 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
[3408] | 35 |
|
---|
[3442] | 36 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
[3408] | 37 | [View("Line Chart View")]
|
---|
| 38 | [Content(typeof(DataAnalysisSolution))]
|
---|
[3442] | 39 | public partial class LineChartView : AsynchronousContentView {
|
---|
| 40 | private const string TARGETVARIABLE_SERIES_NAME = "TargetVariable";
|
---|
| 41 | private const string ESTIMATEDVALUES_SERIES_NAME = "EstimatedValues";
|
---|
| 42 |
|
---|
| 43 | public new DataAnalysisSolution Content {
|
---|
| 44 | get { return (DataAnalysisSolution)base.Content; }
|
---|
| 45 | set {
|
---|
| 46 | base.Content = value;
|
---|
| 47 | }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
[3408] | 50 | public LineChartView()
|
---|
| 51 | : base() {
|
---|
| 52 | InitializeComponent();
|
---|
| 53 | this.Caption = "Line Chart View";
|
---|
| 54 | //configure axis
|
---|
| 55 | this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 56 | this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
|
---|
| 57 | this.chart.ChartAreas[0].CursorX.Interval = 0;
|
---|
| 58 |
|
---|
| 59 | this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
| 60 | this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
|
---|
[3442] | 61 | this.chart.ChartAreas[0].CursorY.Interval = 0;
|
---|
[3408] | 62 | }
|
---|
| 63 |
|
---|
[3462] | 64 | private void RedrawChart() {
|
---|
[3442] | 65 | this.chart.Series.Clear();
|
---|
| 66 | this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
|
---|
| 67 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
|
---|
| 68 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
| 69 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
|
---|
| 70 | this.UpdateStripLines();
|
---|
[3462] | 71 |
|
---|
| 72 | this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME);
|
---|
| 73 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName;
|
---|
| 74 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
| 75 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Points.DataBindY(Content.EstimatedValues.ToArray());
|
---|
| 76 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Tag = Content;
|
---|
[3408] | 77 | }
|
---|
| 78 |
|
---|
[3442] | 79 | #region events
|
---|
| 80 | protected override void RegisterContentEvents() {
|
---|
| 81 | base.RegisterContentEvents();
|
---|
[3462] | 82 | Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
|
---|
[3442] | 83 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
[3408] | 84 | }
|
---|
| 85 |
|
---|
[3442] | 86 | protected override void DeregisterContentEvents() {
|
---|
| 87 | base.DeregisterContentEvents();
|
---|
[3462] | 88 | Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
|
---|
[3442] | 89 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
[3408] | 90 | }
|
---|
| 91 |
|
---|
[3442] | 92 | void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
[3462] | 93 | RedrawChart();
|
---|
[3408] | 94 | }
|
---|
| 95 |
|
---|
[3462] | 96 | void Content_EstimatedValuesChanged(object sender, EventArgs e) {
|
---|
| 97 | UpdateEstimatedValuesLineChart();
|
---|
[3442] | 98 | }
|
---|
| 99 |
|
---|
| 100 | protected override void OnContentChanged() {
|
---|
| 101 | base.OnContentChanged();
|
---|
[3462] | 102 | RedrawChart();
|
---|
[3442] | 103 | }
|
---|
| 104 |
|
---|
| 105 | private void UpdateEstimatedValuesLineChart() {
|
---|
| 106 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
|
---|
| 107 | else {
|
---|
| 108 | if (this.chart.Series.Count > 0) {
|
---|
| 109 | Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
|
---|
| 110 | if (s != null) {
|
---|
| 111 | s.Points.DataBindY(Content.EstimatedValues.ToArray());
|
---|
| 112 | s.LegendText = Content.ItemName;
|
---|
| 113 | this.UpdateStripLines();
|
---|
| 114 | }
|
---|
[3408] | 115 | }
|
---|
| 116 | }
|
---|
| 117 | }
|
---|
[3442] | 118 | #endregion
|
---|
[3408] | 119 |
|
---|
| 120 | private void UpdateStripLines() {
|
---|
| 121 | this.chart.ChartAreas[0].AxisX.StripLines.Clear();
|
---|
[3442] | 122 | this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
|
---|
| 123 | Content.ProblemData.TrainingSamplesStart.Value,
|
---|
| 124 | Content.ProblemData.TrainingSamplesEnd.Value);
|
---|
| 125 | this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
|
---|
| 126 | Content.ProblemData.TestSamplesStart.Value,
|
---|
| 127 | Content.ProblemData.TestSamplesEnd.Value);
|
---|
[3408] | 128 | }
|
---|
| 129 |
|
---|
| 130 | private void CreateAndAddStripLine(string title, Color c, int start, int end) {
|
---|
| 131 | StripLine stripLine = new StripLine();
|
---|
| 132 | stripLine.BackColor = c;
|
---|
| 133 | stripLine.Text = title;
|
---|
| 134 | stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
|
---|
| 135 | stripLine.StripWidth = end - start;
|
---|
| 136 | stripLine.IntervalOffset = start;
|
---|
| 137 | this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
|
---|
| 138 | }
|
---|
| 139 | }
|
---|
| 140 | }
|
---|