Changeset 9532 for stable/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
- Timestamp:
- 05/24/13 17:05:17 (11 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 9496,9520-9521
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs
r9456 r9532 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 Height = 625; 69 70 } finally { SuppressEvents = false; } 70 71 #endregion … … 72 73 73 74 private void UpdateFields() { 74 ChartAreaarea = GetCurrentChartArea();75 var area = GetCurrentChartArea(); 75 76 76 77 try { 77 78 SuppressEvents = true; 78 79 79 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "1 2";80 if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "10"; 80 81 else { 81 82 titleTextBox.Text = workingChart.Titles[0].Text; … … 90 91 axisFontSizeComboBox.Text = area.AxisX.TitleFont.SizeInPoints.ToString(); 91 92 scalesFontSizeComboBox.Text = area.AxisX.LabelStyle.Font.SizeInPoints.ToString(); 92 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = " 8";93 if (workingChart.Legends.Count == 0) legendFontSizeComboBox.Text = "6"; 93 94 else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString(); 94 95 } finally { … … 121 122 } 122 123 123 floatscaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);124 var scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height); 124 125 if (scaleFactor >= 1) { 125 126 previewZoomLabel.Text = "100%"; … … 129 130 rawImageSizeLabel.Text = GetRawImageSizeInMegabytes(width, height).ToString("0.00") + "M " + "(" + Math.Round(width).ToString("0") + " x " + Math.Round(height).ToString("0") + ") pixels"; 130 131 131 Bitmapimage = new Bitmap(previewWidth, previewHeight);132 var image = new Bitmap(previewWidth, previewHeight); 132 133 image.SetResolution(dpi, dpi); 133 134 using (Graphics graphics = Graphics.FromImage(image)) { … … 155 156 originalChart.Serializer.Content = SerializationContents.Default; 156 157 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(); 158 using (var ms = new MemoryStream()) { 159 originalChart.Serializer.Save(ms); 160 161 ms.Seek(0, SeekOrigin.Begin); 162 workingChart = new EnhancedChart(); 163 workingChart.Serializer.Format = originalChart.Serializer.Format; 164 workingChart.Serializer.Load(ms); 165 } 166 167 foreach (var s in workingChart.Series.Where(x => !x.Points.Any()).ToArray()) 168 s.IsVisibleInLegend = false; 165 169 166 170 originalChart.Serializer.Content = prevContent; … … 169 173 170 174 chartAreaComboBox.Items.Clear(); 171 foreach ( ChartAreaarea in originalChart.ChartAreas) {175 foreach (var area in originalChart.ChartAreas) { 172 176 chartAreaComboBox.Items.Add(area.Name); 173 177 } 174 178 chartAreaComboBox.SelectedIndex = 0; 179 SuppressEvents = true; 180 try { 181 showPrimaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Primary); 182 showPrimaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Primary); 183 showSecondaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Secondary); 184 showSecondaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Secondary); 185 186 if (!workingChart.Legends.Any()) { 187 legendPositionComboBox.Enabled = false; 188 legendFontSizeComboBox.Enabled = false; 189 } else { 190 legendPositionComboBox.Enabled = true; 191 legendFontSizeComboBox.Enabled = true; 192 if (workingChart.Legends[0].Enabled) { 193 switch (workingChart.Legends[0].Docking) { 194 case Docking.Top: 195 legendPositionComboBox.SelectedItem = "Top"; 196 break; 197 case Docking.Right: 198 legendPositionComboBox.SelectedItem = "Right"; 199 break; 200 case Docking.Bottom: 201 legendPositionComboBox.SelectedItem = "Bottom"; 202 break; 203 case Docking.Left: 204 legendPositionComboBox.SelectedItem = "Left"; 205 break; 206 } 207 } else { 208 legendPositionComboBox.SelectedItem = "Hidden"; 209 } 210 } 211 } finally { SuppressEvents = false; } 175 212 base.OnShown(e); 176 213 … … 193 230 } 194 231 232 private void legendPositionComboBox_SelectedIndexChanged(object sender, EventArgs e) { 233 if (!SuppressEvents) { 234 if (legendPositionComboBox.SelectedIndex >= 0) { 235 var legend = workingChart.Legends[0]; 236 var legendPosition = legendPositionComboBox.Items[legendPositionComboBox.SelectedIndex].ToString(); 237 if (legendPosition != "Hidden" && !legend.Enabled) 238 legend.Enabled = true; 239 switch (legendPosition) { 240 case "Top": 241 legend.Docking = Docking.Top; 242 break; 243 case "Right": 244 legend.Docking = Docking.Right; 245 break; 246 case "Bottom": 247 legend.Docking = Docking.Bottom; 248 break; 249 case "Left": 250 legend.Docking = Docking.Left; 251 break; 252 case "Hidden": 253 legend.Enabled = false; 254 break; 255 } 256 } 257 UpdatePreview(); 258 } 259 } 260 195 261 private void titleTextBox_TextChanged(object sender, EventArgs e) { 196 262 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); 263 if (string.IsNullOrEmpty(titleTextBox.Text)) 264 workingChart.Titles.Clear(); 265 else { 266 if (workingChart.Titles.Count > 0) { 267 workingChart.Titles[0].Text = titleTextBox.Text; 268 } else { 269 var t = new Title(titleTextBox.Text); 270 t.Font = ChangeFontSizePt(t.Font, float.Parse(titleFontSizeComboBox.Text)); 271 workingChart.Titles.Add(t); 272 } 203 273 } 204 274 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 208 278 private void primaryXTextBox_TextChanged(object sender, EventArgs e) { 209 279 if (!SuppressEvents) { 210 ChartAreaarea = GetCurrentChartArea();280 var area = GetCurrentChartArea(); 211 281 area.AxisX.Title = primaryXTextBox.Text; 212 282 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 216 286 private void primaryYTextBox_TextChanged(object sender, EventArgs e) { 217 287 if (!SuppressEvents) { 218 ChartAreaarea = GetCurrentChartArea();288 var area = GetCurrentChartArea(); 219 289 area.AxisY.Title = primaryYTextBox.Text; 220 290 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 224 294 private void secondaryXTextBox_TextChanged(object sender, EventArgs e) { 225 295 if (!SuppressEvents) { 226 ChartAreaarea = GetCurrentChartArea();296 var area = GetCurrentChartArea(); 227 297 area.AxisX2.Title = secondaryXTextBox.Text; 228 298 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 232 302 private void secondaryYTextBox_TextChanged(object sender, EventArgs e) { 233 303 if (!SuppressEvents) { 234 ChartAreaarea = GetCurrentChartArea();304 var area = GetCurrentChartArea(); 235 305 area.AxisY2.Title = secondaryYTextBox.Text; 306 if (togglePreviewCheckBox.Checked) UpdatePreview(); 307 } 308 } 309 310 private void showPrimaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 311 if (!SuppressEvents) { 312 var area = GetCurrentChartArea(); 313 var isChecked = ((CheckBox)sender).Checked; 314 area.AxisX.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 315 if (togglePreviewCheckBox.Checked) UpdatePreview(); 316 } 317 } 318 319 private void showPrimaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 320 if (!SuppressEvents) { 321 var area = GetCurrentChartArea(); 322 var isChecked = ((CheckBox)sender).Checked; 323 area.AxisY.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 324 if (togglePreviewCheckBox.Checked) UpdatePreview(); 325 } 326 } 327 328 private void showSecondaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 329 if (!SuppressEvents) { 330 var area = GetCurrentChartArea(); 331 var isChecked = ((CheckBox)sender).Checked; 332 area.AxisX2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 333 if (togglePreviewCheckBox.Checked) UpdatePreview(); 334 } 335 } 336 337 private void showSecondaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) { 338 if (!SuppressEvents) { 339 var area = GetCurrentChartArea(); 340 var isChecked = ((CheckBox)sender).Checked; 341 area.AxisY2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False; 236 342 if (togglePreviewCheckBox.Checked) UpdatePreview(); 237 343 } … … 270 376 float fontSize; 271 377 if (float.TryParse(axisFontSizeComboBox.Text, out fontSize)) { 272 ChartAreaarea = GetCurrentChartArea();273 foreach (Axis a in area.Axes) {378 var area = GetCurrentChartArea(); 379 foreach (Axis a in area.Axes) 274 380 a.TitleFont = ChangeFontSizePt(a.TitleFont, fontSize); 275 }276 381 } 277 382 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 283 388 float fontSize; 284 389 if (float.TryParse(scalesFontSizeComboBox.Text, out fontSize)) { 285 ChartAreaarea = GetCurrentChartArea();286 foreach ( Axis a in area.Axes) {390 var area = GetCurrentChartArea(); 391 foreach (var a in area.Axes) 287 392 a.LabelStyle.Font = ChangeFontSizePt(a.LabelStyle.Font, fontSize); 288 }289 393 } 290 394 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 296 400 float fontSize; 297 401 if (float.TryParse(legendFontSizeComboBox.Text, out fontSize)) { 298 foreach ( Legend l in workingChart.Legends) {402 foreach (var l in workingChart.Legends) 299 403 l.Font = ChangeFontSizePt(l.Font, fontSize); 300 }301 404 } 302 405 if (togglePreviewCheckBox.Checked) UpdatePreview(); … … 336 439 GetImageParameters(out dpi, out width, out height); 337 440 338 Bitmapimage = new Bitmap((int)Math.Round(width), (int)Math.Round(height));441 var image = new Bitmap((int)Math.Round(width), (int)Math.Round(height)); 339 442 image.SetResolution(dpi, dpi); 340 using ( Graphicsgraphics = Graphics.FromImage(image)) {443 using (var graphics = Graphics.FromImage(image)) { 341 444 workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height)); 342 445 } … … 344 447 if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim(); 345 448 if (saveFileDialog.ShowDialog() == DialogResult.OK) { 346 ImageFormatformat = ImageFormat.Bmp;347 stringfilename = saveFileDialog.FileName.ToLower();449 var format = ImageFormat.Bmp; 450 var filename = saveFileDialog.FileName.ToLower(); 348 451 if (filename.EndsWith("jpg")) { 349 452 format = ImageFormat.Jpeg;
Note: See TracChangeset
for help on using the changeset viewer.