/// <summary> /// Retrieves the data points of the current active plot. /// </summary> /// <param name="ctrl">The graph controller which controls the graph from which the points are to retrieve.</param> /// <param name="xarr">The array of the data point's x values.</param> /// <param name="yarr">The array of the data point's y values.</param> /// <returns>Null if all is ok, or error message if not.</returns> public static string GetActivePlotPoints(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl, out double[] xarr, out double[] yarr) { List<double> xlist = new List<double>(); List<double> ylist = new List<double>(); xarr = yarr = null; ctrl.EnsureValidityOfCurrentLayerNumber(); ctrl.EnsureValidityOfCurrentPlotNumber(); var xylayer = ctrl.ActiveLayer as XYPlotLayer; if (null == xylayer || ctrl.CurrentPlotNumber < 0) return "No active plot available"; IGPlotItem plotItem = xylayer.PlotItems.Flattened[ctrl.CurrentPlotNumber]; XYColumnPlotItem xyPlotItem = plotItem as XYColumnPlotItem; if (xyPlotItem == null) return "No active plot!"; XYColumnPlotData data = xyPlotItem.XYColumnPlotData; if (data == null) return "Active plot item has no data"; if (!(data.XColumn is Altaxo.Data.INumericColumn) || !(data.YColumn is Altaxo.Data.INumericColumn)) return "X-Y values of plot data are not both numeric"; Altaxo.Data.INumericColumn xcol = (Altaxo.Data.INumericColumn)data.XColumn; Altaxo.Data.INumericColumn ycol = (Altaxo.Data.INumericColumn)data.YColumn; int maxRowIndex = data.GetMaximumRowIndexFromDataColumns(); foreach (int i in data.DataRowSelection.GetSelectedRowIndicesFromTo(0, maxRowIndex, data.DataTable?.DataColumns, maxRowIndex)) { double x = xcol[i]; double y = ycol[i]; if (double.IsNaN(x) || double.IsNaN(y)) continue; xlist.Add(x); ylist.Add(y); } xarr = xlist.ToArray(); yarr = ylist.ToArray(); return null; }
/// <summary> /// Retrieves the data points of the current active plot. /// </summary> /// <param name="ctrl">The graph controller which controls the graph from which the points are to retrieve.</param> /// <param name="xarr">The array of the data point's x values.</param> /// <param name="yarr">The array of the data point's y values.</param> /// <param name="nPlotPoints">The number of plot points (may be smaller than the length of x and y arrays.</param> /// <returns>Null if all is ok, or error message if not.</returns> public static string GetActivePlotPoints(Altaxo.Graph.GUI.GraphController ctrl, ref double[]xarr, ref double[] yarr, out int nPlotPoints) { nPlotPoints=0; ctrl.EnsureValidityOfCurrentLayerNumber(); ctrl.EnsureValidityOfCurrentPlotNumber(); IGPlotItem plotItem = ctrl.ActiveLayer.PlotItems.Flattened[ctrl.CurrentPlotNumber]; XYColumnPlotItem xyPlotItem = plotItem as XYColumnPlotItem; if(xyPlotItem==null) return "No active plot!"; XYColumnPlotData data = xyPlotItem.XYColumnPlotData; if(data==null) return "Active plot item has no data"; if(!(data.XColumn is Altaxo.Data.INumericColumn) || !(data.YColumn is Altaxo.Data.INumericColumn)) return "X-Y values of plot data are not both numeric"; Altaxo.Data.INumericColumn xcol = (Altaxo.Data.INumericColumn)data.XColumn; Altaxo.Data.INumericColumn ycol = (Altaxo.Data.INumericColumn)data.YColumn; int n = data.PlottablePoints; if(null==xarr || xarr.Length<n) xarr = new double[n]; if(null==yarr || yarr.Length<n) yarr = new double[n]; int end = data.PlotRangeEnd; int j=0; for(int i=data.PlotRangeStart;i<end && j<n;i++) { double x = xcol[i]; double y = ycol[i]; if(double.IsNaN(x) || double.IsNaN(y)) continue; xarr[j] = x; yarr[j] = y; ++j; } nPlotPoints = j; return null; }
public override void Run(Altaxo.Graph.GUI.GraphController ctrl) { FunctionEvaluationScript script = null; // if(script==null) script = new FunctionEvaluationScript(); object[] args = new object[]{script,new ScriptExecutionHandler(this.EhScriptExecution)}; if(Current.Gui.ShowDialog(args, "Function script")) { ctrl.EnsureValidityOfCurrentLayerNumber(); script = (FunctionEvaluationScript)args[0]; XYFunctionPlotItem functItem = new XYFunctionPlotItem(new XYFunctionPlotData(script),new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line)); ctrl.Doc.Layers[ctrl.CurrentLayerNumber].PlotItems.Add(functItem); } }
public override void Run(Altaxo.Graph.GUI.GraphController ctrl) { ctrl.EnsureValidityOfCurrentLayerNumber(); ctrl.Doc.Layers[ctrl.CurrentLayerNumber].PlotItems.Add(new XYFunctionPlotItem(new XYFunctionPlotData(new PolynomialFunction(new double[]{0,0,1})),new G2DPlotStyleCollection(LineScatterPlotStyleKind.Line))); }
public override void Run(Altaxo.Graph.GUI.GraphController ctrl) { ctrl.EnsureValidityOfCurrentLayerNumber(); if(null!=ctrl.ActiveLayer) LayerController.ShowDialog(ctrl.ActiveLayer); }