Example #1
0
        AddEdgeWidthAttributesToDConnectorMotif
        (
            ExcelTemplateGroupInfo oGroup,
            Boolean bEdgeWidthColumnAutoFilled,
            AutoFillNumericRangeColumnResults oEdgeWidthResults,
            NumericRangeColumnAutoFillUserSettings oEdgeWidthDetails,
            Dictionary <Int32, Object> oEdgeWidthSourceDictionary,
            ReadWorkbookContext oReadWorkbookContext,
            CollapsedGroupAttributes oCollapsedGroupAttributes,
            Int32 iAnchorVertices
        )
        {
            Debug.Assert(oGroup != null);
            Debug.Assert(oEdgeWidthResults != null);
            Debug.Assert(oReadWorkbookContext != null);
            Debug.Assert(oCollapsedGroupAttributes != null);
            Debug.Assert(iAnchorVertices >= 0);

            // If the edge width column was autofilled, get the average width for
            // the edges incident to the two-connector motif's first anchor, then
            // its second anchor.  Otherwise, don't do anything.

            if (!bEdgeWidthColumnAutoFilled)
            {
                return;
            }

            for (Int32 iAnchorVertexIndex = 0;
                 iAnchorVertexIndex < iAnchorVertices;
                 iAnchorVertexIndex++)
            {
                Double dAverageEdgeWidth;

                if (TableColumnMapper.TryMapAverageNumber(

                        GetRowIDsToAverageForEdges(oGroup,
                                                   oCollapsedGroupAttributes, iAnchorVertexIndex),

                        oEdgeWidthSourceDictionary,
                        oEdgeWidthResults.SourceCalculationNumber1,
                        oEdgeWidthResults.SourceCalculationNumber2,
                        oEdgeWidthResults.DestinationNumber1,
                        oEdgeWidthResults.DestinationNumber2,
                        oEdgeWidthDetails.UseLogs,
                        out dAverageEdgeWidth
                        )
                    )
                {
                    oCollapsedGroupAttributes.Add(

                        CollapsedGroupAttributeKeys.GetAnchorVertexEdgeWidthKey(
                            iAnchorVertexIndex),

                        dAverageEdgeWidth
                        );
                }
            }
        }
        //*************************************************************************
        //  Constructor: NumericRangeColumnAutoFillUserSettingsDialog()
        //
        /// <overloads>
        /// Initializes a new instance of the <see
        /// cref="NumericRangeColumnAutoFillUserSettingsDialog" /> class.
        /// </overloads>
        ///
        /// <summary>
        /// Initializes a new instance of the <see
        /// cref="NumericRangeColumnAutoFillUserSettingsDialog" /> class with a
        /// <see cref="NumericRangeColumnAutoFillUserSettings" /> object.
        /// </summary>
        ///
        /// <param name="numericRangeColumnAutoFillUserSettings">
        /// Object to edit.
        /// </param>
        ///
        /// <param name="dialogCaption">
        /// Dialog caption.
        /// </param>
        ///
        /// <param name="destinationColumnName">
        /// The name of the destination column, suitable for use as the placeholder
        /// in DestinationLabel1 and DestinationLabel2.  Can't be null or empty.
        /// Sample: "vertex opacity".
        /// </param>
        ///
        /// <param name="destinationColumnNamePlural">
        /// Plural and possibly abbreviated form of <paramref
        /// name="destinationColumnName" />, suitable for use as the placeholder in
        /// the "swap destination numbers" button.  Can't be null or empty.
        /// Sample: "Opacities".
        /// </param>
        ///
        /// <param name="minimumDestinationNumber">
        /// Minimum value of a cell in the destination column.
        /// </param>
        ///
        /// <param name="maximumDestinationNumber">
        /// Maximum value of a cell in the destination column.
        /// </param>
        //*************************************************************************

        public NumericRangeColumnAutoFillUserSettingsDialog
        (
            NumericRangeColumnAutoFillUserSettings
            numericRangeColumnAutoFillUserSettings,

            String dialogCaption,
            String destinationColumnName,
            String destinationColumnNamePlural,
            Double minimumDestinationNumber,
            Double maximumDestinationNumber
        )
            : this()
        {
            Debug.Assert(numericRangeColumnAutoFillUserSettings != null);
            Debug.Assert(!String.IsNullOrEmpty(dialogCaption));
            Debug.Assert(!String.IsNullOrEmpty(destinationColumnName));
            Debug.Assert(!String.IsNullOrEmpty(destinationColumnNamePlural));

            m_oNumericRangeColumnAutoFillUserSettings =
                numericRangeColumnAutoFillUserSettings;

            this.Text = dialogCaption;

            lblDestinationNumber1.Text = String.Format(
                DestinationLabel1
                ,
                destinationColumnName
                );

            lblDestinationNumber2.Text = String.Format(
                DestinationLabel2
                ,
                destinationColumnName
                );

            nudDestinationNumber1.Minimum = nudDestinationNumber2.Minimum =
                (Decimal)minimumDestinationNumber;

            nudDestinationNumber1.Maximum = nudDestinationNumber2.Maximum =
                (Decimal)maximumDestinationNumber;

            btnSwapDestinationNumbers.Text = "<- Swap " +
                                             destinationColumnNamePlural + " ->";

            // Instantiate an object that saves and retrieves the position of this
            // dialog.  Note that the object automatically saves the settings when
            // the form closes.

            m_oNumericRangeColumnAutoFillUserSettingsDialogUserSettings =
                new NumericRangeColumnAutoFillUserSettingsDialogUserSettings(this);

            lnkOutliersAndLogs.Tag = AutoFillWorkbookDialog.OutliersAndLogsMessage;

            DoDataExchange(false);

            AssertValid();
        }
    //*************************************************************************
    //  Constructor: NumericRangeColumnAutoFillUserSettingsDialog()
    //
    /// <overloads>
    /// Initializes a new instance of the <see
    /// cref="NumericRangeColumnAutoFillUserSettingsDialog" /> class.
    /// </overloads>
    ///
    /// <summary>
    /// Initializes a new instance of the <see
    /// cref="NumericRangeColumnAutoFillUserSettingsDialog" /> class with a
    /// <see cref="NumericRangeColumnAutoFillUserSettings" /> object.
    /// </summary>
    ///
    /// <param name="numericRangeColumnAutoFillUserSettings">
    /// Object to edit.
    /// </param>
    ///
    /// <param name="dialogCaption">
    /// Dialog caption.
    /// </param>
    ///
    /// <param name="destinationColumnName">
    /// The name of the destination column, suitable for use as the placeholder
    /// in DestinationLabel1 and DestinationLabel2.  Can't be null or empty.
    /// Sample: "vertex opacity".
    /// </param>
    ///
    /// <param name="destinationColumnNamePlural">
    /// Plural and possibly abbreviated form of <paramref
    /// name="destinationColumnName" />, suitable for use as the placeholder in
    /// the "swap destination numbers" button.  Can't be null or empty.
    /// Sample: "Opacities".
    /// </param>
    ///
    /// <param name="minimumDestinationNumber">
    /// Minimum value of a cell in the destination column.
    /// </param>
    ///
    /// <param name="maximumDestinationNumber">
    /// Maximum value of a cell in the destination column.
    /// </param>
    //*************************************************************************

    public NumericRangeColumnAutoFillUserSettingsDialog
    (
        NumericRangeColumnAutoFillUserSettings
            numericRangeColumnAutoFillUserSettings,

        String dialogCaption,
        String destinationColumnName,
        String destinationColumnNamePlural,
        Double minimumDestinationNumber,
        Double maximumDestinationNumber
    )
    : this()
    {
        Debug.Assert(numericRangeColumnAutoFillUserSettings != null);
        Debug.Assert( !String.IsNullOrEmpty(dialogCaption) );
        Debug.Assert( !String.IsNullOrEmpty(destinationColumnName) );
        Debug.Assert( !String.IsNullOrEmpty(destinationColumnNamePlural) );

        m_oNumericRangeColumnAutoFillUserSettings =
            numericRangeColumnAutoFillUserSettings;

        this.Text = dialogCaption;

        lblDestinationNumber1.Text = String.Format(
            DestinationLabel1
            ,
            destinationColumnName
            );

        lblDestinationNumber2.Text = String.Format(
            DestinationLabel2
            ,
            destinationColumnName
            );

        nudDestinationNumber1.Minimum = nudDestinationNumber2.Minimum =
            (Decimal)minimumDestinationNumber;

        nudDestinationNumber1.Maximum = nudDestinationNumber2.Maximum =
            (Decimal)maximumDestinationNumber;

        btnSwapDestinationNumbers.Text = "<- Swap " +
            destinationColumnNamePlural + " ->";

        // Instantiate an object that saves and retrieves the position of this
        // dialog.  Note that the object automatically saves the settings when
        // the form closes.

        m_oNumericRangeColumnAutoFillUserSettingsDialogUserSettings =
            new NumericRangeColumnAutoFillUserSettingsDialogUserSettings(this);

        lnkOutliersAndLogs.Tag = AutoFillWorkbookDialog.OutliersAndLogsMessage;

        DoDataExchange(false);

        AssertValid();
    }
        ConvertFrom
        (
            ITypeDescriptorContext context,
            CultureInfo culture,
            Object value
        )
        {
            Debug.Assert(value != null);
            Debug.Assert(value is String);
            AssertValid();

            NumericRangeColumnAutoFillUserSettings
                oNumericRangeColumnAutoFillUserSettings =
                new NumericRangeColumnAutoFillUserSettings();

            String [] asStrings = ((String)value).Split(new Char[] { '\t' });

            Debug.Assert(asStrings.Length >= 7);

            oNumericRangeColumnAutoFillUserSettings.UseSourceNumber1 =
                Boolean.Parse(asStrings[0]);

            oNumericRangeColumnAutoFillUserSettings.UseSourceNumber2 =
                Boolean.Parse(asStrings[1]);

            oNumericRangeColumnAutoFillUserSettings.SourceNumber1 =
                MathUtil.ParseCultureInvariantDouble(asStrings[2]);

            oNumericRangeColumnAutoFillUserSettings.SourceNumber2 =
                MathUtil.ParseCultureInvariantDouble(asStrings[3]);

            oNumericRangeColumnAutoFillUserSettings.DestinationNumber1 =
                MathUtil.ParseCultureInvariantDouble(asStrings[4]);

            oNumericRangeColumnAutoFillUserSettings.DestinationNumber2 =
                MathUtil.ParseCultureInvariantDouble(asStrings[5]);

            oNumericRangeColumnAutoFillUserSettings.IgnoreOutliers =
                Boolean.Parse(asStrings[6]);

            // The UseLogs property wasn't added until NodeXL version 1.0.1.92.

            oNumericRangeColumnAutoFillUserSettings.UseLogs =
                (asStrings.Length > 7) ? Boolean.Parse(asStrings[7]) : false;

            return(oNumericRangeColumnAutoFillUserSettings);
        }
        TryAutoFillNumericRangeColumn
        (
            ListObject oTable,
            String sSourceColumnName,
            String sDestinationColumnName,
            NumericRangeColumnAutoFillUserSettings oDetails,
            out Double dSourceCalculationNumber1,
            out Double dSourceCalculationNumber2,
            out Int32 iDecimalPlaces
        )
        {
            Debug.Assert(oTable != null);
            Debug.Assert(!String.IsNullOrEmpty(sDestinationColumnName));
            Debug.Assert(oDetails != null);

            dSourceCalculationNumber1 = dSourceCalculationNumber2 =
                Double.MinValue;

            iDecimalPlaces = Int32.MinValue;

            if (String.IsNullOrEmpty(sSourceColumnName))
            {
                return(false);
            }

            return(TableColumnMapper.TryMapToNumericRange(
                       oTable, sSourceColumnName, sDestinationColumnName,
                       oDetails.UseSourceNumber1,
                       oDetails.UseSourceNumber2,
                       oDetails.SourceNumber1,
                       oDetails.SourceNumber2,
                       oDetails.DestinationNumber1,
                       oDetails.DestinationNumber2,
                       oDetails.IgnoreOutliers,
                       oDetails.UseLogs,
                       out dSourceCalculationNumber1,
                       out dSourceCalculationNumber2,
                       out iDecimalPlaces
                       ));
        }
        ConvertTo
        (
            ITypeDescriptorContext context,
            CultureInfo culture,
            Object value,
            Type destinationType
        )
        {
            Debug.Assert(value != null);
            Debug.Assert(value is NumericRangeColumnAutoFillUserSettings);
            Debug.Assert(destinationType == typeof(String));
            AssertValid();

            NumericRangeColumnAutoFillUserSettings
                oNumericRangeColumnAutoFillUserSettings =
                (NumericRangeColumnAutoFillUserSettings)value;

            // Use a simple tab-delimited format.  Sample string:
            //
            // "false\tfalse\t0\t10\t0\t10\tfalse\tfalse"
            //
            // WARNING: If this format is changed, you must also change the
            // DefaultSettingValueAttribute for each property in the
            // AutoFillUserSettings class that is of type
            // NumericRangeColumnAutoFillUserSettings.

            return(String.Format(CultureInfo.InvariantCulture,

                                 "{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}"
                                 ,
                                 oNumericRangeColumnAutoFillUserSettings.UseSourceNumber1,
                                 oNumericRangeColumnAutoFillUserSettings.UseSourceNumber2,
                                 oNumericRangeColumnAutoFillUserSettings.SourceNumber1,
                                 oNumericRangeColumnAutoFillUserSettings.SourceNumber2,
                                 oNumericRangeColumnAutoFillUserSettings.DestinationNumber1,
                                 oNumericRangeColumnAutoFillUserSettings.DestinationNumber2,
                                 oNumericRangeColumnAutoFillUserSettings.IgnoreOutliers,
                                 oNumericRangeColumnAutoFillUserSettings.UseLogs
                                 ));
        }
Example #7
0
        AddCollapsedGroupAttributesInternal
        (
            Microsoft.Office.Interop.Excel.Workbook oWorkbook,
            ReadWorkbookContext oReadWorkbookContext,
            ListObject oEdgeTable,
            ListObject oVertexTable,
            GroupInfo[] aoGroups
        )
        {
            Debug.Assert(oWorkbook != null);
            Debug.Assert(oReadWorkbookContext != null);
            Debug.Assert(oEdgeTable != null);
            Debug.Assert(oVertexTable != null);
            Debug.Assert(aoGroups != null);
            Debug.Assert(aoGroups.Length > 0);

            // Check whether relevant columns have been autofilled using numerical
            // source columns.

            PerWorkbookSettings oPerWorkbookSettings =
                new PerWorkbookSettings(oWorkbook);

            AutoFillColorColumnResults oVertexColorResults =
                oPerWorkbookSettings.AutoFillWorkbookResults.VertexColorResults;

            Boolean bVertexColorColumnAutoFilled =
                oVertexColorResults.ColumnAutoFilled &&
                !oVertexColorResults.ColumnAutoFilledWithCategories;

            AutoFillColorColumnResults oEdgeColorResults =
                oPerWorkbookSettings.AutoFillWorkbookResults.EdgeColorResults;

            Boolean bEdgeColorColumnAutoFilled =
                oEdgeColorResults.ColumnAutoFilled &&
                !oEdgeColorResults.ColumnAutoFilledWithCategories;

            AutoFillNumericRangeColumnResults oEdgeWidthResults =
                oPerWorkbookSettings.AutoFillWorkbookResults.EdgeWidthResults;

            Boolean bEdgeWidthColumnAutoFilled =
                oEdgeWidthResults.ColumnAutoFilled;

            // Some user settings for autofill may be needed.
            //
            // Note: This is a design bug.  The user's current settings should not
            // be required; everything needed here should come from the autofill
            // results.  The long-term fix is to add a UseLogs property to the
            // AutoFillColorColumnResults class.

            AutoFillUserSettings oAutoFillUserSettings =
                new AutoFillUserSettings();

            ColorColumnAutoFillUserSettings oVertexColorDetails =
                oAutoFillUserSettings.VertexColorDetails;

            ColorColumnAutoFillUserSettings oEdgeColorDetails =
                oAutoFillUserSettings.EdgeColorDetails;

            NumericRangeColumnAutoFillUserSettings oEdgeWidthDetails =
                oAutoFillUserSettings.EdgeWidthDetails;

            // The key is the row ID for each visible row in the vertex table and
            // the value is value of the source column cell in that row that was
            // used to autofill the vertex color column, if it was autofilled.

            Dictionary <Int32, Object> oVertexColorSourceDictionary =
                bVertexColorColumnAutoFilled ?

                GetRowIDDictionary(oVertexTable,
                                   oVertexColorResults.SourceColumnName)
            :
                null;

            // Ditto for edge colors and edge widths.

            Dictionary <Int32, Object> oEdgeColorSourceDictionary =
                bEdgeColorColumnAutoFilled ?

                GetRowIDDictionary(oEdgeTable, oEdgeColorResults.SourceColumnName)
            :
                null;

            Dictionary <Int32, Object> oEdgeWidthSourceDictionary =
                bEdgeWidthColumnAutoFilled ?

                GetRowIDDictionary(oEdgeTable, oEdgeWidthResults.SourceColumnName)
            :
                null;

            // Only motifs need to have attributes added to them.

            foreach (ExcelTemplateGroupInfo oGroup in aoGroups.Where(
                         oGroup => oGroup.CollapsedAttributes != null))
            {
                CollapsedGroupAttributes oCollapsedGroupAttributes =
                    CollapsedGroupAttributes.FromString(
                        oGroup.CollapsedAttributes);

                String sType = oCollapsedGroupAttributes.GetGroupType();

                if (
                    sType == CollapsedGroupAttributeValues.FanMotifType
                    ||
                    sType == CollapsedGroupAttributeValues.DConnectorMotifType
                    ||
                    sType == CollapsedGroupAttributeValues.CliqueMotifType
                    )
                {
                    AddVertexColorAttributeToMotif(oGroup, sType,
                                                   bVertexColorColumnAutoFilled, oVertexColorResults,
                                                   oVertexColorDetails, oVertexColorSourceDictionary,
                                                   oReadWorkbookContext, oCollapsedGroupAttributes);
                }

                if (sType == CollapsedGroupAttributeValues.DConnectorMotifType)
                {
                    Int32 iAnchorVertices;

                    if (oCollapsedGroupAttributes.TryGetValue(
                            CollapsedGroupAttributeKeys.AnchorVertices,
                            out iAnchorVertices))
                    {
                        AddEdgeColorAttributesToDConnectorMotif(oGroup,
                                                                bEdgeColorColumnAutoFilled, oEdgeColorResults,
                                                                oEdgeColorDetails, oEdgeColorSourceDictionary,
                                                                oReadWorkbookContext, oCollapsedGroupAttributes,
                                                                iAnchorVertices);

                        AddEdgeWidthAttributesToDConnectorMotif(oGroup,
                                                                bEdgeWidthColumnAutoFilled, oEdgeWidthResults,
                                                                oEdgeWidthDetails, oEdgeWidthSourceDictionary,
                                                                oReadWorkbookContext, oCollapsedGroupAttributes,
                                                                iAnchorVertices);
                    }
                }

                oGroup.CollapsedAttributes = oCollapsedGroupAttributes.ToString();
            }
        }
    AddEdgeWidthAttributesToDConnectorMotif
    (
        ExcelTemplateGroupInfo oGroup,
        Boolean bEdgeWidthColumnAutoFilled,
        AutoFillNumericRangeColumnResults oEdgeWidthResults,
        NumericRangeColumnAutoFillUserSettings oEdgeWidthDetails,
        Dictionary<Int32, Object> oEdgeWidthSourceDictionary,
        ReadWorkbookContext oReadWorkbookContext,
        CollapsedGroupAttributes oCollapsedGroupAttributes,
        Int32 iAnchorVertices
    )
    {
        Debug.Assert(oGroup != null);
        Debug.Assert(oEdgeWidthResults != null);
        Debug.Assert(oReadWorkbookContext != null);
        Debug.Assert(oCollapsedGroupAttributes != null);
        Debug.Assert(iAnchorVertices >= 0);

        // If the edge width column was autofilled, get the average width for
        // the edges incident to the two-connector motif's first anchor, then
        // its second anchor.  Otherwise, don't do anything.

        if (!bEdgeWidthColumnAutoFilled)
        {
            return;
        }

        for (Int32 iAnchorVertexIndex = 0;
            iAnchorVertexIndex < iAnchorVertices;
            iAnchorVertexIndex++)
        {
            Double dAverageEdgeWidth;

            if ( TableColumnMapper.TryMapAverageNumber(

                    GetRowIDsToAverageForEdges(oGroup,
                        oCollapsedGroupAttributes, iAnchorVertexIndex),

                    oEdgeWidthSourceDictionary,
                    oEdgeWidthResults.SourceCalculationNumber1,
                    oEdgeWidthResults.SourceCalculationNumber2,
                    oEdgeWidthResults.DestinationNumber1,
                    oEdgeWidthResults.DestinationNumber2,
                    oEdgeWidthDetails.UseLogs,
                    out dAverageEdgeWidth
                    )
                )
            {
                oCollapsedGroupAttributes.Add(

                    CollapsedGroupAttributeKeys.GetAnchorVertexEdgeWidthKey(
                        iAnchorVertexIndex),

                    dAverageEdgeWidth
                    );
            }
        }
    }
    TryAutoFillNumericRangeColumn
    (
        ListObject oTable,
        String sSourceColumnName,
        String sDestinationColumnName,
        NumericRangeColumnAutoFillUserSettings oDetails,
        out Double dSourceCalculationNumber1,
        out Double dSourceCalculationNumber2,
        out Int32 iDecimalPlaces
    )
    {
        Debug.Assert(oTable != null);
        Debug.Assert( !String.IsNullOrEmpty(sDestinationColumnName) );
        Debug.Assert(oDetails != null);

        dSourceCalculationNumber1 = dSourceCalculationNumber2 =
            Double.MinValue;

        iDecimalPlaces = Int32.MinValue;

        if ( String.IsNullOrEmpty(sSourceColumnName) )
        {
            return (false);
        }

        return (TableColumnMapper.TryMapToNumericRange(
            oTable, sSourceColumnName, sDestinationColumnName,
            oDetails.UseSourceNumber1,
            oDetails.UseSourceNumber2,
            oDetails.SourceNumber1,
            oDetails.SourceNumber2,
            oDetails.DestinationNumber1,
            oDetails.DestinationNumber2,
            oDetails.IgnoreOutliers,
            oDetails.UseLogs,
            out dSourceCalculationNumber1,
            out dSourceCalculationNumber2,
            out iDecimalPlaces
            ) );
    }
    ConvertFrom
    (
        ITypeDescriptorContext context,
        CultureInfo culture,
        Object value
    )
    {
        Debug.Assert(value != null);
        Debug.Assert(value is String);
        AssertValid();

        NumericRangeColumnAutoFillUserSettings
            oNumericRangeColumnAutoFillUserSettings =
            new NumericRangeColumnAutoFillUserSettings();

        String [] asStrings = ( (String)value ).Split( new Char[] {'\t'} );

        Debug.Assert(asStrings.Length >= 7);

        oNumericRangeColumnAutoFillUserSettings.UseSourceNumber1 =
            Boolean.Parse( asStrings[0] );

        oNumericRangeColumnAutoFillUserSettings.UseSourceNumber2 =
            Boolean.Parse( asStrings[1] );

        oNumericRangeColumnAutoFillUserSettings.SourceNumber1 =
            MathUtil.ParseCultureInvariantDouble( asStrings[2] );

        oNumericRangeColumnAutoFillUserSettings.SourceNumber2 =
            MathUtil.ParseCultureInvariantDouble(asStrings[3]);

        oNumericRangeColumnAutoFillUserSettings.DestinationNumber1 =
            MathUtil.ParseCultureInvariantDouble(asStrings[4]);

        oNumericRangeColumnAutoFillUserSettings.DestinationNumber2 =
            MathUtil.ParseCultureInvariantDouble(asStrings[5]);

        oNumericRangeColumnAutoFillUserSettings.IgnoreOutliers =
            Boolean.Parse( asStrings[6] );

        // The UseLogs property wasn't added until NodeXL version 1.0.1.92.

        oNumericRangeColumnAutoFillUserSettings.UseLogs =
            (asStrings.Length > 7) ? Boolean.Parse( asStrings[7] ) : false;

        return (oNumericRangeColumnAutoFillUserSettings);
    }