Example #1
0
        private void LineSpan_Click(object sender, RoutedEventArgs e)
        {
            string   plotType = ((MenuItem)e.OriginalSource).Header.ToString().ToUpperInvariant();
            PlotType type     = new PlotType();

            switch (plotType)
            {
            case "VERTICAL LINE":
                type = PlotType.vertical_line;
                break;

            case "HORIZONTAL LINE":
                type = PlotType.horizontal_line;
                break;

            case "VERTICAL SPAN":
                type = PlotType.vertical_span;
                break;

            case "HORIZONTAL SPAN":
                type = PlotType.horizontal_span;
                break;
            }

            SettingsDialog settingsDialog = new SettingsDialog(type);

            settingsDialog.Owner = App.Current.MainWindow;

            DrawSettings drawSettings;

            drawSettings = FetchSettingsFromDialog(settingsDialog, type);
            if (!drawSettings.valid)
            {
                return;
            }

            PlotParameters plotParams = new PlotParameters();

            plotParams.drawSettings = drawSettings;

            if (type == PlotType.horizontal_line || type == PlotType.vertical_line)
            {
                LineSettingsDialog lineDialog = new LineSettingsDialog();
                lineDialog.Owner = App.Current.MainWindow;

                if (lineDialog.ShowDialog() != true)
                {
                    return;
                }

                double value = 0;

                DateTime date = new DateTime();
                if (DateTime.TryParse(lineDialog.value.Text, out date))
                {
                    plotParams.data = date.ToOADate();
                }
                else if (double.TryParse(lineDialog.value.Text, out value))
                {
                    plotParams.data = value;
                }
                else
                {
                    DialogUtilities.ShowCouldNotParseValueError("Value", lineDialog.value.Text);
                    return;
                }
            }
            else
            {
                SpanSettingsDialog spanDialog = new SpanSettingsDialog();
                spanDialog.Owner = App.Current.MainWindow;

                if (spanDialog.ShowDialog() != true)
                {
                    return;
                }

                double minValue = 0;
                double maxValue = 0;

                DateTime dateMin = new DateTime();
                DateTime dateMax = new DateTime();

                if (DateTime.TryParse(spanDialog.minValue.Text, out dateMin))
                {
                    minValue = dateMin.ToOADate();
                }
                else if (!double.TryParse(spanDialog.minValue.Text, out minValue))
                {
                    DialogUtilities.ShowCouldNotParseValueError("Min Value", spanDialog.minValue.Text);
                    return;
                }

                if (DateTime.TryParse(spanDialog.maxValue.Text, out dateMax))
                {
                    maxValue = dateMax.ToOADate();
                }
                else if (!double.TryParse(spanDialog.maxValue.Text, out maxValue))
                {
                    DialogUtilities.ShowCouldNotParseValueError("Max Value", spanDialog.maxValue.Text);
                    return;
                }

                plotParams.data = (minValue, maxValue);
            }

            try
            {
                ((App)App.Current).AddSeries(plotParams);
            }
            catch
            {
                DialogUtilities.ShowGenericPlotNotAddedError();
                return;
            }
        }
Example #2
0
        private DrawSettings FetchSettingsFromDialog(SettingsDialog settingsDialog, PlotType type)
        {
            DrawSettings drawSettings = new DrawSettings();

            if (settingsDialog.ShowDialog() != true)
            {//it is nullable
                drawSettings.valid = false;
                return(drawSettings);
            }

            drawSettings.valid = true;

            drawSettings.colour               = settingsDialog.plotColour;
            drawSettings.drawLine             = settingsDialog.shouldDrawLine.IsChecked == true; //Because it is nullable
            drawSettings.drawLinearRegression = settingsDialog.linreg.IsChecked == true;         //Because it is nullable
            drawSettings.type             = type;
            drawSettings.label            = settingsDialog.plotNameTextBox.Text;
            drawSettings.polarCoordinates = settingsDialog.polarCoordinates.IsChecked == true; //Nullable
            drawSettings.dateXAxis        = settingsDialog.dateXAxis.IsChecked == true;        //Nullable

            if (type == PlotType.histogram)
            {
                if (settingsDialog.fractionHistogram.IsChecked == true)
                {
                    drawSettings.histogramType = HistogramType.fraction;
                }
                else
                {
                    drawSettings.histogramType = HistogramType.count;
                }

                if (settingsDialog.cumulativeHistogram.IsChecked == true)
                {
                    drawSettings.histogramType |= HistogramType.cumulative;
                }
                else
                {
                    drawSettings.histogramType |= HistogramType.density;
                }
            }

            string markerTypeName = settingsDialog.markerTypeComboBox.Text.ToUpperInvariant();

            switch (markerTypeName)
            {
            case "FILLED CIRCLE":
                drawSettings.markerShape = ScottPlot.MarkerShape.filledCircle;
                break;

            case "FILLED SQUARE":
                drawSettings.markerShape = ScottPlot.MarkerShape.filledSquare;
                break;

            case "OPEN CIRCLE":
                drawSettings.markerShape = ScottPlot.MarkerShape.openCircle;
                break;

            case "OPEN SQUARE":
                drawSettings.markerShape = ScottPlot.MarkerShape.openSquare;
                break;

            case "FILLED DIAMOND":
                drawSettings.markerShape = ScottPlot.MarkerShape.filledDiamond;
                break;

            case "OPEN DIAMOND":
                drawSettings.markerShape = ScottPlot.MarkerShape.openDiamond;
                break;

            case "ASTERISK":
                drawSettings.markerShape = ScottPlot.MarkerShape.asterisk;
                break;

            case "HASHTAG":
                drawSettings.markerShape = ScottPlot.MarkerShape.hashTag;
                break;

            case "CROSS":
                drawSettings.markerShape = ScottPlot.MarkerShape.cross;
                break;

            case "EKS":
                drawSettings.markerShape = ScottPlot.MarkerShape.eks;
                break;

            case "VERTICAL BAR":
                drawSettings.markerShape = ScottPlot.MarkerShape.verticalBar;
                break;

            case "TRI UP":
                drawSettings.markerShape = ScottPlot.MarkerShape.triUp;
                break;

            case "TRI DOWN":
                drawSettings.markerShape = ScottPlot.MarkerShape.triDown;
                break;

            case "NONE":
                drawSettings.markerShape = ScottPlot.MarkerShape.none;
                break;
            }
            return(drawSettings);
        }
Example #3
0
        private void LoadCSVSeries_Click(object sender, RoutedEventArgs e)
        {
            string plotType = ((MenuItem)e.OriginalSource).Header.ToString().ToUpperInvariant();

            PlotType type = new PlotType();

            switch (plotType)
            {
            case "SCATTER PLOT":
                type = PlotType.scatter;
                break;

            case "SIGNAL":
                type = PlotType.signal;
                break;

            case "BAR PLOT":
                type = PlotType.bar;
                break;

            case "HISTOGRAM":
                type = PlotType.histogram;
                break;

            case "BOX AND WHISKER":
                type = PlotType.box_whisker;
                break;

            case "GROUPED BAR PLOT":
                type = PlotType.bar_grouped;
                break;
            }

            SettingsDialog settingsDialog = new SettingsDialog(type);

            settingsDialog.Owner = App.Current.MainWindow;

            DrawSettings drawSettings;

            drawSettings = FetchSettingsFromDialog(settingsDialog, type);
            if (!drawSettings.valid)
            {
                return;
            }

            Dictionary <string, object> metadata = new Dictionary <string, object>();

            if (type == PlotType.signal)
            {
                SignalFrequencyDialog dlg = new SignalFrequencyDialog();
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                double sampleRate;
                if (!double.TryParse(dlg.frequency, out sampleRate))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Sample Rate", dlg.frequency);
                    return;
                }

                double xOffset;
                if (double.TryParse(dlg.xOffsetTextBox.Text, out xOffset))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("X-Offset", dlg.xOffsetTextBox.Text);
                    return;
                }

                metadata.Add("sampleRate", sampleRate);
                metadata.Add("xOffset", xOffset);
            }
            else if (type == PlotType.bar_grouped)
            {
                GroupedPlotDialog dlg = new GroupedPlotDialog();
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                if (dlg.groupNamesTextBox.Text != "")
                {
                    metadata.Add("group_names", dlg.groupNamesTextBox.Text.Split(','));
                }

                if (dlg.seriesNamesTextBox.Text != "")
                {
                    metadata.Add("series_names", dlg.seriesNamesTextBox.Text.Split(','));
                }
            }


            FilePickerDialog filePickerDialog = new FilePickerDialog(drawSettings.type == PlotType.bar_grouped);

            filePickerDialog.Owner = App.Current.MainWindow;

            try
            {
                if (filePickerDialog.ShowDialog() == true)
                {
                    PlotParameters plotParams = new PlotParameters();
                    plotParams = (App.Current as App).AddSeriesFromCSVFile(filePickerDialog.filepath, drawSettings, metadata);
                    if (settingsDialog.errorDataCSV != null)
                    {
                        ((App)App.Current).AddErrorFromCSVFile(plotParams, settingsDialog.errorDataCSV);
                    }
                    statusMessage.Text = $"{filePickerDialog.filepath} loaded";
                }
            }
            catch
            {
                DialogUtilities.ShowGenericPlotNotAddedError();
                return;
            }
        }
Example #4
0
        private void PrefabSeries_Click(object sender, RoutedEventArgs e)
        {
            string plotType = ((MenuItem)e.OriginalSource).Header.ToString().ToUpperInvariant();

            PlotType type = new PlotType();

            switch (plotType)
            {
            case "SIGNAL":
                type = PlotType.signal;
                break;
            }

            SettingsDialog settingsDialog = new SettingsDialog(type);

            settingsDialog.Owner = App.Current.MainWindow;

            DrawSettings drawSettings;

            drawSettings = FetchSettingsFromDialog(settingsDialog, type);
            if (!drawSettings.valid)
            {
                return;
            }

            Dictionary <string, object> metadata = new Dictionary <string, object>();

            if (type == PlotType.signal)
            {
                PrefabSignalDialog prefabSignalDialog = new PrefabSignalDialog();
                prefabSignalDialog.Owner = App.Current.MainWindow;
                if (prefabSignalDialog.ShowDialog() != true) //Nullable
                {
                    return;
                }

                double   cycleCount = 10;
                double   frequency  = 1000;
                WaveType waveType   = WaveType.sine;

                if (!double.TryParse(prefabSignalDialog.cycleCountTextBox.Text, out cycleCount))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Cycle Count", prefabSignalDialog.cycleCountTextBox.Text);
                    return;
                }

                if (!double.TryParse(prefabSignalDialog.frequencyTextBox.Text, out frequency))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Frequency", prefabSignalDialog.frequencyTextBox.Text);
                    return;
                }

                switch (prefabSignalDialog.waveTypeComboBox.Text.ToUpperInvariant())
                {
                case "SINE WAVE":
                    waveType = WaveType.sine;
                    break;

                case "SQUARE WAVE":
                    waveType = WaveType.square;
                    break;
                }

                SignalFrequencyDialog dlg = new SignalFrequencyDialog(true);
                dlg.Owner = App.Current.MainWindow;
                if (dlg.ShowDialog() != true)
                { //Nullable
                    return;
                }

                double sampleRate;
                if (!double.TryParse(dlg.frequency, out sampleRate))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("Sample Rate", dlg.frequency);
                    return;
                }

                double xOffset;
                if (!double.TryParse(dlg.xOffsetTextBox.Text, out xOffset))
                {
                    DialogUtilities.ShowCouldNotParseNumberError("X-Offset", dlg.xOffsetTextBox.Text);
                    return;
                }

                metadata.Add("xOffset", xOffset);

                StringBuilder dataStr = new StringBuilder();

                int      upperBound = (int)Math.Ceiling(cycleCount * frequency);
                double[] data       = new double[upperBound];


                metadata.Add("sampleRate", frequency * frequency);

                if (waveType == WaveType.sine)
                {
                    data = ScottPlot.DataGen.Sin(upperBound, cycleCount);
                }
                else if (waveType == WaveType.square)
                {
                    bool high = false;
                    for (int i = 0; i < upperBound; i++)
                    {
                        if (i % (frequency / 2) == 0)
                        {
                            high = !high;
                        }

                        data[i] = high ? 1 : 0;
                    }
                }

                for (int i = 0; i < upperBound; i++)
                {
                    dataStr.Append(data[i]);
                    if (i != upperBound - 1)
                    {
                        dataStr.Append(',');
                    }
                }


                try
                {
                    ((App)App.Current).AddSeriesFromString(dataStr.ToString(), drawSettings, metadata);
                }
                catch
                {
                    DialogUtilities.ShowGenericPlotNotAddedError();
                    return;
                }
            }
        }