Пример #1
0
        private string GetTextShownForDependentVariable(int i)
        {
            var col     = _fitElement.DependentVariables(i);
            var colColl = DataColumnCollection.GetParentDataColumnCollectionOf(col as DataColumn);

            return(colColl?.GetColumnName(col as DataColumn) ?? col?.FullName ?? "??Unassigned??");
        }
Пример #2
0
        /// <summary>
        /// Try to get a common data table and a group number from all columns (here we don't rely on <see cref="DataTable"/> and GroupNumber of this document).
        /// </summary>
        /// <param name="columns">The columns to consider. <see cref="ITransformedReadableColumn"/> will be stripped to get the underlying data column.</param>
        /// <param name="dataTableIsNotUniform">If the columns gives different result for their underlying data table, the result here will be true.</param>
        /// <param name="commonDataTable">If the previous parameter results in false, this is the common data table of all columns. If the previous parameter is true, this is the first underlying data table that could be deduced from the columns. The result is null if no underlying table could be deduced from the columns.</param>
        /// <param name="groupNumberIsNotUniform">If the columns gives different result for their group number, the result here will be true.</param>
        /// <param name="commonGroupNumber">If the previous parameter results in false, this is the common group number of all columns. If the previous parameter results in true, this is the first group number that could be deduced from the columns. The result is null if no group number could be deduced from the columns.</param>
        public static void GetCommonDataTableAndGroupNumberFromColumns(this IEnumerable <IReadableColumn> columns, out bool dataTableIsNotUniform, out DataTable commonDataTable, out bool groupNumberIsNotUniform, out int?commonGroupNumber)
        {
            dataTableIsNotUniform   = false;
            groupNumberIsNotUniform = false;
            commonDataTable         = null;
            commonGroupNumber       = null;

            foreach (var col in columns)
            {
                IReadableColumn underlyingColumn = col;

                while (underlyingColumn is ITransformedReadableColumn)
                {
                    underlyingColumn = (underlyingColumn as ITransformedReadableColumn).UnderlyingReadableColumn;
                }

                if (underlyingColumn is DataColumn)
                {
                    var colColl     = DataColumnCollection.GetParentDataColumnCollectionOf((DataColumn)underlyingColumn);
                    var dataTable   = DataTable.GetParentDataTableOf(colColl);
                    int?groupNumber = colColl?.GetColumnGroup((DataColumn)underlyingColumn);

                    if (null != dataTable)
                    {
                        if (null == commonDataTable)
                        {
                            commonDataTable = dataTable;
                        }
                        else if (!object.ReferenceEquals(commonDataTable, dataTable))
                        {
                            dataTableIsNotUniform = true;
                        }
                    }

                    if (null != groupNumber)
                    {
                        if (null == commonGroupNumber)
                        {
                            commonGroupNumber = groupNumber;
                        }
                        else if (!(commonGroupNumber == groupNumber))
                        {
                            groupNumberIsNotUniform = true;
                        }
                    }
                }
            }
        }
Пример #3
0
        private DataColumn GetColumnInOtherTable(DataTable table, int groupNumber, IReadableColumnProxy proxyTemplate)
        {
            var oldColumn = (DataColumn)proxyTemplate.Document;

            if (null != oldColumn)
            {
                // first by name, then by position

                var        parentColl = DataColumnCollection.GetParentDataColumnCollectionOf(oldColumn);
                var        oldName    = parentColl.GetColumnName(oldColumn);
                var        oldPos     = parentColl.GetColumnNumber(oldColumn);
                DataColumn newCol     = null;

                if (table.DataColumns.ContainsColumn(oldName))
                {
                    newCol = table.DataColumns[oldName];
                }
                else if (oldPos < table.DataColumns.ColumnCount)
                {
                    newCol = table.DataColumns[oldPos];
                }

                if (null != newCol && table.DataColumns.GetColumnGroup(newCol) == groupNumber)
                {
                    return(newCol);
                }
            }
            else // no document available, try it with the path name
            {
                var        documentPath = proxyTemplate.DocumentPath;
                var        oldName      = documentPath.LastPart;
                DataColumn newCol       = null;

                if (table.DataColumns.ContainsColumn(oldName))
                {
                    newCol = table.DataColumns[oldName];
                }

                if (null != newCol && table.DataColumns.GetColumnGroup(newCol) == groupNumber)
                {
                    return(newCol);
                }
            }

            return(null);
        }
Пример #4
0
        public static string DetermineXIncrement(DataColumn yColumnToTransform, out double xIncrement)
        {
            xIncrement = 1;
            var coll = DataColumnCollection.GetParentDataColumnCollectionOf(yColumnToTransform);

            if (null == coll)
            {
                return("Can't find parent collection of provided data column to transform");
            }

            var xColD = coll.FindXColumnOf(yColumnToTransform);

            if (null == xColD)
            {
                return("Can't find x-column of provided data column to transform");
            }

            var xCol = xColD as DoubleColumn;

            if (null == xCol)
            {
                return("X-column of provided data column to transform is not a numeric column");
            }

            var spacing = new Calc.LinearAlgebra.VectorSpacingEvaluator(xCol.ToROVector());

            if (!spacing.IsStrictlyMonotonicIncreasing)
            {
                return("X-column of provided column to transform is not monotonically increasing");
            }

            xIncrement = spacing.SpaceMeanValue;

            if (!spacing.IsStrictlyEquallySpaced)
            {
                return("X-Column is not strictly equally spaced, the relative deviation is " + spacing.RelativeSpaceDeviation.ToString());
            }
            else
            {
                return(null);
            }
        }
Пример #5
0
        /// <summary>
        /// Removes all data columns, whose parent is not the data table <paramref name="table"/>, or whose column kind is not ColumnKind.V, or whose group number is not equal to <see cref="GroupNumber"/>.
        /// </summary>
        /// <param name="table">The table to compare the parents of the columns with.</param>
        protected void InternalRemoveDataColumnsWithDeviatingParentOrKindOrGroupNumber(DataTable table)
        {
            var tableDataColumns = table.DataColumns;

            var indicesToRemove = new List <int>();

            foreach (var entry in _dataColumnBundles)
            {
                var bundle      = entry.Value;
                var dataColumns = bundle.DataColumns;

                for (int i = dataColumns.Count - 1; i >= 0; --i)
                {
                    if (dataColumns[i].IsEmpty)
                    {
                        InternalRemoveDataColumnAt(bundle, i);
                        continue;
                    }

                    var c = dataColumns[i].Document as DataColumn;
                    if (c == null)
                    {
                        continue; // not yet resolved, leave it as it is
                    }
                    var coll = DataColumnCollection.GetParentDataColumnCollectionOf(c);
                    if (null == coll || !object.ReferenceEquals(coll, tableDataColumns))
                    {
                        InternalRemoveDataColumnAt(bundle, i);
                        continue;
                    }

                    var group = tableDataColumns.GetColumnGroup(c);
                    var kind  = tableDataColumns.GetColumnKind(c);
                    if (group != _groupNumber && kind != ColumnKind.V)
                    {
                        InternalRemoveDataColumnAt(bundle, i);
                        continue;
                    }
                }
            }
        }
Пример #6
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, string yColumnName, G3DPlotStyleCollection templatePlotStyle, HashSet <DataColumn> processedColumns, Altaxo.Main.Properties.IReadOnlyPropertyBag context)
        {
            var result = new List <IGPlotItem>();

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

                var table       = DataTable.GetParentDataTableOf(vcol);
                var tablecoll   = DataColumnCollection.GetParentDataColumnCollectionOf(vcol);
                int groupNumber = tablecoll.GetColumnGroup(vcol);

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

                if (!string.IsNullOrEmpty(yColumnName) && null != table && table.ContainsColumn(yColumnName))
                {
                    ycol = table[yColumnName];
                }
                else
                {
                    ycol = null == table ? null : tablecoll.FindYColumnOf(vcol);
                }

                var pa = new XYZColumnPlotData(
                    table,
                    groupNumber,
                    xcol ?? (IReadableColumn) new IndexerColumn(),
                    ycol ?? (IReadableColumn) new ConstantDoubleColumn(0),
                    vcol);

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

                if (null == table)
                {
                    continue;
                }

                ErrorBarPlotStyle unpairedPositiveError = null;
                ErrorBarPlotStyle unpairedNegativeError = null;

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

                    case ColumnKind.Err:
                        var errStyle = new ErrorBarZPlotStyle(context)
                        {
                            UseCommonErrorColumn = true,
                            CommonErrorColumn    = col as INumericColumn
                        };
                        ps.Add(errStyle);
                        break;

                    case ColumnKind.pErr:
                        if (null != unpairedNegativeError)
                        {
                            unpairedNegativeError.PositiveErrorColumn = col as INumericColumn;
                            ;
                            unpairedNegativeError = null;
                        }
                        else
                        {
                            unpairedPositiveError = new ErrorBarZPlotStyle(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 ErrorBarZPlotStyle(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 XYZColumnPlotItem(pa, ps));
            }
            return(result);
        }
Пример #7
0
        /// <summary>
        /// Updates the information, indicating in <paramref name="hasTableChanged"/> whether the underlying data table has changed.
        /// </summary>
        /// <param name="dataTableOfPlotItem">The data table of plot item.</param>
        /// <param name="groupNumberOfPlotItem">The group number of plot item.</param>
        /// <param name="hasTableChanged">If set to <c>true</c>, the data table has recently changed.</param>
        public void Update(DataTable dataTableOfPlotItem, int groupNumberOfPlotItem, bool hasTableChanged)
        {
            bool hasChanged = false;

            if (!object.ReferenceEquals(_supposedDataTable, dataTableOfPlotItem))
            {
                _supposedDataTable = dataTableOfPlotItem;
                hasChanged         = true;
            }

            if (!(_supposedGroupNumber == groupNumberOfPlotItem))
            {
                _supposedGroupNumber = groupNumberOfPlotItem;
                hasChanged           = true;
            }

            if (null == _underlyingColumn)
            {
                if (string.IsNullOrEmpty(_nameOfUnderlyingDataColumn))
                {
                    hasChanged |= InternalSet(ref _plotColumnBoxText, string.Empty);
                    hasChanged |= InternalSet(ref _plotColumnBoxState, _plotColumnBoxStateIfColumnIsMissing);
                    switch (_plotColumnBoxState)
                    {
                    case PlotColumnControlState.Normal:
                        hasChanged |= InternalSet(ref _plotColumnToolTip, string.Empty);
                        break;

                    case PlotColumnControlState.Warning:
                        hasChanged |= InternalSet(ref _plotColumnToolTip, "Warning: it is highly recommended to set a column!");
                        break;

                    case PlotColumnControlState.Error:
                        hasChanged |= InternalSet(ref _plotColumnToolTip, "Error: it is mandatory to set a column!");
                        break;
                    }
                }
                else
                {
                    hasChanged |= InternalSet(ref _plotColumnBoxText, _nameOfUnderlyingDataColumn);
                    hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("Column {0} can not be found in this table with this group number", _nameOfUnderlyingDataColumn));
                    hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Error);
                }
            }
            else if (_underlyingColumn is DataColumn)
            {
                var dcolumn          = (DataColumn)_underlyingColumn;
                var parentTable      = DataTable.GetParentDataTableOf(dcolumn);
                var parentCollection = DataColumnCollection.GetParentDataColumnCollectionOf(dcolumn);
                if (null == parentTable)
                {
                    hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("This column is an orphaned data column without a parent data table", _nameOfUnderlyingDataColumn));
                    hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Error);
                    if (parentCollection == null)
                    {
                        hasChanged |= InternalSet(ref _plotColumnBoxText, string.Format("Orphaned {0}", dcolumn.GetType().Name));
                    }
                    else
                    {
                        string columnName = parentCollection.GetColumnName(dcolumn);
                        hasChanged |= InternalSet(ref _nameOfUnderlyingDataColumn, columnName);
                        hasChanged |= InternalSet(ref _plotColumnBoxText, columnName);
                    }
                }
                else // UnderlyingColumn has a parent table
                {
                    if (!object.ReferenceEquals(parentTable, dataTableOfPlotItem))
                    {
                        hasChanged |= InternalSet(ref _plotColumnBoxText, parentTable.DataColumns.GetColumnName(dcolumn));
                        hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("The column {0} is a data column with another parent data table: {1}", _nameOfUnderlyingDataColumn, parentTable.Name));
                        hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Warning);
                    }
                    else if (!(parentTable.DataColumns.GetColumnGroup(dcolumn) == _supposedGroupNumber))
                    {
                        string columnName = parentTable.DataColumns.GetColumnName(dcolumn);
                        hasChanged |= InternalSet(ref _nameOfUnderlyingDataColumn, columnName);
                        hasChanged |= InternalSet(ref _plotColumnBoxText, columnName);
                        hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("The column {0} is a data column with another group number: {1}", _nameOfUnderlyingDataColumn, parentTable.DataColumns.GetColumnGroup(dcolumn)));
                        hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Warning);
                    }
                    else
                    {
                        string columnName = parentTable.DataColumns.GetColumnName(dcolumn);
                        hasChanged |= InternalSet(ref _nameOfUnderlyingDataColumn, columnName);
                        hasChanged |= InternalSet(ref _plotColumnBoxText, columnName);
                        hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("UnderlyingColumn {0} of data table {1}", _nameOfUnderlyingDataColumn, parentTable.Name));
                        hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Normal);
                    }
                }
            }
            else // UnderlyingColumn is not a DataColumn, but is something else
            {
                hasChanged |= InternalSet(ref _nameOfUnderlyingDataColumn, null);
                hasChanged |= InternalSet(ref _plotColumnBoxText, _underlyingColumn.FullName);
                hasChanged |= InternalSet(ref _plotColumnToolTip, string.Format("Independent data of type {0}: {1}", _underlyingColumn.GetType(), _underlyingColumn.ToString()));
                hasChanged |= InternalSet(ref _plotColumnBoxState, PlotColumnControlState.Normal);
            }

            // now the transformation
            if (null != _transformation)
            {
                hasChanged |= InternalSet(ref _transformationBoxText, _transformation.RepresentationAsOperator ?? _transformation.RepresentationAsFunction);
                hasChanged |= InternalSet(ref _transformationToolTip, string.Format("Transforms the column data by the function f(x)={0}", _transformation.RepresentationAsFunction));
            }
            else // transformation is null
            {
                hasChanged |= InternalSet(ref _transformationBoxText, string.Empty);
                hasChanged |= InternalSet(ref _transformationToolTip, "No transformation applied.");
            }

            _isDirty |= hasChanged;
            _isDirty |= hasTableChanged;

            if (_isDirty)
            {
                _isDirty = false;
                OnChanged();
            }
        }