Free cookie consent management tool by TermsFeed Policy Generator

source: branches/StatisticalTesting/HeuristicLab.Analysis.Statistics/3.3/SampleSizeInfluenceView.cs @ 11375

Last change on this file since 11375 was 11375, checked in by ascheibe, 10 years ago

#2031 updated license headers and version

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