source: branches/HeuristicLab.RegressionSolutionGradientView/HeuristicLab.Problems.DataAnalysis.Views/3.4/GradientChart.cs @ 13995

Last change on this file since 13995 was 13995, checked in by bburlacu, 5 years ago

#2597: Improved drag & drop support for all charts. Added configuration option to adjust the number of columns in the view. Fixed bug where attempting to set row & column style would result in an exception. Fixed boundaries of the vertical annotation line in the GradientChart.

File size: 24.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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
22using System;
23using System.Collections.Generic;
24using System.Drawing;
25using System.Globalization;
26using System.Linq;
27using System.Threading;
28using System.Threading.Tasks;
29using System.Windows.Forms;
30using System.Windows.Forms.DataVisualization.Charting;
31using HeuristicLab.Common;
32using HeuristicLab.MainForm.WindowsForms;
33using HeuristicLab.Visualization.ChartControlsExtensions;
34
35namespace HeuristicLab.Problems.DataAnalysis.Views {
36  public partial class GradientChart : UserControl {
37    private ModifiableDataset sharedFixedVariables; // used for syncronising variable values between charts
38    private ModifiableDataset internalDataset; // holds the x values for each point drawn
39
40    private CancellationTokenSource cancelCurrentRecalculateSource;
41
42    private readonly List<IRegressionSolution> solutions;
43    private readonly Dictionary<IRegressionSolution, Series> seriesCache;
44    private readonly Dictionary<IRegressionSolution, Series> ciSeriesCache;
45
46    private readonly ToolStripMenuItem configToolStripMenuItem;
47    private readonly GradientChartConfigurationDialog configurationDialog;
48
49    #region Properties
50    public bool ShowLegend {
51      get { return chart.Legends[0].Enabled; }
52      set { chart.Legends[0].Enabled = value; }
53    }
54    public bool ShowCursor {
55      get { return chart.Annotations[0].Visible; }
56      set {
57        chart.Annotations[0].Visible = value;
58        if (!value) chart.ChartAreas[0].AxisX.Title = string.Empty;
59      }
60    }
61
62    public bool ShowConfigButton {
63      get { return configurationButton.Visible; }
64      set { configurationButton.Visible = value; }
65    }
66
67    private int xAxisTicks = 5;
68    public int XAxisTicks {
69      get { return xAxisTicks; }
70      set {
71        if (value != xAxisTicks) {
72          xAxisTicks = value;
73          SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
74          RecalculateInternalDataset();
75        }
76      }
77    }
78    private double? fixedXAxisMin;
79    public double? FixedXAxisMin {
80      get { return fixedXAxisMin; }
81      set {
82        if ((value.HasValue && fixedXAxisMin.HasValue && !value.Value.IsAlmost(fixedXAxisMin.Value)) || (value.HasValue != fixedXAxisMin.HasValue)) {
83          fixedXAxisMin = value;
84          SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
85          RecalculateInternalDataset();
86        }
87      }
88    }
89    private double? fixedXAxisMax;
90    public double? FixedXAxisMax {
91      get { return fixedXAxisMax; }
92      set {
93        if ((value.HasValue && fixedXAxisMax.HasValue && !value.Value.IsAlmost(fixedXAxisMax.Value)) || (value.HasValue != fixedXAxisMax.HasValue)) {
94          fixedXAxisMax = value;
95          SetupAxis(chart.ChartAreas[0].AxisX, trainingMin, trainingMax, XAxisTicks, FixedXAxisMin, FixedXAxisMax);
96          RecalculateInternalDataset();
97        }
98      }
99    }
100
101    private int yAxisTicks = 5;
102    public int YAxisTicks {
103      get { return yAxisTicks; }
104      set {
105        if (value != yAxisTicks) {
106          yAxisTicks = value;
107          SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
108          RecalculateInternalDataset();
109        }
110      }
111    }
112    private double? fixedYAxisMin;
113    public double? FixedYAxisMin {
114      get { return fixedYAxisMin; }
115      set {
116        if ((value.HasValue && fixedYAxisMin.HasValue && !value.Value.IsAlmost(fixedYAxisMin.Value)) || (value.HasValue != fixedYAxisMin.HasValue)) {
117          fixedYAxisMin = value;
118          // the check below prevents an exception when yMin >= yMax
119          if (yMin < yMax)
120            SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
121        }
122      }
123    }
124    private double? fixedYAxisMax;
125    public double? FixedYAxisMax {
126      get { return fixedYAxisMax; }
127      set {
128        if ((value.HasValue && fixedYAxisMax.HasValue && !value.Value.IsAlmost(fixedYAxisMax.Value)) || (value.HasValue != fixedYAxisMax.HasValue)) {
129          fixedYAxisMax = value;
130          // the check below prevents an exception when yMin >= yMax
131          if (yMin < yMax)
132            SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
133        }
134      }
135    }
136
137    private double trainingMin = 1;
138    private double trainingMax = -1;
139
140    private int drawingSteps = 1000;
141    public int DrawingSteps {
142      get { return drawingSteps; }
143      set {
144        if (value != drawingSteps) {
145          drawingSteps = value;
146          RecalculateInternalDataset();
147          ResizeAllSeriesData();
148        }
149      }
150    }
151
152    private string freeVariable;
153    public string FreeVariable {
154      get { return freeVariable; }
155      set {
156        if (value == freeVariable) return;
157        if (solutions.Any(s => !s.ProblemData.Dataset.DoubleVariables.Contains(value))) {
158          throw new ArgumentException("Variable does not exist in the ProblemData of the Solutions.");
159        }
160        freeVariable = value;
161        RecalculateInternalDataset();
162      }
163    }
164
165    private double yMin;
166    public double YMin {
167      get { return yMin; }
168    }
169    private double yMax;
170    public double YMax {
171      get { return yMax; }
172    }
173
174    private VerticalLineAnnotation VerticalLineAnnotation {
175      get { return (VerticalLineAnnotation)chart.Annotations.SingleOrDefault(x => x is VerticalLineAnnotation); }
176    }
177
178    internal ElementPosition InnerPlotPosition {
179      get { return chart.ChartAreas[0].InnerPlotPosition; }
180    }
181    #endregion
182
183    public GradientChart() {
184      InitializeComponent();
185
186      solutions = new List<IRegressionSolution>();
187      seriesCache = new Dictionary<IRegressionSolution, Series>();
188      ciSeriesCache = new Dictionary<IRegressionSolution, Series>();
189
190      // Configure axis
191      chart.CustomizeAllChartAreas();
192      chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true;
193      chart.ChartAreas[0].AxisX.ScaleView.Zoomable = true;
194      chart.ChartAreas[0].CursorX.Interval = 0;
195
196      chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true;
197      chart.ChartAreas[0].AxisY.ScaleView.Zoomable = true;
198      chart.ChartAreas[0].CursorY.Interval = 0;
199
200      configToolStripMenuItem = new ToolStripMenuItem("Configuration");
201      configToolStripMenuItem.Click += config_Click;
202      chart.ContextMenuStrip.Items.Add(new ToolStripSeparator());
203      chart.ContextMenuStrip.Items.Add(configToolStripMenuItem);
204
205      configurationDialog = new GradientChartConfigurationDialog(this);
206
207      Disposed += GradientChart_Disposed;
208    }
209
210    private void GradientChart_Disposed(object sender, EventArgs e) {
211      if (cancelCurrentRecalculateSource != null)
212        cancelCurrentRecalculateSource.Cancel();
213    }
214
215    public void Configure(IEnumerable<IRegressionSolution> solutions, ModifiableDataset sharedFixedVariables, string freeVariable, int drawingSteps, bool initializeAxisRanges = true) {
216      if (!SolutionsCompatible(solutions))
217        throw new ArgumentException("Solutions are not compatible with the problem data.");
218      this.freeVariable = freeVariable;
219      this.drawingSteps = drawingSteps;
220
221      this.solutions.Clear();
222      this.solutions.AddRange(solutions);
223
224      // add an event such that whenever a value is changed in the shared dataset,
225      // this change is reflected in the internal dataset (where the value becomes a whole column)
226      if (this.sharedFixedVariables != null)
227        this.sharedFixedVariables.ItemChanged -= sharedFixedVariables_ItemChanged;
228      this.sharedFixedVariables = sharedFixedVariables;
229      this.sharedFixedVariables.ItemChanged += sharedFixedVariables_ItemChanged;
230
231      RecalculateTrainingLimits(initializeAxisRanges);
232      RecalculateInternalDataset();
233
234      chart.Series.Clear();
235      seriesCache.Clear();
236      ciSeriesCache.Clear();
237      foreach (var solution in this.solutions) {
238        var series = CreateSeries(solution);
239        seriesCache.Add(solution, series.Item1);
240        if (series.Item2 != null)
241          ciSeriesCache.Add(solution, series.Item2);
242      }
243
244      ResizeAllSeriesData();
245      OrderAndColorSeries();
246    }
247
248    public async Task RecalculateAsync(bool updateOnFinish = true, bool resetYAxis = true) {
249      if (IsDisposed
250        || sharedFixedVariables == null || !solutions.Any() || string.IsNullOrEmpty(freeVariable)
251        || trainingMin.IsAlmost(trainingMax) || trainingMin > trainingMax || drawingSteps == 0)
252        return;
253
254      calculationPendingTimer.Start();
255
256      Update(); // immediately show label
257
258      // cancel previous recalculate call
259      if (cancelCurrentRecalculateSource != null)
260        cancelCurrentRecalculateSource.Cancel();
261      cancelCurrentRecalculateSource = new CancellationTokenSource();
262
263      // Set cursor and x-axis
264      // Make sure to allow a small offset to be able to distinguish the vertical line annotation from the axis
265      var defaultValue = sharedFixedVariables.GetDoubleValue(freeVariable, 0);
266      var step = (trainingMax - trainingMin) / drawingSteps;
267      var minimum = chart.ChartAreas[0].AxisX.Minimum;
268      var maximum = chart.ChartAreas[0].AxisX.Maximum;
269      if (defaultValue.IsAlmost(minimum))
270        VerticalLineAnnotation.X = minimum + step;
271      else if (defaultValue.IsAlmost(maximum))
272        VerticalLineAnnotation.X = maximum - step;
273      else
274        VerticalLineAnnotation.X = defaultValue;
275
276      if (ShowCursor)
277        chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + defaultValue.ToString("N3", CultureInfo.CurrentCulture);
278
279      // Update series
280      var cancellationToken = cancelCurrentRecalculateSource.Token;
281      try {
282        var limits = await UpdateAllSeriesDataAsync(cancellationToken);
283        //cancellationToken.ThrowIfCancellationRequested();
284
285        yMin = limits.Lower;
286        yMax = limits.Upper;
287        // Set y-axis
288        if (resetYAxis)
289          SetupAxis(chart.ChartAreas[0].AxisY, yMin, yMax, YAxisTicks, FixedYAxisMin, FixedYAxisMax);
290
291        UpdateOutOfTrainingRangeStripLines();
292
293        calculationPendingTimer.Stop();
294        calculationPendingLabel.Visible = false;
295        if (updateOnFinish)
296          Update();
297      }
298      catch (OperationCanceledException) { }
299      catch (AggregateException ae) {
300        if (!ae.InnerExceptions.Any(e => e is OperationCanceledException))
301          throw;
302      }
303    }
304
305    private void SetupAxis(Axis axis, double minValue, double maxValue, int ticks, double? fixedAxisMin, double? fixedAxisMax) {
306      double axisMin, axisMax, axisInterval;
307      ChartUtil.CalculateAxisInterval(minValue, maxValue, ticks, out axisMin, out axisMax, out axisInterval);
308      axis.Minimum = fixedAxisMin ?? axisMin;
309      axis.Maximum = fixedAxisMax ?? axisMax;
310      axis.Interval = (axis.Maximum - axis.Minimum) / ticks;
311
312      try {
313        chart.ChartAreas[0].RecalculateAxesScale();
314      }
315      catch (InvalidOperationException) {
316        // Can occur if eg. axis min == axis max
317      }
318    }
319
320    private void RecalculateTrainingLimits(bool initializeAxisRanges) {
321      trainingMin = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Min()).Max();
322      trainingMax = solutions.Select(s => s.ProblemData.Dataset.GetDoubleValues(freeVariable, s.ProblemData.TrainingIndices).Max()).Min();
323
324      if (initializeAxisRanges) {
325        double xmin, xmax, xinterval;
326        ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
327        FixedXAxisMin = xmin;
328        FixedXAxisMax = xmax;
329      }
330    }
331
332    private void RecalculateInternalDataset() {
333      if (sharedFixedVariables == null)
334        return;
335
336      // we expand the range in order to get nice tick intervals on the x axis
337      double xmin, xmax, xinterval;
338      ChartUtil.CalculateAxisInterval(trainingMin, trainingMax, XAxisTicks, out xmin, out xmax, out xinterval);
339
340      if (FixedXAxisMin.HasValue) xmin = FixedXAxisMin.Value;
341      if (FixedXAxisMax.HasValue) xmax = FixedXAxisMax.Value;
342      double step = (xmax - xmin) / drawingSteps;
343
344      var xvalues = new List<double>();
345      for (int i = 0; i < drawingSteps; i++)
346        xvalues.Add(xmin + i * step);
347
348      var variables = sharedFixedVariables.DoubleVariables.ToList();
349      internalDataset = new ModifiableDataset(variables,
350        variables.Select(x => x == FreeVariable
351          ? xvalues
352          : Enumerable.Repeat(sharedFixedVariables.GetDoubleValue(x, 0), xvalues.Count).ToList()
353        )
354      );
355    }
356
357    private Tuple<Series, Series> CreateSeries(IRegressionSolution solution) {
358      var series = new Series {
359        ChartType = SeriesChartType.Line,
360        Name = solution.ProblemData.TargetVariable + " " + solutions.IndexOf(solution)
361      };
362      series.LegendText = series.Name;
363
364      var confidenceBoundSolution = solution as IConfidenceBoundRegressionSolution;
365      Series confidenceIntervalSeries = null;
366      if (confidenceBoundSolution != null) {
367        confidenceIntervalSeries = new Series {
368          ChartType = SeriesChartType.Range,
369          YValuesPerPoint = 2,
370          Name = "95% Conf. Interval " + series.Name,
371          IsVisibleInLegend = false
372        };
373      }
374      return Tuple.Create(series, confidenceIntervalSeries);
375    }
376
377    private void OrderAndColorSeries() {
378      chart.SuspendRepaint();
379
380      chart.Series.Clear();
381      // Add mean series for applying palette colors
382      foreach (var solution in solutions) {
383        chart.Series.Add(seriesCache[solution]);
384      }
385
386      chart.Palette = ChartColorPalette.BrightPastel;
387      chart.ApplyPaletteColors();
388      chart.Palette = ChartColorPalette.None;
389
390      // Add confidence interval series before its coresponding series for correct z index
391      foreach (var solution in solutions) {
392        Series ciSeries;
393        if (ciSeriesCache.TryGetValue(solution, out ciSeries)) {
394          var series = seriesCache[solution];
395          ciSeries.Color = Color.FromArgb(40, series.Color);
396          int idx = chart.Series.IndexOf(seriesCache[solution]);
397          chart.Series.Insert(idx, ciSeries);
398        }
399      }
400
401      chart.ResumeRepaint(true);
402    }
403
404    private async Task<DoubleLimit> UpdateAllSeriesDataAsync(CancellationToken cancellationToken) {
405      var updateTasks = solutions.Select(solution => UpdateSeriesDataAsync(solution, cancellationToken));
406
407      double min = double.MaxValue, max = double.MinValue;
408      foreach (var update in updateTasks) {
409        var limit = await update;
410        if (limit.Lower < min) min = limit.Lower;
411        if (limit.Upper > max) max = limit.Upper;
412      }
413
414      return new DoubleLimit(min, max);
415    }
416
417    private Task<DoubleLimit> UpdateSeriesDataAsync(IRegressionSolution solution, CancellationToken cancellationToken) {
418      return Task.Run(() => {
419        var xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList();
420        var yvalues = solution.Model.GetEstimatedValues(internalDataset, Enumerable.Range(0, internalDataset.Rows)).ToList();
421
422        double min = double.MaxValue, max = double.MinValue;
423
424        var series = seriesCache[solution];
425        for (int i = 0; i < xvalues.Count; i++) {
426          series.Points[i].SetValueXY(xvalues[i], yvalues[i]);
427          if (yvalues[i] < min) min = yvalues[i];
428          if (yvalues[i] > max) max = yvalues[i];
429        }
430
431        var confidenceBoundSolution = solution as IConfidenceBoundRegressionSolution;
432        if (confidenceBoundSolution != null) {
433          var confidenceIntervalSeries = ciSeriesCache[solution];
434
435          cancellationToken.ThrowIfCancellationRequested();
436          var variances =
437            confidenceBoundSolution.Model.GetEstimatedVariances(internalDataset,
438              Enumerable.Range(0, internalDataset.Rows)).ToList();
439          for (int i = 0; i < xvalues.Count; i++) {
440            var lower = yvalues[i] - 1.96 * Math.Sqrt(variances[i]);
441            var upper = yvalues[i] + 1.96 * Math.Sqrt(variances[i]);
442            confidenceIntervalSeries.Points[i].SetValueXY(xvalues[i], lower, upper);
443            if (lower < min) min = lower;
444            if (upper > max) max = upper;
445          }
446        }
447
448        cancellationToken.ThrowIfCancellationRequested();
449        return new DoubleLimit(min, max);
450      }, cancellationToken);
451    }
452
453    private void ResizeAllSeriesData() {
454      if (internalDataset == null)
455        return;
456
457      var xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList();
458      foreach (var solution in solutions)
459        ResizeSeriesData(solution, xvalues);
460    }
461    private void ResizeSeriesData(IRegressionSolution solution, IList<double> xvalues = null) {
462      if (xvalues == null)
463        xvalues = internalDataset.GetDoubleValues(FreeVariable).ToList();
464
465      var series = seriesCache[solution];
466      series.Points.SuspendUpdates();
467      series.Points.Clear();
468      for (int i = 0; i < xvalues.Count; i++)
469        series.Points.Add(new DataPoint(xvalues[i], 0.0));
470      series.Points.ResumeUpdates();
471
472      Series confidenceIntervalSeries;
473      if (ciSeriesCache.TryGetValue(solution, out confidenceIntervalSeries)) {
474        confidenceIntervalSeries.Points.SuspendUpdates();
475        confidenceIntervalSeries.Points.Clear();
476        for (int i = 0; i < xvalues.Count; i++)
477          confidenceIntervalSeries.Points.Add(new DataPoint(xvalues[i], new[] { -1.0, 1.0 }));
478        confidenceIntervalSeries.Points.ResumeUpdates();
479      }
480    }
481
482    public async Task AddSolutionAsync(IRegressionSolution solution) {
483      if (!SolutionsCompatible(solutions.Concat(new[] { solution })))
484        throw new ArgumentException("The solution is not compatible with the problem data.");
485      if (solutions.Contains(solution))
486        return;
487
488      solutions.Add(solution);
489      RecalculateTrainingLimits(true);
490
491      var series = CreateSeries(solution);
492      seriesCache.Add(solution, series.Item1);
493      if (series.Item2 != null)
494        ciSeriesCache.Add(solution, series.Item2);
495
496      ResizeSeriesData(solution);
497      OrderAndColorSeries();
498
499      await RecalculateAsync();
500      var args = new EventArgs<IRegressionSolution>(solution);
501      OnSolutionAdded(this, args);
502    }
503
504    public async Task RemoveSolutionAsync(IRegressionSolution solution) {
505      if (!solutions.Remove(solution))
506        return;
507
508      RecalculateTrainingLimits(true);
509
510      seriesCache.Remove(solution);
511      ciSeriesCache.Remove(solution);
512
513      await RecalculateAsync();
514      var args = new EventArgs<IRegressionSolution>(solution);
515      OnSolutionRemoved(this, args);
516    }
517
518    private static bool SolutionsCompatible(IEnumerable<IRegressionSolution> solutions) {
519      foreach (var solution1 in solutions) {
520        var variables1 = solution1.ProblemData.Dataset.DoubleVariables;
521        foreach (var solution2 in solutions) {
522          if (solution1 == solution2)
523            continue;
524          var variables2 = solution2.ProblemData.Dataset.DoubleVariables;
525          if (!variables1.All(variables2.Contains))
526            return false;
527        }
528      }
529      return true;
530    }
531
532    private void UpdateOutOfTrainingRangeStripLines() {
533      var axisX = chart.ChartAreas[0].AxisX;
534      var lowerStripLine = axisX.StripLines[0];
535      var upperStripLine = axisX.StripLines[1];
536
537      lowerStripLine.IntervalOffset = axisX.Minimum;
538      lowerStripLine.StripWidth = trainingMin - axisX.Minimum;
539
540      upperStripLine.IntervalOffset = trainingMax;
541      upperStripLine.StripWidth = axisX.Maximum - trainingMax;
542    }
543
544    #region Events
545    public event EventHandler<EventArgs<IRegressionSolution>> SolutionAdded;
546    public void OnSolutionAdded(object sender, EventArgs<IRegressionSolution> args) {
547      var added = SolutionAdded;
548      if (added == null) return;
549      added(sender, args);
550    }
551
552    public event EventHandler<EventArgs<IRegressionSolution>> SolutionRemoved;
553    public void OnSolutionRemoved(object sender, EventArgs<IRegressionSolution> args) {
554      var removed = SolutionRemoved;
555      if (removed == null) return;
556      removed(sender, args);
557    }
558
559    public event EventHandler VariableValueChanged;
560    public void OnVariableValueChanged(object sender, EventArgs args) {
561      var changed = VariableValueChanged;
562      if (changed == null) return;
563      changed(sender, args);
564    }
565
566    private void sharedFixedVariables_ItemChanged(object o, EventArgs<int, int> e) {
567      if (o != sharedFixedVariables) return;
568      var variables = sharedFixedVariables.DoubleVariables.ToList();
569      var rowIndex = e.Value;
570      var columnIndex = e.Value2;
571
572      var variableName = variables[columnIndex];
573      if (variableName == FreeVariable) return;
574      var v = sharedFixedVariables.GetDoubleValue(variableName, rowIndex);
575      var values = new List<double>(Enumerable.Repeat(v, DrawingSteps));
576      internalDataset.ReplaceVariable(variableName, values);
577    }
578
579    private void chart_AnnotationPositionChanging(object sender, AnnotationPositionChangingEventArgs e) {
580      var step = (trainingMax - trainingMin) / drawingSteps;
581      double newLocation = step * (long)Math.Round(e.NewLocationX / step);
582      var axisX = chart.ChartAreas[0].AxisX;
583      if (newLocation >= axisX.Maximum)
584        newLocation = axisX.Maximum - step;
585      if (newLocation <= axisX.Minimum)
586        newLocation = axisX.Minimum + step;
587
588      e.NewLocationX = newLocation;
589      var annotation = VerticalLineAnnotation;
590      var x = annotation.X;
591      sharedFixedVariables.SetVariableValue(x, FreeVariable, 0);
592
593      if (ShowCursor) {
594        chart.ChartAreas[0].AxisX.Title = FreeVariable + " : " + x.ToString("N3", CultureInfo.CurrentCulture);
595        chart.Update();
596      }
597
598      OnVariableValueChanged(this, EventArgs.Empty);
599    }
600
601    private void chart_MouseMove(object sender, MouseEventArgs e) {
602      bool hitCursor = chart.HitTest(e.X, e.Y).ChartElementType == ChartElementType.Annotation;
603      chart.Cursor = hitCursor ? Cursors.VSplit : Cursors.Default;
604    }
605
606    private void chart_DragDrop(object sender, DragEventArgs e) {
607      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
608      if (data != null) {
609        var solution = data as IRegressionSolution;
610        if (!solutions.Contains(solution))
611          AddSolutionAsync(solution);
612      }
613    }
614    private void chart_DragEnter(object sender, DragEventArgs e) {
615      if (!e.Data.GetDataPresent(HeuristicLab.Common.Constants.DragDropDataFormat)) return;
616      e.Effect = DragDropEffects.None;
617
618      var data = e.Data.GetData(HeuristicLab.Common.Constants.DragDropDataFormat);
619      var regressionSolution = data as IRegressionSolution;
620      if (regressionSolution != null) {
621        e.Effect = DragDropEffects.Copy;
622      }
623    }
624
625    private void calculationPendingTimer_Tick(object sender, EventArgs e) {
626      calculationPendingLabel.Visible = true;
627      Update();
628    }
629
630    private void config_Click(object sender, EventArgs e) {
631      configurationDialog.ShowDialog(this);
632    }
633    #endregion
634  }
635}
Note: See TracBrowser for help on using the repository browser.