Changeset 11203 for branches/HiveStatistics/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
- Timestamp:
- 07/18/14 12:35:00 (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.dll11 10 HeuristicLab 3.3.5.1.ReSharper.user 12 11 HeuristicLab 3.3.6.0.ReSharper.user 13 12 HeuristicLab.4.5.resharper.user 14 13 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development16 14 HeuristicLab.resharper.user 17 15 ProtoGen.exe … … 19 17 _ReSharper.HeuristicLab 20 18 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests22 19 _ReSharper.HeuristicLab.ExtLibs 23 20 bin 24 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/HiveStatistics/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
r11202 r11203 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2012 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;28 27 using System.Windows.Forms; 29 28 using System.Windows.Forms.DataVisualization.Charting; … … 59 58 else lengthUnitComboBox.SelectedIndex = 0; 60 59 61 titleFontSizeComboBox.Text = "1 0";60 titleFontSizeComboBox.Text = "12"; 62 61 axisFontSizeComboBox.Text = "8"; 63 62 scalesFontSizeComboBox.Text = "6"; 64 63 legendFontSizeComboBox.Text = "6"; 65 resolutionComboBox.Text = " 150";64 resolutionComboBox.Text = "300"; 66 65 SuppressEvents = false; 67 66 splitContainer.Panel2Collapsed = true; 68 67 Width = 305; 69 Height = 625; 70 } 71 finally { SuppressEvents = false; } 68 Height = 550; 69 } finally { SuppressEvents = false; } 72 70 #endregion 73 71 } 74 72 75 73 private void UpdateFields() { 76 vararea = GetCurrentChartArea();74 ChartArea area = GetCurrentChartArea(); 77 75 78 76 try { 79 77 SuppressEvents = true; 80 78 81 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "1 0";79 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "12"; 82 80 else { 83 81 titleTextBox.Text = workingChart.Titles[0].Text; … … 92 90 axisFontSizeComboBox.Text = area.AxisX.TitleFont.SizeInPoints.ToString(); 93 91 scalesFontSizeComboBox.Text = area.AxisX.LabelStyle.Font.SizeInPoints.ToString(); 94 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = " 6";92 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = "8"; 95 93 else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString(); 96 } 97 finally { 94 } finally { 98 95 SuppressEvents = false; 99 96 } … … 124 121 } 125 122 126 varscaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);123 float scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height); 127 124 if (scaleFactor >= 1) { 128 125 previewZoomLabel.Text = "100%"; … … 132 129 rawImageSizeLabel.Text = GetRawImageSizeInMegabytes(width, height).ToString("0.00") + "M " + "(" + Math.Round(width).ToString("0") + " x " + Math.Round(height).ToString("0") + ") pixels"; 133 130 134 varimage = new Bitmap(previewWidth, previewHeight);131 Bitmap image = new Bitmap(previewWidth, previewHeight); 135 132 image.SetResolution(dpi, dpi); 136 133 using (Graphics graphics = Graphics.FromImage(image)) { … … 158 155 originalChart.Serializer.Content = SerializationContents.Default; 159 156 originalChart.Serializer.Format = SerializationFormat.Binary; 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; 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(); 171 165 172 166 originalChart.Serializer.Content = prevContent; … … 175 169 176 170 chartAreaComboBox.Items.Clear(); 177 foreach ( vararea in originalChart.ChartAreas) {171 foreach (ChartArea area in originalChart.ChartAreas) { 178 172 chartAreaComboBox.Items.Add(area.Name); 179 173 } 180 174 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; }215 175 base.OnShown(e); 216 176 … … 233 193 } 234 194 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 264 195 private void titleTextBox_TextChanged(object sender, EventArgs e) { 265 196 if (!SuppressEvents) { 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 } 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); 276 203 } 277 204 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 281 208 private void primaryXTextBox_TextChanged(object sender, EventArgs e) { 282 209 if (!SuppressEvents) { 283 vararea = GetCurrentChartArea();210 ChartArea area = GetCurrentChartArea(); 284 211 area.AxisX.Title = primaryXTextBox.Text; 285 212 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 289 216 private void primaryYTextBox_TextChanged(object sender, EventArgs e) { 290 217 if (!SuppressEvents) { 291 vararea = GetCurrentChartArea();218 ChartArea area = GetCurrentChartArea(); 292 219 area.AxisY.Title = primaryYTextBox.Text; 293 220 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 297 224 private void secondaryXTextBox_TextChanged(object sender, EventArgs e) { 298 225 if (!SuppressEvents) { 299 vararea = GetCurrentChartArea();226 ChartArea area = GetCurrentChartArea(); 300 227 area.AxisX2.Title = secondaryXTextBox.Text; 301 228 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 305 232 private void secondaryYTextBox_TextChanged(object sender, EventArgs e) { 306 233 if (!SuppressEvents) { 307 vararea = GetCurrentChartArea();234 ChartArea area = GetCurrentChartArea(); 308 235 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;345 236 if (togglePreviewCheckBox.Checked) UpdatePreview(); 346 237 } … … 379 270 float fontSize; 380 271 if (float.TryParse(axisFontSizeComboBox.Text, out fontSize)) { 381 vararea = GetCurrentChartArea();382 foreach (Axis a in area.Axes) 272 ChartArea area = GetCurrentChartArea(); 273 foreach (Axis a in area.Axes) { 383 274 a.TitleFont = ChangeFontSizePt(a.TitleFont, fontSize); 275 } 384 276 } 385 277 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 391 283 float fontSize; 392 284 if (float.TryParse(scalesFontSizeComboBox.Text, out fontSize)) { 393 vararea = GetCurrentChartArea();394 foreach ( var a in area.Axes)285 ChartArea area = GetCurrentChartArea(); 286 foreach (Axis a in area.Axes) { 395 287 a.LabelStyle.Font = ChangeFontSizePt(a.LabelStyle.Font, fontSize); 288 } 396 289 } 397 290 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 403 296 float fontSize; 404 297 if (float.TryParse(legendFontSizeComboBox.Text, out fontSize)) { 405 foreach ( var l in workingChart.Legends)298 foreach (Legend l in workingChart.Legends) { 406 299 l.Font = ChangeFontSizePt(l.Font, fontSize); 300 } 407 301 } 408 302 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 441 335 float height; 442 336 GetImageParameters(out dpi, out width, out height); 443 var image = new Bitmap((int)Math.Round(width), (int)Math.Round(height)); 337 338 Bitmap image = new Bitmap((int)Math.Round(width), (int)Math.Round(height)); 444 339 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 445 344 if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim(); 446 345 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 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 } 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 475 362 image.Dispose(); 363 476 364 Cleanup(); 477 365 }
Note: See TracChangeset
for help on using the changeset viewer.