Esempio n. 1
0
        private static Tuple <string, NonlinearFitDocument, string, XYPlotLayer> SelectFitDocument(Gui.Graph.Gdi.Viewing.IGraphController ctrl, XYColumnPlotItem columnPlotItem)
        {
            if (null == columnPlotItem)
            {
                throw new ArgumentNullException(nameof(columnPlotItem));
            }

            var        activeLayer             = Altaxo.Main.AbsoluteDocumentPath.GetRootNodeImplementing <XYPlotLayer>(columnPlotItem);
            DataColumn columPlotItemDataColumn = columnPlotItem.Data.YColumn.GetUnderlyingDataColumnOrDefault();

            if (null != columPlotItemDataColumn)
            {
                // try to find a nonlinear function plot item whose dependent variable equals to the y of the column plot item
                foreach (var funcItem in TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYNonlinearFitFunctionPlotItem>())
                {
                    if (object.ReferenceEquals(columPlotItemDataColumn, funcItem.DependentVariableColumn.GetUnderlyingDataColumnOrDefault()))
                    {
                        return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(string.Empty, funcItem.FitDocumentCopy, funcItem.FitDocumentIdentifier, activeLayer));
                    }
                }
            }
            // Get a new fit document from the selected xy plot item
            return(GetNewFitDocumentFor(columnPlotItem, ctrl));
        }
Esempio n. 2
0
        private static Tuple <string, NonlinearFitDocument, string, XYPlotLayer> SelectFitDocument(Gui.Graph.Gdi.Viewing.IGraphController ctrl, XYPlotLayer activeLayer)
        {
            if (null == activeLayer)
            {
                throw new ArgumentNullException(nameof(activeLayer));
            }

            // try to use the first nonlinear function plot item of the active layer
            // ------------------------------------------------------------------------------------
            {
                var plotItem = TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYNonlinearFitFunctionPlotItem>().FirstOrDefault();
                if (null != plotItem)
                {
                    return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(string.Empty, plotItem.FitDocumentCopy, plotItem.FitDocumentIdentifier, activeLayer));
                }
            }

            // try to use the active plot item of the active layer
            // ------------------------------------------------------------------------------------

            if (ctrl.CurrentPlotNumber >= 0)
            {
                var plotItem = activeLayer.PlotItems.Flattened[ctrl.CurrentPlotNumber] as XYColumnPlotItem;
                return(SelectFitDocument(ctrl, plotItem));
            }

            // try to use the first plot item of the active layer
            // ------------------------------------------------------------------------------------
            {
                var plotItem = TreeNodeExtensions.TakeFromHereToFirstLeaves((IGPlotItem)activeLayer.PlotItems).OfType <XYColumnPlotItem>().FirstOrDefault();
                if (null != plotItem)
                {
                    return(SelectFitDocument(ctrl, plotItem));
                }
            }

            return(new Tuple <string, NonlinearFitDocument, string, XYPlotLayer>(null, null, null, null));
        }