//*************************************************************************
        //  Method: AutoFillByEdgeTimestamp()
        //
        /// <summary>
        /// Assigns attributes based on an edge timestamp column.
        /// </summary>
        ///
        /// <param name="workbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="edgeTimestampColumnName">
        /// The name of the edge table column containing edge timestamps.
        /// </param>
        ///
        /// <param name="showVertexLabels">
        /// true if vertex labels should be shown.
        /// </param>
        ///
        /// <param name="vertexLabelColumnName">
        /// The name of the vertex table column containing vertex labels.  Used
        /// only if <paramref name="showVertexLabels" /> is true.
        /// </param>
        ///
        /// <remarks>
        /// This method maps an edge timestamp column to the edge color column,
        /// fills in other attribute columns with constant values, and fills in the
        /// vertex label column if <paramref name="showVertexLabels" /> is true.
        ///
        /// <para>
        /// In addition to autofilling columns, this method stores the results of
        /// the autofill as a <see cref="AutoFillWorkbookWithSchemeResults" />
        /// using <see cref="PerWorkbookSettings" />.
        /// </para>
        ///
        /// </remarks>
        //*************************************************************************
        public static void AutoFillByEdgeTimestamp(
            Microsoft.Office.Interop.Excel.Workbook workbook,
            String edgeTimestampColumnName,
            Boolean showVertexLabels,
            String vertexLabelColumnName
            )
        {
            Debug.Assert(workbook != null);
            Debug.Assert( !String.IsNullOrEmpty(edgeTimestampColumnName) );

            Debug.Assert( !showVertexLabels ||
            !String.IsNullOrEmpty(vertexLabelColumnName) );

            ListObject oVertexTable = null;
            ListObject oEdgeTable = null;
            ExcelHiddenColumns oHiddenVertexColumns = null;
            ExcelHiddenColumns oHiddenEdgeColumns = null;

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
            new AutoFillWorkbookWithSchemeResults();

            try
            {
            if (
                !TryStartAutoFill(workbook, showVertexLabels,
                    vertexLabelColumnName, out oEdgeTable, out oVertexTable,
                    out oHiddenEdgeColumns, out oHiddenVertexColumns)
                ||
                ExcelUtil.VisibleTableRangeIsEmpty(oEdgeTable)
                )
            {
                return;
            }

            // Map the edge timestamp column to the edge color column.

            Double dSourceCalculationNumber1, dSourceCalculationNumber2;
            Int32 iDecimalPlaces;

            if ( !TableColumnMapper.TryMapToColor(oEdgeTable,
                edgeTimestampColumnName, EdgeTableColumnNames.Color, false,
                false, 0, 0, MinimumEdgeTimestampColor,
                MaximumEdgeTimestampColor, false, false,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
                return;
            }

            // Fill in other columns with constants.

            FillColumnsWithConstants(

                oEdgeTable, EdgeTableColumnNames.Width, 2.0F,

                oEdgeTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook,

                oVertexTable, VertexTableColumnNames.Shape,
                    ( new VertexShapeConverter() ).GraphToWorkbook(
                        VertexShape.Circle),

                oVertexTable, VertexTableColumnNames.Color,
                    ( new ColorConverter2() ).GraphToWorkbook(
                        Color.FromArgb(0, 0, 0) ),

                oVertexTable, VertexTableColumnNames.Radius, 1.5F,

                oVertexTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook
                );

            // Save the results.

            ListColumn oEdgeTimestampColumn;

            ExcelUtil.TryGetTableColumn(oEdgeTable, edgeTimestampColumnName,
                out oEdgeTimestampColumn);

            oAutoFillWorkbookWithSchemeResults.SetEdgeTimestampResults(
                edgeTimestampColumnName,
                ExcelUtil.GetColumnFormat(oEdgeTimestampColumn),
                dSourceCalculationNumber1, dSourceCalculationNumber2);
            }
            finally
            {
            ( new PerWorkbookSettings(workbook) ).
                AutoFillWorkbookWithSchemeResults =
                    oAutoFillWorkbookWithSchemeResults;

            EndAutoFill(workbook, oEdgeTable, oVertexTable,
                oHiddenEdgeColumns, oHiddenVertexColumns);
            }
        }
示例#2
0
        ConvertFromString
        (
            String theString
        )
        {
            Debug.Assert(!String.IsNullOrEmpty(theString));

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
                new AutoFillWorkbookWithSchemeResults();

            String [] asFields = theString.Split(
                PerWorkbookSettings.FieldSeparator);

            Int32 iFields = asFields.Length;

            if (iFields == 0)
            {
                goto Done;
            }

            AutoFillSchemeType eSchemeType;

            try
            {
                eSchemeType = (AutoFillSchemeType)Enum.Parse(
                    typeof(AutoFillSchemeType), asFields[0]);
            }
            catch (ArgumentException)
            {
                goto Done;
            }

            switch (eSchemeType)
            {
            case AutoFillSchemeType.VertexCategory:

                if (iFields == 3)
                {
                    String [] asVertexCategoryNames = asFields[2].Split(
                        VertexCategoryNameSeparator);

                    oAutoFillWorkbookWithSchemeResults.
                    SetVertexCategoryResults(asFields[1],
                                             asVertexCategoryNames);
                }

                break;

            case AutoFillSchemeType.EdgeWeight:

                if (iFields == 5)
                {
                    oAutoFillWorkbookWithSchemeResults.SetEdgeWeightResults(
                        asFields[1],
                        MathUtil.ParseCultureInvariantDouble(asFields[2]),
                        MathUtil.ParseCultureInvariantDouble(asFields[3]),
                        MathUtil.ParseCultureInvariantInt32(asFields[4])
                        );
                }

                break;

            case AutoFillSchemeType.EdgeTimestamp:

                if (iFields == 5)
                {
                    oAutoFillWorkbookWithSchemeResults.SetEdgeTimestampResults(
                        asFields[1],

                        (ExcelColumnFormat)Enum.Parse(
                            typeof(ExcelColumnFormat), asFields[2]),

                        MathUtil.ParseCultureInvariantDouble(asFields[3]),
                        MathUtil.ParseCultureInvariantDouble(asFields[4])
                        );
                }

                break;

            default:

                break;
            }

Done:

            return(oAutoFillWorkbookWithSchemeResults);
        }
示例#3
0
        AutoFillByEdgeTimestamp
        (
            Microsoft.Office.Interop.Excel.Workbook workbook,
            String edgeTimestampColumnName,
            Boolean showVertexLabels,
            String vertexLabelColumnName
        )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(!String.IsNullOrEmpty(edgeTimestampColumnName));

            Debug.Assert(!showVertexLabels ||
                         !String.IsNullOrEmpty(vertexLabelColumnName));

            ListObject         oVertexTable         = null;
            ListObject         oEdgeTable           = null;
            ExcelHiddenColumns oHiddenVertexColumns = null;
            ExcelHiddenColumns oHiddenEdgeColumns   = null;

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
                new AutoFillWorkbookWithSchemeResults();

            try
            {
                if (
                    !TryStartAutoFill(workbook, showVertexLabels,
                                      vertexLabelColumnName, out oEdgeTable, out oVertexTable,
                                      out oHiddenEdgeColumns, out oHiddenVertexColumns)
                    ||
                    ExcelUtil.VisibleTableRangeIsEmpty(oEdgeTable)
                    )
                {
                    return;
                }

                // Map the edge timestamp column to the edge color column.

                Double dSourceCalculationNumber1, dSourceCalculationNumber2;
                Int32  iDecimalPlaces;

                if (!TableColumnMapper.TryMapToColor(oEdgeTable,
                                                     edgeTimestampColumnName, EdgeTableColumnNames.Color, false,
                                                     false, 0, 0, MinimumEdgeTimestampColor,
                                                     MaximumEdgeTimestampColor, false, false,
                                                     out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                                                     out iDecimalPlaces
                                                     ))
                {
                    return;
                }

                // Fill in other columns with constants.

                FillColumnsWithConstants(

                    oEdgeTable, EdgeTableColumnNames.Width, 2.0F,

                    oEdgeTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook,

                    oVertexTable, VertexTableColumnNames.Shape,
                    (new VertexShapeConverter()).GraphToWorkbook(
                        VertexShape.Circle),

                    oVertexTable, VertexTableColumnNames.Color,
                    (new ColorConverter2()).GraphToWorkbook(
                        Color.FromArgb(0, 0, 0)),

                    oVertexTable, VertexTableColumnNames.Radius, 1.5F,

                    oVertexTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook
                    );

                // Save the results.

                ListColumn oEdgeTimestampColumn;

                ExcelUtil.TryGetTableColumn(oEdgeTable, edgeTimestampColumnName,
                                            out oEdgeTimestampColumn);

                oAutoFillWorkbookWithSchemeResults.SetEdgeTimestampResults(
                    edgeTimestampColumnName,
                    ExcelUtil.GetColumnFormat(oEdgeTimestampColumn),
                    dSourceCalculationNumber1, dSourceCalculationNumber2);
            }
            finally
            {
                (new PerWorkbookSettings(workbook)).
                AutoFillWorkbookWithSchemeResults =
                    oAutoFillWorkbookWithSchemeResults;

                EndAutoFill(workbook, oEdgeTable, oVertexTable,
                            oHiddenEdgeColumns, oHiddenVertexColumns);
            }
        }
        //*************************************************************************
        //  Method: ConvertFromString()
        //
        /// <summary>
        /// Creates a <see cref="AutoFillWorkbookWithSchemeResults" /> object from
        /// a persisted string.
        /// </summary>
        ///
        /// <param name="theString">
        /// String created by <see cref="ConvertToString()" />.
        /// </param>
        ///
        /// <returns>
        /// A <see cref="AutoFillWorkbookWithSchemeResults" /> object created from
        /// <paramref name="theString" />.
        /// </returns>
        //*************************************************************************
        public static AutoFillWorkbookWithSchemeResults ConvertFromString(
            String theString
            )
        {
            Debug.Assert( !String.IsNullOrEmpty(theString) );

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
            new AutoFillWorkbookWithSchemeResults();

            String [] asFields = theString.Split(
            PerWorkbookSettings.FieldSeparator);

            Int32 iFields = asFields.Length;

            if (iFields == 0)
            {
            goto Done;
            }

            AutoFillSchemeType eSchemeType;

            try
            {
            eSchemeType = (AutoFillSchemeType)Enum.Parse(
                typeof(AutoFillSchemeType), asFields[0] );
            }
            catch (ArgumentException)
            {
            goto Done;
            }

            switch (eSchemeType)
            {
            case AutoFillSchemeType.VertexCategory:

                if (iFields == 3)
                {
                    String [] asVertexCategoryNames = asFields[2].Split(
                        VertexCategoryNameSeparator);

                    oAutoFillWorkbookWithSchemeResults.
                        SetVertexCategoryResults(asFields[1],
                            asVertexCategoryNames);
                }

                break;

            case AutoFillSchemeType.EdgeWeight:

                if (iFields == 5)
                {
                    oAutoFillWorkbookWithSchemeResults.SetEdgeWeightResults(
                        asFields[1],
                        MathUtil.ParseCultureInvariantDouble( asFields[2] ),
                        MathUtil.ParseCultureInvariantDouble( asFields[3] ),
                        MathUtil.ParseCultureInvariantInt32( asFields[4] )
                        );
                }

                break;

            case AutoFillSchemeType.EdgeTimestamp:

                if (iFields == 5)
                {
                    oAutoFillWorkbookWithSchemeResults.SetEdgeTimestampResults(
                        asFields[1],

                        (ExcelColumnFormat)Enum.Parse(
                            typeof(ExcelColumnFormat), asFields[2] ),

                        MathUtil.ParseCultureInvariantDouble( asFields[3] ),
                        MathUtil.ParseCultureInvariantDouble( asFields[4] )
                        );
                }

                break;

            default:

                break;
            }

            Done:

            return (oAutoFillWorkbookWithSchemeResults);
        }