Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/18/14 12:35:00 (10 years ago)
Author:
ascheibe
Message:

reverted last commit

Location:
branches/HiveStatistics/sources
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/HiveStatistics/sources

  • branches/HiveStatistics/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs

    r11202 r11203  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2525using System.Drawing.Imaging;
    2626using System.IO;
    27 using System.Linq;
    2827using System.Windows.Forms;
    2928using System.Windows.Forms.DataVisualization.Charting;
     
    5958        else lengthUnitComboBox.SelectedIndex = 0;
    6059
    61         titleFontSizeComboBox.Text = "10";
     60        titleFontSizeComboBox.Text = "12";
    6261        axisFontSizeComboBox.Text = "8";
    6362        scalesFontSizeComboBox.Text = "6";
    6463        legendFontSizeComboBox.Text = "6";
    65         resolutionComboBox.Text = "150";
     64        resolutionComboBox.Text = "300";
    6665        SuppressEvents = false;
    6766        splitContainer.Panel2Collapsed = true;
    6867        Width = 305;
    69         Height = 625;
    70       }
    71       finally { SuppressEvents = false; }
     68        Height = 550;
     69      } finally { SuppressEvents = false; }
    7270      #endregion
    7371    }
    7472
    7573    private void UpdateFields() {
    76       var area = GetCurrentChartArea();
     74      ChartArea area = GetCurrentChartArea();
    7775
    7876      try {
    7977        SuppressEvents = true;
    8078
    81         if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "10";
     79        if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "12";
    8280        else {
    8381          titleTextBox.Text = workingChart.Titles[0].Text;
     
    9290        axisFontSizeComboBox.Text = area.AxisX.TitleFont.SizeInPoints.ToString();
    9391        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";
    9593        else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString();
    96       }
    97       finally {
     94      } finally {
    9895        SuppressEvents = false;
    9996      }
     
    124121      }
    125122
    126       var scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);
     123      float scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);
    127124      if (scaleFactor >= 1) {
    128125        previewZoomLabel.Text = "100%";
     
    132129      rawImageSizeLabel.Text = GetRawImageSizeInMegabytes(width, height).ToString("0.00") + "M   " + "(" + Math.Round(width).ToString("0") + " x " + Math.Round(height).ToString("0") + ") pixels";
    133130
    134       var image = new Bitmap(previewWidth, previewHeight);
     131      Bitmap image = new Bitmap(previewWidth, previewHeight);
    135132      image.SetResolution(dpi, dpi);
    136133      using (Graphics graphics = Graphics.FromImage(image)) {
     
    158155      originalChart.Serializer.Content = SerializationContents.Default;
    159156      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();
    171165
    172166      originalChart.Serializer.Content = prevContent;
     
    175169
    176170      chartAreaComboBox.Items.Clear();
    177       foreach (var area in originalChart.ChartAreas) {
     171      foreach (ChartArea area in originalChart.ChartAreas) {
    178172        chartAreaComboBox.Items.Add(area.Name);
    179173      }
    180174      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; }
    215175      base.OnShown(e);
    216176
     
    233193    }
    234194
    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 
    264195    private void titleTextBox_TextChanged(object sender, EventArgs e) {
    265196      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);
    276203        }
    277204        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    281208    private void primaryXTextBox_TextChanged(object sender, EventArgs e) {
    282209      if (!SuppressEvents) {
    283         var area = GetCurrentChartArea();
     210        ChartArea area = GetCurrentChartArea();
    284211        area.AxisX.Title = primaryXTextBox.Text;
    285212        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    289216    private void primaryYTextBox_TextChanged(object sender, EventArgs e) {
    290217      if (!SuppressEvents) {
    291         var area = GetCurrentChartArea();
     218        ChartArea area = GetCurrentChartArea();
    292219        area.AxisY.Title = primaryYTextBox.Text;
    293220        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    297224    private void secondaryXTextBox_TextChanged(object sender, EventArgs e) {
    298225      if (!SuppressEvents) {
    299         var area = GetCurrentChartArea();
     226        ChartArea area = GetCurrentChartArea();
    300227        area.AxisX2.Title = secondaryXTextBox.Text;
    301228        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    305232    private void secondaryYTextBox_TextChanged(object sender, EventArgs e) {
    306233      if (!SuppressEvents) {
    307         var area = GetCurrentChartArea();
     234        ChartArea area = GetCurrentChartArea();
    308235        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;
    345236        if (togglePreviewCheckBox.Checked) UpdatePreview();
    346237      }
     
    379270        float fontSize;
    380271        if (float.TryParse(axisFontSizeComboBox.Text, out fontSize)) {
    381           var area = GetCurrentChartArea();
    382           foreach (Axis a in area.Axes)
     272          ChartArea area = GetCurrentChartArea();
     273          foreach (Axis a in area.Axes) {
    383274            a.TitleFont = ChangeFontSizePt(a.TitleFont, fontSize);
     275          }
    384276        }
    385277        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    391283        float fontSize;
    392284        if (float.TryParse(scalesFontSizeComboBox.Text, out fontSize)) {
    393           var area = GetCurrentChartArea();
    394           foreach (var a in area.Axes)
     285          ChartArea area = GetCurrentChartArea();
     286          foreach (Axis a in area.Axes) {
    395287            a.LabelStyle.Font = ChangeFontSizePt(a.LabelStyle.Font, fontSize);
     288          }
    396289        }
    397290        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    403296        float fontSize;
    404297        if (float.TryParse(legendFontSizeComboBox.Text, out fontSize)) {
    405           foreach (var l in workingChart.Legends)
     298          foreach (Legend l in workingChart.Legends) {
    406299            l.Font = ChangeFontSizePt(l.Font, fontSize);
     300          }
    407301        }
    408302        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    441335      float height;
    442336      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));
    444339      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
    445344      if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim();
    446345      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
    475362      image.Dispose();
     363
    476364      Cleanup();
    477365    }
Note: See TracChangeset for help on using the changeset viewer.