Exemple #1
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);
        }
Exemple #2
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);
        }
Exemple #3
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);

				DataColumnCollection 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 ? (G2DPlotStyleCollection)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:
							LabelPlotStyle labelStyle = new LabelPlotStyle(col, context);
							ps.Insert(0, labelStyle);
							break;

						case ColumnKind.Err:
							ErrorBarPlotStyle errStyle = new ErrorBarYPlotStyle(context);
							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 ErrorBarYPlotStyle(context);
								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);
								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;
		}