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 | RedrawChart();
|
---|
68 | }
|
---|
69 |
|
---|
70 | private void RedrawChart() {
|
---|
71 | this.chart.Series.Clear();
|
---|
72 | this.chart.Series.Add(TARGETVARIABLE_SERIES_NAME);
|
---|
73 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].LegendText = Content.ProblemData.TargetVariable.Value;
|
---|
74 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
75 | this.chart.Series[TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset[Content.ProblemData.TargetVariable.Value]);
|
---|
76 | this.UpdateStripLines();
|
---|
77 |
|
---|
78 | this.chart.Series.Add(ESTIMATEDVALUES_SERIES_NAME);
|
---|
79 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].LegendText = Content.ItemName;
|
---|
80 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
81 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Points.DataBindY(Content.EstimatedValues.ToArray());
|
---|
82 | this.chart.Series[ESTIMATEDVALUES_SERIES_NAME].Tag = Content;
|
---|
83 | }
|
---|
84 |
|
---|
85 | #region events
|
---|
86 | protected override void RegisterContentEvents() {
|
---|
87 | base.RegisterContentEvents();
|
---|
88 | Content.EstimatedValuesChanged += new EventHandler(Content_EstimatedValuesChanged);
|
---|
89 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
90 | }
|
---|
91 |
|
---|
92 | protected override void DeregisterContentEvents() {
|
---|
93 | base.DeregisterContentEvents();
|
---|
94 | Content.EstimatedValuesChanged -= new EventHandler(Content_EstimatedValuesChanged);
|
---|
95 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
96 | }
|
---|
97 |
|
---|
98 | void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
99 | RedrawChart();
|
---|
100 | }
|
---|
101 |
|
---|
102 | void Content_EstimatedValuesChanged(object sender, EventArgs e) {
|
---|
103 | UpdateEstimatedValuesLineChart();
|
---|
104 | }
|
---|
105 |
|
---|
106 | protected override void OnContentChanged() {
|
---|
107 | base.OnContentChanged();
|
---|
108 | RedrawChart();
|
---|
109 | }
|
---|
110 |
|
---|
111 | private void UpdateEstimatedValuesLineChart() {
|
---|
112 | if (InvokeRequired) Invoke((Action)UpdateEstimatedValuesLineChart);
|
---|
113 | else {
|
---|
114 | if (this.chart.Series.Count > 0) {
|
---|
115 | Series s = this.chart.Series.SingleOrDefault(x => x.Tag == Content);
|
---|
116 | if (s != null) {
|
---|
117 | s.Points.DataBindY(Content.EstimatedValues.ToArray());
|
---|
118 | s.LegendText = Content.ItemName;
|
---|
119 | this.UpdateStripLines();
|
---|
120 | }
|
---|
121 | }
|
---|
122 | }
|
---|
123 | }
|
---|
124 | #endregion
|
---|
125 |
|
---|
126 | private void UpdateStripLines() {
|
---|
127 | this.chart.ChartAreas[0].AxisX.StripLines.Clear();
|
---|
128 | this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
|
---|
129 | Content.ProblemData.TrainingSamplesStart.Value,
|
---|
130 | Content.ProblemData.TrainingSamplesEnd.Value);
|
---|
131 | this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
|
---|
132 | Content.ProblemData.TestSamplesStart.Value,
|
---|
133 | Content.ProblemData.TestSamplesEnd.Value);
|
---|
134 | }
|
---|
135 |
|
---|
136 | private void CreateAndAddStripLine(string title, Color c, int start, int end) {
|
---|
137 | StripLine stripLine = new StripLine();
|
---|
138 | stripLine.BackColor = c;
|
---|
139 | stripLine.Text = title;
|
---|
140 | stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
|
---|
141 | stripLine.StripWidth = end - start;
|
---|
142 | stripLine.IntervalOffset = start;
|
---|
143 | this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|