Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/16/13 09:11:15 (11 years ago)
Author:
abeham
Message:

#2054:

  • Added check boxes to hide or show a certain axis
  • Fixed tab order
  • Changed some of the default values
  • Improved layout of controls
  • Clear title if the text is set to empty
  • Added tooltips to most controls
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization.ChartControlsExtensions/3.3/ImageExportDialog.cs

    r9456 r9496  
    2525using System.Drawing.Imaging;
    2626using System.IO;
     27using System.Linq;
    2728using System.Windows.Forms;
    2829using System.Windows.Forms.DataVisualization.Charting;
     
    5859        else lengthUnitComboBox.SelectedIndex = 0;
    5960
    60         titleFontSizeComboBox.Text = "12";
     61        titleFontSizeComboBox.Text = "10";
    6162        axisFontSizeComboBox.Text = "8";
    6263        scalesFontSizeComboBox.Text = "6";
    6364        legendFontSizeComboBox.Text = "6";
    64         resolutionComboBox.Text = "300";
     65        resolutionComboBox.Text = "150";
    6566        SuppressEvents = false;
    6667        splitContainer.Panel2Collapsed = true;
    6768        Width = 305;
    68         Height = 550;
     69        Height = 560;
    6970      } finally { SuppressEvents = false; }
    7071      #endregion
     
    7273
    7374    private void UpdateFields() {
    74       ChartArea area = GetCurrentChartArea();
     75      var area = GetCurrentChartArea();
    7576
    7677      try {
    7778        SuppressEvents = true;
    7879
    79         if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "12";
     80        if (workingChart.Titles.Count == 0) titleFontSizeComboBox.Text = "10";
    8081        else {
    8182          titleTextBox.Text = workingChart.Titles[0].Text;
     
    9091        axisFontSizeComboBox.Text = area.AxisX.TitleFont.SizeInPoints.ToString();
    9192        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";
    9394        else legendFontSizeComboBox.Text = workingChart.Legends[0].Font.SizeInPoints.ToString();
    9495      } finally {
     
    121122      }
    122123
    123       float scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);
     124      var scaleFactor = (float)Math.Min(previewWidth / width, previewHeight / height);
    124125      if (scaleFactor >= 1) {
    125126        previewZoomLabel.Text = "100%";
     
    129130      rawImageSizeLabel.Text = GetRawImageSizeInMegabytes(width, height).ToString("0.00") + "M   " + "(" + Math.Round(width).ToString("0") + " x " + Math.Round(height).ToString("0") + ") pixels";
    130131
    131       Bitmap image = new Bitmap(previewWidth, previewHeight);
     132      var image = new Bitmap(previewWidth, previewHeight);
    132133      image.SetResolution(dpi, dpi);
    133134      using (Graphics graphics = Graphics.FromImage(image)) {
     
    155156      originalChart.Serializer.Content = SerializationContents.Default;
    156157      originalChart.Serializer.Format = SerializationFormat.Binary;
    157       MemoryStream ms = new MemoryStream();
     158      var ms = new MemoryStream();
    158159      originalChart.Serializer.Save(ms);
    159160
     
    169170
    170171      chartAreaComboBox.Items.Clear();
    171       foreach (ChartArea area in originalChart.ChartAreas) {
     172      foreach (var area in originalChart.ChartAreas) {
    172173        chartAreaComboBox.Items.Add(area.Name);
    173174      }
    174175      chartAreaComboBox.SelectedIndex = 0;
     176      SuppressEvents = true;
     177      try {
     178        showPrimaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Primary);
     179        showPrimaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Primary);
     180        showSecondaryXAxisCheckBox.Checked = originalChart.Series.Any(x => x.XAxisType == AxisType.Secondary);
     181        showSecondaryYAxisCheckBox.Checked = originalChart.Series.Any(x => x.YAxisType == AxisType.Secondary);
     182      } finally { SuppressEvents = false; }
    175183      base.OnShown(e);
    176184
     
    195203    private void titleTextBox_TextChanged(object sender, EventArgs e) {
    196204      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);
     205        if (string.IsNullOrEmpty(titleTextBox.Text))
     206          workingChart.Titles.Clear();
     207        else {
     208          if (workingChart.Titles.Count > 0) {
     209            workingChart.Titles[0].Text = titleTextBox.Text;
     210          } else {
     211            var t = new Title(titleTextBox.Text);
     212            t.Font = ChangeFontSizePt(t.Font, float.Parse(titleFontSizeComboBox.Text));
     213            workingChart.Titles.Add(t);
     214          }
    203215        }
    204216        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    208220    private void primaryXTextBox_TextChanged(object sender, EventArgs e) {
    209221      if (!SuppressEvents) {
    210         ChartArea area = GetCurrentChartArea();
     222        var area = GetCurrentChartArea();
    211223        area.AxisX.Title = primaryXTextBox.Text;
    212224        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    216228    private void primaryYTextBox_TextChanged(object sender, EventArgs e) {
    217229      if (!SuppressEvents) {
    218         ChartArea area = GetCurrentChartArea();
     230        var area = GetCurrentChartArea();
    219231        area.AxisY.Title = primaryYTextBox.Text;
    220232        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    224236    private void secondaryXTextBox_TextChanged(object sender, EventArgs e) {
    225237      if (!SuppressEvents) {
    226         ChartArea area = GetCurrentChartArea();
     238        var area = GetCurrentChartArea();
    227239        area.AxisX2.Title = secondaryXTextBox.Text;
    228240        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    232244    private void secondaryYTextBox_TextChanged(object sender, EventArgs e) {
    233245      if (!SuppressEvents) {
    234         ChartArea area = GetCurrentChartArea();
     246        var area = GetCurrentChartArea();
    235247        area.AxisY2.Title = secondaryYTextBox.Text;
     248        if (togglePreviewCheckBox.Checked) UpdatePreview();
     249      }
     250    }
     251
     252    private void showPrimaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
     253      if (!SuppressEvents) {
     254        var area = GetCurrentChartArea();
     255        var isChecked = ((CheckBox)sender).Checked;
     256        area.AxisX.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False;
     257        if (togglePreviewCheckBox.Checked) UpdatePreview();
     258      }
     259    }
     260
     261    private void showPrimaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
     262      if (!SuppressEvents) {
     263        var area = GetCurrentChartArea();
     264        var isChecked = ((CheckBox)sender).Checked;
     265        area.AxisY.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False;
     266        if (togglePreviewCheckBox.Checked) UpdatePreview();
     267      }
     268    }
     269
     270    private void showSecondaryXAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
     271      if (!SuppressEvents) {
     272        var area = GetCurrentChartArea();
     273        var isChecked = ((CheckBox)sender).Checked;
     274        area.AxisX2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False;
     275        if (togglePreviewCheckBox.Checked) UpdatePreview();
     276      }
     277    }
     278
     279    private void showSecondaryYAxisCheckBox_CheckedChanged(object sender, EventArgs e) {
     280      if (!SuppressEvents) {
     281        var area = GetCurrentChartArea();
     282        var isChecked = ((CheckBox)sender).Checked;
     283        area.AxisY2.Enabled = isChecked ? AxisEnabled.True : AxisEnabled.False;
    236284        if (togglePreviewCheckBox.Checked) UpdatePreview();
    237285      }
     
    270318        float fontSize;
    271319        if (float.TryParse(axisFontSizeComboBox.Text, out fontSize)) {
    272           ChartArea area = GetCurrentChartArea();
    273           foreach (Axis a in area.Axes) {
     320          var area = GetCurrentChartArea();
     321          foreach (Axis a in area.Axes)
    274322            a.TitleFont = ChangeFontSizePt(a.TitleFont, fontSize);
    275           }
    276323        }
    277324        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    283330        float fontSize;
    284331        if (float.TryParse(scalesFontSizeComboBox.Text, out fontSize)) {
    285           ChartArea area = GetCurrentChartArea();
    286           foreach (Axis a in area.Axes) {
     332          var area = GetCurrentChartArea();
     333          foreach (var a in area.Axes)
    287334            a.LabelStyle.Font = ChangeFontSizePt(a.LabelStyle.Font, fontSize);
    288           }
    289335        }
    290336        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    296342        float fontSize;
    297343        if (float.TryParse(legendFontSizeComboBox.Text, out fontSize)) {
    298           foreach (Legend l in workingChart.Legends) {
     344          foreach (var l in workingChart.Legends)
    299345            l.Font = ChangeFontSizePt(l.Font, fontSize);
    300           }
    301346        }
    302347        if (togglePreviewCheckBox.Checked) UpdatePreview();
     
    336381      GetImageParameters(out dpi, out width, out height);
    337382
    338       Bitmap image = new Bitmap((int)Math.Round(width), (int)Math.Round(height));
     383      var image = new Bitmap((int)Math.Round(width), (int)Math.Round(height));
    339384      image.SetResolution(dpi, dpi);
    340       using (Graphics graphics = Graphics.FromImage(image)) {
     385      using (var graphics = Graphics.FromImage(image)) {
    341386        workingChart.Printing.PrintPaint(graphics, new Rectangle(0, 0, image.Width, image.Height));
    342387      }
     
    344389      if (titleTextBox.Text.Trim() != String.Empty) saveFileDialog.FileName = titleTextBox.Text.Trim();
    345390      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
    346         ImageFormat format = ImageFormat.Bmp;
    347         string filename = saveFileDialog.FileName.ToLower();
     391        var format = ImageFormat.Bmp;
     392        var filename = saveFileDialog.FileName.ToLower();
    348393        if (filename.EndsWith("jpg")) {
    349394          format = ImageFormat.Jpeg;
Note: See TracChangeset for help on using the changeset viewer.