Stores one graph metric value for one worksheet row, where the value is mapped to the next empty row.
The array of GraphMetricValueOrdered objects within should be written to the worksheet in sequential row order -- the first value in the first row, the second value in the second row, and so on.
Inheritance: GraphMetricValue
    //*************************************************************************
    //  Constructor: GraphMetricColumnOrdered()
    //
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="GraphMetricColumnOrdered" /> class.
    /// </summary>
    ///
    /// <param name="worksheetName">
    /// Name of the worksheet containing the column.
    /// </param>
    ///
    /// <param name="tableName">
    /// Name of the table (ListObject) containing the column.
    /// </param>
    ///
    /// <param name="columnName">
    /// Name of the column.
    /// </param>
    ///
    /// <param name="columnWidthChars">
    /// Width of the column, in characters, or <see
    /// cref="Smrf.AppLib.ExcelTableUtil.
    /// AutoColumnWidth" /> to set the width automatically.
    /// </param>
    ///
    /// <param name="numberFormat">
    /// Number format of the column, or null if the column is not numeric.
    /// Sample: "0.00".
    /// </param>
    ///
    /// <param name="style">
    /// Style of the column, or null to not apply a style.  Sample: "Bad".
    /// </param>
    ///
    /// <param name="graphMetricValuesOrdered">
    /// Array of graph metric values, one value per calculated column cell.
    /// </param>
    //*************************************************************************

    public GraphMetricColumnOrdered
    (
        String worksheetName,
        String tableName,
        String columnName,
        Double columnWidthChars,
        String numberFormat,
        String style,
        GraphMetricValueOrdered [] graphMetricValuesOrdered
    )
    : base(worksheetName, tableName, columnName, columnWidthChars,
        numberFormat, style)
    {
        m_aoGraphMetricValuesOrdered = graphMetricValuesOrdered;

        AssertValid();
    }
示例#2
0
        WriteGraphMetricColumnOrderedToWorkbook
        (
            GraphMetricColumnOrdered oGraphMetricColumnOrdered,
            ListObject oTable
        )
        {
            Debug.Assert(oGraphMetricColumnOrdered != null);
            Debug.Assert(oTable != null);
            AssertValid();

            GraphMetricValueOrdered [] aoGraphMetricValuesOrdered =
                oGraphMetricColumnOrdered.GraphMetricValuesOrdered;

            Int32 iRows = aoGraphMetricValuesOrdered.Length;

            // Make sure the table has enough rows.

            ResizeTable(oTable, iRows);

            Range oVisibleColumnData;

            // Get the specified column.

            if (!TryGetRequiredColumnInformation(oGraphMetricColumnOrdered,
                                                 oTable, out oVisibleColumnData))
            {
                return;
            }

            // Copy the graph metric values to an array.

            Object [,] aoValues = ExcelUtil.GetSingleColumn2DArray(iRows);
            Boolean bStyleSpecified = false;

            for (Int32 i = 0; i < iRows; i++)
            {
                GraphMetricValueOrdered oGraphMetricValueOrdered =
                    aoGraphMetricValuesOrdered[i];

                aoValues[i + 1, 1] = oGraphMetricValueOrdered.Value;

                if (oGraphMetricValueOrdered.Style != null)
                {
                    // A style was specified for this row.  It will need to be
                    // applied later.  (It should be possible to apply the style
                    // here, but that does not work reliably when values are
                    // written to the cells afterwards, as they are after this
                    // loop.)

                    bStyleSpecified = true;
                }
            }

            // Write the array to the column.

            Range oWrittenRange = ExcelUtil.SetRangeValues(
                oVisibleColumnData, aoValues);

            if (oGraphMetricColumnOrdered.ConvertUrlsToHyperlinks)
            {
                ExcelUtil.ConvertUrlsToHyperlinks(oWrittenRange);
            }

            if (bStyleSpecified)
            {
                for (Int32 i = 0; i < iRows; i++)
                {
                    String sStyle = aoGraphMetricValuesOrdered[i].Style;

                    if (sStyle != null)
                    {
                        // This row has a style.  Apply it.

                        ExcelUtil.SetRangeStyle(
                            (Range)oVisibleColumnData.Cells[i + 1, 1], sStyle);
                    }
                }
            }
        }
        Convert <TGroup>
        (
            ICollection <TGroup> groups,
            GroupToGroupVertices <TGroup> groupToGroupVertices,
            GroupToString <TGroup> groupToGroupName,
            Boolean collapseGroups,
            GroupToString <TGroup> groupToCollapsedGroupAttributes
        )
        {
            Debug.Assert(groups != null);
            Debug.Assert(groupToGroupVertices != null);

            // These columns are needed:
            //
            // * Group name on the group worksheet.
            //
            // * Vertex color on the group worksheet.
            //
            // * Vertex shape on the group worksheet.
            //
            // * Group name on the group-vertex worksheet.
            //
            // * Vertex name on the group-vertex worksheet.
            //
            // * Vertex ID on the group-vertex worksheet.  This gets copied from
            //   the hidden ID column on the Vertex worksheet via an Excel
            //   formula.

            // These columns might be needed:
            //
            // * Collapsed flag on the group worksheet.
            //
            // * Collapsed group attributes on the group worksheet.


            List <GraphMetricValueOrdered> oGroupNamesForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexColorsForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexShapesForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oCollapsedFlagsForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oCollapsedAttributesForGroupWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oGroupNamesForGroupVertexWorksheet =
                new List <GraphMetricValueOrdered>();

            List <GraphMetricValueOrdered> oVertexNamesForGroupVertexWorksheet =
                new List <GraphMetricValueOrdered>();

            // This column contains a constant value, which is a formula.

            GraphMetricValueOrdered [] aoVertexIDsForGroupVertexWorksheet =
            {
                new GraphMetricValueOrdered(
                    GroupManager.GetExcelFormulaForVertexID())
            };

            Int32 iGroups = groups.Count;
            Int32 iGroup  = 0;

            ColorConverter2 oColorConverter2 = new ColorConverter2();

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            GraphMetricValueOrdered oTrueGraphMetricValueOrdered =
                new GraphMetricValueOrdered(
                    (new BooleanConverter()).GraphToWorkbook(true));

            foreach (TGroup oGroup in
                     from oGroup in groups
                     orderby groupToGroupVertices(oGroup).Count descending
                     select oGroup)
            {
                String sGroupName;

                if (groupToGroupName == null)
                {
                    sGroupName = 'G' + (iGroup + 1).ToString(
                        CultureInfo.InvariantCulture);
                }
                else
                {
                    sGroupName = groupToGroupName(oGroup);
                }

                Color       oColor;
                VertexShape eShape;

                GroupManager.GetVertexAttributes(iGroup, iGroups, out oColor,
                                                 out eShape);

                GraphMetricValueOrdered oGroupNameGraphMetricValue =
                    new GraphMetricValueOrdered(sGroupName);

                oGroupNamesForGroupWorksheet.Add(oGroupNameGraphMetricValue);

                // Write the color in a format that is understood by
                // ColorConverter2.WorkbookToGraph(), which is what
                // WorksheetReaderBase uses.

                oVertexColorsForGroupWorksheet.Add(
                    new GraphMetricValueOrdered(
                        oColorConverter2.GraphToWorkbook(oColor)));

                oVertexShapesForGroupWorksheet.Add(
                    new GraphMetricValueOrdered(
                        oVertexShapeConverter.GraphToWorkbook(eShape)));

                if (collapseGroups)
                {
                    oCollapsedFlagsForGroupWorksheet.Add(
                        oTrueGraphMetricValueOrdered);
                }

                if (groupToCollapsedGroupAttributes != null)
                {
                    oCollapsedAttributesForGroupWorksheet.Add(
                        new GraphMetricValueOrdered(
                            groupToCollapsedGroupAttributes(oGroup)));
                }

                Int32 iVertices = 0;

                foreach (IVertex oVertex in groupToGroupVertices(oGroup))
                {
                    oGroupNamesForGroupVertexWorksheet.Add(
                        oGroupNameGraphMetricValue);

                    oVertexNamesForGroupVertexWorksheet.Add(
                        new GraphMetricValueOrdered(
                            ExcelTextUtil.ForceCellText(oVertex.Name)));

                    iVertices++;
                }

                iGroup++;
            }

            List <GraphMetricColumn> oGraphMetricColumns =
                new List <GraphMetricColumn>();

            oGraphMetricColumns.AddRange(

                new GraphMetricColumn [] {
                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.Name,
                                             ExcelTableUtil.AutoColumnWidth, null,
                                             CellStyleNames.Required,
                                             oGroupNamesForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.VertexColor,
                                             ExcelTableUtil.AutoColumnWidth, null,
                                             CellStyleNames.VisualProperty,
                                             oVertexColorsForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                             TableNames.Groups,
                                             GroupTableColumnNames.VertexShape,
                                             ExcelTableUtil.AutoColumnWidth, null,
                                             CellStyleNames.VisualProperty,
                                             oVertexShapesForGroupWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.GroupName,
                                             ExcelTableUtil.AutoColumnWidth, null, null,
                                             oGroupNamesForGroupVertexWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.VertexName,
                                             ExcelTableUtil.AutoColumnWidth, null, null,
                                             oVertexNamesForGroupVertexWorksheet.ToArray()
                                             ),

                new GraphMetricColumnOrdered(WorksheetNames.GroupVertices,
                                             TableNames.GroupVertices,
                                             GroupVertexTableColumnNames.VertexID,
                                             ExcelTableUtil.AutoColumnWidth, null, null,
                                             aoVertexIDsForGroupVertexWorksheet
                                             ),
            });

            if (collapseGroups)
            {
                oGraphMetricColumns.Add(
                    new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                                 TableNames.Groups,
                                                 GroupTableColumnNames.Collapsed,
                                                 ExcelTableUtil.AutoColumnWidth, null,
                                                 CellStyleNames.VisualProperty,
                                                 oCollapsedFlagsForGroupWorksheet.ToArray()
                                                 ));
            }

            if (groupToCollapsedGroupAttributes != null)
            {
                oGraphMetricColumns.Add(
                    new GraphMetricColumnOrdered(WorksheetNames.Groups,
                                                 TableNames.Groups,
                                                 GroupTableColumnNames.CollapsedAttributes,
                                                 ExcelTableUtil.AutoColumnWidth, null,
                                                 CellStyleNames.DoNotEdit,
                                                 oCollapsedAttributesForGroupWorksheet.ToArray()
                                                 ));
            }

            return(oGraphMetricColumns.ToArray());
        }
        AddColumnsForRankedVertices
        (
            IEnumerable <IVertex> oVertices,
            String sRankedColumnName,
            Int32 iMaximumVertices,
            String sGraphMetricWorksheetName,
            String sGraphMetricTableName,
            String sGraphMetricColumn1Name,
            String sGraphMetricColumn2Name,
            List <GraphMetricColumn> oGraphMetricColumns
        )
        {
            Debug.Assert(oVertices != null);
            Debug.Assert(!String.IsNullOrEmpty(sRankedColumnName));
            Debug.Assert(iMaximumVertices >= 1);
            Debug.Assert(!String.IsNullOrEmpty(sGraphMetricWorksheetName));
            Debug.Assert(!String.IsNullOrEmpty(sGraphMetricTableName));
            Debug.Assert(!String.IsNullOrEmpty(sGraphMetricColumn1Name));
            Debug.Assert(!String.IsNullOrEmpty(sGraphMetricColumn2Name));
            Debug.Assert(oGraphMetricColumns != null);
            AssertValid();

            // Get a collection of information about the specified column on the
            // vertex worksheet, sorted by descending RankedValue.

            IList <ItemInformation> oItems = RankVertices(
                oVertices, sRankedColumnName);

            // Add an ordered column containing the top vertex names, and a
            // corresponding ordered column containing the ranked values.

            iMaximumVertices = Math.Min(iMaximumVertices, oItems.Count);

            GraphMetricValueOrdered[] aoVertexNames =
                new GraphMetricValueOrdered[iMaximumVertices];

            GraphMetricValueOrdered[] aoRankedValues =
                new GraphMetricValueOrdered[iMaximumVertices];

            for (Int32 i = 0; i < iMaximumVertices; i++)
            {
                ItemInformation oItem = oItems[i];

                aoVertexNames[i] = new GraphMetricValueOrdered(oItem.Name);

                aoRankedValues[i] =
                    new GraphMetricValueOrdered(oItem.RankedValue);
            }

            oGraphMetricColumns.Add(new GraphMetricColumnOrdered(
                                        sGraphMetricWorksheetName,
                                        sGraphMetricTableName,
                                        sGraphMetricColumn1Name,
                                        ExcelTableUtil.AutoColumnWidth,
                                        null,
                                        null,
                                        aoVertexNames
                                        ));

            oGraphMetricColumns.Add(new GraphMetricColumnOrdered(
                                        sGraphMetricWorksheetName,
                                        sGraphMetricTableName,
                                        sGraphMetricColumn2Name,
                                        ExcelTableUtil.AutoColumnWidth,
                                        null,
                                        null,
                                        aoRankedValues
                                        ));
        }
    AddColumnsForRankedVertices
    (
        IEnumerable<IVertex> oVertices,
        String sRankedColumnName,
        Int32 iMaximumVertices,
        String sGraphMetricWorksheetName,
        String sGraphMetricTableName,
        String sGraphMetricColumn1Name,
        String sGraphMetricColumn2Name,
        List<GraphMetricColumn> oGraphMetricColumns
    )
    {
        Debug.Assert(oVertices != null);
        Debug.Assert( !String.IsNullOrEmpty(sRankedColumnName) );
        Debug.Assert(iMaximumVertices >= 1);
        Debug.Assert( !String.IsNullOrEmpty(sGraphMetricWorksheetName) );
        Debug.Assert( !String.IsNullOrEmpty(sGraphMetricTableName) );
        Debug.Assert( !String.IsNullOrEmpty(sGraphMetricColumn1Name) );
        Debug.Assert( !String.IsNullOrEmpty(sGraphMetricColumn2Name) );
        Debug.Assert(oGraphMetricColumns != null);
        AssertValid();

        // Get a collection of information about the specified column on the
        // vertex worksheet, sorted by descending RankedValue.

        IList<ItemInformation> oItems = RankVertices(
            oVertices, sRankedColumnName);

        // Add an ordered column containing the top vertex names, and a
        // corresponding ordered column containing the ranked values.

        iMaximumVertices = Math.Min(iMaximumVertices, oItems.Count);

        GraphMetricValueOrdered[] aoVertexNames =
            new GraphMetricValueOrdered[iMaximumVertices];

        GraphMetricValueOrdered[] aoRankedValues =
            new GraphMetricValueOrdered[iMaximumVertices];

        for (Int32 i = 0; i < iMaximumVertices; i++)
        {
            ItemInformation oItem = oItems[i];

            aoVertexNames[i] = new GraphMetricValueOrdered(oItem.Name);

            aoRankedValues[i] =
                new GraphMetricValueOrdered(oItem.RankedValue);
        }

        oGraphMetricColumns.Add( new GraphMetricColumnOrdered(
            sGraphMetricWorksheetName,
            sGraphMetricTableName,
            sGraphMetricColumn1Name,
            ExcelTableUtil.AutoColumnWidth,
            null,
            null,
            aoVertexNames
            ) );

        oGraphMetricColumns.Add( new GraphMetricColumnOrdered(
            sGraphMetricWorksheetName,
            sGraphMetricTableName,
            sGraphMetricColumn2Name,
            ExcelTableUtil.AutoColumnWidth,
            null,
            null,
            aoRankedValues
            ) );
    }
    CopyWordMetricsForGroup
    (
        String groupNameOrDummyGroupName,
        GraphMetricValueOrdered [] word1Values,
        GraphMetricValueOrdered [] word2Values,
        GraphMetricValueOrdered [] countValues,
        GraphMetricValueOrdered [] groupNameValues,
        Int32 firstRowForGroup,
        Int32 maximumTopWordsOrWordPairs,
        List<GraphMetricValueOrdered> topWordsOrWordPairs,
        List<GraphMetricValueOrdered> topCounts
    )
    {
        Debug.Assert( !String.IsNullOrEmpty(groupNameOrDummyGroupName) );
        Debug.Assert(word1Values != null);
        // word2Values
        Debug.Assert(countValues != null);
        Debug.Assert(groupNameValues != null);
        Debug.Assert(firstRowForGroup >= 0);
        Debug.Assert(maximumTopWordsOrWordPairs > 0);
        Debug.Assert(topWordsOrWordPairs != null);
        Debug.Assert(topCounts != null);

        Int32 iRows = groupNameValues.Length;

        for (Int32 iRow = firstRowForGroup, iItems = 0;
            iRow < iRows && iItems < maximumTopWordsOrWordPairs;
            iRow++, iItems++)
        {
            Object oWord1AsObject = word1Values[iRow].Value;
            Object oCountAsObject = countValues[iRow].Value;
            Object oGroupNameAsObject = groupNameValues[iRow].Value;

            if (
                !(oGroupNameAsObject is String)
                ||
                (String)oGroupNameAsObject != groupNameOrDummyGroupName
                ||
                !(oWord1AsObject is String)
                ||
                !(oCountAsObject is Int32)
                )
            {
                break;
            }

            String sWordOrWordPair = ExcelUtil.UnforceCellText(
                (String)oWord1AsObject );

            if (word2Values != null)
            {
                Object oWord2AsObject = word2Values[iRow].Value;

                if ( !(oWord2AsObject is String) )
                {
                    break;
                }

                sWordOrWordPair = FormatWordPair(
                    sWordOrWordPair,
                    ExcelUtil.UnforceCellText( (String)oWord2AsObject ) );
            }

            topWordsOrWordPairs.Add( new GraphMetricValueOrdered(
                ExcelUtil.ForceCellText(sWordOrWordPair) ) );

            topCounts.Add( new GraphMetricValueOrdered(oCountAsObject) );
        }
    }
    GetGroupNameIndexesFromWordMetrics
    (
        GraphMetricValueOrdered [] groupNameValues
    )
    {
        Debug.Assert(groupNameValues != null);

        Dictionary<String, Int32> oGroupNameIndexes =
            new Dictionary<String, Int32>();

        Int32 iRows = groupNameValues.Length;
        String sCurrentGroupName = String.Empty;

        for (Int32 iRow = 0; iRow < iRows; iRow++)
        {
            Object oGroupNameAsObject = groupNameValues[iRow].Value;

            if (oGroupNameAsObject is String)
            {
                String sGroupName = (String)oGroupNameAsObject;

                if (sGroupName != sCurrentGroupName)
                {
                    oGroupNameIndexes.Add(sGroupName, iRow);
                    sCurrentGroupName = sGroupName;
                }
            }
        }

        return (oGroupNameIndexes);
    }