Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Analysis.Statistics.Views/3.3/SampleSizeInfluenceView.cs @ 12599

Last change on this file since 12599 was 12599, checked in by abeham, 9 years ago

#2270: Fixed several of the runcollection views

  • Added InvokeRequired checks where missing
  • Added suppressUpdates check where missing
  • Fixed some bugs, added some null checks
File size: 24.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2015 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.Linq;
25using System.Windows.Forms;
26using System.Windows.Forms.DataVisualization.Charting;
27using HeuristicLab.Collections;
28using HeuristicLab.Common;
29using HeuristicLab.Core;
30using HeuristicLab.Data;
31using HeuristicLab.MainForm;
32using HeuristicLab.MainForm.WindowsForms;
33using HeuristicLab.Optimization;
34using HeuristicLab.PluginInfrastructure;
35
36namespace HeuristicLab.Analysis.Statistics.Views {
37  [View("Sample Size Influence", "HeuristicLab.Analysis.Statistics.Views.InfoResources.SampleSizeInfluenceInfo.rtf")]
38  [Content(typeof(RunCollection), false)]
39  public partial class SampleSizeInfluenceView : AsynchronousContentView {
40    private enum AxisDimension { Color = 0 }
41    private const string BoxPlotSeriesName = "BoxPlotSeries";
42    private const string BoxPlotChartAreaName = "BoxPlotChartArea";
43    private const string delimiter = ";";
44
45    private bool suppressUpdates = false;
46    private string yAxisValue;
47    private Dictionary<int, Dictionary<object, double>> categoricalMapping;
48    private SortedDictionary<double, Series> seriesCache;
49
50    public SampleSizeInfluenceView() {
51      InitializeComponent();
52      categoricalMapping = new Dictionary<int, Dictionary<object, double>>();
53      seriesCache = new SortedDictionary<double, Series>();
54      chart.ChartAreas[0].Visible = false;
55      chart.Series.Clear();
56      chart.ChartAreas.Add(BoxPlotChartAreaName);
57      chart.CustomizeAllChartAreas();
58      chart.ChartAreas[BoxPlotChartAreaName].Axes.ToList().ForEach(x => { x.ScaleView.Zoomable = true; x.ScaleView.MinSize = 0; });
59      chart.ChartAreas[BoxPlotChartAreaName].CursorX.Interval = 0.5;
60      chart.ChartAreas[BoxPlotChartAreaName].CursorY.Interval = 1e-5;
61    }
62
63    public new RunCollection Content {
64      get { return (RunCollection)base.Content; }
65      set { base.Content = value; }
66    }
67    public IStringConvertibleMatrix Matrix {
68      get { return this.Content; }
69    }
70
71    #region RunCollection and Run events
72    protected override void RegisterContentEvents() {
73      base.RegisterContentEvents();
74      Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged);
75      Content.ItemsAdded += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
76      Content.ItemsRemoved += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
77      Content.CollectionReset += new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
78      Content.UpdateOfRunsInProgressChanged += new EventHandler(Content_UpdateOfRunsInProgressChanged);
79      Content.OptimizerNameChanged += new EventHandler(Content_AlgorithmNameChanged);
80      RegisterRunEvents(Content);
81    }
82    protected override void DeregisterContentEvents() {
83      base.DeregisterContentEvents();
84      Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged);
85      Content.ItemsAdded -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsAdded);
86      Content.ItemsRemoved -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_ItemsRemoved);
87      Content.CollectionReset -= new HeuristicLab.Collections.CollectionItemsChangedEventHandler<IRun>(Content_CollectionReset);
88      Content.UpdateOfRunsInProgressChanged -= new EventHandler(Content_UpdateOfRunsInProgressChanged);
89      Content.OptimizerNameChanged -= new EventHandler(Content_AlgorithmNameChanged);
90      DeregisterRunEvents(Content);
91    }
92
93    protected virtual void RegisterRunEvents(IEnumerable<IRun> runs) {
94      foreach (IRun run in runs) {
95        RegisterRunParametersEvents(run);
96        RegisterRunResultsEvents(run);
97      }
98    }
99
100    protected virtual void DeregisterRunEvents(IEnumerable<IRun> runs) {
101      foreach (IRun run in runs) {
102        DeregisterRunParametersEvents(run);
103        DeregisterRunResultsEvents(run);
104      }
105    }
106
107    private void RegisterRunParametersEvents(IRun run) {
108      IObservableDictionary<string, IItem> dict = run.Parameters;
109      dict.ItemsAdded += run_Changed;
110      dict.ItemsRemoved += run_Changed;
111      dict.ItemsReplaced += run_Changed;
112      dict.CollectionReset += run_Changed;
113    }
114
115    private void RegisterRunResultsEvents(IRun run) {
116      IObservableDictionary<string, IItem> dict = run.Results;
117      dict.ItemsAdded += run_Changed;
118      dict.ItemsRemoved += run_Changed;
119      dict.ItemsReplaced += run_Changed;
120      dict.CollectionReset += run_Changed;
121    }
122
123    private void DeregisterRunParametersEvents(IRun run) {
124      IObservableDictionary<string, IItem> dict = run.Parameters;
125      dict.ItemsAdded -= run_Changed;
126      dict.ItemsRemoved -= run_Changed;
127      dict.ItemsReplaced -= run_Changed;
128      dict.CollectionReset -= run_Changed;
129    }
130
131    private void DeregisterRunResultsEvents(IRun run) {
132      IObservableDictionary<string, IItem> dict = run.Results;
133      dict.ItemsAdded -= run_Changed;
134      dict.ItemsRemoved -= run_Changed;
135      dict.ItemsReplaced -= run_Changed;
136      dict.CollectionReset -= run_Changed;
137    }
138
139    private void Content_CollectionReset(object sender, CollectionItemsChangedEventArgs<IRun> e) {
140      DeregisterRunEvents(e.OldItems);
141      RegisterRunEvents(e.Items);
142      if (!suppressUpdates) UpdateAll();
143    }
144    private void Content_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IRun> e) {
145      DeregisterRunEvents(e.Items);
146      if (!suppressUpdates) UpdateComboBoxes();
147    }
148    private void Content_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IRun> e) {
149      RegisterRunEvents(e.Items);
150      if (!suppressUpdates) UpdateComboBoxes();
151    }
152    private void Content_UpdateOfRunsInProgressChanged(object sender, EventArgs e) {
153      if (InvokeRequired)
154        Invoke(new EventHandler(Content_UpdateOfRunsInProgressChanged), sender, e);
155      else {
156        suppressUpdates = Content.UpdateOfRunsInProgress;
157        if (!suppressUpdates) UpdateAll();
158      }
159    }
160    private void Content_ColumnNamesChanged(object sender, EventArgs e) {
161      if (InvokeRequired)
162        Invoke(new EventHandler(Content_ColumnNamesChanged), sender, e);
163      else {
164        if (!suppressUpdates) UpdateComboBoxes();
165      }
166    }
167    private void run_Changed(object sender, EventArgs e) {
168      if (InvokeRequired)
169        this.Invoke(new EventHandler(run_Changed), sender, e);
170      else if (!suppressUpdates) UpdateDataPoints();
171    }
172
173    private void Content_AlgorithmNameChanged(object sender, EventArgs e) {
174      if (InvokeRequired)
175        Invoke(new EventHandler(Content_AlgorithmNameChanged), sender, e);
176      else if (!suppressUpdates) UpdateCaption();
177    }
178    #endregion
179
180    #region update comboboxes, datapoints, runs
181    protected override void OnContentChanged() {
182      base.OnContentChanged();
183      UpdateAll();
184    }
185
186    private void UpdateAll() {
187      this.categoricalMapping.Clear();
188      UpdateComboBoxes();
189      UpdateDataPoints();
190      UpdateCaption();
191    }
192
193    private void UpdateCaption() {
194      Caption = Content != null ? Content.OptimizerName + " Sample Size Influence" : ViewAttribute.GetViewName(GetType());
195    }
196
197    private void UpdateSampleSizes(bool forceUpdate = false) {
198      string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
199
200      if (selectedYAxis != null && (xAxisTextBox.Text.Trim() == string.Empty || forceUpdate)) {
201        xAxisTextBox.Clear();
202        List<double> values = new List<double>();
203        foreach (IRun run in Content.Where(x => x.Visible)) {
204          double? cv = GetValue(run, selectedYAxis);
205          if (cv.HasValue) {
206            values.Add(cv.Value);
207          }
208        }
209
210        if (values.Any()) {
211          if (hypergeometricCheckBox.Checked) {
212            xAxisTextBox.Text += ((int)(values.Count() / 16)) + delimiter + " ";
213            xAxisTextBox.Text += ((int)(values.Count() / 8)) + delimiter + " ";
214            xAxisTextBox.Text += (int)(values.Count() / 4);
215          } else {
216            xAxisTextBox.Text += ((int)(values.Count() / 4)) + delimiter + " ";
217            xAxisTextBox.Text += ((int)(values.Count() / 2)) + delimiter + " ";
218            xAxisTextBox.Text += ((int)(values.Count() / 4 * 3)) + delimiter + " ";
219            xAxisTextBox.Text += (int)(values.Count());
220          }
221        }
222      }
223    }
224
225    private void UpdateComboBoxes() {
226      string selectedYAxis = (string)this.yAxisComboBox.SelectedItem;
227      this.xAxisTextBox.Text = string.Empty;
228      this.yAxisComboBox.Items.Clear();
229      if (Content != null) {
230        string[] additionalAxisDimension = Enum.GetNames(typeof(AxisDimension));
231        UpdateSampleSizes();
232        this.yAxisComboBox.Items.AddRange(additionalAxisDimension);
233        this.yAxisComboBox.Items.AddRange(Matrix.ColumnNames.ToArray());
234
235        if (selectedYAxis != null && yAxisComboBox.Items.Contains(selectedYAxis)) {
236          yAxisComboBox.SelectedItem = selectedYAxis;
237          UpdateDataPoints();
238        }
239      }
240    }
241
242    private void UpdateDataPoints() {
243      this.chart.Series.Clear();
244      this.seriesCache.Clear();
245      if (Content != null) {
246        var usableRuns = Content.Where(r => r.Visible).ToList();
247        List<int> groupSizes = ParseGroupSizesFromText(xAxisTextBox.Text);
248
249        if (hypergeometricCheckBox.Checked) {
250          CalculateGroupsHypergeometric(usableRuns, groupSizes);
251        } else {
252          CalculateGroups(usableRuns, groupSizes);
253        }
254
255        foreach (Series s in this.seriesCache.Values)
256          this.chart.Series.Add(s);
257
258        UpdateStatistics();
259        if (seriesCache.Count > 0) {
260          Series boxPlotSeries = CreateBoxPlotSeries();
261          this.chart.Series.Add(boxPlotSeries);
262        }
263
264        UpdateAxisLabels();
265        if (groupSizes.Any())
266          AddSampleSizeText();
267      } else {
268        sampleSizeTextBox.Text = string.Empty;
269      }
270      UpdateNoRunsVisibleLabel();
271    }
272
273    private void CalculateGroups(List<IRun> usableRuns, List<int> groupSizes) {
274      Random rand = new Random();
275
276      foreach (int gs in groupSizes) {
277        int idx = gs;
278        List<IRun> runGroup = new List<IRun>();
279        if (idx > usableRuns.Count()) {
280          idx = usableRuns.Count();
281        }
282
283        for (int i = 0; i < idx; i++) {
284          int r = rand.Next(usableRuns.Count());
285          runGroup.Add(usableRuns[r]);
286        }
287        runGroup.ForEach(x => AddDataPoint(x, idx));
288      }
289    }
290
291    private void CalculateGroupsHypergeometric(List<IRun> usableRuns, List<int> groupSizes) {
292      Random rand = new Random();
293      var runs = new List<IRun>(usableRuns);
294
295      foreach (int gs in groupSizes) {
296        int idx = gs;
297        List<IRun> runGroup = new List<IRun>();
298        if (idx > runs.Count()) {
299          idx = runs.Count();
300        }
301
302        for (int i = 0; i < idx; i++) {
303          int r = rand.Next(runs.Count());
304          runGroup.Add(runs[r]);
305          runs.Remove(runs[r]);
306        }
307        runGroup.ForEach(x => AddDataPoint(x, idx));
308      }
309    }
310
311    private void AddSampleSizeText() {
312      sampleSizeTextBox.Text = string.Empty;
313      var usableRuns = Content.Where(r => r.Visible).ToList();
314
315      if (!yAxisComboBox.DroppedDown)
316        this.yAxisValue = (string)yAxisComboBox.SelectedItem;
317
318      List<double?> yValue = usableRuns.Select(x => GetValue(x, this.yAxisValue)).ToList();
319      if (yValue.Any(x => !x.HasValue)) return;
320
321      double estimatedSampleSize = SampleSizeDetermination.DetermineSampleSizeByEstimatingMean(yValue.Select(x => x.Value).ToArray());
322      sampleSizeTextBox.Text = estimatedSampleSize.ToString();
323    }
324
325    private List<int> ParseGroupSizesFromText(string groupsText, bool verbose = true) {
326      string[] gs = groupsText.Split(delimiter.ToCharArray());
327      List<int> vals = new List<int>();
328
329      foreach (string s in gs) {
330        string ns = s.Trim();
331
332        if (ns != string.Empty) {
333          int v = 0;
334          try {
335            v = int.Parse(ns);
336            vals.Add(v);
337          } catch (Exception ex) {
338            if (verbose) {
339              ErrorHandling.ShowErrorDialog("Can't parse group sizes. Please only use numbers seperated by a " + delimiter + ". ", ex);
340            }
341          }
342        }
343      }
344      return vals;
345    }
346
347    private void UpdateStatistics() {
348      DoubleMatrix matrix = new DoubleMatrix(11, seriesCache.Count);
349      matrix.SortableView = false;
350      List<string> columnNames = new List<string>();
351      foreach (Series series in seriesCache.Values) {
352        DataPoint datapoint = series.Points.FirstOrDefault();
353        if (datapoint != null) {
354          IRun run = (IRun)datapoint.Tag;
355          string selectedAxis = xAxisTextBox.Text;
356          IItem value = null;
357
358          if (Enum.IsDefined(typeof(AxisDimension), selectedAxis)) {
359            AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), selectedAxis);
360            switch (axisDimension) {
361              case AxisDimension.Color: value = new StringValue(run.Color.ToString());
362                break;
363            }
364          }
365
366          string columnName = series.Name;
367          columnNames.Add(columnName);
368        }
369      }
370      matrix.ColumnNames = columnNames;
371      matrix.RowNames = new string[] { "Count", "Minimum", "Maximum", "Average", "Median", "Standard Deviation", "Variance", "25th Percentile", "75th Percentile", "Lower Confidence Int.", "Upper Confidence Int." };
372
373      for (int i = 0; i < seriesCache.Count; i++) {
374        Series series = seriesCache.ElementAt(i).Value;
375        double[] seriesValues = series.Points.Select(p => p.YValues[0]).OrderBy(d => d).ToArray();
376        Tuple<double, double> confIntervals = seriesValues.ConfidenceIntervals(0.95);
377        matrix[0, i] = seriesValues.Length;
378        matrix[1, i] = seriesValues.Min();
379        matrix[2, i] = seriesValues.Max();
380        matrix[3, i] = seriesValues.Average();
381        matrix[4, i] = seriesValues.Median();
382        matrix[5, i] = seriesValues.StandardDeviation();
383        matrix[6, i] = seriesValues.Variance();
384        matrix[7, i] = seriesValues.Percentile(0.25);
385        matrix[8, i] = seriesValues.Percentile(0.75);
386        matrix[9, i] = confIntervals.Item1;
387        matrix[10, i] = confIntervals.Item2;
388      }
389      statisticsMatrixView.Content = matrix;
390    }
391
392    private Series CreateBoxPlotSeries() {
393      Series boxPlotSeries = new Series(BoxPlotSeriesName);
394      string seriesNames = string.Concat(seriesCache.Keys.Select(x => x.ToString() + ";").ToArray());
395      seriesNames = seriesNames.Remove(seriesNames.Length - 1); //delete last ; from string
396
397      boxPlotSeries.ChartArea = BoxPlotChartAreaName;
398      boxPlotSeries.ChartType = SeriesChartType.BoxPlot;
399      boxPlotSeries["BoxPlotSeries"] = seriesNames;
400      boxPlotSeries["BoxPlotShowUnusualValues"] = "true";
401      boxPlotSeries["PointWidth"] = "0.4";
402      boxPlotSeries.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.VerticalCenter;
403      boxPlotSeries.BackSecondaryColor = System.Drawing.Color.FromArgb(130, 224, 64, 10);
404      boxPlotSeries.BorderColor = System.Drawing.Color.FromArgb(64, 64, 64);
405      boxPlotSeries.Color = System.Drawing.Color.FromArgb(224, 64, 10);
406
407      return boxPlotSeries;
408    }
409
410    private void AddDataPoint(IRun run, int idx) {
411      double xValue;
412      double? yValue;
413
414
415      if (!yAxisComboBox.DroppedDown)
416        this.yAxisValue = (string)yAxisComboBox.SelectedItem;
417
418      xValue = idx;
419      yValue = GetValue(run, this.yAxisValue);
420
421      if (yValue.HasValue) {
422        if (!this.seriesCache.ContainsKey(xValue))
423          seriesCache[xValue] = new Series(xValue.ToString());
424
425        Series series = seriesCache[xValue];
426        DataPoint point = new DataPoint(xValue, yValue.Value);
427        point.Tag = run;
428        series.Points.Add(point);
429      }
430    }
431    #endregion
432
433    #region get values from run
434    private double? GetValue(IRun run, string columnName) {
435      if (run == null || string.IsNullOrEmpty(columnName))
436        return null;
437
438      if (Enum.IsDefined(typeof(AxisDimension), columnName)) {
439        AxisDimension axisDimension = (AxisDimension)Enum.Parse(typeof(AxisDimension), columnName);
440        return GetValue(run, axisDimension);
441      } else {
442        int columnIndex = Matrix.ColumnNames.ToList().IndexOf(columnName);
443        IItem value = Content.GetValue(run, columnIndex);
444        if (value == null)
445          return null;
446
447        DoubleValue doubleValue = value as DoubleValue;
448        IntValue intValue = value as IntValue;
449        TimeSpanValue timeSpanValue = value as TimeSpanValue;
450        double? ret = null;
451        if (doubleValue != null) {
452          if (!double.IsNaN(doubleValue.Value) && !double.IsInfinity(doubleValue.Value))
453            ret = doubleValue.Value;
454        } else if (intValue != null)
455          ret = intValue.Value;
456        else if (timeSpanValue != null) {
457          ret = timeSpanValue.Value.TotalSeconds;
458        } else
459          ret = GetCategoricalValue(columnIndex, value.ToString());
460
461        return ret;
462      }
463    }
464    private double GetCategoricalValue(int dimension, string value) {
465      if (!this.categoricalMapping.ContainsKey(dimension)) {
466        this.categoricalMapping[dimension] = new Dictionary<object, double>();
467        var orderedCategories = Content.Where(r => r.Visible && Content.GetValue(r, dimension) != null).Select(r => Content.GetValue(r, dimension).ToString())
468                                          .Distinct().OrderBy(x => x, new NaturalStringComparer());
469        int count = 1;
470        foreach (var category in orderedCategories) {
471          this.categoricalMapping[dimension].Add(category, count);
472          count++;
473        }
474      }
475      return this.categoricalMapping[dimension][value];
476    }
477    private double GetValue(IRun run, AxisDimension axisDimension) {
478      double value = double.NaN;
479      switch (axisDimension) {
480        case AxisDimension.Color: {
481            value = GetCategoricalValue(-1, run.Color.ToString());
482            break;
483          }
484        default: {
485            throw new ArgumentException("No handling strategy for " + axisDimension.ToString() + " is defined.");
486          }
487      }
488      return value;
489    }
490    #endregion
491
492    #region GUI events
493    private void UpdateNoRunsVisibleLabel() {
494      if (this.chart.Series.Count > 0) {
495        noRunsLabel.Visible = false;
496        showStatisticsCheckBox.Enabled = true;
497        splitContainer.Panel2Collapsed = !showStatisticsCheckBox.Checked;
498      } else {
499        noRunsLabel.Visible = true;
500        showStatisticsCheckBox.Enabled = false;
501        splitContainer.Panel2Collapsed = true;
502      }
503    }
504
505    private void RecalculateButton_Click(object sender, EventArgs e) {
506      UpdateDataPoints();
507    }
508
509    private void hypergeometricCheckBox_CheckedChanged(object sender, EventArgs e) {
510      UpdateSampleSizes(true);
511      UpdateDataPoints();
512    }
513
514    private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) {
515      UpdateSampleSizes();
516      UpdateDataPoints();
517    }
518    private void UpdateAxisLabels() {
519      Axis xAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisX;
520      Axis yAxis = this.chart.ChartAreas[BoxPlotChartAreaName].AxisY;
521      int axisDimensionCount = Enum.GetNames(typeof(AxisDimension)).Count();
522
523      SetCustomAxisLabels(xAxis, -1);
524      SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex - axisDimensionCount);
525
526      xAxis.Title = "Group Size";
527      if (yAxisComboBox.SelectedItem != null)
528        yAxis.Title = yAxisComboBox.SelectedItem.ToString();
529    }
530
531    private void chart_AxisViewChanged(object sender, System.Windows.Forms.DataVisualization.Charting.ViewEventArgs e) {
532      this.UpdateAxisLabels();
533    }
534
535    private void SetCustomAxisLabels(Axis axis, int dimension) {
536      axis.CustomLabels.Clear();
537      if (categoricalMapping.ContainsKey(dimension)) {
538        int position = 1;
539        foreach (var pair in categoricalMapping[dimension].Where(x => seriesCache.ContainsKey(x.Value))) {
540          string labelText = pair.Key.ToString();
541          CustomLabel label = new CustomLabel();
542          label.ToolTip = labelText;
543          if (labelText.Length > 25)
544            labelText = labelText.Substring(0, 25) + " ... ";
545          label.Text = labelText;
546          label.GridTicks = GridTickTypes.TickMark;
547          label.FromPosition = position - 0.5;
548          label.ToPosition = position + 0.5;
549          axis.CustomLabels.Add(label);
550          position++;
551        }
552      } else if (dimension > 0 && Content.GetValue(0, dimension) is TimeSpanValue) {
553        this.chart.ChartAreas[0].RecalculateAxesScale();
554        Axis correspondingAxis = this.chart.ChartAreas[0].Axes.Where(x => x.Name == axis.Name).SingleOrDefault();
555        if (correspondingAxis == null)
556          correspondingAxis = axis;
557        for (double i = correspondingAxis.Minimum; i <= correspondingAxis.Maximum; i += correspondingAxis.LabelStyle.Interval) {
558          TimeSpan time = TimeSpan.FromSeconds(i);
559          string x = string.Format("{0:00}:{1:00}:{2:00}", (int)time.Hours, time.Minutes, time.Seconds);
560          axis.CustomLabels.Add(i - correspondingAxis.LabelStyle.Interval / 2, i + correspondingAxis.LabelStyle.Interval / 2, x);
561        }
562      } else if (chart.ChartAreas[BoxPlotChartAreaName].AxisX == axis) {
563        double position = 1.0;
564        foreach (Series series in chart.Series) {
565          if (series.Name != BoxPlotSeriesName) {
566            string labelText = series.Points[0].XValue.ToString();
567            CustomLabel label = new CustomLabel();
568            label.FromPosition = position - 0.5;
569            label.ToPosition = position + 0.5;
570            label.GridTicks = GridTickTypes.TickMark;
571            label.Text = labelText;
572            axis.CustomLabels.Add(label);
573            position++;
574          }
575        }
576      }
577    }
578
579    private void chart_MouseMove(object sender, MouseEventArgs e) {
580      string newTooltipText = string.Empty;
581      string oldTooltipText;
582      HitTestResult h = this.chart.HitTest(e.X, e.Y);
583      if (h.ChartElementType == ChartElementType.AxisLabels) {
584        newTooltipText = ((CustomLabel)h.Object).ToolTip;
585      }
586
587      oldTooltipText = this.tooltip.GetToolTip(chart);
588      if (newTooltipText != oldTooltipText)
589        this.tooltip.SetToolTip(chart, newTooltipText);
590    }
591    #endregion
592
593    private void showStatisticsCheckBox_CheckedChanged(object sender, EventArgs e) {
594      splitContainer.Panel2Collapsed = !showStatisticsCheckBox.Checked;
595    }
596
597    private void defineSampleSizeButton_Click(object sender, EventArgs e) {
598      int min = 0, max = 0, step = 1;
599      var groupSizes = ParseGroupSizesFromText(xAxisTextBox.Text);
600      if (groupSizes.Count() > 0) {
601        min = groupSizes.Min();
602        max = groupSizes.Max();
603      }
604
605      using (var dialog = new DefineArithmeticProgressionDialog(true, min, max, step)) {
606        if (dialog.ShowDialog(this) == DialogResult.OK) {
607          var values = dialog.Values;
608          string newVals = "";
609          foreach (int v in values) {
610            newVals += v + delimiter + " ";
611          }
612          xAxisTextBox.Text = newVals;
613        }
614      }
615    }
616
617    private void xAxisTextBox_TextChanged(object sender, EventArgs e) {
618      var result = ParseGroupSizesFromText(xAxisTextBox.Text, false);
619
620      if (seriesCache.Count() == result.Count()) {
621        bool changed = false;
622        int i = 0;
623        foreach (var gs in seriesCache.Keys) {
624          if (((int)gs) != result[i]) {
625            changed = true;
626            break;
627          }
628          i++;
629        }
630
631        if (changed) {
632          UpdateDataPoints();
633        }
634      } else {
635        UpdateDataPoints();
636      }
637    }
638  }
639}
Note: See TracBrowser for help on using the repository browser.