private void Check(object sender, EventArgs e)
        {
            ArgsTrend sel;

            try
            {
                sel = this.GetSelection();
            }
            catch
            {
                sel = null;
            }

            bool valid = sel != null;

            this._txtName.Watermark = sel != null ? sel.DefaultDisplayName : Texts.default_name;

            this._lnkError.Visible = false;

            if (sel != null)
            {
                StylisedPeak sPeak = new StylisedPeak(this._previewPeak);

                ConfigurationTrend temporary = new ConfigurationTrend()
                {
                    Args = sel
                };
                IntensityMatrix source = this._ecbSource.SelectedItem.Provide;

                if (this._previewPeak != null)
                {
                    try
                    {
                        sPeak.OverrideDefaultOptions = new StylisedPeakOptions(this._core)
                        {
                            SelectedTrend = temporary
                        };
                        this._chart1.Plot(sPeak);
                    }
                    catch (Exception ex)
                    {
                        this._lnkError.Visible       = true;
                        this._lnkError.Tag           = ex.ToString();
                        sPeak.OverrideDefaultOptions = null;
                        this._chart1.Plot(sPeak);
                    }
                }
            }

            this._btnOk.Enabled      = valid;
            this._tlpPreview.Visible = valid;
        }
Exemple #2
0
        public void Plot(StylisedPeak stylisedPeak)
        {
            // Get observations
            Vector vector;

            if (stylisedPeak.ForceObservations != null)
            {
                vector = stylisedPeak.ForceObservations;
            }
            else
            {
                IntensityMatrix matrix = this._core.Options.SelectedMatrix;

                if (matrix == null)
                {
                    vector = null;
                }
                else
                {
                    vector = matrix.Find(stylisedPeak.Peak);
                }
            }

            Debug.WriteLine("PeakPlot: " + stylisedPeak);
            Dictionary <string, MCharting.Series> seriesNames = new Dictionary <string, MCharting.Series>();
            Peak peak = stylisedPeak?.Peak;

            // Clear plot
            MCharting.Plot plot = this.PrepareNewPlot(stylisedPeak != null && !stylisedPeak.IsPreview, peak, vector?.Source);

            try // <- CompletNewPlot
            {
                // Get selection
                this.SelectedPeak = peak;
                this.SetCaption("Plot of {0}.", peak);

                if (peak == null)
                {
                    return;
                }

                // Get options
                StylisedPeakOptions opts = stylisedPeak.OverrideDefaultOptions ?? new StylisedPeakOptions(this._core);

                // Get order data
                ObservationInfo[] obsOrder = this._core.Observations.ToArray();

                // Group legends
                IEnumerable <GroupInfoBase> order = opts.ShowAcqisition ? (IEnumerable <GroupInfoBase>)opts.ViewBatches : (IEnumerable <GroupInfoBase>)opts.ViewGroups;
                Dictionary <GroupInfoBase, MCharting.Series> groupLegends = this.DrawLegend(plot, order);

                if (vector == null)
                {
                    return;
                }

                // Show acquisition and batches?
                if (opts.ShowAcqisition)
                {
                    // --- RAW DATA (points) ---
                    MCharting.Series legendEntry = new MCharting.Series();
                    legendEntry.Name             = "Observations";
                    legendEntry.Style.DrawPoints = new SolidBrush(Color.Black);
                    plot.LegendEntries.Add(legendEntry);

                    this.AddToPlot(plot, peak, seriesNames, vector, "Raw data", opts, EPlot.ByBatch, groupLegends, legendEntry);

                    // --- TREND (thick line) ---
                    if (stylisedPeak.ForceTrend != null)
                    {
                        MCharting.Series legendEntry2 = new MCharting.Series();
                        legendEntry2.Name                  = "Trend";
                        legendEntry2.Style.DrawLines       = new Pen(Color.Black, this._core.Options.LineWidth);
                        legendEntry2.Style.DrawLines.Width = 4;
                        plot.LegendEntries.Add(legendEntry2);

                        this.AddToPlot(plot, peak, seriesNames, stylisedPeak.ForceTrend, "Trend data", opts, EPlot.ByBatch | EPlot.DrawLine | EPlot.DrawBold, groupLegends, legendEntry2);
                    }

                    this.DrawLabels(plot, opts.ConditionsSideBySide, order, opts.DrawExperimentalGroupAxisLabels);
                    return;
                }

                // Sort data
                ConfigurationTrend trend = opts.SelectedTrend;
                Vector             avg   = stylisedPeak.ForceTrend ?? trend.CreateTrend(this._core, vector);
                Vector             min   = MinSmoother.CreateTrend(this._core, vector);
                Vector             max   = MaxSmoother.CreateTrend(this._core, vector);

                // --- PLOT MEAN & SD (lines across)
                if (opts.ShowVariableMean)
                {
                    this.AddMeanAndSdLines(plot, opts, vector.Values, peak, groupLegends);
                }

                // --- RANGE (shaded area) ---
                if (opts.ShowRanges)
                {
                    this.AddUpperAndLowerShade(plot, opts, seriesNames, peak, min, max, groupLegends);
                }

                // --- RAW DATA (points) ---
                if (opts.ShowPoints && !stylisedPeak.IsPreview)
                {
                    MCharting.Series legendEntry = new MCharting.Series();
                    legendEntry.Name             = "Observations";
                    legendEntry.Style.DrawPoints = new SolidBrush(Color.Black);
                    plot.LegendEntries.Add(legendEntry);

                    this.AddToPlot(plot, peak, seriesNames, vector, "Raw data", opts, EPlot.None, groupLegends, legendEntry);
                }

                // --- RANGE (lines) ---
                if (opts.ShowMinMax)
                {
                    MCharting.Series legendEntry = new MCharting.Series();
                    legendEntry.Name            = "Range min/max";
                    legendEntry.Style.DrawLines = new Pen(Color.Gray, this._core.Options.LineWidth);
                    plot.LegendEntries.Add(legendEntry);

                    this.AddToPlot(plot, peak, seriesNames, min, "Min value", opts, EPlot.DrawLine, groupLegends, legendEntry);
                    this.AddToPlot(plot, peak, seriesNames, max, "Max value", opts, EPlot.DrawLine, groupLegends, legendEntry);
                }

                // --- TREND (thick line) ---
                if (opts.ShowTrend)
                {
                    MCharting.Series legendEntry = new MCharting.Series();
                    legendEntry.Name                  = "Trend";
                    legendEntry.Style.DrawLines       = new Pen(Color.Black, this._core.Options.LineWidth);
                    legendEntry.Style.DrawLines.Width = this._core.Options.LineWidth * 4;
                    plot.LegendEntries.Add(legendEntry);

                    this.AddToPlot(plot, peak, seriesNames, avg, "Trend data", opts, EPlot.DrawLine | EPlot.DrawBold, groupLegends, legendEntry);
                }

                // --- LABELS ---
                this.DrawLabels(plot, opts.ConditionsSideBySide, order, opts.DrawExperimentalGroupAxisLabels);
            }
            finally
            {
                this.CompleteNewPlot(plot);
            }
        }
        /// <summary>
        /// Generates the preview image.
        /// </summary>
        /// <param name="sel">Correction to generate the preview for</param>
        private void GeneratePreview(ArgsCorrection sel)
        {
            // No error unless otherwise
            this._lnkError.Visible = false;

            // No selection, no preview
            if (sel == null)
            {
                this.SetPreviewError("Nothing to preview", null);
                return;
            }

            // No peak, no preview
            if (this._selectedPeak == null)
            {
                this.SetPreviewError("No peak selected", null);
                return;
            }

            // Title
            this._lblPreviewTitle.Text = "Preview (" + this._selectedPeak.DisplayName + ")";

            // Get source matrix
            IntensityMatrix source = sel.SourceProvider?.Provide;

            if (source == null)
            {
                this.SetPreviewError(StrRes.NoPreview, StrRes.MissingSourceDetails(sel));
                return;
            }

            // Get vectors
            Vector original = source.Find(this._selectedPeak);
            Vector trend;
            Vector corrected;

            ConfigurationCorrection temp = new ConfigurationCorrection()
            {
                Args = sel
            };

            try
            {
                IReadOnlyList <ObservationInfo> order;
                double[] trendData = temp.ExtractTrend(this._core, original.Values, out order);
                trend     = (trendData != null) ? new Vector(trendData, original.Header, order.Select(z => new IntensityMatrix.ColumnHeader(z)).ToArray()) : null;
                corrected = new Vector(temp.Calculate(this._core, original.Values), original.Header, original.ColHeaders);
            }
            catch (Exception ex)
            {
                this._chartOrig.Plot(null);
                this._chartChanged.Plot(null);
                this._lnkError.Text    = StrRes.PreviewError;
                this._lnkError.Tag     = ex.ToString();
                this._lnkError.Visible = true;
                return;
            }

            // Special flag for batch ordering
            bool isBatchMode;

            if (sel.IsUsingTrend)
            {
                isBatchMode = sel.Mode == ECorrectionMode.Batch;
            }
            else
            {
                isBatchMode = false;
            }

            // Create displays
            StylisedPeak oldDisplay = new StylisedPeak(this._selectedPeak)
            {
                OverrideDefaultOptions = new StylisedPeakOptions(this._core)
                {
                    ShowAcqisition       = isBatchMode,
                    ViewBatches          = this._vBatches,
                    ViewGroups           = this._vTypes,
                    ConditionsSideBySide = true,
                    ShowPoints           = true,
                    ShowTrend            = sel.IsUsingTrend,
                    ShowRanges           = false,
                },

                ForceTrend = trend
            };

            StylisedPeak newDisplay = new StylisedPeak(this._selectedPeak)
            {
                OverrideDefaultOptions = oldDisplay.OverrideDefaultOptions.Clone(),
                ForceObservations      = corrected
            };

            newDisplay.OverrideDefaultOptions.ShowTrend = false;

            // Draw it!
            this._chartOrig.Plot(oldDisplay);
            this._chartChanged.Plot(newDisplay);
        }
Exemple #4
0
 public Bitmap CreateBitmap(int width, int height, StylisedPeak peak)
 {
     this.Plot(peak);
     return(this.CreateBitmap(width, height));
 }