[4401] | 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.Drawing;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using System.Windows.Forms;
|
---|
| 25 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
| 26 | using HeuristicLab.MainForm;
|
---|
| 27 | using HeuristicLab.MainForm.WindowsForms;
|
---|
| 28 | using System.Collections.Generic;
|
---|
| 29 |
|
---|
| 30 | namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.Views {
|
---|
| 31 | [View("Multi-Variate Line Chart View")]
|
---|
| 32 | [Content(typeof(IMultiVariateDataAnalysisSolution))]
|
---|
| 33 | public partial class LineChartView : AsynchronousContentView {
|
---|
| 34 | private const string TARGETVARIABLE_SERIES_NAME = "(target)";
|
---|
| 35 | private const string ESTIMATEDVALUES_SERIES_NAME = "(estimated)";
|
---|
| 36 |
|
---|
| 37 | public new IMultiVariateDataAnalysisSolution Content {
|
---|
| 38 | get { return (IMultiVariateDataAnalysisSolution)base.Content; }
|
---|
| 39 | set { base.Content = value; }
|
---|
| 40 | }
|
---|
| 41 |
|
---|
| 42 | public LineChartView()
|
---|
| 43 | : base() {
|
---|
| 44 | InitializeComponent();
|
---|
| 45 | //configure axis
|
---|
| 46 | this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
|
---|
| 47 | this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
|
---|
| 48 | this.chart.ChartAreas[0].CursorX.Interval = 1;
|
---|
| 49 |
|
---|
| 50 | this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
|
---|
| 51 | this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
|
---|
| 52 | this.chart.ChartAreas[0].CursorY.Interval = 0;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | private void RedrawChart() {
|
---|
| 56 | this.chart.Series.Clear();
|
---|
| 57 | if (Content != null) {
|
---|
[4556] | 58 | IEnumerable<double[]> values = Content.EstimatedValues;
|
---|
[4401] | 59 | List<string> targetVariables = Content.ProblemData.TargetVariables.CheckedItems.Select(x => x.Value.Value).ToList();
|
---|
| 60 | for (int col = 0; col < targetVariables.Count; col++) {
|
---|
| 61 | string targetVariable = targetVariables[col];
|
---|
| 62 | this.chart.Series.Add(targetVariable + " " + TARGETVARIABLE_SERIES_NAME);
|
---|
| 63 | this.chart.Series[targetVariable + " " + TARGETVARIABLE_SERIES_NAME].LegendText = targetVariable;
|
---|
| 64 | this.chart.Series[targetVariable + " " + TARGETVARIABLE_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
| 65 | this.chart.Series[targetVariable + " " + TARGETVARIABLE_SERIES_NAME].Points.DataBindY(Content.ProblemData.Dataset.GetVariableValues(targetVariable));
|
---|
| 66 |
|
---|
| 67 | this.chart.Series.Add(targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME);
|
---|
| 68 | this.chart.Series[targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME].LegendText = targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME;
|
---|
| 69 | this.chart.Series[targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME].ChartType = SeriesChartType.FastLine;
|
---|
| 70 | this.chart.Series[targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME].Points.DataBindY(values.Select(x => x[col]).ToArray());
|
---|
| 71 | this.chart.Series[targetVariable + " " + ESTIMATEDVALUES_SERIES_NAME].Tag = Content;
|
---|
| 72 | }
|
---|
| 73 | this.UpdateStripLines();
|
---|
| 74 | UpdateCursorInterval();
|
---|
| 75 | }
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | private void UpdateCursorInterval() {
|
---|
| 79 | var allValues = (from series in this.chart.Series
|
---|
| 80 | from point in series.Points
|
---|
| 81 | select point.YValues[0])
|
---|
| 82 | .DefaultIfEmpty(1.0);
|
---|
| 83 | double range = allValues.Max() - allValues.Min();
|
---|
| 84 | double interestingValuesRange = Math.Min(Math.Max(range, 1.0), Math.Max(range, 1.0));
|
---|
| 85 | double digits = (int)Math.Log10(interestingValuesRange) - 3;
|
---|
| 86 | double yZoomInterval = Math.Max(Math.Pow(10, digits), 10E-5);
|
---|
| 87 | this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | #region events
|
---|
| 91 | protected override void RegisterContentEvents() {
|
---|
| 92 | base.RegisterContentEvents();
|
---|
| 93 | Content.ProblemDataChanged += new EventHandler(Content_ProblemDataChanged);
|
---|
| 94 | }
|
---|
| 95 | protected override void DeregisterContentEvents() {
|
---|
| 96 | base.DeregisterContentEvents();
|
---|
| 97 | Content.ProblemDataChanged -= new EventHandler(Content_ProblemDataChanged);
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | private void Content_ProblemDataChanged(object sender, EventArgs e) {
|
---|
| 101 | RedrawChart();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | protected override void OnContentChanged() {
|
---|
| 105 | base.OnContentChanged();
|
---|
| 106 | RedrawChart();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | #endregion
|
---|
| 110 |
|
---|
| 111 | private void UpdateStripLines() {
|
---|
| 112 | this.chart.ChartAreas[0].AxisX.StripLines.Clear();
|
---|
| 113 | this.CreateAndAddStripLine("Training", Color.FromArgb(20, Color.Green),
|
---|
| 114 | Content.ProblemData.TrainingSamplesStart.Value,
|
---|
| 115 | Content.ProblemData.TrainingSamplesEnd.Value);
|
---|
| 116 | this.CreateAndAddStripLine("Test", Color.FromArgb(20, Color.Red),
|
---|
| 117 | Content.ProblemData.TestSamplesStart.Value,
|
---|
| 118 | Content.ProblemData.TestSamplesEnd.Value);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | private void CreateAndAddStripLine(string title, Color c, int start, int end) {
|
---|
| 122 | StripLine stripLine = new StripLine();
|
---|
| 123 | stripLine.BackColor = c;
|
---|
| 124 | stripLine.Text = title;
|
---|
| 125 | stripLine.Font = new Font("Times New Roman", 12, FontStyle.Bold);
|
---|
| 126 | stripLine.StripWidth = end - start;
|
---|
| 127 | stripLine.IntervalOffset = start;
|
---|
| 128 | this.chart.ChartAreas[0].AxisX.StripLines.Add(stripLine);
|
---|
| 129 | }
|
---|
| 130 | }
|
---|
| 131 | }
|
---|