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;
|
---|
34 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
35 |
|
---|
36 | namespace HeuristicLab.Problems.DataAnalysis.Views {
|
---|
37 | [View("Line Chart View")]
|
---|
38 | [Content(typeof(DataAnalysisSolution))]
|
---|
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 |
|
---|
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;
|
---|
61 | this.chart.ChartAreas[0].CursorY.Interval = 0;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public LineChartView(DataAnalysisSolution dataAnalysisSolution)
|
---|
65 | : this() {
|
---|
66 | Content = dataAnalysisSolution;
|
---|
67 | DrawTargetVariableValues();
|
---|
68 | DrawEstimatedValues();
|
---|
69 | }
|
---|
70 |
|
---|
71 | private void DrawEstimatedValues() {
|
---|
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;
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void DrawTargetVariableValues() {
|
---|
80 | this.chart.Series.Clear();
|
---|
81 | this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
|
---|
82 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
|
---|
83 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
84 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
|
---|
85 | this.UpdateStripLines();
|
---|
86 | }
|
---|
87 |
|
---|
88 | #region events
|
---|
89 | protected override void RegisterContentEvents() {
|
---|
90 | base.RegisterContentEvents();
|
---|
91 | Content.ModelChanged += new EventHandler(Content_ModelChanged);
|
---|
92 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
93 | }
|
---|
94 |
|
---|
95 | protected override void DeregisterContentEvents() {
|
---|
96 | base.DeregisterContentEvents();
|
---|
97 | Content.ModelChanged -= new EventHandler(Content_ModelChanged);
|
---|
98 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
99 | }
|
---|
100 |
|
---|
101 | void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
102 | OnContentChanged();
|
---|
103 | }
|
---|
104 |
|
---|
105 | void Content_ModelChanged(object sender, EventArgs e) {
|
---|
106 | OnContentChanged();
|
---|
107 | }
|
---|
108 |
|
---|
109 | protected override void OnContentChanged() {
|
---|
110 | base.OnContentChanged();
|
---|
111 | UpdateEstimatedValuesLineChart();
|
---|
112 | }
|
---|
113 |
|
---|
114 | private void UpdateEstimatedValuesLineChart() {
|
---|
115 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
|
---|
116 | else {
|
---|
117 | if (this.chart.Series.Count > 0) {
|
---|
118 | Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
|
---|
119 | if (s != null) {
|
---|
120 | s.Points.DataBindY(Content.EstimatedValues.ToArray());
|
---|
121 | s.LegendText = Content.ItemName;
|
---|
122 | this.UpdateStripLines();
|
---|
123 | }
|
---|
124 | }
|
---|
125 | }
|
---|
126 | }
|
---|
127 | #endregion
|
---|
128 |
|
---|
129 | private void UpdateStripLines() {
|
---|
130 | this.chart.ChartAreas[0].AxisX.StripLines.Clear();
|
---|
131 | this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
|
---|
132 | Content.ProblemData.TrainingSamplesStart.Value,
|
---|
133 | Content.ProblemData.TrainingSamplesEnd.Value);
|
---|
134 | this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
|
---|
135 | Content.ProblemData.TestSamplesStart.Value,
|
---|
136 | Content.ProblemData.TestSamplesEnd.Value);
|
---|
137 | }
|
---|
138 |
|
---|
139 | private void CreateAndAddStripLine(string title, Color c, int start, int end) {
|
---|
140 | StripLine stripLine = new StripLine();
|
---|
141 | stripLine.BackColor = c;
|
---|
142 | stripLine.Text = title;
|
---|
143 | stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
|
---|
144 | stripLine.StripWidth = end - start;
|
---|
145 | stripLine.IntervalOffset = start;
|
---|
146 | this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|