public PlotParameters AddSeriesFromCSVFile(string[] filenames, DrawSettings drawSettings, Dictionary <string, object> metadata = null) { if (drawSettings.type == PlotType.bar_grouped) { string[] raw = new string[filenames.Length]; for (int i = 0; i < raw.Length; i++) { using (StreamReader file = new StreamReader(filenames[i])) { raw[i] = (file.ReadToEnd()); } } return(AddSeriesFromString(raw, drawSettings, metadata)); } else { throw new NotSupportedException(); } }
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); }
public PlotParameters AddSeriesFromString(string dataString, DrawSettings drawSettings, Dictionary <string, object> metadata) { object data = new object(); string[] raw = dataString.Split(new char[] { ',', '\n' }); if (!drawSettings.dateXAxis) { List <double> serialData = raw.Where(m => double.TryParse(m, out _)).Select(m => double.Parse(m)).ToList(); if (drawSettings.type == PlotType.scatter || drawSettings.type == PlotType.bar) { double[] xs = new double[serialData.Count / 2]; double[] ys = new double[serialData.Count / 2]; for (int i = 0; i < serialData.Count; i++) { int row = i / 2; int col = i % 2; if (col == 0) { xs[row] = serialData[i]; } else { ys[row] = serialData[i]; } data = new double[][] { xs, ys }; } } else if (drawSettings.type == PlotType.signal || drawSettings.type == PlotType.histogram) { data = serialData.ToArray(); } else if (drawSettings.type == PlotType.box_whisker) { ScottPlot.Statistics.Population dataPopulation = new ScottPlot.Statistics.Population(serialData.ToArray()); data = dataPopulation; } if (drawSettings.type == PlotType.scatter && drawSettings.polarCoordinates) { (((double[][])data)[0], ((double[][])data)[1]) = ScottPlot.Tools.ConvertPolarCoordinates(((double[][])data)[0], ((double[][])data)[1]); } } else { if (drawSettings.type == PlotType.scatter || drawSettings.type == PlotType.bar) { List <DateTime> dataX = new List <DateTime>(); List <double> dataY = new List <double>(); int successfullyParsed = 0; for (int i = 0; i < raw.Length; i++) { if (successfullyParsed % 2 == 0) { DateTime temp; if (DateTime.TryParse(raw[i], out temp)) { dataX.Add(temp); successfullyParsed++; } } else { double temp; if (double.TryParse(raw[i], out temp)) { dataY.Add(temp); successfullyParsed++; } } } long totalDistanceTicks = 0; for (int i = 0; i < dataX.Count; i++) { if (i == dataX.Count - 1) { break; } totalDistanceTicks += Math.Abs(dataX[i].Ticks - dataX[i + 1].Ticks); } long averageTickDistance = totalDistanceTicks / (dataX.Count - dataX.Count % 2); //The fact that this is rounded doesn't matter, bc ticks are so obsenely small long averageSecondsDistance = averageTickDistance / 10_000_000; metadata["numTimeUnits"] = 1; if (averageSecondsDistance > 0.75 * 86400 * 365) { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Year; } else if (averageSecondsDistance > 0.75 * 86400 * 30) { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Month; } else if (averageSecondsDistance > 0.75 * 86400) { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Day; } else if (averageSecondsDistance > 0.75 * 3600) { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Hour; } else if (averageSecondsDistance > 0.75 * 60) { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Minute; } else { metadata["timeUnit"] = ScottPlot.Config.DateTimeUnit.Second; } metadata["startDate"] = dataX[0]; metadata["numTimeUnits"] = (dataX.Count / 30) + 1; double[] dataXDouble = dataX.Select((dt, i) => dt.ToOADate()).ToArray(); data = new double[][] { dataXDouble, dataY.ToArray() }; } } PlotParameters plotParams = new PlotParameters { data = data, drawSettings = drawSettings, metaData = metadata }; series.Add(plotParams); ((MainWindow)this.MainWindow).RenderPlot(); return(plotParams); }