void ConstuctPlot(DataPointCollection dataPointCollection) { // function to filter the results if we're not auto-scaling Func <DataPoint, bool> isWithinAxes = p => (AutoScaleX || (p.X <= MaxXValue && p.X >= MinXValue)) && (AutoScaleY || (p.Y <= MaxYValue && p.Y >= MinYValue)); // function to filter out any invalid data points Func <DataPoint, bool> isValidDataPoint = p => !double.IsInfinity(Math.Abs(p.X)) && !double.IsNaN(p.X) && !double.IsInfinity(Math.Abs(p.Y)) && !double.IsNaN(p.Y); //check if any normalization is selected var normToCurve = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToCurve && DataSeriesCollection.Count > 1; var normToMax = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToMax && DataSeriesCollection.Count > 0; var tempPointArrayA = new List <Point>(); var tempPointArrayB = new List <Point>(); double x; double y; var lineSeriesA = new LineSeries(); var lineSeriesB = new LineSeries(); //we need B for complex if (dataPointCollection.DataPoints[0] is ComplexDataPoint) { // normalization calculations var max = 1.0; if (normToMax) { var points = dataPointCollection.DataPoints.Cast <ComplexDataPoint>().ToArray(); max = points.Select(p => p.Y.Real).Max(); } double[] tempY = null; if (normToCurve) { tempY = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Real).ToArray(); } var curveIndex = 0; foreach (var dp in dataPointCollection.DataPoints.Cast <ComplexDataPoint>()) { x = XAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(dp.X) : dp.X; switch (PlotToggleTypeOptionVM.SelectedValue) { case PlotToggleType.Phase: y = -(dp.Y.Phase * (180 / Math.PI)); break; case PlotToggleType.Amp: y = dp.Y.Magnitude; break; default: // case PlotToggleType.Complex: y = dp.Y.Real; switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: y = y / max; break; } y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y; var p = new DataPoint(x, y); if (isValidDataPoint(p) && isWithinAxes(p)) { lineSeriesB.Points.Add(p); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayB.Add(new Point(x, y)); } y = dp.Y.Imaginary; break; } switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: y = y / max; break; } y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y; var point = new DataPoint(x, y); if (isValidDataPoint(point) && isWithinAxes(point)) { lineSeriesA.Points.Add(point); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayA.Add(new Point(x, y)); } curveIndex += 1; } ShowComplexPlotToggle = true; // right now, it's all or nothing - assume all plots are ComplexDataPoints } else { // normalization calculations var max = 1.0; if (normToMax) { var points = dataPointCollection.DataPoints.Cast <DoubleDataPoint>().ToArray(); max = points.Select(p => p.Y).Max(); } double[] tempY = null; if (normToCurve) { tempY = (from DoubleDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y).ToArray(); } var curveIndex = 0; foreach (var dp in dataPointCollection.DataPoints.Cast <DoubleDataPoint>()) { x = XAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(dp.X) : dp.X; switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0; y = dp.Y / curveY; break; case PlotNormalizationType.RelativeToMax: y = dp.Y / max; break; default: y = dp.Y; break; } y = YAxisSpacingOptionVM.SelectedValue == ScalingType.Log ? Math.Log10(y) : y; var point = new DataPoint(x, y); if (isValidDataPoint(point) && isWithinAxes(point)) { lineSeriesA.Points.Add(point); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayA.Add(new Point(x, y)); } curveIndex += 1; } } if (ShowComplexPlotToggle) { switch (PlotToggleTypeOptionVM.SelectedValue) { case PlotToggleType.Complex: lineSeriesA.Title = dataPointCollection.Title + " (imag)"; lineSeriesB.Title = dataPointCollection.Title + " (real)"; lineSeriesB.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesB); PlotSeriesCollection.Add(tempPointArrayB.ToArray()); break; case PlotToggleType.Phase: lineSeriesA.Title = dataPointCollection.Title + " (phase)"; break; case PlotToggleType.Amp: lineSeriesA.Title = dataPointCollection.Title + " (amp)"; break; } lineSeriesA.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesA); PlotModel.Title = PlotTitles[PlotTitles.Count - 1]; PlotSeriesCollection.Add(tempPointArrayA.ToArray()); } else { lineSeriesA.Title = dataPointCollection.Title; lineSeriesA.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesA); PlotModel.Title = PlotTitles[PlotTitles.Count - 1]; PlotSeriesCollection.Add(tempPointArrayA.ToArray()); } }
private void ConstuctPlot(DataPointCollection dataPointCollection) { // function to filter the results if we're not auto-scaling Func <DataPoint, bool> isWithinAxes = p => (!ManualScaleX || (p.X <= MaxXValue && p.X >= MinXValue)) && (!ManualScaleY || (p.Y <= MaxYValue && p.Y >= MinYValue)); // function to filter out any invalid data points Func <DataPoint, bool> isValidDataPoint = p => !double.IsInfinity(Math.Abs(p.X)) && !double.IsNaN(p.X) && !double.IsInfinity(Math.Abs(p.Y)) && !double.IsNaN(p.Y); // //check if any normalization is selected var normToCurve = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToCurve && DataSeriesCollection.Count > 1; var normToMax = PlotNormalizationTypeOptionVM.SelectedValue == PlotNormalizationType.RelativeToMax && DataSeriesCollection.Count > 0; var tempPointArrayA = new List <Point>(); var tempPointArrayB = new List <Point>(); double x; double y; var lineSeriesA = new LineSeries(); var lineSeriesB = new LineSeries(); //we need B for complex if (dataPointCollection.DataPoints[0] is ComplexDataPoint) { // normalization calculations var max = 1.0; var maxRe = 1.0; var maxIm = 1.0; if (normToMax) { var points = dataPointCollection.DataPoints.Cast <ComplexDataPoint>().ToArray(); switch (PlotToggleTypeOptionVM.SelectedValue) { case PlotToggleType.Phase: max = points.Select(p => p.Y.Phase * (-180 / Math.PI)).Max(); break; case PlotToggleType.Amp: max = points.Select(p => p.Y.Magnitude).Max(); break; case PlotToggleType.Complex: maxRe = points.Select(p => p.Y.Real).Max(); maxIm = points.Select(p => p.Y.Imaginary).Max(); break; } } double[] tempAmp = null; double[] tempPh = null; double[] tempRe = null; double[] tempIm = null; if (normToCurve) { tempAmp = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Magnitude).ToArray(); tempPh = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Phase * (-180 / Math.PI)).ToArray(); tempRe = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Real).ToArray(); tempIm = (from ComplexDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y.Imaginary).ToArray(); } var curveIndex = 0; foreach (var dp in dataPointCollection.DataPoints.Cast <ComplexDataPoint>()) { x = XAxisLog10 ? Math.Log10(dp.X) : dp.X; switch (PlotToggleTypeOptionVM.SelectedValue) { case PlotToggleType.Phase: y = -(dp.Y.Phase * (180 / Math.PI)); // force phase to be between 0 and 360 if (y < 0) { y += 360; } switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempPh != null ? tempPh[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: y = y / max; break; } break; case PlotToggleType.Amp: y = dp.Y.Magnitude; switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempAmp != null ? tempAmp[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: y = y / max; break; } break; default: // case PlotToggleType.Complex: y = dp.Y.Real; switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempRe != null ? tempRe[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: max = maxRe; y = y / max; break; } y = YAxisLog10 ? Math.Log10(y) : y; var p = new DataPoint(x, y); if (isValidDataPoint(p) && isWithinAxes(p)) { lineSeriesB.Points.Add(p); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayB.Add(new Point(x, y)); } y = dp.Y.Imaginary; //break; // handle imag within switch switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempIm != null ? tempIm[curveIndex] : 1.0; y = y / curveY; break; case PlotNormalizationType.RelativeToMax: max = maxIm; y = y / max; break; } break; } // ckh 8/13/18 code does not need to repeat here since inside switch above now for all cases //switch (PlotNormalizationTypeOptionVM.SelectedValue) //{ // case PlotNormalizationType.RelativeToCurve: // var curveY = normToCurve && tempAmp != null ? tempAmp[curveIndex] : 1.0; // y = y/curveY; // break; // case PlotNormalizationType.RelativeToMax: // y = y/max; // break; //} y = YAxisLog10 ? Math.Log10(y) : y; var point = new DataPoint(x, y); if (isValidDataPoint(point) && isWithinAxes(point)) { lineSeriesA.Points.Add(point); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayA.Add(new Point(x, y)); } curveIndex += 1; } ShowComplexPlotToggle = true; // right now, it's all or nothing - assume all plots are ComplexDataPoints } else { // normalization calculations var max = 1.0; if (normToMax) { var points = dataPointCollection.DataPoints.Cast <DoubleDataPoint>().ToArray(); max = points.Select(p => p.Y).Max(); } double[] tempY = null; if (normToCurve) { tempY = (from DoubleDataPoint dp in DataSeriesCollection[0].DataPoints select dp.Y).ToArray(); } var curveIndex = 0; foreach (var dp in dataPointCollection.DataPoints.Cast <DoubleDataPoint>()) { x = XAxisLog10 ? Math.Log10(dp.X) : dp.X; switch (PlotNormalizationTypeOptionVM.SelectedValue) { case PlotNormalizationType.RelativeToCurve: var curveY = normToCurve && tempY != null ? tempY[curveIndex] : 1.0; y = dp.Y / curveY; break; case PlotNormalizationType.RelativeToMax: y = dp.Y / max; break; default: y = dp.Y; break; } y = YAxisLog10 ? Math.Log10(y) : y; var point = new DataPoint(x, y); if (isValidDataPoint(point) && isWithinAxes(point)) { lineSeriesA.Points.Add(point); //Add the data to the tempPointArray to add to the PlotSeriesCollection tempPointArrayA.Add(new Point(x, y)); } curveIndex += 1; } } if (ShowComplexPlotToggle) { switch (PlotToggleTypeOptionVM.SelectedValue) { case PlotToggleType.Complex: lineSeriesA.Title = dataPointCollection.Title + StringLookup.GetLocalizedString("Label_Imaginary"); lineSeriesB.Title = dataPointCollection.Title + StringLookup.GetLocalizedString("Label_Real"); lineSeriesB.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesB); PlotSeriesCollection.Add(tempPointArrayB.ToArray()); break; case PlotToggleType.Phase: lineSeriesA.Title = dataPointCollection.Title + StringLookup.GetLocalizedString("Label_Phase"); break; case PlotToggleType.Amp: lineSeriesA.Title = dataPointCollection.Title + StringLookup.GetLocalizedString("Label_Amplitude"); break; } lineSeriesA.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesA); PlotModel.Title = PlotTitles[PlotTitles.Count - 1]; PlotSeriesCollection.Add(tempPointArrayA.ToArray()); } else { lineSeriesA.Title = dataPointCollection.Title; lineSeriesA.MarkerType = MarkerType.Circle; PlotModel.Series.Add(lineSeriesA); PlotModel.Title = PlotTitles[PlotTitles.Count - 1]; PlotSeriesCollection.Add(tempPointArrayA.ToArray()); } PlotModel.Axes.Clear(); PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Bottom, Title = XAxis, TitleFontWeight = FontWeights.Bold }); PlotModel.Axes.Add(new LinearAxis { Position = AxisPosition.Left, Title = YAxis, TitleFontWeight = FontWeights.Bold }); }