GraphToWorkbook() public method

public GraphToWorkbook ( PointF graphLocation, System.Single &workbookX, System.Single &workbookY ) : void
graphLocation System.Drawing.PointF
workbookX System.Single
workbookY System.Single
return void
Example #1
0
        SetLocations <TLocationInfo>
        (
            IEnumerable <TLocationInfo> oLocationInfo,
            System.Drawing.Rectangle oGraphRectangle,
            TryGetRowIDAndLocation <TLocationInfo> oTryGetRowIDAndLocation,
            Dictionary <Int32, Int32> oRowIDDictionary,
            Range oXColumnData,
            Range oYColumnData,
            Object [,] aoLockedColumnValues
        )
        {
            Debug.Assert(oLocationInfo != null);
            Debug.Assert(oTryGetRowIDAndLocation != null);
            Debug.Assert(oRowIDDictionary != null);
            Debug.Assert(oXColumnData != null);
            Debug.Assert(oYColumnData != null);
            AssertValid();

            Int32 iRowNumberOneBased;

            Object [,] aoXValues = ExcelUtil.GetRangeValues(oXColumnData);
            Object [,] aoYValues = ExcelUtil.GetRangeValues(oYColumnData);

            // This is the row number of the table's first data row.

            Int32 iDataBodyRangeRowOneBased = oXColumnData.Row;

            // Create an object that converts a location between coordinates used
            // in the NodeXL graph and coordinates used in the worksheet.

            VertexLocationConverter oVertexLocationConverter =
                new VertexLocationConverter(oGraphRectangle);

            foreach (TLocationInfo oOneLocationInfo in oLocationInfo)
            {
                Int32  iRowID;
                PointF oLocationToSet;

                if (
                    !oTryGetRowIDAndLocation(oOneLocationInfo, out iRowID,
                                             out oLocationToSet)
                    ||
                    !oRowIDDictionary.TryGetValue(iRowID, out iRowNumberOneBased)
                    )
                {
                    continue;
                }

                Int32 iRowToWriteOneBased =
                    iRowNumberOneBased - iDataBodyRangeRowOneBased + 1;

                if (
                    aoLockedColumnValues != null
                    &&
                    VertexIsLocked(aoLockedColumnValues, iRowToWriteOneBased)
                    )
                {
                    continue;
                }

                // Convert the location to workbook coordinates before writing it
                // to the X and Y column cells.

                Single fWorkbookX, fWorkbookY;

                oVertexLocationConverter.GraphToWorkbook(oLocationToSet,
                                                         out fWorkbookX, out fWorkbookY);

                aoXValues[iRowToWriteOneBased, 1] = fWorkbookX;
                aoYValues[iRowToWriteOneBased, 1] = fWorkbookY;
            }

            // Write the X and Y columns.

            oXColumnData.set_Value(Missing.Value, aoXValues);
            oYColumnData.set_Value(Missing.Value, aoYValues);
        }
    TestGraphToWorkbook4()
    {
        // Empty rectangle.

        m_oVertexLocationConverter = new VertexLocationConverter(
            Rectangle.FromLTRB(100, 200, 100, 200) );

        Single fGraphX = 600;
        Single fGraphY = 1200;

        Single ExpectedWorkbookX = VertexLocationConverter.MinimumXYWorkbook;
        Single ExpectedWorkbookY = ExpectedWorkbookX;

        Single fWorkbookX, fWorkbookY;

        m_oVertexLocationConverter.GraphToWorkbook(
            new PointF(fGraphX, fGraphY), out fWorkbookX, out fWorkbookY);

        Assert.AreEqual(ExpectedWorkbookX, fWorkbookX);
        Assert.AreEqual(ExpectedWorkbookY, fWorkbookY);
    }