コード例 #1
0
        //*************************************************************************
        //  Method: AutoFillByEdgeWeight()
        //
        /// <summary>
        /// Assigns attributes based on an edge weight column.
        /// </summary>
        ///
        /// <param name="workbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="edgeWeightColumnName">
        /// The name of the edge table column containing edge weights.
        /// </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 weight column to the edge width 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 AutoFillByEdgeWeight(
            Microsoft.Office.Interop.Excel.Workbook workbook,
            String edgeWeightColumnName,
            Boolean showVertexLabels,
            String vertexLabelColumnName
            )
        {
            Debug.Assert(workbook != null);
            Debug.Assert( !String.IsNullOrEmpty(edgeWeightColumnName) );

            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 weight column to the edge width column.

            Double dSourceCalculationNumber1, dSourceCalculationNumber2;
            Int32 iDecimalPlaces;

            if ( !TableColumnMapper.TryMapToNumericRange(oEdgeTable,
                edgeWeightColumnName, EdgeTableColumnNames.Width, false, false,
                0, 0,
                MinimumEdgeWeightWidthWorkbook, MaximumEdgeWeightWidthWorkbook,
                false, false,
                out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                out iDecimalPlaces
                ) )
            {
                return;
            }

            // Fill in other columns with constants.

            String sBlack = ( new ColorConverter2() ).GraphToWorkbook(
                Color.FromArgb(0, 0, 0) );

            FillColumnsWithConstants(

                oEdgeTable, EdgeTableColumnNames.Color, sBlack,

                oEdgeTable, CommonTableColumnNames.Alpha,
                    0.6F * (AlphaConverter.MaximumAlphaWorkbook -
                        AlphaConverter.MinimumAlphaWorkbook),

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

                oVertexTable, VertexTableColumnNames.Color, sBlack,

                oVertexTable, VertexTableColumnNames.Radius, 3.0F,

                oVertexTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook
                );

            // Save the results.

            oAutoFillWorkbookWithSchemeResults.SetEdgeWeightResults(
                edgeWeightColumnName, dSourceCalculationNumber1,
                dSourceCalculationNumber2, iDecimalPlaces);
            }
            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
        AutoFillByEdgeWeight
        (
            Microsoft.Office.Interop.Excel.Workbook workbook,
            String edgeWeightColumnName,
            Boolean showVertexLabels,
            String vertexLabelColumnName
        )
        {
            Debug.Assert(workbook != null);
            Debug.Assert(!String.IsNullOrEmpty(edgeWeightColumnName));

            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 weight column to the edge width column.

                Double dSourceCalculationNumber1, dSourceCalculationNumber2;
                Int32  iDecimalPlaces;

                if (!TableColumnMapper.TryMapToNumericRange(oEdgeTable,
                                                            edgeWeightColumnName, EdgeTableColumnNames.Width, false, false,
                                                            0, 0,
                                                            MinimumEdgeWeightWidthWorkbook, MaximumEdgeWeightWidthWorkbook,
                                                            false, false,
                                                            out dSourceCalculationNumber1, out dSourceCalculationNumber2,
                                                            out iDecimalPlaces
                                                            ))
                {
                    return;
                }

                // Fill in other columns with constants.

                String sBlack = (new ColorConverter2()).GraphToWorkbook(
                    Color.FromArgb(0, 0, 0));

                FillColumnsWithConstants(

                    oEdgeTable, EdgeTableColumnNames.Color, sBlack,

                    oEdgeTable, CommonTableColumnNames.Alpha,
                    0.6F * (AlphaConverter.MaximumAlphaWorkbook -
                            AlphaConverter.MinimumAlphaWorkbook),

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

                    oVertexTable, VertexTableColumnNames.Color, sBlack,

                    oVertexTable, VertexTableColumnNames.Radius, 3.0F,

                    oVertexTable, CommonTableColumnNames.Alpha,
                    AlphaConverter.MaximumAlphaWorkbook
                    );

                // Save the results.

                oAutoFillWorkbookWithSchemeResults.SetEdgeWeightResults(
                    edgeWeightColumnName, dSourceCalculationNumber1,
                    dSourceCalculationNumber2, iDecimalPlaces);
            }
            finally
            {
                (new PerWorkbookSettings(workbook)).
                AutoFillWorkbookWithSchemeResults =
                    oAutoFillWorkbookWithSchemeResults;

                EndAutoFill(workbook, oEdgeTable, oVertexTable,
                            oHiddenEdgeColumns, oHiddenVertexColumns);
            }
        }
コード例 #4
0
        //*************************************************************************
        //  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);
        }