Changeset 8280 for trunk/sources/HeuristicLab.Analysis.Views
- Timestamp:
- 07/11/12 00:25:26 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Analysis.Views/3.3
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Analysis.Views/3.3/DataTableVisualPropertiesControl.cs
r7259 r8280 26 26 27 27 namespace HeuristicLab.Analysis.Views { 28 [View("Data RowVisual Properties")]28 [View("DataTable Visual Properties")] 29 29 public partial class DataTableVisualPropertiesControl : UserControl { 30 30 protected bool SuppressEvents { get; set; } -
trunk/sources/HeuristicLab.Analysis.Views/3.3/HeuristicLab.Analysis.Views-3.3.csproj
r7978 r8280 122 122 <DependentUpon>ScatterPlotView.cs</DependentUpon> 123 123 </Compile> 124 <Compile Include="ScatterPlotHistoryView.cs"> 125 <SubType>UserControl</SubType> 126 </Compile> 127 <Compile Include="ScatterPlotHistoryView.Designer.cs"> 128 <DependentUpon>ScatterPlotHistoryView.cs</DependentUpon> 129 </Compile> 124 130 <None Include="Plugin.cs.frame" /> 125 131 <Compile Include="AlleleFrequencyCollectionView.cs"> -
trunk/sources/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.Designer.cs
r7829 r8280 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 22 22 namespace HeuristicLab.Analysis.Views { 23 23 partial class ScatterPlotView { 24 /// <summary> 24 /// <summary> 25 25 /// Required designer variable. 26 26 /// </summary> 27 27 private System.ComponentModel.IContainer components = null; 28 28 29 /// <summary> 29 /// <summary> 30 30 /// Clean up any resources being used. 31 31 /// </summary> 32 32 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> 33 33 protected override void Dispose(bool disposing) { 34 if (disposing && (components != null)) {35 components.Dispose();34 if (disposing) { 35 if (components != null) components.Dispose(); 36 36 } 37 37 base.Dispose(disposing); 38 38 } 39 39 40 #region Windows FormDesigner generated code40 #region Component Designer generated code 41 41 42 /// <summary> 43 /// Required method for Designer support - do not modify 42 /// <summary> 43 /// Required method for Designer support - do not modify 44 44 /// the contents of this method with the code editor. 45 45 /// </summary> 46 46 private void InitializeComponent() { 47 47 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea1 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 48 System.Windows.Forms.DataVisualization.Charting.Legend legend1 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 48 49 System.Windows.Forms.DataVisualization.Charting.Series series1 = new System.Windows.Forms.DataVisualization.Charting.Series(); 49 50 System.Windows.Forms.DataVisualization.Charting.Title title1 = new System.Windows.Forms.DataVisualization.Charting.Title(); … … 57 58 this.errorProvider.SetIconAlignment(this.nameTextBox, System.Windows.Forms.ErrorIconAlignment.MiddleLeft); 58 59 this.errorProvider.SetIconPadding(this.nameTextBox, 2); 59 this.nameTextBox.Size = new System.Drawing.Size(596, 20); 60 this.nameTextBox.Location = new System.Drawing.Point(55, 0); 61 this.nameTextBox.Size = new System.Drawing.Size(279, 20); 62 // 63 // infoLabel 64 // 65 this.infoLabel.Location = new System.Drawing.Point(340, 3); 60 66 // 61 67 // chart 62 68 // 63 this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 64 | System.Windows.Forms.AnchorStyles.Left) 65 | System.Windows.Forms.AnchorStyles.Right))); 66 chartArea1.Name = "ChartArea1"; 69 this.chart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 70 | System.Windows.Forms.AnchorStyles.Left) 71 | System.Windows.Forms.AnchorStyles.Right))); 72 this.chart.BorderlineColor = System.Drawing.Color.Black; 73 this.chart.BorderlineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Solid; 74 chartArea1.AxisX.Minimum = 0D; 75 chartArea1.CursorX.IsUserEnabled = true; 76 chartArea1.CursorX.IsUserSelectionEnabled = true; 77 chartArea1.CursorY.IsUserEnabled = true; 78 chartArea1.CursorY.IsUserSelectionEnabled = true; 79 chartArea1.Name = "Default"; 67 80 this.chart.ChartAreas.Add(chartArea1); 81 legend1.Alignment = System.Drawing.StringAlignment.Center; 82 legend1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 83 legend1.Name = "Default"; 84 this.chart.Legends.Add(legend1); 68 85 this.chart.Location = new System.Drawing.Point(0, 26); 69 86 this.chart.Name = "chart"; 70 series1.ChartArea = "ChartArea1"; 71 series1.ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastPoint; 72 series1.EmptyPointStyle.BackGradientStyle = System.Windows.Forms.DataVisualization.Charting.GradientStyle.LeftRight; 73 series1.MarkerSize = 3; 74 series1.MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Circle; 75 series1.Name = "Series1"; 87 series1.ChartArea = "Default"; 88 series1.Legend = "Default"; 89 series1.Name = "Default"; 76 90 this.chart.Series.Add(series1); 77 this.chart.Size = new System.Drawing.Size(668, 378); 78 this.chart.TabIndex = 5; 79 title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 80 title1.Name = "Title1"; 81 title1.Text = "Scatter Plot"; 91 this.chart.Size = new System.Drawing.Size(359, 248); 92 this.chart.TabIndex = 3; 93 this.chart.Text = "chart"; 94 title1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); 95 title1.Name = "Default"; 96 title1.Text = "Title"; 82 97 this.chart.Titles.Add(title1); 98 this.chart.CustomizeLegend += new System.EventHandler<System.Windows.Forms.DataVisualization.Charting.CustomizeLegendEventArgs>(this.chart_CustomizeLegend); 99 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 100 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 83 101 // 84 102 // ScatterPlotView 85 103 // 86 this.AllowDrop = true;87 104 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 105 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; 88 106 this.Controls.Add(this.chart); 89 107 this.Name = "ScatterPlotView"; 90 this.Size = new System.Drawing.Size( 668, 404);108 this.Size = new System.Drawing.Size(359, 274); 91 109 this.Controls.SetChildIndex(this.infoLabel, 0); 92 110 this.Controls.SetChildIndex(this.chart, 0); … … 102 120 #endregion 103 121 104 private HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart; 122 protected HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart chart; 123 105 124 } 106 125 } -
trunk/sources/HeuristicLab.Analysis.Views/3.3/ScatterPlotView.cs
r7829 r8280 1 #region License Information1 #region License Information 2 2 /* HeuristicLab 3 3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) … … 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Drawing; 25 using System.Linq; 24 26 using System.Windows.Forms; 27 using System.Windows.Forms.DataVisualization.Charting; 25 28 using HeuristicLab.Collections; 29 using HeuristicLab.Common; 26 30 using HeuristicLab.Core.Views; 27 31 using HeuristicLab.MainForm; … … 30 34 [View("ScatterPlot View")] 31 35 [Content(typeof(ScatterPlot), true)] 32 public partial class ScatterPlotView : NamedItemView { 36 public partial class ScatterPlotView : NamedItemView, IConfigureableView { 37 protected List<Series> invisibleSeries; 38 protected Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow> pointsRowsTable; 39 33 40 public new ScatterPlot Content { 34 41 get { return (ScatterPlot)base.Content; } … … 38 45 public ScatterPlotView() { 39 46 InitializeComponent(); 47 pointsRowsTable = new Dictionary<IObservableList<Point2D<double>>, ScatterPlotDataRow>(); 48 invisibleSeries = new List<Series>(); 40 49 chart.CustomizeAllChartAreas(); 41 } 42 50 chart.ChartAreas[0].CursorX.Interval = 1; 51 } 52 53 #region Event Handler Registration 43 54 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); 55 foreach (ScatterPlotDataRow row in Content.Rows) 56 DeregisterScatterPlotDataRowEvents(row); 57 Content.VisualPropertiesChanged -= new EventHandler(Content_VisualPropertiesChanged); 58 Content.Rows.ItemsAdded -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded); 59 Content.Rows.ItemsRemoved -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved); 60 Content.Rows.ItemsReplaced -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced); 61 Content.Rows.CollectionReset -= new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset); 49 62 base.DeregisterContentEvents(); 50 63 } 51 52 64 protected override void RegisterContentEvents() { 53 65 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 } 66 Content.VisualPropertiesChanged += new EventHandler(Content_VisualPropertiesChanged); 67 Content.Rows.ItemsAdded += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded); 68 Content.Rows.ItemsRemoved += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved); 69 Content.Rows.ItemsReplaced += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced); 70 Content.Rows.CollectionReset += new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset); 71 } 72 73 protected virtual void RegisterScatterPlotDataRowEvents(ScatterPlotDataRow row) { 74 row.NameChanged += new EventHandler(Row_NameChanged); 75 row.VisualPropertiesChanged += new EventHandler(Row_VisualPropertiesChanged); 76 pointsRowsTable.Add(row.Points, row); 77 row.Points.ItemsAdded += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded); 78 row.Points.ItemsRemoved += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved); 79 row.Points.ItemsReplaced += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced); 80 row.Points.CollectionReset += new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset); 81 } 82 protected virtual void DeregisterScatterPlotDataRowEvents(ScatterPlotDataRow row) { 83 row.Points.ItemsAdded -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded); 84 row.Points.ItemsRemoved -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved); 85 row.Points.ItemsReplaced -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced); 86 row.Points.CollectionReset -= new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset); 87 pointsRowsTable.Remove(row.Points); 88 row.VisualPropertiesChanged -= new EventHandler(Row_VisualPropertiesChanged); 89 row.NameChanged -= new EventHandler(Row_NameChanged); 90 } 91 #endregion 64 92 65 93 protected override void OnContentChanged() { 66 94 base.OnContentChanged(); 95 invisibleSeries.Clear(); 96 chart.Titles[0].Text = string.Empty; 97 chart.ChartAreas[0].AxisX.Title = string.Empty; 98 chart.ChartAreas[0].AxisY.Title = string.Empty; 99 chart.Series.Clear(); 67 100 if (Content != null) { 68 ConfigureChart(); 69 RedrawChart(); 101 chart.Titles[0].Text = Content.Name; 102 AddScatterPlotDataRows(Content.Rows); 103 ConfigureChartArea(chart.ChartAreas[0]); 104 RecalculateAxesScale(chart.ChartAreas[0]); 105 } 106 } 107 108 protected override void SetEnabledStateOfControls() { 109 base.SetEnabledStateOfControls(); 110 chart.Enabled = Content != null; 111 } 112 113 public void ShowConfiguration() { 114 //if (Content != null) { 115 // using (ScatterPlotVisualPropertiesDialog dialog = new ScatterPlotVisualPropertiesDialog(Content)) { 116 // dialog.ShowDialog(this); 117 // } 118 //} else MessageBox.Show("Nothing to configure."); 119 } 120 protected virtual void AddScatterPlotDataRows(IEnumerable<ScatterPlotDataRow> rows) { 121 foreach (var row in rows) { 122 RegisterScatterPlotDataRowEvents(row); 123 Series series = new Series(row.Name); 124 if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName; 125 else series.LegendText = row.Name; 126 ConfigureSeries(series, row); 127 FillSeriesWithRowValues(series, row); 128 chart.Series.Add(series); 129 } 130 ConfigureChartArea(chart.ChartAreas[0]); 131 RecalculateAxesScale(chart.ChartAreas[0]); 132 UpdateYCursorInterval(); 133 } 134 135 protected virtual void RemoveScatterPlotDataRows(IEnumerable<ScatterPlotDataRow> rows) { 136 foreach (var row in rows) { 137 DeregisterScatterPlotDataRowEvents(row); 138 Series series = chart.Series[row.Name]; 139 chart.Series.Remove(series); 140 if (invisibleSeries.Contains(series)) 141 invisibleSeries.Remove(series); 142 } 143 RecalculateAxesScale(chart.ChartAreas[0]); 144 } 145 146 private void ConfigureSeries(Series series, ScatterPlotDataRow row) { 147 series.BorderWidth = 1; 148 series.BorderDashStyle = ChartDashStyle.Solid; 149 series.BorderColor = Color.Empty; 150 151 if (row.VisualProperties.Color != Color.Empty) 152 series.Color = row.VisualProperties.Color; 153 else series.Color = Color.Empty; 154 series.IsVisibleInLegend = row.VisualProperties.IsVisibleInLegend; 155 series.ChartType = SeriesChartType.FastPoint; 156 series.MarkerSize = row.VisualProperties.PointSize; 157 series.MarkerStyle = ConvertPointStyle(row.VisualProperties.PointStyle); 158 series.XAxisType = AxisType.Primary; 159 series.YAxisType = AxisType.Primary; 160 161 if (row.VisualProperties.DisplayName.Trim() != String.Empty) series.LegendText = row.VisualProperties.DisplayName; 162 else series.LegendText = row.Name; 163 164 string xAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.XAxisTitle) 165 ? "X" 166 : Content.VisualProperties.XAxisTitle; 167 string yAxisTitle = string.IsNullOrEmpty(Content.VisualProperties.YAxisTitle) 168 ? "Y" 169 : Content.VisualProperties.YAxisTitle; 170 series.ToolTip = 171 series.LegendText + Environment.NewLine + 172 xAxisTitle + " = " + "#VALX," + Environment.NewLine + 173 yAxisTitle + " = " + "#VAL"; 174 } 175 176 private void ConfigureChartArea(ChartArea area) { 177 if (Content.VisualProperties.TitleFont != null) chart.Titles[0].Font = Content.VisualProperties.TitleFont; 178 if (!Content.VisualProperties.TitleColor.IsEmpty) chart.Titles[0].ForeColor = Content.VisualProperties.TitleColor; 179 chart.Titles[0].Text = Content.VisualProperties.Title; 180 181 if (Content.VisualProperties.AxisTitleFont != null) area.AxisX.TitleFont = Content.VisualProperties.AxisTitleFont; 182 if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisX.TitleForeColor = Content.VisualProperties.AxisTitleColor; 183 area.AxisX.Title = Content.VisualProperties.XAxisTitle; 184 185 if (Content.VisualProperties.AxisTitleFont != null) area.AxisY.TitleFont = Content.VisualProperties.AxisTitleFont; 186 if (!Content.VisualProperties.AxisTitleColor.IsEmpty) area.AxisY.TitleForeColor = Content.VisualProperties.AxisTitleColor; 187 area.AxisY.Title = Content.VisualProperties.YAxisTitle; 188 } 189 190 private void RecalculateAxesScale(ChartArea area) { 191 // Reset the axes bounds so that RecalculateAxesScale() will assign new bounds 192 foreach (Axis a in area.Axes) { 193 a.Minimum = double.NaN; 194 a.Maximum = double.NaN; 195 } 196 area.RecalculateAxesScale(); 197 area.AxisX.IsMarginVisible = false; 198 199 if (!Content.VisualProperties.XAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.XAxisMinimumFixedValue)) area.AxisX.Minimum = Content.VisualProperties.XAxisMinimumFixedValue; 200 if (!Content.VisualProperties.XAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.XAxisMaximumFixedValue)) area.AxisX.Maximum = Content.VisualProperties.XAxisMaximumFixedValue; 201 if (!Content.VisualProperties.YAxisMinimumAuto && !double.IsNaN(Content.VisualProperties.YAxisMinimumFixedValue)) area.AxisY.Minimum = Content.VisualProperties.YAxisMinimumFixedValue; 202 if (!Content.VisualProperties.YAxisMaximumAuto && !double.IsNaN(Content.VisualProperties.YAxisMaximumFixedValue)) area.AxisY.Maximum = Content.VisualProperties.YAxisMaximumFixedValue; 203 if (area.AxisX.Minimum >= area.AxisX.Maximum) area.AxisX.Maximum = area.AxisX.Minimum + 1; 204 if (area.AxisY.Minimum >= area.AxisY.Maximum) area.AxisY.Maximum = area.AxisY.Minimum + 1; 205 } 206 207 protected virtual void UpdateYCursorInterval() { 208 double interestingValuesRange = ( 209 from series in chart.Series 210 where series.Enabled 211 let values = (from point in series.Points 212 where !point.IsEmpty 213 select point.YValues[0]).DefaultIfEmpty(1.0) 214 let range = values.Max() - values.Min() 215 where range > 0.0 216 select range 217 ).DefaultIfEmpty(1.0).Min(); 218 219 double digits = (int)Math.Log10(interestingValuesRange) - 3; 220 double yZoomInterval = Math.Pow(10, digits); 221 this.chart.ChartAreas[0].CursorY.Interval = yZoomInterval; 222 } 223 224 #region Event Handlers 225 #region Content Event Handlers 226 protected override void Content_NameChanged(object sender, EventArgs e) { 227 if (InvokeRequired) 228 Invoke(new EventHandler(Content_NameChanged), sender, e); 229 else { 230 chart.Titles[0].Text = Content.Name; 231 base.Content_NameChanged(sender, e); 232 } 233 } 234 private void Content_VisualPropertiesChanged(object sender, EventArgs e) { 235 if (InvokeRequired) 236 Invoke(new EventHandler(Content_VisualPropertiesChanged), sender, e); 237 else { 238 ConfigureChartArea(chart.ChartAreas[0]); 239 RecalculateAxesScale(chart.ChartAreas[0]); // axes min/max could have changed 240 } 241 } 242 #endregion 243 #region Rows Event Handlers 244 private void Rows_ItemsAdded(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 245 if (InvokeRequired) 246 Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsAdded), sender, e); 247 else { 248 AddScatterPlotDataRows(e.Items); 249 } 250 } 251 private void Rows_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 252 if (InvokeRequired) 253 Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsRemoved), sender, e); 254 else { 255 RemoveScatterPlotDataRows(e.Items); 256 } 257 } 258 private void Rows_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 259 if (InvokeRequired) 260 Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_ItemsReplaced), sender, e); 261 else { 262 RemoveScatterPlotDataRows(e.OldItems); 263 AddScatterPlotDataRows(e.Items); 264 } 265 } 266 private void Rows_CollectionReset(object sender, CollectionItemsChangedEventArgs<ScatterPlotDataRow> e) { 267 if (InvokeRequired) 268 Invoke(new CollectionItemsChangedEventHandler<ScatterPlotDataRow>(Rows_CollectionReset), sender, e); 269 else { 270 RemoveScatterPlotDataRows(e.OldItems); 271 AddScatterPlotDataRows(e.Items); 272 } 273 } 274 #endregion 275 #region Row Event Handlers 276 private void Row_VisualPropertiesChanged(object sender, EventArgs e) { 277 if (InvokeRequired) 278 Invoke(new EventHandler(Row_VisualPropertiesChanged), sender, e); 279 else { 280 ScatterPlotDataRow row = (ScatterPlotDataRow)sender; 281 Series series = chart.Series[row.Name]; 282 series.Points.Clear(); 283 ConfigureSeries(series, row); 284 FillSeriesWithRowValues(series, row); 285 RecalculateAxesScale(chart.ChartAreas[0]); 286 } 287 } 288 private void Row_NameChanged(object sender, EventArgs e) { 289 if (InvokeRequired) 290 Invoke(new EventHandler(Row_NameChanged), sender, e); 291 else { 292 ScatterPlotDataRow row = (ScatterPlotDataRow)sender; 293 chart.Series[row.Name].Name = row.Name; 294 } 295 } 296 #endregion 297 #region Points Event Handlers 298 private void Points_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 299 if (InvokeRequired) 300 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsAdded), sender, e); 301 else { 302 ScatterPlotDataRow row = null; 303 pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row); 304 if (row != null) { 305 Series rowSeries = chart.Series[row.Name]; 306 if (!invisibleSeries.Contains(rowSeries)) { 307 rowSeries.Points.Clear(); 308 FillSeriesWithRowValues(rowSeries, row); 309 RecalculateAxesScale(chart.ChartAreas[0]); 310 UpdateYCursorInterval(); 311 } 312 } 313 } 314 } 315 private void Points_ItemsRemoved(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 316 if (InvokeRequired) 317 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsRemoved), sender, e); 318 else { 319 ScatterPlotDataRow row = null; 320 pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row); 321 if (row != null) { 322 Series rowSeries = chart.Series[row.Name]; 323 if (!invisibleSeries.Contains(rowSeries)) { 324 rowSeries.Points.Clear(); 325 FillSeriesWithRowValues(rowSeries, row); 326 RecalculateAxesScale(chart.ChartAreas[0]); 327 UpdateYCursorInterval(); 328 } 329 } 330 } 331 } 332 private void Points_ItemsReplaced(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 333 if (InvokeRequired) 334 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_ItemsReplaced), sender, e); 335 else { 336 ScatterPlotDataRow row = null; 337 pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row); 338 if (row != null) { 339 Series rowSeries = chart.Series[row.Name]; 340 if (!invisibleSeries.Contains(rowSeries)) { 341 rowSeries.Points.Clear(); 342 FillSeriesWithRowValues(rowSeries, row); 343 RecalculateAxesScale(chart.ChartAreas[0]); 344 UpdateYCursorInterval(); 345 } 346 } 347 } 348 } 349 private void Points_CollectionReset(object sender, CollectionItemsChangedEventArgs<IndexedItem<Point2D<double>>> e) { 350 if (InvokeRequired) 351 Invoke(new CollectionItemsChangedEventHandler<IndexedItem<Point2D<double>>>(Points_CollectionReset), sender, e); 352 else { 353 ScatterPlotDataRow row = null; 354 pointsRowsTable.TryGetValue((IObservableList<Point2D<double>>)sender, out row); 355 if (row != null) { 356 Series rowSeries = chart.Series[row.Name]; 357 if (!invisibleSeries.Contains(rowSeries)) { 358 rowSeries.Points.Clear(); 359 FillSeriesWithRowValues(rowSeries, row); 360 RecalculateAxesScale(chart.ChartAreas[0]); 361 UpdateYCursorInterval(); 362 } 363 } 364 } 365 } 366 #endregion 367 #endregion 368 369 #region Chart Event Handlers 370 private void chart_MouseDown(object sender, MouseEventArgs e) { 371 HitTestResult result = chart.HitTest(e.X, e.Y); 372 if (result.ChartElementType == ChartElementType.LegendItem) { 373 ToggleSeriesVisible(result.Series); 374 } 375 } 376 private void chart_MouseMove(object sender, MouseEventArgs e) { 377 HitTestResult result = chart.HitTest(e.X, e.Y); 378 if (result.ChartElementType == ChartElementType.LegendItem) 379 this.Cursor = Cursors.Hand; 380 else 381 this.Cursor = Cursors.Default; 382 } 383 private void chart_CustomizeLegend(object sender, CustomizeLegendEventArgs e) { 384 foreach (LegendItem legendItem in e.LegendItems) { 385 var series = chart.Series[legendItem.SeriesName]; 386 if (series != null) { 387 bool seriesIsInvisible = invisibleSeries.Contains(series); 388 foreach (LegendCell cell in legendItem.Cells) { 389 cell.ForeColor = seriesIsInvisible ? Color.Gray : Color.Black; 390 } 391 } 392 } 393 } 394 #endregion 395 396 private void ToggleSeriesVisible(Series series) { 397 if (!invisibleSeries.Contains(series)) { 398 series.Points.Clear(); 399 invisibleSeries.Add(series); 70 400 } 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 } 401 invisibleSeries.Remove(series); 402 if (Content != null) { 403 404 var row = (from r in Content.Rows 405 where r.Name == series.Name 406 select r).Single(); 407 FillSeriesWithRowValues(series, row); 408 this.chart.Legends[series.Legend].ForeColor = Color.Black; 409 RecalculateAxesScale(chart.ChartAreas[0]); 410 UpdateYCursorInterval(); 411 } 412 } 413 } 414 415 private void FillSeriesWithRowValues(Series series, ScatterPlotDataRow row) { 416 for (int i = 0; i < row.Points.Count; i++) { 417 var value = row.Points[i]; 418 DataPoint point = new DataPoint(); 419 if (IsInvalidValue(value.X) || IsInvalidValue(value.Y)) 420 point.IsEmpty = true; 421 else { 422 point.XValue = value.X; 423 point.YValues = new double[] { value.Y }; 424 } 425 series.Points.Add(point); 426 } 427 } 428 429 #region Helpers 430 public static IEnumerable<double> DoubleRange(double min, double max, double step) { 431 double i; 432 for (i = min; i <= max; i += step) 433 yield return i; 434 435 if (i != max + step) 436 yield return i; 437 } 438 439 private double HumanRoundRange(double range) { 440 double base10 = Math.Pow(10.0, Math.Floor(Math.Log10(range))); 441 double rounding = range / base10; 442 if (rounding <= 1.5) rounding = 1; 443 else if (rounding <= 2.25) rounding = 2; 444 else if (rounding <= 3.75) rounding = 2.5; 445 else if (rounding <= 7.5) rounding = 5; 446 else rounding = 10; 447 return rounding * base10; 448 } 449 450 private double HumanRoundMax(double max) { 451 double base10; 452 if (max > 0) base10 = Math.Pow(10.0, Math.Floor(Math.Log10(max))); 453 else base10 = Math.Pow(10.0, Math.Ceiling(Math.Log10(-max))); 454 double rounding = (max > 0) ? base10 : -base10; 455 while (rounding < max) rounding += base10; 456 return rounding; 457 } 458 459 private MarkerStyle ConvertPointStyle(ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle pointStyle) { 460 switch (pointStyle) { 461 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Circle: 462 return MarkerStyle.Circle; 463 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Cross: 464 return MarkerStyle.Cross; 465 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Diamond: 466 return MarkerStyle.Diamond; 467 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Square: 468 return MarkerStyle.Square; 469 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star4: 470 return MarkerStyle.Star4; 471 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star5: 472 return MarkerStyle.Star5; 473 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star6: 474 return MarkerStyle.Star6; 475 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Star10: 476 return MarkerStyle.Star10; 477 case ScatterPlotDataRowVisualProperties.ScatterPlotDataRowPointStyle.Triangle: 478 return MarkerStyle.Triangle; 479 default: 480 return MarkerStyle.None; 481 } 482 } 483 484 protected static bool IsInvalidValue(double x) { 485 return double.IsNaN(x) || x < (double)decimal.MinValue || x > (double)decimal.MaxValue; 486 } 487 #endregion 112 488 } 113 489 }
Note: See TracChangeset
for help on using the changeset viewer.