/// <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); }