public static string Fit(Altaxo.Graph.GUI.GraphController ctrl) { if (ctrl.CurrentPlotNumber < 0) { return("No active plot!"); } IGPlotItem plotItem = ctrl.ActiveLayer.PlotItems.Flattened[ctrl.CurrentPlotNumber]; XYColumnPlotItem xyPlotItem = plotItem as XYColumnPlotItem; if (xyPlotItem == null) { return("Active plot is not a X-Y Plot!"); } INumericColumn xColumn = xyPlotItem.XYColumnPlotData.XColumn as INumericColumn; INumericColumn yColumn = xyPlotItem.XYColumnPlotData.YColumn as INumericColumn; if (xColumn == null) { return("The x-column is not numeric"); } if (yColumn == null) { return("The y-column is not numeric"); } Calc.Regression.Nonlinear.NonlinearFitDocument localdoc = ctrl.Doc.GetGraphProperty(FitDocumentPropertyName) as Calc.Regression.Nonlinear.NonlinearFitDocument; if (localdoc == null) { if (_lastFitDocument == null) { localdoc = new Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument(); } else { localdoc = (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)_lastFitDocument.Clone(); } } if (localdoc.FitEnsemble.Count == 0) { Calc.Regression.Nonlinear.FitElement fitele = new Altaxo.Calc.Regression.Nonlinear.FitElement( xColumn, yColumn, xyPlotItem.XYColumnPlotData.PlotRangeStart, xyPlotItem.XYColumnPlotData.PlotRangeLength); localdoc.FitEnsemble.Add(fitele); } else // localdoc.FitEnsemble.Count>0 { localdoc.FitEnsemble[0].SetIndependentVariable(0, xColumn); localdoc.FitEnsemble[0].SetDependentVariable(0, yColumn); localdoc.FitEnsemble[0].SetRowRange(xyPlotItem.XYColumnPlotData.PlotRangeStart, xyPlotItem.XYColumnPlotData.PlotRangeLength); } localdoc.FitContext = ctrl; object fitdocasobject = localdoc; if (true == Current.Gui.ShowDialog(ref fitdocasobject, "Non-linear fitting")) { // store the fit document in the graphs property ctrl.Doc.SetGraphProperty(FitDocumentPropertyName, localdoc); _lastFitDocument = (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)localdoc.Clone(); } return(null); }
public static string Fit(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl) { if (ctrl.CurrentPlotNumber < 0) return "No active plot!"; var xylayer = ctrl.ActiveLayer as XYPlotLayer; if (null == xylayer) return "No XYPlotLayer active"; IGPlotItem plotItem = xylayer.PlotItems.Flattened[ctrl.CurrentPlotNumber]; XYColumnPlotItem xyPlotItem = plotItem as XYColumnPlotItem; if (xyPlotItem == null) return "Active plot is not a X-Y Plot!"; var xColumn = xyPlotItem.XYColumnPlotData.XColumn as IReadableColumn; var yColumn = xyPlotItem.XYColumnPlotData.YColumn as IReadableColumn; if (xColumn == null || xColumn.ItemType!=typeof(double)) return "The x-column is not numeric"; if (yColumn == null || yColumn.ItemType!=typeof(double)) return "The y-column is not numeric"; Calc.Regression.Nonlinear.NonlinearFitDocument localdoc = ctrl.Doc.GetGraphProperty(FitDocumentPropertyName) as Calc.Regression.Nonlinear.NonlinearFitDocument; if (localdoc == null) { if (_lastFitDocument == null) { localdoc = new Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument(); } else { localdoc = (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)_lastFitDocument.Clone(); } } if (localdoc.FitEnsemble.Count == 0) // if there was no fit before { Calc.Regression.Nonlinear.FitElement fitele = new Altaxo.Calc.Regression.Nonlinear.FitElement( xyPlotItem.Data.DataTable, xyPlotItem.Data.GroupNumber, xyPlotItem.Data.DataRowSelection, xColumn, yColumn); localdoc.FitEnsemble.Add(fitele); } else // there was a fit before, thus localdoc.FitEnsemble.Count>0 { bool hasColumnsChanged = false; hasColumnsChanged |= !(object.ReferenceEquals(localdoc.FitEnsemble[0].DataTable, xyPlotItem.Data.DataTable)); hasColumnsChanged |= !(object.ReferenceEquals(localdoc.FitEnsemble[0].GroupNumber, xyPlotItem.Data.GroupNumber)); hasColumnsChanged |= !(object.ReferenceEquals(localdoc.FitEnsemble[0].IndependentVariables(0), xColumn)); hasColumnsChanged |= !(object.ReferenceEquals(localdoc.FitEnsemble[0].DependentVariables(0), yColumn)); localdoc.FitEnsemble[0].SetIndependentVariable(0, xColumn); localdoc.FitEnsemble[0].SetDependentVariable(0, yColumn); if (hasColumnsChanged) // if some of the columns has changed, take the data row selection of the plot item { localdoc.FitEnsemble[0].DataRowSelection = xyPlotItem.Data.DataRowSelection; } } localdoc.FitContext = ctrl; object fitdocasobject = localdoc; if (true == Current.Gui.ShowDialog(ref fitdocasobject, "Non-linear fitting")) { // store the fit document in the graphs property ctrl.Doc.SetGraphProperty(FitDocumentPropertyName, localdoc); _lastFitDocument = (Altaxo.Calc.Regression.Nonlinear.NonlinearFitDocument)localdoc.Clone(); } return null; }