Changeset 11202 for branches/HiveStatistics/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
- Timestamp:
- 07/18/14 12:01:13 (10 years ago)
- Location:
- branches/HiveStatistics/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HiveStatistics/sources
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
r7259 r11202 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 2Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using System.Drawing.Imaging; 26 26 using System.IO; 27 using System.Linq; 27 28 using System.Windows.Forms; 28 29 using System.Windows.Forms.DataVisualization.Charting; … … 58 59 else lengthUnitComboBox.SelectedIndex = 0; 59 60 60 titleFontSizeComboBox.Text = "1 2";61 titleFontSizeComboBox.Text = "10"; 61 62 axisFontSizeComboBox.Text = "8"; 62 63 scalesFontSizeComboBox.Text = "6"; 63 64 legendFontSizeComboBox.Text = "6"; 64 resolutionComboBox.Text = " 300";65 resolutionComboBox.Text = "150"; 65 66 SuppressEvents = false; 66 67 splitContainer.Panel2Collapsed = true; 67 68 Width = 305; 68 Height = 550; 69 } finally { SuppressEvents = false; } 69 Height = 625; 70 } 71 finally { SuppressEvents = false; } 70 72 #endregion 71 73 } 72 74 73 75 private void UpdateFields() { 74 ChartAreaarea = GetCurrentChartArea();76 var area = GetCurrentChartArea(); 75 77 76 78 try { 77 79 SuppressEvents = true; 78 80 79 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "1 2";81 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "10"; 80 82 else { 81 83 titleTextBox.Text = workingChart.Titles[0].Text; … … 90 92 axisFontSizeComboBox.Text = area.AxisX.TitleFont.SizeInPoints.ToString(); 91 93 scalesFontSizeComboBox.Text = area.AxisX.LabelStyle.Font.SizeInPoints.ToString(); 92 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = " 8";94 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = "6"; 93 95 else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString(); 94 } finally { 96 } 97 finally { 95 98 SuppressEvents = false; 96 99 } … … 121 124 } 122 125 123 floatscaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);126 var scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height); 124 127 if (scaleFactor >= 1) { 125 128 previewZoomLabel.Text = "100%"; … … 129 132 rawImageSizeLabel.Text = GetRawImageSizeInMegabytes(width, height).ToString("0.00") + "M " + "(" + Math.Round(width).ToString("0") + " x " + Math.Round(height).ToString("0") + ") pixels"; 130 133 131 Bitmapimage = new Bitmap(previewWidth, previewHeight);134 var image = new Bitmap(previewWidth, previewHeight); 132 135 image.SetResolution(dpi, dpi); 133 136 using (Graphics graphics = Graphics.FromImage(image)) { … … 155 158 originalChart.Serializer.Content = SerializationContents.Default; 156 159 originalChart.Serializer.Format = SerializationFormat.Binary; 157 MemoryStream ms = new MemoryStream(); 158 originalChart.Serializer.Save(ms); 159 160 ms.Seek(0, SeekOrigin.Begin); 161 workingChart = new EnhancedChart(); 162 workingChart.Serializer.Format = originalChart.Serializer.Format; 163 workingChart.Serializer.Load(ms); 164 ms.Close(); 160 using (var ms = new MemoryStream()) { 161 originalChart.Serializer.Save(ms); 162 163 ms.Seek(0, SeekOrigin.Begin); 164 workingChart = new EnhancedChart(); 165 workingChart.Serializer.Format = originalChart.Serializer.Format; 166 workingChart.Serializer.Load(ms); 167 } 168 169 foreach (var s in workingChart.Series.Where(x => !x.Points.Any()).ToArray()) 170 s.IsVisibleInLegend = false; 165 171 166 172 originalChart.Serializer.Content = prevContent; … … 169 175 170 176 chartAreaComboBox.Items.Clear(); 171 foreach ( ChartAreaarea in originalChart.ChartAreas) {177 foreach (var area in originalChart.ChartAreas) { 172 178 chartAreaComboBox.Items.Add(area.Name); 173 179 } 174 180 chartAreaComboBox.SelectedIndex = 0; 181 SuppressEvents = true; 182 try { 183 showPrimaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Primary); 184 showPrimaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Primary); 185 showSecondaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Secondary); 186 showSecondaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Secondary); 187 188 if (!workingChart.Legends.Any()) { 189 legendPositionComboBox.Enabled = false; 190 legendFontSizeComboBox.Enabled = false; 191 } else { 192 legendPositionComboBox.Enabled = true; 193 legendFontSizeComboBox.Enabled = true; 194 if (workingChart.Legends[0].Enabled) { 195 switch (workingChart.Legends[0].Docking) { 196 case Docking.Top: 197 legendPositionComboBox.SelectedItem = "Top"; 198 break; 199 case Docking.Right: 200 legendPositionComboBox.SelectedItem = "Right"; 201 break; 202 case Docking.Bottom: 203 legendPositionComboBox.SelectedItem = "Bottom"; 204 break; 205 case Docking.Left: 206 legendPositionComboBox.SelectedItem = "Left"; 207 break; 208 } 209 } else { 210 legendPositionComboBox.SelectedItem = "Hidden"; 211 } 212 } 213 } 214 finally { SuppressEvents = false; } 175 215 base.OnShown(e); 176 216 … … 193 233 } 194 234 235 private void legendPositionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 236 if (!SuppressEvents) { 237 if (legendPositionComboBox.SelectedIndex >= 0) { 238 var legend = workingChart.Legends[0]; 239 var legendPosition = legendPositionComboBox.Items[legendPositionComboBox.SelectedIndex].ToString(); 240 if (legendPosition != "Hidden" && !legend.Enabled) 241 legend.Enabled = true; 242 switch (legendPosition) { 243 case "Top": 244 legend.Docking = Docking.Top; 245 break; 246 case "Right": 247 legend.Docking = Docking.Right; 248 break; 249 case "Bottom": 250 legend.Docking = Docking.Bottom; 251 break; 252 case "Left": 253 legend.Docking = Docking.Left; 254 break; 255 case "Hidden": 256 legend.Enabled = false; 257 break; 258 } 259 } 260 UpdatePreview(); 261 } 262 } 263 195 264 private void titleTextBox_TextChanged(object sender, EventArgs e) { 196 265 if (!SuppressEvents) { 197 if (workingChart.Titles.Count > 0) { 198 workingChart.Titles[0].Text = titleTextBox.Text; 199 } else { 200 Title t = new Title(titleTextBox.Text); 201 t.Font = ChangeFontSizePt(t.Font, float.Parse(titleFontSizeComboBox.Text)); 202 workingChart.Titles.Add(t); 266 if (string.IsNullOrEmpty(titleTextBox.Text)) 267 workingChart.Titles.Clear(); 268 else { 269 if (workingChart.Titles.Count > 0) { 270 workingChart.Titles[0].Text = titleTextBox.Text; 271 } else { 272 var t = new Title(titleTextBox.Text); 273 t.Font = ChangeFontSizePt(t.Font, float.Parse(titleFontSizeComboBox.Text)); 274 workingChart.Titles.Add(t); 275 } 203 276 } 204 277 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 208 281 private void primaryXTextBox_TextChanged(object sender, EventArgs e) { 209 282 if (!SuppressEvents) { 210 ChartAreaarea = GetCurrentChartArea();283 var area = GetCurrentChartArea(); 211 284 area.AxisX.Title = primaryXTextBox.Text; 212 285 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 216 289 private void primaryYTextBox_TextChanged(object sender, EventArgs e) { 217 290 if (!SuppressEvents) { 218 ChartAreaarea = GetCurrentChartArea();291 var area = GetCurrentChartArea(); 219 292 area.AxisY.Title = primaryYTextBox.Text; 220 293 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 224 297 private void secondaryXTextBox_TextChanged(object sender, EventArgs e) { 225 298 if (!SuppressEvents) { 226 ChartAreaarea = GetCurrentChartArea();299 var area = GetCurrentChartArea(); 227 300 area.AxisX2.Title = secondaryXTextBox.Text; 228 301 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 232 305 private void secondaryYTextBox_TextChanged(object sender, EventArgs e) { 233 306 if (!SuppressEvents) { 234 ChartAreaarea = GetCurrentChartArea();307 var area = GetCurrentChartArea(); 235 308 area.AxisY2.Title = secondaryYTextBox.Text; 309 if (togglePreviewCheckBox.Checked) UpdatePreview(); 310 } 311 } 312 313 private void showPrimaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 314 if (!SuppressEvents) { 315 var area = GetCurrentChartArea(); 316 var isChecked = ((CheckBox)sender).Checked; 317 area.AxisX.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 318 if (togglePreviewCheckBox.Checked) UpdatePreview(); 319 } 320 } 321 322 private void showPrimaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 323 if (!SuppressEvents) { 324 var area = GetCurrentChartArea(); 325 var isChecked = ((CheckBox)sender).Checked; 326 area.AxisY.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 327 if (togglePreviewCheckBox.Checked) UpdatePreview(); 328 } 329 } 330 331 private void showSecondaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 332 if (!SuppressEvents) { 333 var area = GetCurrentChartArea(); 334 var isChecked = ((CheckBox)sender).Checked; 335 area.AxisX2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 336 if (togglePreviewCheckBox.Checked) UpdatePreview(); 337 } 338 } 339 340 private void showSecondaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 341 if (!SuppressEvents) { 342 var area = GetCurrentChartArea(); 343 var isChecked = ((CheckBox)sender).Checked; 344 area.AxisY2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 236 345 if (togglePreviewCheckBox.Checked) UpdatePreview(); 237 346 } … … 270 379 float fontSize; 271 380 if (float.TryParse(axisFontSizeComboBox.Text, out fontSize)) { 272 ChartAreaarea = GetCurrentChartArea();273 foreach (Axis a in area.Axes) {381 var area = GetCurrentChartArea(); 382 foreach (Axis a in area.Axes) 274 383 a.TitleFont = ChangeFontSizePt(a.TitleFont, fontSize); 275 }276 384 } 277 385 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 283 391 float fontSize; 284 392 if (float.TryParse(scalesFontSizeComboBox.Text, out fontSize)) { 285 ChartAreaarea = GetCurrentChartArea();286 foreach ( Axis a in area.Axes) {393 var area = GetCurrentChartArea(); 394 foreach (var a in area.Axes) 287 395 a.LabelStyle.Font = ChangeFontSizePt(a.LabelStyle.Font, fontSize); 288 }289 396 } 290 397 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 296 403 float fontSize; 297 404 if (float.TryParse(legendFontSizeComboBox.Text, out fontSize)) { 298 foreach ( Legend l in workingChart.Legends) {405 foreach (var l in workingChart.Legends) 299 406 l.Font = ChangeFontSizePt(l.Font, fontSize); 300 }301 407 } 302 408 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 335 441 float height; 336 442 GetImageParameters(out dpi, out width, out height); 337 338 Bitmap image = new Bitmap((int)Math.Round(width), (int)Math.Round(height)); 443 var image = new Bitmap((int)Math.Round(width), (int)Math.Round(height)); 339 444 image.SetResolution(dpi, dpi); 340 using (Graphics graphics = Graphics.FromImage(image)) {341 workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height));342 }343 344 445 if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim(); 345 446 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 346 ImageFormat format = ImageFormat.Bmp; 347 string filename = saveFileDialog.FileName.ToLower(); 348 if (filename.EndsWith("jpg")) { 349 format = ImageFormat.Jpeg; 350 } else if (filename.EndsWith("emf")) { 351 format = ImageFormat.Emf; 352 } else if (filename.EndsWith("gif")) { 353 format = ImageFormat.Gif; 354 } else if (filename.EndsWith("png")) { 355 format = ImageFormat.Png; 356 } else if (filename.EndsWith("tif")) { 357 format = ImageFormat.Tiff; 358 } 359 image.Save(saveFileDialog.FileName, format); 360 } 361 447 var format = ImageFormat.Bmp; 448 var filename = saveFileDialog.FileName.ToLower(); 449 if (filename.EndsWith("emf")) { 450 using (var graphics = Graphics.FromImage(image)) { 451 var rectangle = new Rectangle(0, 0, image.Width, image.Height); 452 using (var metafile = new Metafile(filename, graphics.GetHdc(), rectangle, MetafileFrameUnit.Pixel, EmfType.EmfPlusDual)) { 453 graphics.ReleaseHdc(); 454 using (var g = Graphics.FromImage(metafile)) { 455 workingChart.Printing.PrintPaint(g, rectangle); 456 } 457 } 458 } 459 } else { 460 using (var graphics = Graphics.FromImage(image)) { 461 workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height)); 462 } 463 if (filename.EndsWith("jpg")) { 464 format = ImageFormat.Jpeg; 465 } else if (filename.EndsWith("gif")) { 466 format = ImageFormat.Gif; 467 } else if (filename.EndsWith("png")) { 468 format = ImageFormat.Png; 469 } else if (filename.EndsWith("tif")) { 470 format = ImageFormat.Tiff; 471 } 472 image.Save(saveFileDialog.FileName, format); 473 } 474 } 362 475 image.Dispose(); 363 364 476 Cleanup(); 365 477 }
Note: See TracChangeset
for help on using the changeset viewer.