Esempio n. 1
0
        private void UpdatePlot()
        {
            if (this._scores == null)
            {
                this._lblSelection.Text      = this._errorMessage;
                this._lblSelection.ForeColor = Color.Red;
                this._chart.Visible          = false;
                return;
            }

            this._chart.Visible          = true;
            this._lblSelection.Text      = "";
            this._lblSelection.ForeColor = ForeColor;

            MCharting.Plot plot = new MCharting.Plot();

            plot.Title    = $"{this._lblMethod.Text} of {this._core.FileNames.Title}";
            plot.SubTitle = $"Source: {this._lblPcaSource.Text}, View: {this._lblPlotView.Text}, Legend: {this._lblLegend.Text}, Corrections: {this._lblCorrections.Text}, Observations: {this._lblObs.Text}, Peaks: {this._lblPeaks.Text}";

            switch (this._method)
            {
            case EMethod.Pca:
                plot.XLabel = $"PC{this._component + 1}";
                plot.YLabel = $"PC{this._component + 2}";
                break;

            case EMethod.Plsr:
                plot.XLabel    = $"Component {this._component + 1}";
                plot.YLabel    = $"Component {this._component + 2}";
                plot.SubTitle += ", PLSR Response: " + this._lblPlsrSource.Text;
                break;
            }

            this._chart.Style.Margin = new Padding(48, 48, 48, 48);
            plot.Style.GridStyle     = new Pen(Color.FromArgb(224, 224, 224));

            // Get the "rows"
            IEnumerator enSources;
            Column      column;

            this.GetSource(this._colourBy, out enSources, out column);

            // Get the "columns"
            double[,] plotPoints;

            if (this._plotSource == EPlotSource.Loadings)
            {
                plotPoints = this._loadings;
            }
            else
            {
                plotPoints = this._scores;
            }

            // Get the component
            if (this._component < 0)
            {
                this._component = 0;
            }

            if (this._component >= plotPoints.GetLength(1))
            {
                this._component = plotPoints.GetLength(1) - 1;
            }

            this._btnPrevPc.Enabled = this._component != 0;
            this._btnNextPc.Enabled = this._component != plotPoints.GetLength(1) - 1;

            this._lblPlotView.Text    = this._plotSource == EPlotSource.Loadings ? "Loadings" : "Scores";
            this._btnScores.Checked   = this._plotSource == EPlotSource.Scores;
            this._btnLoadings.Checked = this._plotSource == EPlotSource.Loadings;

            this._lblPcNumber.Text = "PC" + (this._component + 1).ToString() + " / " + plotPoints.GetLength(1);

            this._lblLegend.Text = column.DisplayName;

            bool isGroup = false;

            // Iterate scores
            for (int r = 0; r < plotPoints.GetLength(0); r++)
            {
                enSources.MoveNext();

                MCharting.Series series = GetOrCreateSeriesForValue(plot, column, (Visualisable)enSources.Current, ref isGroup);

                var coord = new MCharting.DataPoint(plotPoints[r, this._component], plotPoints[r, this._component + 1]);
                coord.Tag = enSources.Current;

                series.Points.Add(coord);
            }

            // Assign colours
            if (!column.HasColourSupport && !isGroup)
            {
                foreach (var colour in PlotCreator.AutoColour(plot.Series))
                {
                    colour.Key.Style.DrawPoints = new SolidBrush(colour.Value);
                }
            }

            this._chart.Style.Animate         = true;
            this._chart.Style.SelectionColour = Color.Yellow;

            this._chart.SetPlot(plot);
        }