1 | using System;
|
---|
2 | using System.CodeDom.Compiler;
|
---|
3 | using System.Collections.Generic;
|
---|
4 | using System.ComponentModel;
|
---|
5 | using System.Drawing;
|
---|
6 | using System.Data;
|
---|
7 | using System.Linq;
|
---|
8 | using System.Runtime.CompilerServices;
|
---|
9 | using System.Runtime.InteropServices;
|
---|
10 | using System.Security.Permissions;
|
---|
11 | using System.Text;
|
---|
12 | using System.Text.RegularExpressions;
|
---|
13 | using System.Threading.Tasks;
|
---|
14 | using System.Windows.Forms;
|
---|
15 | using System.Windows.Forms.DataVisualization.Charting;
|
---|
16 | using HeuristicLab.BioBoost.Representation;
|
---|
17 | using HeuristicLab.Collections;
|
---|
18 | using HeuristicLab.Common;
|
---|
19 | using HeuristicLab.Core;
|
---|
20 | using HeuristicLab.Core.Views;
|
---|
21 | using HeuristicLab.MainForm;
|
---|
22 | using HeuristicLab.MainForm.WindowsForms;
|
---|
23 | using HeuristicLab.PluginInfrastructure;
|
---|
24 | using NetTopologySuite.Noding;
|
---|
25 |
|
---|
26 | namespace HeuristicLab.BioBoost.Views {
|
---|
27 |
|
---|
28 | [Content(typeof (ItemCollection<BioBoostCompoundSolution>), false)]
|
---|
29 | public partial class BioBoostParetoSetView : ItemView {
|
---|
30 |
|
---|
31 | private Point mouseDownPos;
|
---|
32 |
|
---|
33 | public new ItemCollection<BioBoostCompoundSolution> Content {
|
---|
34 | get { return (ItemCollection<BioBoostCompoundSolution>)base.Content; }
|
---|
35 | set { base.Content = value; }
|
---|
36 | }
|
---|
37 |
|
---|
38 | public BioBoostParetoSetView() {
|
---|
39 | InitializeComponent();
|
---|
40 | }
|
---|
41 |
|
---|
42 | protected override void RegisterContentEvents() {
|
---|
43 | base.RegisterContentEvents();
|
---|
44 | Content.ItemsAdded += UpdateChart;
|
---|
45 | Content.ItemsRemoved += UpdateChart;
|
---|
46 | Content.CollectionReset += UpdateChart;
|
---|
47 | }
|
---|
48 |
|
---|
49 | protected override void DeregisterContentEvents() {
|
---|
50 | base.DeregisterContentEvents();
|
---|
51 | Content.CollectionReset -= UpdateChart;
|
---|
52 | Content.ItemsRemoved -= UpdateChart;
|
---|
53 | Content.CollectionReset -= UpdateChart;
|
---|
54 | }
|
---|
55 |
|
---|
56 | protected override void OnContentChanged() {
|
---|
57 | base.OnContentChanged();
|
---|
58 | UpdateChart(this, EventArgs.Empty);
|
---|
59 | }
|
---|
60 |
|
---|
61 | protected virtual void UpdateChart(object sender, EventArgs args) {
|
---|
62 | if (InvokeRequired) {
|
---|
63 | Invoke(new EventHandler(UpdateChart), sender, args);
|
---|
64 | } else {
|
---|
65 | try {
|
---|
66 | if (paretoSetChart.IsDisposed) return;
|
---|
67 | var points = paretoSetChart.Series[0].Points;
|
---|
68 | if (Content == null) {
|
---|
69 | points.Clear();
|
---|
70 | return;
|
---|
71 | }
|
---|
72 | var newPoints = Content.Where(solution => solution.Qualities.Length >= 2).Select(s => new { x = s.Qualities[0], y = s.Qualities[1], solution = s}).ToList();
|
---|
73 | if (newPoints.Count > 0) {
|
---|
74 | var chartArea = paretoSetChart.ChartAreas[0];
|
---|
75 | AdaptAxis(chartArea.AxisX, newPoints.Select(p => p.x), 1);
|
---|
76 | AdaptAxis(chartArea.AxisY, newPoints.Select(p => p.y), 1);
|
---|
77 | paretoSetChart.BeginInit();
|
---|
78 | points.Clear();
|
---|
79 | foreach (var point in newPoints) {
|
---|
80 | points.Add(new DataPoint(point.x, point.y) {
|
---|
81 | Tag = point.solution,
|
---|
82 | });
|
---|
83 | }
|
---|
84 | paretoSetChart.EndInit();
|
---|
85 | }
|
---|
86 | } catch (Exception x) {
|
---|
87 | ErrorHandling.ShowErrorDialog(x);
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|
91 |
|
---|
92 | private void AdaptAxis(Axis axis, IEnumerable<double> values, int precision = 0, double overshot = 0.5, double margin = 0.25) {
|
---|
93 | var newMax = values.Max();
|
---|
94 | var newMin = values.Min();
|
---|
95 | var range = newMax - newMin;
|
---|
96 | newMax = newMax + range*margin;
|
---|
97 | newMin = newMin - range*margin;
|
---|
98 | if (range == 0) return;
|
---|
99 | var oldRange = axis.Maximum - axis.Minimum;
|
---|
100 | if (range*3 < oldRange) {
|
---|
101 | axis.Maximum = Math.Round(newMax+range*overshot, precision);
|
---|
102 | axis.Minimum = Math.Round(newMin-range*overshot , precision);
|
---|
103 | } else {
|
---|
104 | if (newMax > axis.Maximum) axis.Maximum = Math.Round(newMax+range*overshot, precision);
|
---|
105 | if (newMin < axis.Minimum) axis.Minimum = Math.Round(newMin-range*overshot, precision);
|
---|
106 | }
|
---|
107 | }
|
---|
108 |
|
---|
109 | private void paretoSetChart_MouseDown(object sender, MouseEventArgs e) { mouseDownPos = e.Location; }
|
---|
110 | private void paretoSetChart_DoubleClick(object sender, EventArgs e) {
|
---|
111 | var pos = mouseDownPos;
|
---|
112 | var result = paretoSetChart.HitTest(pos.X, pos.Y, ChartElementType.DataPoint);
|
---|
113 | var point = result.Object as DataPoint;
|
---|
114 | if (point != null && point.Tag is IContent)
|
---|
115 | MainFormManager.MainForm.ShowContent((IContent)point.Tag);
|
---|
116 | }
|
---|
117 |
|
---|
118 |
|
---|
119 | }
|
---|
120 | }
|
---|