Exemplo n.º 1
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                XYColumnPlotData       pa   = (XYColumnPlotData)info.GetValue("Data", typeof(XYColumnPlotData));
                XYLineScatterPlotStyle lsps = (XYLineScatterPlotStyle)info.GetValue("Style", typeof(XYLineScatterPlotStyle));

                if (lsps.XYPlotLineStyle != null)
                {
                    lsps.XYPlotLineStyle.LineSymbolGap = lsps.LineSymbolGap; // this has changed and is now hosted in the LineStyle itself
                }
                G2DPlotStyleCollection ps = new G2DPlotStyleCollection(new IG2DPlotStyle[] { lsps.XYPlotLineStyle, lsps.ScatterStyle, lsps.XYPlotLabelStyle });

                if (lsps.XYPlotLabelStyle != null)
                {
                    XmlSerializationSurrogate0 surr = new XmlSerializationSurrogate0();
                    surr._item  = pa;
                    surr._label = lsps.XYPlotLabelStyle;
                    info.DeserializationFinished += new Altaxo.Serialization.Xml.XmlDeserializationCallbackEventHandler(surr.info_DeserializationFinished);
                }



                if (null == o)
                {
                    return(new XYColumnPlotItem(pa, ps));
                }
                else
                {
                    XYColumnPlotItem s = (XYColumnPlotItem)o;
                    s.Data  = pa;
                    s.Style = ps;
                    return(s);
                }
            }
Exemplo n.º 2
0
        /// <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)
        {
            var xlist = new List <double>();
            var 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];

            var 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");
            }

            var xcol = (Altaxo.Data.INumericColumn)data.XColumn;
            var 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);
        }
Exemplo n.º 3
0
 private System.Collections.Generic.IEnumerable <DocumentNodeAndName> GetLocalDocumentNodeChildrenWithName()
 {
     if (null != _plotData)
     {
         yield return(new DocumentNodeAndName(_plotData, () => _plotData = null, "Data"));
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Get the names of the x and y column of the active plot.
        /// </summary>
        /// <param name="ctrl">The current active graph controller.</param>
        /// <returns>An array of two strings. The first string is the name of the x-column, the second
        /// the name of the y-column.</returns>
        public static string[] GetActivePlotName(Altaxo.Gui.Graph.Gdi.Viewing.IGraphController ctrl)
        {
            string[] result = new string[2] {
                string.Empty, string.Empty
            };

            var xylayer = ctrl.ActiveLayer as XYPlotLayer;

            if (null == xylayer || ctrl.CurrentPlotNumber < 0)
            {
                return(result);
            }

            IGPlotItem plotItem = xylayer.PlotItems.Flattened[ctrl.CurrentPlotNumber];

            var xyPlotItem = plotItem as XYColumnPlotItem;

            if (xyPlotItem == null)
            {
                return(result);
            }

            XYColumnPlotData data = xyPlotItem.XYColumnPlotData;

            if (data == null)
            {
                return(result);
            }

            result[0] = data.XColumn.FullName;
            result[1] = data.YColumn.FullName;

            return(result);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Get the names of the x and y column of the active plot.
        /// </summary>
        /// <param name="ctrl">The current active graph controller.</param>
        /// <returns>An array of two strings. The first string is the name of the x-column, the second
        /// the name of the y-column.</returns>
        public static string[] GetActivePlotName(Altaxo.Graph.GUI.GraphController ctrl)
        {
            string[] result = new string[2] {
                String.Empty, String.Empty
            };

            IGPlotItem plotItem = ctrl.ActiveLayer.PlotItems.Flattened[ctrl.CurrentPlotNumber];

            XYColumnPlotItem xyPlotItem = plotItem as XYColumnPlotItem;

            if (xyPlotItem == null)
            {
                return(result);
            }

            XYColumnPlotData data = xyPlotItem.XYColumnPlotData;

            if (data == null)
            {
                return(result);
            }

            result[0] = data.XColumn.FullName;
            result[1] = data.YColumn.FullName;

            return(result);
        }
Exemplo n.º 6
0
 public XYLineScatterPlotStyle(XYColumnPlotData pa)
 {
     this.m_LineStyle    = new LinePlotStyle();
     this.m_ScatterStyle = new ScatterPlotStyle();
     // this.m_PlotAssociation = pa;
     this.m_LineSymbolGap = true;
 }
Exemplo n.º 7
0
        /// <summary>
        /// This plots a label plot into the provided layer.
        /// </summary>
        /// <param name="layer">The layer to plot into.</param>
        /// <param name="xcol">The x column.</param>
        /// <param name="ycol">The y column.</param>
        /// <param name="labelcol">The label column.</param>
        public static void PlotOnlyLabel(XYPlotLayer layer, Altaxo.Data.DataColumn xcol, Altaxo.Data.DataColumn ycol, Altaxo.Data.DataColumn labelcol)
        {
            XYColumnPlotData pa = new XYColumnPlotData(xcol, ycol);

            G2DPlotStyleCollection ps         = new G2DPlotStyleCollection(LineScatterPlotStyleKind.Empty);
            LabelPlotStyle         labelStyle = new LabelPlotStyle(labelcol);

            labelStyle.FontSize        = 10;
            labelStyle.BackgroundStyle = new FilledRectangle(System.Drawing.Color.LightCyan);
            ps.Add(labelStyle);

            layer.PlotItems.Add(new XYColumnPlotItem(pa, ps));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Plots the cross PRESS value into a provided layer.
        /// </summary>
        /// <param name="table">The table of PLS output data.</param>
        /// <param name="layer">The layer to plot into.</param>
        public static void PlotCrossPRESSValue(Altaxo.Data.DataTable table, XYPlotLayer layer)
        {
            Altaxo.Data.DataColumn ycol = table[WorksheetAnalysis.GetCrossPRESSValue_ColumnName()];
            Altaxo.Data.DataColumn xcol = table[WorksheetAnalysis.GetNumberOfFactors_ColumnName()];

            XYColumnPlotData       pa = new XYColumnPlotData(xcol, ycol);
            G2DPlotStyleCollection ps = new G2DPlotStyleCollection(LineScatterPlotStyleKind.LineAndScatter);

            layer.PlotItems.Add(new XYColumnPlotItem(pa, ps));

            layer.DefaultXAxisTitleString = "Number of factors";
            layer.DefaultYAxisTitleString = "Cross PRESS value";
        }
Exemplo n.º 9
0
      private string GetName(object obj)
      {
        string result = string.Empty;

        // first of all, retrieve the actual name
        var mylayer = obj as HostLayer;
        if (null == mylayer)
          return result;

        var layer = mylayer as XYPlotLayer;
        if (_layerNumber >= 0 && mylayer.SiblingLayers != null && _layerNumber < mylayer.SiblingLayers.Count)
          layer = mylayer.SiblingLayers[_layerNumber] as XYPlotLayer;
        if (null == layer)
          return result;
        IGPlotItem pa = null;
        if (_plotNumber < layer.PlotItems.Flattened.Length)
        {
          pa = layer.PlotItems.Flattened[_plotNumber];
        }
        if (pa != null)
        {
          result = pa.GetName(0);

          if (_plotLabelStyle != null && !_plotLabelStyleIsPropColName && pa is XYColumnPlotItem)
          {
            XYColumnPlotItemLabelTextStyle style = XYColumnPlotItemLabelTextStyle.YS;
            try
            { style = (XYColumnPlotItemLabelTextStyle)Enum.Parse(typeof(XYColumnPlotItemLabelTextStyle), _plotLabelStyle, true); }
            catch (Exception) { }
            result = ((XYColumnPlotItem)pa).GetName(style);
          }

          if (_plotLabelStyleIsPropColName && _plotLabelStyle != null && pa is XYColumnPlotItem)
          {
            XYColumnPlotData pb = ((XYColumnPlotItem)pa).Data;
            Data.DataTable tbl = null;
            if (pb.YColumn is Data.DataColumn)
              tbl = Data.DataTable.GetParentDataTableOf((Data.DataColumn)pb.YColumn);

            if (tbl != null)
            {
              int colNumber = tbl.DataColumns.GetColumnNumber((Data.DataColumn)pb.YColumn);
              if (tbl.PropertyColumns.ContainsColumn(_plotLabelStyle))
                result = tbl.PropertyColumns[_plotLabelStyle][colNumber].ToString();
            }
          }
        }

        return result;
      }
Exemplo n.º 10
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                XYColumnPlotData       pa = (XYColumnPlotData)info.GetValue("Data", typeof(XYColumnPlotData));
                G2DPlotStyleCollection ps = (G2DPlotStyleCollection)info.GetValue("Style", typeof(G2DPlotStyleCollection));

                if (null == o)
                {
                    return(new XYColumnPlotItem(pa, ps));
                }
                else
                {
                    XYColumnPlotItem s = (XYColumnPlotItem)o;
                    s.Data  = pa;
                    s.Style = ps;
                    return(s);
                }
            }
Exemplo n.º 11
0
        public static List <IGPlotItem> CreatePlotItems(DataTable table, IAscendingIntegerCollection selectedColumns, G2DPlotStyleCollection templatePlotStyle)
        {
            int len        = selectedColumns.Count;
            int numColumns = table.DataColumnCount;

            List <IGPlotItem>          result = new List <IGPlotItem>();
            ErrorBarPlotStyle          unpairedPositiveError = null;
            ErrorBarPlotStyle          unpairedNegativeError = null;
            AscendingIntegerCollection processedColumns      = new AscendingIntegerCollection();

            int idx;

            for (int sci = 0; sci < len; sci++)
            {
                idx = selectedColumns[sci];
                if (processedColumns.Contains(idx))
                {
                    continue;
                }
                else
                {
                    processedColumns.Add(idx);
                }

                Altaxo.Data.DataColumn ycol = table[idx];
                Altaxo.Data.DataColumn xcol = table.DataColumns.FindXColumnOf(ycol);
                XYColumnPlotData       pa;
                if (null != xcol)
                {
                    pa = new XYColumnPlotData(xcol, ycol);
                }
                else
                {
                    pa = new XYColumnPlotData(new Altaxo.Data.IndexerColumn(), ycol);
                }

                G2DPlotStyleCollection ps = templatePlotStyle != null? (G2DPlotStyleCollection)templatePlotStyle.Clone() : new G2DPlotStyleCollection();

                bool foundMoreColumns = true;
                for (idx = idx + 1; foundMoreColumns && idx < numColumns; idx++)
                {
                    DataColumn col = table.DataColumns[idx];
                    switch (table.DataColumns.GetColumnKind(idx))
                    {
                    case ColumnKind.Label:
                        LabelPlotStyle labelStyle = new LabelPlotStyle(col);
                        ps.Insert(0, labelStyle);
                        break;

                    case ColumnKind.Err:
                        ErrorBarPlotStyle errStyle = new ErrorBarPlotStyle();
                        errStyle.PositiveErrorColumn = col as INumericColumn;
                        errStyle.NegativeErrorColumn = col as INumericColumn;
                        ps.Add(errStyle);
                        break;

                    case ColumnKind.pErr:
                        if (null != unpairedNegativeError)
                        {
                            unpairedNegativeError.PositiveErrorColumn = col as INumericColumn;;
                            unpairedNegativeError = null;
                        }
                        else
                        {
                            unpairedPositiveError = new ErrorBarPlotStyle();
                            unpairedPositiveError.PositiveErrorColumn = col as INumericColumn;
                            ps.Add(unpairedPositiveError);
                        }
                        break;

                    case ColumnKind.mErr:
                        if (null != unpairedPositiveError)
                        {
                            unpairedPositiveError.NegativeErrorColumn = col as INumericColumn;
                            unpairedPositiveError = null;
                        }
                        else
                        {
                            unpairedNegativeError = new ErrorBarPlotStyle();
                            unpairedNegativeError.NegativeErrorColumn = col as INumericColumn;
                            ps.Add(unpairedNegativeError);
                        }
                        break;

                    default:
                        foundMoreColumns = false;
                        break;
                    }

                    if (foundMoreColumns)
                    {
                        processedColumns.Add(idx);
                    }
                }

                result.Add(new XYColumnPlotItem(pa, ps));
            }

            return(result);
        }
 public LineScatterPlotDataController(XYColumnPlotData pa)
 {
     m_PlotAssociation = pa;
     SetElements(true);
 }
Exemplo n.º 13
0
		public XYColumnPlotItem(XYColumnPlotData pa, G2DPlotStyleCollection ps)
		{
			this.Data = pa;
			this.Style = ps;
		}
Exemplo n.º 14
0
		private System.Collections.Generic.IEnumerable<DocumentNodeAndName> GetLocalDocumentNodeChildrenWithName()
		{
			if (null != _plotData)
				yield return new DocumentNodeAndName(_plotData, () => _plotData = null, "Data");
		}
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
0
        /// <summary>
        /// Creates a list of plot items from data columns, using a template plot style.
        /// </summary>
        /// <param name="selectedColumns">Columns for which to create plot items.</param>
        /// <param name="xColumnName">Name of the x column. If it is null or empty, or that column is not found in the table, the current assigned x column is used.</param>
        /// <param name="templatePlotStyle">The template plot style used to create the basic plot item.</param>
        /// <param name="processedColumns">On return, contains all columns that where used in creating the plot items. That are
        /// not only the columns given in the first argument, but maybe also columns that are right to those columns in the table and have special kinds, like
        /// labels, yerr, and so on.</param>
        /// <param name="context">Property context used to determine default values, e.g. for the pen width or symbol size.</param>
        /// <returns>List of plot items created.</returns>
        public static List <IGPlotItem> CreatePlotItems(IEnumerable <DataColumn> selectedColumns, string xColumnName, G2DPlotStyleCollection templatePlotStyle, HashSet <DataColumn> processedColumns, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
        {
            var result = new List <IGPlotItem>();

            foreach (DataColumn ycol in selectedColumns)
            {
                if (processedColumns.Contains(ycol))
                {
                    continue;
                }
                else
                {
                    processedColumns.Add(ycol);
                }

                var table = DataColumnCollection.GetParentDataColumnCollectionOf(ycol);
                Altaxo.Data.DataColumn xcol;
                if (!string.IsNullOrEmpty(xColumnName) && null != table && table.ContainsColumn(xColumnName))
                {
                    xcol = table[xColumnName];
                }
                else
                {
                    xcol = null == table ? null : table.FindXColumnOf(ycol);
                }

                int groupNumber = table.GetColumnGroup(ycol);
                var parentTable = DataTable.GetParentDataTableOf(table);

                XYColumnPlotData pa;
                if (null != xcol)
                {
                    pa = new XYColumnPlotData(parentTable, groupNumber, xcol, ycol);
                }
                else
                {
                    pa = new XYColumnPlotData(parentTable, groupNumber, new Altaxo.Data.IndexerColumn(), ycol);
                }

                G2DPlotStyleCollection ps = templatePlotStyle != null?templatePlotStyle.Clone() : new G2DPlotStyleCollection();

                if (null == table)
                {
                    continue;
                }

                ErrorBarPlotStyle unpairedPositiveError = null;
                ErrorBarPlotStyle unpairedNegativeError = null;

                bool foundMoreColumns = true;
                for (int idx = 1 + table.GetColumnNumber(ycol); foundMoreColumns && idx < table.ColumnCount; idx++)
                {
                    DataColumn col = table[idx];
                    switch (table.GetColumnKind(idx))
                    {
                    case ColumnKind.Label:
                        var labelStyle = new LabelPlotStyle(col, context);
                        ps.Insert(0, labelStyle);
                        break;

                    case ColumnKind.Err:
                        ErrorBarPlotStyle errStyle = new ErrorBarYPlotStyle(context)
                        {
                            CommonErrorColumn = col as INumericColumn
                        };
                        ps.Add(errStyle);
                        break;

                    case ColumnKind.pErr:
                        if (null != unpairedNegativeError)
                        {
                            unpairedNegativeError.PositiveErrorColumn = col as INumericColumn;
                            ;
                            unpairedNegativeError = null;
                        }
                        else
                        {
                            unpairedPositiveError = new ErrorBarYPlotStyle(context)
                            {
                                UseCommonErrorColumn = false
                            };
                            unpairedPositiveError.PositiveErrorColumn = col as INumericColumn;
                            ps.Add(unpairedPositiveError);
                        }
                        break;

                    case ColumnKind.mErr:
                        if (null != unpairedPositiveError)
                        {
                            unpairedPositiveError.NegativeErrorColumn = col as INumericColumn;
                            unpairedPositiveError = null;
                        }
                        else
                        {
                            unpairedNegativeError = new ErrorBarYPlotStyle(context)
                            {
                                UseCommonErrorColumn = false
                            };
                            unpairedNegativeError.NegativeErrorColumn = col as INumericColumn;
                            ps.Add(unpairedNegativeError);
                        }
                        break;

                    default:
                        foundMoreColumns = false;
                        break;
                    }

                    if (foundMoreColumns)
                    {
                        processedColumns.Add(table[idx]);
                    }
                }

                result.Add(new XYColumnPlotItem(pa, ps));
            }
            return(result);
        }
Exemplo n.º 17
0
 public XYColumnPlotItem(XYColumnPlotData pa, G2DPlotStyleCollection ps)
 {
     this.Data  = pa;
     this.Style = ps;
 }
 public XYLineScatterPlotStyle(XYColumnPlotData pa)
 {
   this.m_LineStyle = new LinePlotStyle();
   this.m_ScatterStyle = new ScatterPlotStyle();
   // this.m_PlotAssociation = pa;
   this.m_LineSymbolGap = true;
 }