示例#1
0
        SaveVertexCategoryResults
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            String sVertexCategoryColumnName,
            Dictionary <String, Int32> oCategoryDictionary
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(!String.IsNullOrEmpty(sVertexCategoryColumnName));

            // Convert the dictionary keys to an array ordered by scheme index.

            Int32 iCategories = oCategoryDictionary.Count;

            String [] asVertexCategoryNames = new String[iCategories];

            foreach (KeyValuePair <String, Int32> oKeyValuePair in
                     oCategoryDictionary)
            {
                Debug.Assert(asVertexCategoryNames[oKeyValuePair.Value] == null);

                asVertexCategoryNames[oKeyValuePair.Value] = oKeyValuePair.Key;
            }

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
                new AutoFillWorkbookWithSchemeResults();

            oAutoFillWorkbookWithSchemeResults.SetVertexCategoryResults(
                sVertexCategoryColumnName, asVertexCategoryNames);

            (new PerWorkbookSettings(oWorkbook)).
            AutoFillWorkbookWithSchemeResults =
                oAutoFillWorkbookWithSchemeResults;
        }
        //*************************************************************************
        //  Method: SaveVertexCategoryResults()
        //
        /// <summary>
        /// Stores the results of a vertex category autofill as an <see
        /// cref="AutoFillWorkbookWithSchemeResults" /> using <see
        /// cref="PerWorkbookSettings" />.
        /// </summary>
        ///
        /// <param name="oWorkbook">
        /// The workbook to autofill.
        /// </param>
        ///
        /// <param name="sVertexCategoryColumnName">
        /// The name of the vertex table column containing vertex categories.
        /// </param>
        ///
        /// <param name="oCategoryDictionary">
        /// The key is a unique category name and the value is a scheme index.
        /// </param>
        //*************************************************************************
        private static void SaveVertexCategoryResults(
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            String sVertexCategoryColumnName,
            Dictionary<String, Int32> oCategoryDictionary
            )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert( !String.IsNullOrEmpty(sVertexCategoryColumnName) );

            // Convert the dictionary keys to an array ordered by scheme index.

            Int32 iCategories = oCategoryDictionary.Count;

            String [] asVertexCategoryNames = new String[iCategories];

            foreach (KeyValuePair<String, Int32> oKeyValuePair in
            oCategoryDictionary)
            {
            Debug.Assert(asVertexCategoryNames[oKeyValuePair.Value] == null);

            asVertexCategoryNames[oKeyValuePair.Value] = oKeyValuePair.Key;
            }

            AutoFillWorkbookWithSchemeResults oAutoFillWorkbookWithSchemeResults =
            new AutoFillWorkbookWithSchemeResults();

            oAutoFillWorkbookWithSchemeResults.SetVertexCategoryResults(
            sVertexCategoryColumnName, asVertexCategoryNames);

            ( new PerWorkbookSettings(oWorkbook) ).
            AutoFillWorkbookWithSchemeResults =
                oAutoFillWorkbookWithSchemeResults;
        }
        //*************************************************************************
        //  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);
            }
        }
示例#4
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);
            }
        }
示例#5
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);
        }
        //*************************************************************************
        //  Method: Update()
        //
        /// <summary>
        /// Updates the graph legend with results for the "autofill with scheme"
        /// feature.
        /// </summary>
        ///
        /// <param name="autoFillWorkbookWithSchemeResults">
        /// The results of the "autofill with scheme."
        /// </param>
        //*************************************************************************
        public void Update(
            AutoFillWorkbookWithSchemeResults
            autoFillWorkbookWithSchemeResults
            )
        {
            Debug.Assert(autoFillWorkbookWithSchemeResults != null);
            AssertValid();

            Update(new AutoFillWorkbookResults(),
            autoFillWorkbookWithSchemeResults);
        }
        //*************************************************************************
        //  Method: Update()
        //
        /// <summary>
        /// Updates the graph legend.
        /// </summary>
        ///
        /// <param name="oAutoFillWorkbookResults">
        /// The results of the autofill.
        /// </param>
        ///
        /// <param name="oAutoFillWorkbookWithSchemeResults">
        /// The results of the "autofill with scheme."
        /// </param>
        //*************************************************************************
        protected void Update(
            AutoFillWorkbookResults oAutoFillWorkbookResults,
            
            AutoFillWorkbookWithSchemeResults
            oAutoFillWorkbookWithSchemeResults
            )
        {
            Debug.Assert(oAutoFillWorkbookResults != null);
            Debug.Assert(oAutoFillWorkbookWithSchemeResults != null);
            AssertValid();

            m_oAutoFillWorkbookResults = oAutoFillWorkbookResults;

            m_oAutoFillWorkbookWithSchemeResults =
            oAutoFillWorkbookWithSchemeResults;

            this.Height = CalculateHeight();
            Invalidate();
        }
        //*************************************************************************
        //  Constructor: AutoFillResultsLegendControl()
        //
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="AutoFillResultsLegendControl" /> class.
        /// </summary>
        //*************************************************************************
        public AutoFillResultsLegendControl()
        {
            m_iLastResizeWidth = Int32.MinValue;

            // Start with empty (but not null) objects.

            m_oAutoFillWorkbookResults = new AutoFillWorkbookResults();

            m_oAutoFillWorkbookWithSchemeResults =
            new AutoFillWorkbookWithSchemeResults();

            this.DoubleBuffered = true;
            this.BackColor = SystemColors.Window;

            AssertValid();
        }
        //*************************************************************************
        //  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);
        }