#region License Information /* HeuristicLab * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Windows.Forms; using System.Windows.Forms.DataVisualization.Charting; using HeuristicLab.Core.Views; using HeuristicLab.MainForm; namespace HeuristicLab.Analysis.FitnessLandscape { [View("ScatterPlot View")] [Content(typeof(ScatterPlot), true)] public partial class ScatterPlotView : NamedItemView { public new ScatterPlot Content { get { return (ScatterPlot)base.Content; } set { base.Content = value; } } public ScatterPlotView() { InitializeComponent(); chart.CustomizeAllChartAreas(); } protected override void OnContentChanged() { base.OnContentChanged(); if (Content != null) UpdateBitmap(); } protected override void RegisterContentEvents() { base.RegisterContentEvents(); Content.PixelsChanged += new EventHandler(Content_PixelChanged); Content.AxisNameChanged += new EventHandler(Content_AxisNameChanged); } protected override void DeregisterContentEvents() { Content.PixelsChanged -= new EventHandler(Content_PixelChanged); Content.AxisNameChanged += new EventHandler(Content_AxisNameChanged); base.DeregisterContentEvents(); } void Content_AxisNameChanged(object sender, EventArgs e) { if (InvokeRequired) { Invoke(new EventHandler(Content_AxisNameChanged), sender, e); } else { chart.ChartAreas[0].Axes[0].Title = Content.XAxisName; chart.ChartAreas[0].Axes[1].Title = Content.YAxisName; } } void Content_PixelChanged(object sender, PointsEventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_PixelChanged), sender, e); else AddPixels(e.NewPoints); } void Content_AreaChanged(object sender, EventArgs e) { if (InvokeRequired) Invoke(new EventHandler(Content_AreaChanged), sender, e); else UpdateBitmap(); } private void AddPixels(IEnumerable points) { foreach (var p in points) chart.Series[0].Points.AddXY(p.X, p.Y); } private void ConfigureChart() { chart.ChartAreas[0].Axes[0].Title = Content.XAxisName; chart.ChartAreas[0].Axes[1].Title = Content.YAxisName; chart.Titles.Clear(); Title t = chart.Titles.Add(Content.Name); t.Font = new System.Drawing.Font(t.Font.FontFamily, 10, FontStyle.Bold); } private void UpdateBitmap() { chart.Series.Clear(); var series1 = new Series("Series1") { ChartArea = "ChartArea1", ChartType = SeriesChartType.FastPoint, EmptyPointStyle = {BackGradientStyle = GradientStyle.LeftRight}, MarkerSize = 3, MarkerStyle = MarkerStyle.Circle, }; chart.Series.Add(series1); ConfigureChart(); var points = Content.Points.ToArray(); correlationLabel.Text = alglib.basestat.pearsoncorrelation(points.Select(x => (double)x.X).ToArray(), points.Select(x => (double)x.Y).ToArray(), points.Length).ToString(); foreach (var p in points) { chart.Series[0].Points.AddXY(p.X, p.Y); } } private void ScatterPlotView_DragEnter(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("HeuristicLab")) e.Effect = DragDropEffects.Copy; else e.Effect = DragDropEffects.None; } private void ScatterPlotView_DragDrop(object sender, DragEventArgs e) { ConfigureChart(); ScatterPlot sp = (ScatterPlot)e.Data.GetData("HeuristicLab"); AddPixels(sp.Points); } private void calcPearsonButton_Click(object sender, EventArgs e) { correlationLabel.Text = alglib.basestat.pearsoncorrelation(chart.Series[0].Points.Select(x => x.XValue).ToArray(), chart.Series[0].Points.Select(x => x.YValues[0]).ToArray(), chart.Series[0].Points.Count).ToString(); } } }