1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2012 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 |
|
---|
22 | using System;
|
---|
23 | using System.Drawing;
|
---|
24 | using System.Windows.Forms;
|
---|
25 | using HeuristicLab.Collections;
|
---|
26 | using HeuristicLab.Core.Views;
|
---|
27 | using HeuristicLab.MainForm;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Analysis.Views {
|
---|
30 | [View("ScatterPlot View")]
|
---|
31 | [Content(typeof(ScatterPlot), true)]
|
---|
32 | public partial class ScatterPlotView : NamedItemView {
|
---|
33 | public new ScatterPlot Content {
|
---|
34 | get { return (ScatterPlot)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public ScatterPlotView() {
|
---|
39 | InitializeComponent();
|
---|
40 | chart.CustomizeAllChartAreas();
|
---|
41 | }
|
---|
42 |
|
---|
43 | protected override void DeregisterContentEvents() {
|
---|
44 | Content.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
45 | Content.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
46 | Content.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
47 | Content.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
48 | Content.AxisNameChanged -= new EventHandler(Content_AxisNameChanged);
|
---|
49 | base.DeregisterContentEvents();
|
---|
50 | }
|
---|
51 |
|
---|
52 | protected override void RegisterContentEvents() {
|
---|
53 | base.RegisterContentEvents();
|
---|
54 | Content.Points.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
55 | Content.Points.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
56 | Content.Points.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
57 | Content.Points.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<PointF>>(Content_Points_Changed);
|
---|
58 | Content.AxisNameChanged += new EventHandler(Content_AxisNameChanged);
|
---|
59 | }
|
---|
60 |
|
---|
61 | private void Content_Points_Changed(object sender, CollectionItemsChangedEventArgs<IndexedItem<PointF>> e) {
|
---|
62 | RedrawChart();
|
---|
63 | }
|
---|
64 |
|
---|
65 | protected override void OnContentChanged() {
|
---|
66 | base.OnContentChanged();
|
---|
67 | if (Content != null) {
|
---|
68 | ConfigureChart();
|
---|
69 | RedrawChart();
|
---|
70 | } else {
|
---|
71 | ClearChart();
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | private void Content_AxisNameChanged(object sender, EventArgs e) {
|
---|
76 | ConfigureChart();
|
---|
77 | }
|
---|
78 |
|
---|
79 | private void ConfigureChart() {
|
---|
80 | if (InvokeRequired) {
|
---|
81 | Invoke((Action)ConfigureChart);
|
---|
82 | } else {
|
---|
83 | chart.ChartAreas[0].AxisX.Title = Content.XAxisName;
|
---|
84 | chart.ChartAreas[0].AxisY.Title = Content.YAxisName;
|
---|
85 | chart.Titles[0].Text = Content.Name;
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | private void ClearChart() {
|
---|
90 | if (InvokeRequired) {
|
---|
91 | Invoke((Action)ClearChart);
|
---|
92 | } else {
|
---|
93 | chart.Series[0].Points.Clear();
|
---|
94 | chart.ChartAreas[0].AxisX.Title = String.Empty;
|
---|
95 | chart.ChartAreas[0].AxisY.Title = String.Empty;
|
---|
96 | chart.Titles[0].Text = String.Empty;
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | private void RedrawChart() {
|
---|
101 | if (InvokeRequired) {
|
---|
102 | Invoke((Action)RedrawChart);
|
---|
103 | } else {
|
---|
104 | chart.Series[0].Points.SuspendUpdates();
|
---|
105 | chart.Series[0].Points.Clear();
|
---|
106 | foreach (var p in Content.Points.ToArray()) {
|
---|
107 | chart.Series[0].Points.AddXY(p.X, p.Y);
|
---|
108 | }
|
---|
109 | chart.Series[0].Points.ResumeUpdates();
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 | }
|
---|