- Timestamp:
- 04/19/10 17:13:02 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization.Views/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.Designer.cs
r3349 r3411 79 79 this.xTrackBar.TabIndex = 11; 80 80 this.xTrackBar.TickStyle = System.Windows.Forms.TickStyle.None; 81 this.xTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged); 81 82 // 82 83 // xAxisLabel … … 133 134 this.yTrackBar.TabIndex = 10; 134 135 this.yTrackBar.TickStyle = System.Windows.Forms.TickStyle.None; 136 this.yTrackBar.ValueChanged += new System.EventHandler(this.jitterTrackBar_ValueChanged); 135 137 // 136 138 // sizeComboBox … … 144 146 this.sizeComboBox.Size = new System.Drawing.Size(121, 21); 145 147 this.sizeComboBox.TabIndex = 14; 148 this.sizeComboBox.SelectedIndexChanged += new System.EventHandler(this.AxisComboBox_SelectedIndexChanged); 146 149 // 147 150 // sizeLabel … … 176 179 this.chart.TabIndex = 16; 177 180 this.chart.Text = "chart1"; 181 this.chart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 182 this.chart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 183 this.chart.LostFocus += new System.EventHandler(this.chart_LostFocus); 178 184 // 179 185 // zoomButton … … 189 195 this.zoomButton.Text = "Zoom"; 190 196 this.zoomButton.UseVisualStyleBackColor = true; 197 this.zoomButton.CheckedChanged += new System.EventHandler(this.zoomButton_CheckedChanged); 191 198 // 192 199 // selectButton … … 224 231 this.colorButton.TextAlign = System.Drawing.ContentAlignment.MiddleRight; 225 232 this.colorButton.UseVisualStyleBackColor = true; 233 this.colorButton.Click += new System.EventHandler(this.colorButton_Click); 226 234 // 227 235 // colorDialog -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionBubbleChartView.cs
r3376 r3411 38 38 [Content(typeof(RunCollection), false)] 39 39 public partial class RunCollectionBubbleChartView : AsynchronousContentView { 40 private const string constantLabel = "constant"; 40 41 private Dictionary<int, Dictionary<object, double>> categoricalMapping; 42 private Dictionary<IRun, double> xJitter; 43 private Dictionary<IRun, double> yJitter; 44 private double xJitterFactor = 0.0; 45 private double yJitterFactor = 0.0; 46 private Random random; 47 private bool isSelecting = false; 41 48 42 49 public RunCollectionBubbleChartView() { 43 50 InitializeComponent(); 44 51 Caption = "Run Collection Bubble Chart"; 52 45 53 this.categoricalMapping = new Dictionary<int, Dictionary<object, double>>(); 54 this.xJitter = new Dictionary<IRun, double>(); 55 this.yJitter = new Dictionary<IRun, double>(); 56 this.random = new Random(); 57 58 this.chart.Series[0]["BubbleMaxSize"] = "0"; 59 this.chart.Series[0]["BubbleMaxScale"] = "Auto"; 60 this.chart.Series[0]["BubbleMinScale"] = "Auto"; 61 this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 62 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 63 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !this.isSelecting; 64 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !this.isSelecting; 65 this.chart.ChartAreas[0].CursorX.Interval = 0; 66 this.chart.ChartAreas[0].CursorY.Interval = 0; 67 46 68 base.ReadOnly = true; 47 69 } … … 66 88 Content.ColumnNamesChanged += new EventHandler(Content_ColumnNamesChanged); 67 89 } 68 69 90 protected override void DeregisterContentEvents() { 70 91 base.DeregisterContentEvents(); … … 72 93 Content.ColumnNamesChanged -= new EventHandler(Content_ColumnNamesChanged); 73 94 } 74 75 95 protected override void OnContentChanged() { 76 96 base.OnContentChanged(); 97 this.categoricalMapping.Clear(); 77 98 this.UpdateComboBoxes(); 78 99 } … … 88 109 this.xAxisComboBox.Items.Clear(); 89 110 this.yAxisComboBox.Items.Clear(); 111 this.sizeComboBox.Items.Clear(); 90 112 this.xAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray()); 91 113 this.yAxisComboBox.Items.AddRange(Content.ColumnNames.ToArray()); 114 this.sizeComboBox.Items.Add(constantLabel); 115 this.sizeComboBox.Items.AddRange(Content.ColumnNames.ToArray()); 92 116 } 93 117 … … 107 131 double? xValue; 108 132 double? yValue; 133 double? sizeValue; 109 134 for (int row = 0; row < Content.Count; row++) { 110 135 xValue = GetValue(row, xAxisComboBox.SelectedIndex); 111 136 yValue = GetValue(row, yAxisComboBox.SelectedIndex); 112 if (xValue.HasValue && yValue.HasValue) 113 series.Points.Add(new DataPoint(xValue.Value, yValue.Value)); 114 } 115 } 116 117 private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) { 118 UpdateDataPoints(); 119 UpdateAxisLabels(); 120 } 121 137 sizeValue = 1.0; 138 if (xValue.HasValue && yValue.HasValue) { 139 if (sizeComboBox.SelectedIndex > 0) 140 sizeValue = GetValue(row, sizeComboBox.SelectedIndex-1); 141 xValue = xValue.Value + xValue.Value * GetXJitter(Content.ElementAt(row)) * xJitterFactor; 142 yValue = yValue.Value + yValue.Value * GetYJitter(Content.ElementAt(row)) * yJitterFactor; 143 DataPoint point = new DataPoint(xValue.Value, new double[] { yValue.Value, sizeValue.Value }); 144 point.ToolTip = this.CreateTooltip(row); 145 point.Tag = this.Content.ElementAt(row); 146 series.Points.Add(point); 147 } 148 } 149 } 122 150 private double? GetValue(int row, int column) { 123 151 if (column < 0 || row < 0) … … 145 173 } 146 174 175 #region drag and drop 176 private IRun draggedRun; 177 private bool isDragOperationInProgress = false; 178 179 private void chart_MouseDown(object sender, MouseEventArgs e) { 180 HitTestResult h = this.chart.HitTest(e.X, e.Y); 181 if (h.ChartElementType == ChartElementType.DataPoint) { 182 this.draggedRun = (IRun)((DataPoint)h.Object).Tag; 183 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = false; 184 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = false; 185 this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = false; 186 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = false; 187 } 188 } 189 190 private void chart_MouseMove(object sender, MouseEventArgs e) { 191 HitTestResult h = this.chart.HitTest(e.X, e.Y); 192 if (this.draggedRun != null && h.ChartElementType != ChartElementType.DataPoint) { 193 //this.isDragOperationInProgress = true; 194 DataObject data = new DataObject(); 195 data.SetData("Type", draggedRun.GetType()); 196 data.SetData("Value", draggedRun); 197 if (ReadOnly) { 198 DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link); 199 } else { 200 DragDropEffects result = DoDragDrop(data, DragDropEffects.Copy | DragDropEffects.Link | DragDropEffects.Move); 201 if ((result & DragDropEffects.Move) == DragDropEffects.Move) 202 Content.Remove(draggedRun); 203 } 204 this.draggedRun = null; 205 } 206 } 207 private void chart_LostFocus(object sender, EventArgs e) { 208 if (this.isDragOperationInProgress) { 209 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting; 210 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting; 211 this.chart.ChartAreas[0].CursorX.SetSelectionPosition(0, 0); 212 this.chart.ChartAreas[0].CursorY.SetSelectionPosition(0, 0); 213 this.chart.ChartAreas[0].CursorX.IsUserSelectionEnabled = true; 214 this.chart.ChartAreas[0].CursorY.IsUserSelectionEnabled = true; 215 this.isDragOperationInProgress = false; 216 } 217 } 218 #endregion 219 220 #region GUI events and updating 221 private double GetXJitter(IRun run) { 222 if (!this.xJitter.ContainsKey(run)) 223 this.xJitter[run] = random.NextDouble() * 2.0 - 1.0; 224 return this.xJitter[run]; 225 } 226 private double GetYJitter(IRun run) { 227 if (!this.yJitter.ContainsKey(run)) 228 this.yJitter[run] = random.NextDouble() * 2.0 - 1.0; 229 return this.yJitter[run]; 230 } 231 private void jitterTrackBar_ValueChanged(object sender, EventArgs e) { 232 this.xJitterFactor = xTrackBar.Value / 100.0; 233 this.yJitterFactor = yTrackBar.Value / 100.0; 234 this.UpdateDataPoints(); 235 } 236 237 private void AxisComboBox_SelectedIndexChanged(object sender, EventArgs e) { 238 UpdateDataPoints(); 239 UpdateAxisLabels(); 240 } 147 241 private void UpdateAxisLabels() { 148 242 Axis xAxis = this.chart.ChartAreas[0].AxisX; 149 243 Axis yAxis = this.chart.ChartAreas[0].AxisY; 150 SetAxisLabels(xAxis, xAxisComboBox.SelectedIndex); 151 SetAxisLabels(yAxis, yAxisComboBox.SelectedIndex); 152 } 153 private void SetAxisLabels(Axis axis, int dimension) { 244 SetCustomAxisLabels(xAxis, xAxisComboBox.SelectedIndex); 245 SetCustomAxisLabels(yAxis, yAxisComboBox.SelectedIndex); 246 } 247 private void SetCustomAxisLabels(Axis axis, int dimension) { 248 axis.CustomLabels.Clear(); 154 249 if (categoricalMapping.ContainsKey(dimension)) { 155 axis.CustomLabels.Clear();156 250 CustomLabel label = null; 157 251 foreach (var pair in categoricalMapping[dimension]) { … … 165 259 } 166 260 } 261 262 private string CreateTooltip(int runIndex) { 263 StringBuilder builder = new StringBuilder(); 264 builder.AppendLine(this.Content.ElementAt(runIndex).Name); 265 int columnIndex = 0; 266 foreach (string columnName in this.Content.ColumnNames) { 267 builder.Append(columnName); 268 builder.Append(": "); 269 builder.AppendLine(this.Content.GetValue(runIndex, columnIndex)); 270 columnIndex++; 271 } 272 return builder.ToString(); 273 } 274 275 private void zoomButton_CheckedChanged(object sender, EventArgs e) { 276 this.isSelecting = selectButton.Checked; 277 this.colorButton.Enabled = this.isSelecting; 278 this.chart.ChartAreas[0].AxisX.ScaleView.Zoomable = !isSelecting; 279 this.chart.ChartAreas[0].AxisY.ScaleView.Zoomable = !isSelecting; 280 } 281 282 private void colorButton_Click(object sender, EventArgs e) { 283 if (colorDialog.ShowDialog(this) == DialogResult.OK) { 284 this.colorButton.Image = this.GenerateImage(16, 16, this.colorDialog.Color); 285 } 286 } 287 private Image GenerateImage(int width, int height, Color fillColor) { 288 Image colorImage = new Bitmap(width, height); 289 using (Graphics gfx = Graphics.FromImage(colorImage)) { 290 using (SolidBrush brush = new SolidBrush(fillColor)) { 291 gfx.FillRectangle(brush, 0, 0, width, height); 292 } 293 } 294 return colorImage; 295 } 296 #endregion 167 297 } 168 298 }
Note: See TracChangeset
for help on using the changeset viewer.