Exemple #1
0
        TryGetVertexShape
        (
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            out VertexShape eShape
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(!String.IsNullOrEmpty(sColumnName));
            AssertValid();

            eShape = VertexShape.Circle;
            String sShape;

            if (!oRow.TryGetNonEmptyStringFromCell(sColumnName, out sShape))
            {
                return(false);
            }

            VertexShapeConverter oVertexShapeConverter =
                new VertexShapeConverter();

            if (!oVertexShapeConverter.TryWorkbookToGraph(sShape, out eShape))
            {
                OnWorkbookFormatErrorWithDropDown(oRow, sColumnName, "shape");
            }

            return(true);
        }
Exemple #2
0
        GetVertexAttributes
        (
            Int32 groupIndex,
            Int32 totalGroups,
            out Color color,
            out VertexShape shape
        )
        {
            Debug.Assert(groupIndex >= 0);
            Debug.Assert(totalGroups > 0);
            Debug.Assert(groupIndex < totalGroups);

            // Algorithm:
            //
            // Cycle through the set of hues with one shape, then cycle through the
            // set of hues with the next shape, and so on.  When all shapes have
            // been used, repeat the process with another saturation.

            Int32 iHues   = Hues.Length;
            Int32 iShapes = Shapes.Length;

            Int32 iSaturations = (Int32)Math.Ceiling(
                (Single)totalGroups / (Single)(iHues * iShapes));

            Int32 iHueIndex        = groupIndex % iHues;
            Int32 iDividend        = groupIndex / iHues;
            Int32 iShapeIndex      = iDividend % iShapes;
            Int32 iSaturationIndex = iDividend / iShapes;

            Single fHue = Hues[iHueIndex];

            Single fSaturation;

            if (iSaturations == 1)
            {
                fSaturation = StartSaturation;
            }
            else
            {
                fSaturation = StartSaturation
                              + ((Single)iSaturationIndex / (Single)(iSaturations - 1))
                              * (EndSaturation - StartSaturation);
            }

            color = ColorUtil.HsbToRgb(fHue, fSaturation, Brightness);

            if (color == Color.FromArgb(255, 172, 0))
            {
                // Due to rounding errors, the above code produces (255,172,0) for
                // orange, which should actually be (255,165,0).
                // ColorConverter2.GraphToWorkbook() converts (255,165,0) to the
                // string "Orange", so use the correct RGB values.

                color = Color.FromArgb(255, 165, 0);
            }

            shape = Shapes[iShapeIndex];
        }
Exemple #3
0
 public DrawnMapNode(MapNode source, Unit occupyingUnit, Powers owningPower)
 {
     OccupationSize = 40;
     GeometrySize   = 200;
     MapNode        = source;
     RenderStyle    = MapNodeStyles.Get(source);
     ID             = MapNode.SequenceNumber;
     Shape          = RenderStyle.Shape;
     Text           = MapNode.ShortName;
     if (occupyingUnit != null)
     {
         AddOccupyingUnit(occupyingUnit);
     }
 }
        //*************************************************************************
        //  Constructor: GroupInformation()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupInformation" />
        /// class.
        /// </summary>
        ///
        /// <param name="name">
        /// The name of the group.
        /// </param>
        ///
        /// <param name="rowID">
        /// The group's row ID in the group worksheet, or null if an ID isn't
        /// available.
        /// </param>
        ///
        /// <param name="vertexColor">
        /// The color to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="vertexShape">
        /// The shape to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="isCollapsed">
        /// true if the group should be collapsed.
        /// </param>
        //*************************************************************************
        public GroupInformation(
            String name,
            Nullable<Int32> rowID,
            Color vertexColor,
            VertexShape vertexShape,
            Boolean isCollapsed
            )
        {
            m_sName = name;
            m_iRowID = rowID;
            m_oVertexColor = vertexColor;
            m_eVertexShape = vertexShape;
            m_bIsCollapsed = isCollapsed;
            m_oVertices = null;

            AssertValid();
        }
        DrawColorColumnResults
        (
            DrawingObjects oDrawingObjects,
            String sCaption,
            AutoFillColorColumnResults oColorResults,
            VertexShape eCategoryShape,
            Rectangle oColumnRectangle,
            Int32 iResultsLeft,
            Int32 iResultsRight,
            ref Int32 iTop
        )
        {
            Debug.Assert(oDrawingObjects != null);
            Debug.Assert(!String.IsNullOrEmpty(sCaption));
            Debug.Assert(oColorResults != null);

            if (oColorResults.SourceColumnContainsNumbers)
            {
                DrawColorBarResults(oDrawingObjects,
                                    oColorResults.SourceColumnName, ColorCaption,
                                    oColorResults.SourceCalculationNumber1,
                                    oColorResults.SourceCalculationNumber2,
                                    oColorResults.DecimalPlaces,
                                    oColorResults.DestinationColor1,
                                    oColorResults.DestinationColor2,
                                    oColumnRectangle, iResultsLeft, iResultsRight,
                                    ref iTop);
            }
            else
            {
                DrawColorCategoryResults(oDrawingObjects,
                                         oColorResults.CategoryNames,

                                         (Int32 categoryIndex, out VertexShape categoryShape,
                                          out Color categoryColor) =>
                {
                    categoryShape = eCategoryShape;

                    categoryColor = ColorUtil.GetUniqueColor(categoryIndex,
                                                             oColorResults.CategoryNames.Count);
                },

                                         oColumnRectangle, ref iTop
                                         );
            }
        }
Exemple #6
0
        //*************************************************************************
        //  Constructor: GroupInformation()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="GroupInformation" />
        /// class.
        /// </summary>
        ///
        /// <param name="name">
        /// The name of the group.
        /// </param>
        ///
        /// <param name="rowID">
        /// The group's row ID in the group worksheet, or null if an ID isn't
        /// available.
        /// </param>
        ///
        /// <param name="vertexColor">
        /// The color to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="vertexShape">
        /// The shape to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="isCollapsed">
        /// true if the group should be collapsed.
        /// </param>
        //*************************************************************************

        public GroupInformation
        (
            String name,
            Nullable <Int32> rowID,
            Color vertexColor,
            VertexShape vertexShape,
            Boolean isCollapsed
        )
        {
            m_sName        = name;
            m_iRowID       = rowID;
            m_oVertexColor = vertexColor;
            m_eVertexShape = vertexShape;
            m_bIsCollapsed = isCollapsed;
            m_oVertices    = null;

            AssertValid();
        }
    //*************************************************************************
    //  Constructor: ExcelTemplateGroupInfo()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="ExcelTemplateGroupInfo" />
    /// class.
    /// </summary>
    ///
    /// <param name="name">
    /// The unique name of the group.
    /// </param>
    ///
    /// <param name="rowID">
    /// The group's row ID in the group worksheet, or null if an ID isn't
    /// available.
    /// </param>
    ///
    /// <param name="vertexColor">
    /// The color to use for each of the group's vertices.
    /// </param>
    ///
    /// <param name="vertexShape">
    /// The shape to use for each of the group's vertices.
    /// </param>
    ///
    /// <param name="isCollapsed">
    /// true if the group should be collapsed.
    /// </param>
    ///
    /// <param name="collapsedAttributes">
    /// String containing the attributes describing what the group should look
    /// like when it is collapsed, or null to give the collapsed group a
    /// default appearance.  If not null, this should be a string that was
    /// returned by <see
    /// cref="Smrf.AppLib.PersistableStringDictionary.ToString" />.
    /// </param>
    //*************************************************************************

    public ExcelTemplateGroupInfo
    (
        String name,
        Nullable<Int32> rowID,
        Color vertexColor,
        VertexShape vertexShape,
        Boolean isCollapsed,
        String collapsedAttributes
    )
    : base(name, isCollapsed, collapsedAttributes)
    {
        Debug.Assert( !String.IsNullOrEmpty(name) );

        m_iRowID = rowID;
        m_oVertexColor = vertexColor;
        m_eVertexShape = vertexShape;

        AssertValid();
    }
Exemple #8
0
        //*************************************************************************
        //  Constructor: ExcelTemplateGroupInfo()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="ExcelTemplateGroupInfo" />
        /// class.
        /// </summary>
        ///
        /// <param name="name">
        /// The unique name of the group.
        /// </param>
        ///
        /// <param name="rowID">
        /// The group's row ID in the group worksheet, or null if an ID isn't
        /// available.
        /// </param>
        ///
        /// <param name="vertexColor">
        /// The color to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="vertexShape">
        /// The shape to use for each of the group's vertices.
        /// </param>
        ///
        /// <param name="isCollapsed">
        /// true if the group should be collapsed.
        /// </param>
        ///
        /// <param name="collapsedAttributes">
        /// String containing the attributes describing what the group should look
        /// like when it is collapsed, or null to give the collapsed group a
        /// default appearance.  If not null, this should be a string that was
        /// returned by <see
        /// cref="Smrf.AppLib.PersistableStringDictionary.ToString" />.
        /// </param>
        //*************************************************************************

        public ExcelTemplateGroupInfo
        (
            String name,
            Nullable <Int32> rowID,
            Color vertexColor,
            VertexShape vertexShape,
            Boolean isCollapsed,
            String collapsedAttributes
        )
            : base(name, isCollapsed, collapsedAttributes)
        {
            Debug.Assert(!String.IsNullOrEmpty(name));

            m_iRowID       = rowID;
            m_oVertexColor = vertexColor;
            m_eVertexShape = vertexShape;

            AssertValid();
        }
        ReadShape
        (
            ExcelTableReader.ExcelTableRow oRow,
            IVertex oVertex,
            out VertexShape eShape
        )
        {
            Debug.Assert(oRow != null);
            Debug.Assert(oVertex != null);
            AssertValid();

            if (TryGetVertexShape(oRow, VertexTableColumnNames.Shape,
                                  out eShape))
            {
                oVertex.SetValue(ReservedMetadataKeys.PerVertexShape, eShape);
                return(true);
            }

            return(false);
        }
Exemple #10
0
        GetVertexAttributes
        (
            Int32 groupIndex,
            Int32 totalGroups,
            out Color color,
            out VertexShape shape
        )
        {
            Debug.Assert(groupIndex >= 0);
            Debug.Assert(totalGroups > 0);
            Debug.Assert(groupIndex < totalGroups);

            // Algorithm:
            //
            // Cycle through a set of hues with one shape, then the same set of
            // hues with the next shape, and so on.  When all shapes have been
            // used, repeat the process with another saturation.

            Int32 iHues   = ColorUtil.UniqueColorHues;
            Int32 iShapes = Shapes.Length;

            Int32 iSaturations = (Int32)Math.Ceiling(
                (Single)totalGroups / (Single)(iHues * iShapes)
                );

            Int32 iMaximumUniqueColors = iSaturations * iHues;

            Int32 iColorIndex = (groupIndex % iHues) +
                                (iHues * (groupIndex / (iHues * iShapes)));

            color = ColorUtil.GetUniqueColor(iColorIndex, iMaximumUniqueColors);

            Int32 iShapeIndex = (groupIndex / ColorUtil.UniqueColorHues) % iShapes;

            shape = Shapes[iShapeIndex];
        }
Exemple #11
0
        GetVertexCategoryScheme
        (
            Int32 schemeIndex,
            out VertexShape shape,
            out Color color,
            out Single radius
        )
        {
            Debug.Assert(schemeIndex >= 0);

            // 96 categories are supported -- 12 colors and 8 shapes.  Each shape
            // has its own assigned radius.

            Color [] aoColors = new Color [] {
                Color.FromArgb(0, 11, 96),
                Color.FromArgb(0, 134, 227),
                Color.FromArgb(0, 100, 50),
                Color.FromArgb(0, 176, 21),
                Color.FromArgb(192, 0, 0),
                Color.FromArgb(230, 118, 0),
                Color.FromArgb(255, 192, 0),
                Color.FromArgb(150, 200, 0),
                Color.FromArgb(200, 0, 120),
                Color.FromArgb(78, 0, 96),
                Color.FromArgb(91, 0, 192),
                Color.FromArgb(0, 97, 129),
            };

            VertexShape [] aeShapes = new VertexShape [] {
                VertexShape.Disk,
                VertexShape.Circle,
                VertexShape.SolidSquare,
                VertexShape.Square,
                VertexShape.SolidTriangle,
                VertexShape.Triangle,
                VertexShape.SolidDiamond,
                VertexShape.Diamond,
            };

            Single [] afRadii = new Single [] {
                3.0F,
                3.0F,
                2.7F,
                2.7F,
                3.2F,
                3.2F,
                3.3F,
                3.3F,
            };

            Int32 iColors = aoColors.Length;
            Int32 iShapes = aeShapes.Length;

            Debug.Assert(afRadii.Length == iShapes);

            Int32 iColorIndex          = schemeIndex % iColors;
            Int32 iShapeAndRadiusIndex = (schemeIndex / iColors) % iShapes;

            color  = aoColors[iColorIndex];
            shape  = aeShapes[iShapeAndRadiusIndex];
            radius = afRadii[iShapeAndRadiusIndex];
        }
        //*************************************************************************
        //  Method: TryGetVertexShape()
        //
        /// <summary>
        /// Attempts to get a vertex shape from a worksheet cell.
        /// </summary>
        ///
        /// <param name="oRow">
        /// Row containing the vertex data.
        /// </param>
        ///
        /// <param name="sColumnName">
        /// Name of the column containing the vertex shape.
        /// </param>
        ///
        /// <param name="eShape">
        /// Where the vertex shape gets stored if true is returned.
        /// </param>
        ///
        /// <returns>
        /// true if the specified cell contains a valid vertex shape.
        /// </returns>
        ///
        /// <remarks>
        /// If the specified shape cell is empty, false is returned.  If the cell
        /// contains a valid vertex shape, the shape gets stored at <paramref
        /// name="eShape" /> and true is returned.  If the cell contains an invalid
        /// shape, a <see cref="WorkbookFormatException" /> is thrown.
        /// </remarks>
        //*************************************************************************
        protected Boolean TryGetVertexShape(
            ExcelTableReader.ExcelTableRow oRow,
            String sColumnName,
            out VertexShape eShape
            )
        {
            Debug.Assert(oRow != null);
            Debug.Assert( !String.IsNullOrEmpty(sColumnName) );
            AssertValid();

            eShape = VertexShape.Circle;
            String sShape;

            if ( !oRow.TryGetNonEmptyStringFromCell(sColumnName, out sShape) )
            {
            return (false);
            }

            VertexShapeConverter oVertexShapeConverter =
            new VertexShapeConverter();

            if ( !oVertexShapeConverter.TryWorkbookToGraph(sShape, out eShape) )
            {
            OnWorkbookFormatErrorWithDropDown(oRow, sColumnName, "shape");
            }

            return (true);
        }
        //*************************************************************************
        //  Constructor: ReadWorkbookContext()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="ReadWorkbookContext" />
        /// class.
        /// </summary>
        //*************************************************************************
        public ReadWorkbookContext()
        {
            m_bIgnoreVertexLocations = true;
            m_bFillIDColumns = false;
            m_bPopulateVertexWorksheet = false;
            m_bReadEdgeWeights = false;
            m_bReadGroups = false;
            m_bSaveGroupVertices = false;
            m_bReadVertexLabels = false;
            m_bReadEdgeLabels = false;
            m_bReadVertexImages = false;
            m_oDefaultVertexImageSize = new Nullable<Single>();
            m_eDefaultVertexShape = VertexShape.Disk;
            m_bReadAllEdgeAndVertexColumns = false;
            m_oGraphRectangle = Rectangle.FromLTRB(0, 0, 100, 100);
            m_oColorConverter2 = new ColorConverter2();
            m_oBooleanConverter = new BooleanConverter();
            m_oEdgeWidthConverter = new EdgeWidthConverter();
            m_oEdgeStyleConverter = new EdgeStyleConverter();
            m_oVertexRadiusConverter = new VertexRadiusConverter();

            m_oVertexLocationConverter =
            new VertexLocationConverter(m_oGraphRectangle);

            m_oVertexNameDictionary = new Dictionary<String, IVertex>();
            m_oEdgeRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();
            m_oVertexRowIDDictionary = new Dictionary<Int32, IIdentityProvider>();

            AssertValid();
        }
        //*************************************************************************
        //  Method: GetVertexCategoryScheme()
        //
        /// <summary>
        /// Gets the attributes to use for a vertex category scheme.
        /// </summary>
        ///
        /// <param name="schemeIndex">
        /// Scheme index.
        /// </param>
        ///
        /// <param name="shape">
        /// Where the vertex shape gets stored.
        /// </param>
        ///
        /// <param name="color">
        /// Where the vertex color gets stored.
        /// </param>
        ///
        /// <param name="radius">
        /// Where the vertex radius gets stored.
        /// </param>
        //*************************************************************************
        public static void GetVertexCategoryScheme(
            Int32 schemeIndex,
            out VertexShape shape,
            out Color color,
            out Single radius
            )
        {
            Debug.Assert(schemeIndex >= 0);

            // 96 categories are supported -- 12 colors and 8 shapes.  Each shape
            // has its own assigned radius.

            Color [] aoColors = new Color [] {
            Color.FromArgb(0, 11, 96),
            Color.FromArgb(0, 134, 227),
            Color.FromArgb(0, 100, 50),
            Color.FromArgb(0, 176, 21),
            Color.FromArgb(192, 0, 0),
            Color.FromArgb(230, 118, 0),
            Color.FromArgb(255, 192, 0),
            Color.FromArgb(150, 200, 0),
            Color.FromArgb(200, 0, 120),
            Color.FromArgb(78, 0, 96),
            Color.FromArgb(91, 0, 192),
            Color.FromArgb(0, 97, 129),
            };

            VertexShape [] aeShapes = new VertexShape [] {
            VertexShape.Disk,
            VertexShape.Circle,
            VertexShape.SolidSquare,
            VertexShape.Square,
            VertexShape.SolidTriangle,
            VertexShape.Triangle,
            VertexShape.SolidDiamond,
            VertexShape.Diamond,
            };

            Single [] afRadii = new Single [] {
            3.0F,
            3.0F,
            2.7F,
            2.7F,
            3.2F,
            3.2F,
            3.3F,
            3.3F,
            };

            Int32 iColors = aoColors.Length;
            Int32 iShapes = aeShapes.Length;
            Debug.Assert(afRadii.Length == iShapes);

            Int32 iColorIndex = schemeIndex % iColors;
            Int32 iShapeAndRadiusIndex = (schemeIndex / iColors) % iShapes;

            color = aoColors[iColorIndex];
            shape = aeShapes[iShapeAndRadiusIndex];
            radius = afRadii[iShapeAndRadiusIndex];
        }
    PostDrawVertex
    (
        VertexShape vertexShape,
        Color vertexColor,
        GraphDrawingContext graphDrawingContext,
        DrawingContext drawingContext,
        Boolean drawAsSelected,
        Double graphScale,
        VertexLabelDrawer vertexLabelDrawer,
        FormattedTextManager formattedTextManager,
        VertexDrawingHistory vertexDrawingHistory
    )
    {
        Debug.Assert(graphDrawingContext != null);
        Debug.Assert(drawingContext != null);
        Debug.Assert(graphScale >= GraphDrawer.MinimumGraphScale);
        Debug.Assert(graphScale <= GraphDrawer.MaximumGraphScale);
        Debug.Assert(vertexLabelDrawer != null);
        Debug.Assert(formattedTextManager != null);
        Debug.Assert(vertexDrawingHistory != null);
        AssertValid();

        if (m_oCollapsedGroupVertex == null)
        {
            // The vertex that was drawn is not a collapsed group vertex.  Do
            // nothing.

            return;
        }

        if (m_oCollapsedGroupAttributes.Count == 0)
        {
            // The vertex that was drawn represents a collapsed group, but no
            // attributes were specified for it.  By default, such a vertex
            // gets a plus sign drawn on top of it.

            DrawPlusSign(vertexShape, vertexColor, graphDrawingContext,
                drawingContext, graphScale, vertexLabelDrawer,
                formattedTextManager, vertexDrawingHistory);
        }
        else
        {
            // Check whether this this is a collapsed motif.

            switch ( m_oCollapsedGroupAttributes.GetGroupType() )
            {
                case CollapsedGroupAttributeValues.FanMotifType:

                    DrawFanMotifFan(vertexColor, drawingContext,
                        drawAsSelected, graphScale, vertexDrawingHistory);

                    break;

                default:

                    // Do nothing.  This includes the D-connector motif case,
                    // which requires no post-drawing action.

                    break;
            }
        }
    }
Exemple #16
0
 private MapNodeRenderStyle(VertexShape shape, double x, double y)
 {
     Shape = shape;
     X     = x;
     Y     = y;
 }
    ReadShape
    (
        ExcelTableReader.ExcelTableRow oRow,
        IVertex oVertex,
        out VertexShape eShape
    )
    {
        Debug.Assert(oRow != null);
        Debug.Assert(oVertex != null);
        AssertValid();

        if ( TryGetVertexShape(oRow, VertexTableColumnNames.Shape,
            out eShape) )
        {
            oVertex.SetValue(ReservedMetadataKeys.PerVertexShape, eShape);
            return (true);
        }

        return (false);
    }
    GetVertexAttributes
    (
        Int32 groupIndex,
        Int32 totalGroups,
        out Color color,
        out VertexShape shape
    )
    {
        Debug.Assert(groupIndex >= 0);
        Debug.Assert(totalGroups > 0);
        Debug.Assert(groupIndex < totalGroups);

        // Algorithm:
        //
        // Cycle through a set of hues with one shape, then the same set of
        // hues with the next shape, and so on.  When all shapes have been
        // used, repeat the process with another saturation.

        Int32 iHues = ColorUtil.UniqueColorHues;
        Int32 iShapes = Shapes.Length;

        Int32 iSaturations = (Int32)Math.Ceiling(
            (Single)totalGroups / (Single)(iHues * iShapes)
            );

        Int32 iMaximumUniqueColors = iSaturations * iHues;

        Int32 iColorIndex = (groupIndex % iHues) +
            ( iHues * ( groupIndex / (iHues * iShapes) ) );

        color = ColorUtil.GetUniqueColor(iColorIndex, iMaximumUniqueColors);

        Int32 iShapeIndex = (groupIndex / ColorUtil.UniqueColorHues) % iShapes;

        shape = Shapes[iShapeIndex];
    }
        DrawVertexCategoryShape
        (
            DrawingObjects oDrawingObjects,
            VertexShape eVertexShape,
            Pen oPen,
            SolidBrush oBrush,
            Color oColor,
            Single fXShapeCenter,
            Single fYShapeCenter,
            Single fShapeHalfWidth
        )
        {
            Debug.Assert(oDrawingObjects != null);
            Debug.Assert(oPen != null);
            Debug.Assert(oBrush != null);
            Debug.Assert(fShapeHalfWidth >= 0);
            AssertValid();

            Graphics oGraphics = oDrawingObjects.Graphics;

            oPen.Color   = oColor;
            oBrush.Color = oColor;

            switch (eVertexShape)
            {
            case VertexShape.Circle:

                GraphicsUtil.DrawCircle(oGraphics, oPen, fXShapeCenter,
                                        fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Disk:

                GraphicsUtil.FillCircle(oGraphics, oBrush, fXShapeCenter,
                                        fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Sphere:

                GraphicsUtil.FillCircle3D(oGraphics, oColor,
                                          fXShapeCenter, fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Square:

                GraphicsUtil.DrawSquare(oGraphics, oPen, fXShapeCenter,
                                        fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidSquare:

                GraphicsUtil.FillSquare(oGraphics, oBrush, fXShapeCenter,
                                        fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Diamond:

                GraphicsUtil.DrawDiamond(oGraphics, oPen, fXShapeCenter,
                                         fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidDiamond:

                GraphicsUtil.FillDiamond(oGraphics, oBrush, fXShapeCenter,
                                         fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Triangle:

                GraphicsUtil.DrawTriangle(oGraphics, oPen, fXShapeCenter,
                                          fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidTriangle:

                GraphicsUtil.FillTriangle(oGraphics, oBrush, fXShapeCenter,
                                          fYShapeCenter, fShapeHalfWidth);

                break;

            default:

                Debug.Assert(false);
                break;
            }
        }
Exemple #20
0
        //*************************************************************************
        //  Method: GetVertexAttributes()
        //
        /// <summary>
        /// Gets the vertex attributes for a specified group.
        /// </summary>
        ///
        /// <param name="groupIndex">
        /// Zero-based group index.
        /// </param>
        ///
        /// <param name="totalGroups">
        /// Total number of groups.
        /// </param>
        ///
        /// <param name="color">
        /// Where the color gets stored.
        /// </param>
        ///
        /// <param name="shape">
        /// Where the shape gets stored.
        /// </param>
        //*************************************************************************
        public static void GetVertexAttributes(
            Int32 groupIndex,
            Int32 totalGroups,
            out Color color,
            out VertexShape shape
            )
        {
            Debug.Assert(groupIndex >= 0);
            Debug.Assert(totalGroups > 0);
            Debug.Assert(groupIndex < totalGroups);

            // Algorithm:
            //
            // Cycle through the set of hues with one shape, then cycle through the
            // set of hues with the next shape, and so on.  When all shapes have
            // been used, repeat the process with another saturation.

            Int32 iHues = Hues.Length;
            Int32 iShapes = Shapes.Length;

            Int32 iSaturations = (Int32)Math.Ceiling(
            (Single)totalGroups / (Single)(iHues * iShapes) );

            Int32 iHueIndex = groupIndex % iHues;
            Int32 iDividend = groupIndex / iHues;
            Int32 iShapeIndex = iDividend % iShapes;
            Int32 iSaturationIndex = iDividend / iShapes;

            Single fHue = Hues[iHueIndex];

            Single fSaturation;

            if (iSaturations == 1)
            {
            fSaturation = StartSaturation;
            }
            else
            {
            fSaturation = StartSaturation
                + ( (Single)iSaturationIndex /  (Single)(iSaturations - 1) )
                * (EndSaturation - StartSaturation);
            }

            color = ColorUtil.HsbToRgb(fHue, fSaturation, Brightness);

            if ( color == Color.FromArgb(255, 172, 0) )
            {
            // Due to rounding errors, the above code produces (255,172,0) for
            // orange, which should actually be (255,165,0).
            // ColorConverter2.GraphToWorkbook() converts (255,165,0) to the
            // string "Orange", so use the correct RGB values.

            color = Color.FromArgb(255, 165, 0);
            }

            shape = Shapes[iShapeIndex];
        }
    DrawPlusSign
    (
        VertexShape eVertexShape,
        Color oVertexColor,
        GraphDrawingContext oGraphDrawingContext,
        DrawingContext oDrawingContext,
        Double dGraphScale,
        VertexLabelDrawer oVertexLabelDrawer,
        FormattedTextManager oFormattedTextManager,
        VertexDrawingHistory oVertexDrawingHistory
    )
    {
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oDrawingContext != null);
        Debug.Assert(dGraphScale >= GraphDrawer.MinimumGraphScale);
        Debug.Assert(dGraphScale <= GraphDrawer.MaximumGraphScale);
        Debug.Assert(oVertexLabelDrawer != null);
        Debug.Assert(oFormattedTextManager != null);
        Debug.Assert(oVertexDrawingHistory != null);
        AssertValid();

        Color oFillColor;

        switch (eVertexShape)
        {
            case VertexShape.Circle:
            case VertexShape.Square:
            case VertexShape.Diamond:
            case VertexShape.Triangle:

                // The fill color is the color of the background.  Adjust the
                // fill color for the opacity of the vertex.

                oFillColor = WpfGraphicsUtil.SetWpfColorAlpha(
                    oGraphDrawingContext.BackColor, oVertexColor.A);

                break;

            default:

                oFillColor = oVertexColor;
                break;
        }

        Color oContrastingColor =
            WpfGraphicsUtil.GetContrastingColor(oFillColor);

        // The font size used below was chosen so that it is large enough to be
        // easily readable, but small enough to fit within the smallest
        // collapsed group vertex created by this class.

        oVertexLabelDrawer.DrawLabel(oDrawingContext, oGraphDrawingContext,
            oVertexDrawingHistory, VertexLabelPosition.MiddleCenter,

            oFormattedTextManager.CreateFormattedText("+", oContrastingColor,
                15.0, dGraphScale),

            oContrastingColor, false);
    }
    DrawVertexCategoryShape
    (
        DrawingObjects oDrawingObjects,
        VertexShape eVertexShape,
        Pen oPen,
        SolidBrush oBrush,
        Color oColor,
        Single fXShapeCenter,
        Single fYShapeCenter,
        Single fShapeHalfWidth
    )
    {
        Debug.Assert(oDrawingObjects != null);
        Debug.Assert(oPen != null);
        Debug.Assert(oBrush != null);
        Debug.Assert(fShapeHalfWidth >= 0);
        AssertValid();

        Graphics oGraphics = oDrawingObjects.Graphics;
        oPen.Color = oColor;
        oBrush.Color = oColor;

        switch (eVertexShape)
        {
            case VertexShape.Circle:

                GraphicsUtil.DrawCircle(oGraphics, oPen, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Disk:

                GraphicsUtil.FillCircle(oGraphics, oBrush, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Sphere:

                GraphicsUtil.FillCircle3D(oGraphics, oColor,
                    fXShapeCenter, fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Square:

                GraphicsUtil.DrawSquare(oGraphics, oPen, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidSquare:

                GraphicsUtil.FillSquare(oGraphics, oBrush, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Diamond:

                GraphicsUtil.DrawDiamond(oGraphics, oPen, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidDiamond:

                GraphicsUtil.FillDiamond(oGraphics, oBrush, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.Triangle:

                GraphicsUtil.DrawTriangle(oGraphics, oPen, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            case VertexShape.SolidTriangle:

                GraphicsUtil.FillTriangle(oGraphics, oBrush, fXShapeCenter,
                    fYShapeCenter, fShapeHalfWidth);

                break;

            default:

                Debug.Assert(false);
                break;
        }
    }
 public static Point GetEdgeEndpoint(Point source, Rect sourceSize, Point target, VertexShape shape)
 {
     switch (shape)
     {
         case VertexShape.Circle:
             return GetEdgeEndpointOnCircle(source, Math.Max(sourceSize.Height, sourceSize.Width) * .5, target);
         case VertexShape.Diamond:
             return GetEdgeEndpointOnDiamond(source, sourceSize.Width * .5, target);
         case VertexShape.Triangle:
             return GetEdgeEndpointOnTriangle(source, sourceSize.Width * .5, target);
         default:
             return GetEdgeEndpointOnRectangle(source, sourceSize, target);
     }
 }
    DrawColorColumnResults
    (
        DrawingObjects oDrawingObjects,
        String sCaption,
        AutoFillColorColumnResults oColorResults,
        VertexShape eCategoryShape,
        Rectangle oColumnRectangle,
        Int32 iResultsLeft,
        Int32 iResultsRight,
        ref Int32 iTop
    )
    {
        Debug.Assert(oDrawingObjects != null);
        Debug.Assert( !String.IsNullOrEmpty(sCaption) );
        Debug.Assert(oColorResults != null);

        if (oColorResults.SourceColumnContainsNumbers)
        {
            DrawColorBarResults(oDrawingObjects,
                oColorResults.SourceColumnName, ColorCaption,
                oColorResults.SourceCalculationNumber1,
                oColorResults.SourceCalculationNumber2,
                oColorResults.DecimalPlaces,
                oColorResults.DestinationColor1,
                oColorResults.DestinationColor2,
                oColumnRectangle, iResultsLeft, iResultsRight,
                ref iTop);
        }
        else
        {
            DrawColorCategoryResults(oDrawingObjects,
                oColorResults.CategoryNames,

                (Int32 categoryIndex, out VertexShape categoryShape,
                    out Color categoryColor) =>
                {
                    categoryShape = eCategoryShape;

                    categoryColor = ColorUtil.GetUniqueColor(categoryIndex,
                        oColorResults.CategoryNames.Count);
                },

                oColumnRectangle, ref iTop
                );
        }
    }
Exemple #25
0
        //*************************************************************************
        //  Method: DrawPlusSign()
        //
        /// <summary>
        /// Draws a plus sign on top of the vertex.
        /// </summary>
        ///
        /// <param name="eShape">
        /// The simple vertex shape.
        /// </param>
        ///
        /// <param name="oGraphDrawingContext">
        /// Provides access to objects needed for graph-drawing operations.
        /// </param>
        ///
        /// <param name="oVertexLocation">
        /// The location of the vertex.
        /// </param>
        ///
        /// <param name="oDrawingContext">
        /// The DrawingContext to use.
        /// </param>
        ///
        /// <param name="oVertexColor">
        /// The color of the vertex.
        /// </param>
        ///
        /// <param name="oVertexLabelDrawer">
        /// Object that draws a vertex label as an annotation.
        /// </param>
        ///
        /// <param name="oVertexDrawingHistory">
        /// A <see cref="VertexDrawingHistory" /> object that retains information
        /// about how the vertex was drawn.
        /// </param>
        ///
        /// <param name="oVertexBounds">
        /// The rectangle defining the bounds of the vertex.
        /// </param>
        //*************************************************************************
        protected void DrawPlusSign(
            VertexShape eShape,
            Point oVertexLocation,
            Rect oVertexBounds,
            Color oVertexColor,
            GraphDrawingContext oGraphDrawingContext,
            DrawingContext oDrawingContext,
            VertexLabelDrawer oVertexLabelDrawer,
            VertexDrawingHistory oVertexDrawingHistory
            )
        {
            Debug.Assert(oGraphDrawingContext != null);
            Debug.Assert(oDrawingContext != null);
            Debug.Assert(oVertexLabelDrawer != null);
            Debug.Assert(oVertexDrawingHistory != null);
            AssertValid();

            Color oFillColor;

            switch (eShape)
            {
            case VertexShape.Circle:
            case VertexShape.Square:
            case VertexShape.Diamond:
            case VertexShape.Triangle:

                // The fill color is the color of the background.  Adjust the
                // fill color for the opacity of the vertex.

                oFillColor = WpfGraphicsUtil.SetWpfColorAlpha(
                    oGraphDrawingContext.BackColor, oVertexColor.A);

                break;

            default:

                oFillColor = oVertexColor;
                break;
            }

            Color oContrastingColor =
            WpfGraphicsUtil.GetContrastingColor(oFillColor);

            // The font size used below was chosen so that it is large enough to be
            // easily readable, but small enough to fit within the smallest
            // collapsed group vertex created by the NodeXLControl.

            oVertexLabelDrawer.DrawLabel( oDrawingContext, oGraphDrawingContext,
            oVertexDrawingHistory, oVertexBounds,
            VertexLabelPosition.MiddleCenter,
            CreateFormattedText("+", oContrastingColor, 15.0) );
        }
Exemple #26
0
        //*************************************************************************
        //  Method: DrawSimpleShape()
        //
        /// <summary>
        /// Draws a vertex as a simple shape.
        /// </summary>
        ///
        /// <param name="oVertex">
        /// The vertex to draw.
        /// </param>
        ///
        /// <param name="eShape">
        /// The vertex shape to use.  Can't be <see cref="VertexShape.Image" /> or
        /// <see cref="VertexShape.Label" />.
        /// </param>
        ///
        /// <param name="oGraphDrawingContext">
        /// Provides access to objects needed for graph-drawing operations.
        /// </param>
        ///
        /// <param name="oDrawingContext">
        /// The DrawingContext to use.
        /// </param>
        ///
        /// <param name="oDrawingVisual">
        /// The <see cref="DrawingVisual" /> object from which <paramref
        /// name="oDrawingContext" /> was obtained.
        /// </param>
        ///
        /// <param name="eVisibility">
        /// The visibility of the vertex.
        /// </param>
        ///
        /// <param name="bDrawAsSelected">
        /// true to draw the vertex as selected.
        /// </param>
        ///
        /// <param name="sAnnotation">
        /// The annotation to draw next to the shape, or null if there is no
        /// annotation.
        /// </param>
        ///
        /// <param name="oVertexLabelDrawer">
        /// Object that draws a vertex label as an annotation.
        /// </param>
        ///
        /// <returns>
        /// A VertexDrawingHistory object that retains information about how the
        /// vertex was drawn.
        /// </returns>
        ///
        /// <remarks>
        /// "Simple" means "not <see cref="VertexShape.Image" /> and not <see
        /// cref="VertexShape.Label" />."
        /// </remarks>
        //*************************************************************************
        protected VertexDrawingHistory DrawSimpleShape(
            IVertex oVertex,
            VertexShape eShape,
            GraphDrawingContext oGraphDrawingContext,
            DrawingContext oDrawingContext,
            DrawingVisual oDrawingVisual,
            VisibilityKeyValue eVisibility,
            Boolean bDrawAsSelected,
            String sAnnotation,
            VertexLabelDrawer oVertexLabelDrawer
            )
        {
            Debug.Assert(oVertex != null);
            Debug.Assert(oGraphDrawingContext != null);
            Debug.Assert(oDrawingContext != null);
            Debug.Assert(oDrawingVisual != null);
            Debug.Assert(oVertexLabelDrawer != null);
            AssertValid();

            Double dRadius = GetRadius(oVertex);
            Color oColor = GetColor(oVertex, eVisibility, bDrawAsSelected);
            Point oVertexLocation = GetVertexLocation(oVertex);

            Rect oVertexBounds;

            if (eShape == VertexShape.Triangle ||
            eShape == VertexShape.SolidTriangle)
            {
            oVertexBounds =
                WpfGraphicsUtil.TriangleBoundsFromCenterAndHalfWidth(
                    oVertexLocation, dRadius);
            }
            else
            {
            oVertexBounds = WpfGraphicsUtil.SquareFromCenterAndHalfWidth(
                oVertexLocation, dRadius);
            }

            // Move the vertex if it falls outside the graph rectangle.

            MoveVertexIfNecessary(oVertex, ref oVertexBounds,
            oGraphDrawingContext);

            Point oLocation = GetVertexLocation(oVertex);
            VertexDrawingHistory oVertexDrawingHistory = null;

            // Note that for the "hollow" shapes -- Circle, Square, Diamond, and
            // Triangle -- Brushes.Transparent is used instead of a null brush.
            // This allows the entire area of these shapes to be hit-tested.  Using
            // a null brush would cause hit-testing to fail if the shapes'
            // interiors were clicked.

            switch (eShape)
            {
            case VertexShape.Circle:
            case VertexShape.Disk:

                Boolean bIsDisk = (eShape == VertexShape.Disk);

                oDrawingContext.DrawEllipse(
                    bIsDisk ? GetBrush(oColor) : Brushes.Transparent,
                    bIsDisk ? null : GetPen(oColor, DefaultPenThickness),
                    oLocation, dRadius, dRadius
                    );

                oVertexDrawingHistory = bIsDisk ?

                    new DiskVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new CircleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Sphere:

                RadialGradientBrush oRadialGradientBrush =
                    new RadialGradientBrush();

                oRadialGradientBrush.GradientOrigin =
                    oRadialGradientBrush.Center = new Point(0.3, 0.3);

                GradientStopCollection oGradientStops =
                    oRadialGradientBrush.GradientStops;

                oGradientStops.Add( new GradientStop(Colors.White, 0.0) );
                oGradientStops.Add( new GradientStop(oColor, 1.0) );

                WpfGraphicsUtil.FreezeIfFreezable(oRadialGradientBrush);

                oDrawingContext.DrawEllipse(oRadialGradientBrush, null,
                    oLocation, dRadius, dRadius);

                oVertexDrawingHistory = new SphereVertexDrawingHistory(
                    oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Square:
            case VertexShape.SolidSquare:

                Boolean bIsSolidSquare = (eShape == VertexShape.SolidSquare);

                oDrawingContext.DrawRectangle(
                    bIsSolidSquare ? GetBrush(oColor) : Brushes.Transparent,
                    bIsSolidSquare? null : GetPen(oColor, DefaultPenThickness),
                    oVertexBounds
                    );

                oVertexDrawingHistory = bIsSolidSquare ?

                    new SolidSquareVertexDrawingHistory(oVertex,
                        oDrawingVisual, bDrawAsSelected, oVertexBounds)
                    :
                    new SquareVertexDrawingHistory(oVertex,
                        oDrawingVisual, bDrawAsSelected, oVertexBounds);

                break;

            case VertexShape.Diamond:
            case VertexShape.SolidDiamond:

                Boolean bIsSolidDiamond = (eShape == VertexShape.SolidDiamond);

                PathGeometry oDiamond =
                    WpfGraphicsUtil.DiamondFromCenterAndHalfWidth(
                        oLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidDiamond ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidDiamond ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oDiamond
                    );

                oVertexDrawingHistory = bIsSolidDiamond ?

                    new SolidDiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new DiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Triangle:
            case VertexShape.SolidTriangle:

                Boolean bIsSolidTriangle =
                    (eShape == VertexShape.SolidTriangle);

                PathGeometry oTriangle =
                    WpfGraphicsUtil.TriangleFromCenterAndHalfWidth(
                        oLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidTriangle ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidTriangle ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oTriangle
                    );

                oVertexDrawingHistory = bIsSolidTriangle ?

                    new SolidTriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new TriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            default:

                Debug.Assert(false);
                break;
            }

            if (sAnnotation != null)
            {
            oVertexLabelDrawer.DrawLabel( oDrawingContext,
                oGraphDrawingContext, oVertexDrawingHistory, oVertexBounds,
                CreateFormattedText(sAnnotation, oColor) );
            }

            if ( oVertex.ContainsKey(ReservedMetadataKeys.PerVertexDrawPlusSign) )
            {
            DrawPlusSign(eShape, oVertexLocation, oVertexBounds, oColor,
                oGraphDrawingContext, oDrawingContext, oVertexLabelDrawer,
                oVertexDrawingHistory);
            }

            Debug.Assert(oVertexDrawingHistory != null);

            return (oVertexDrawingHistory);
        }
Exemple #27
0
        PopulateGraph()
        {
            IGraph            oGraph    = m_oNodeXLControl.Graph;
            IVertexCollection oVertices = oGraph.Vertices;
            IEdgeCollection   oEdges    = oGraph.Edges;
            Double            dWidth    = this.Width;
            Double            dHeight   = this.Height;
            Random            oRandom   = new Random();

            // m_oNodeXLControl.Layout.Margin = 0;

            {
        #if false  // Two shapes only.
                IVertex oVertex1 = oVertices.Add();

                oVertex1.SetValue(ReservedMetadataKeys.PerVertexShape,
                                  VertexShape.Circle);

                oVertex1.SetValue(ReservedMetadataKeys.PerVertexRadius, 5.0F);
                oVertex1.SetValue(ReservedMetadataKeys.LockVertexLocation, true);
                oVertex1.Location = new System.Drawing.PointF(300, 300);

                oVertex1.SetValue(ReservedMetadataKeys.PerVertexLabel,
                                  "This is A: " + oVertex1.Location);

                IVertex oVertex2 = oVertices.Add();

                oVertex2.SetValue(ReservedMetadataKeys.PerVertexShape,
                                  VertexShape.Circle);

                oVertex2.SetValue(ReservedMetadataKeys.PerVertexRadius, 5.0F);
                oVertex2.SetValue(ReservedMetadataKeys.LockVertexLocation, true);
                oVertex2.Location = new System.Drawing.PointF(500, 300);

                oVertex2.SetValue(ReservedMetadataKeys.PerVertexLabel,
                                  "This is B: " + oVertex2.Location);

                IEdge oEdge = oEdges.Add(oVertex1, oVertex2, true);

                // oEdge.SetValue(ReservedMetadataKeys.PerEdgeWidth, 20F);

                m_oNodeXLControl.DrawGraph(true);

                return;
        #endif
            }

            {
        #if false  // Two labels only.
                IVertex oVertex1 = oVertices.Add();

                oVertex1.SetValue(ReservedMetadataKeys.PerVertexShape,
                                  VertexShape.Label);

                oVertex1.SetValue(ReservedMetadataKeys.PerVertexLabel,
                                  "This is a label.");

                oVertex1.SetValue(ReservedMetadataKeys.LockVertexLocation, true);
                oVertex1.Location = new System.Drawing.PointF(300, 300);

                IVertex oVertex2 = oVertices.Add();

                oVertex2.SetValue(ReservedMetadataKeys.PerVertexShape,
                                  VertexShape.Label);

                oVertex2.SetValue(ReservedMetadataKeys.PerVertexLabel,
                                  "This is another label.");

                oVertex2.SetValue(ReservedMetadataKeys.LockVertexLocation, true);
                oVertex2.Location = new System.Drawing.PointF(500, 100);

                oEdges.Add(oVertex1, oVertex2, true);

                m_oNodeXLControl.DrawGraph(true);

                return;
        #endif
            }

            Smrf.NodeXL.Visualization.Wpf.VertexShape[] aeShapes
                = (Smrf.NodeXL.Visualization.Wpf.VertexShape[])
                  Enum.GetValues(typeof(Smrf.NodeXL.Visualization.Wpf.
                                        VertexShape));

            Int32 iShapes = aeShapes.Length;

            Int32 Vertices = 100;

            IVertex oFirstVertex = oVertices.Add();

            oFirstVertex.SetValue(ReservedMetadataKeys.PerVertexRadius, 4.0F);

            IVertex oPreviousVertex = oFirstVertex;

            for (Int32 i = 1; i < Vertices; i++)
            {
                IVertex     oVertex = oVertices.Add();
                VertexShape eShape  = aeShapes[oRandom.Next(iShapes)];
                oVertex.SetValue(ReservedMetadataKeys.PerVertexShape, eShape);

            #if false  // Hard-coded vertex shape.
                oVertex.SetValue(ReservedMetadataKeys.PerVertexShape,
                                 VertexDrawer.VertexShape.Diamond);
            #endif

            #if true  // Vertex color.
                oVertex.SetValue(ReservedMetadataKeys.PerColor,
                                 System.Windows.Media.Color.FromArgb(255,
                                                                     (Byte)oRandom.Next(256),
                                                                     (Byte)oRandom.Next(256),
                                                                     (Byte)oRandom.Next(256))
                                 );
            #endif

            #if true  // Vertex radius.
                Single fRadius = (Single)(
                    Smrf.NodeXL.Visualization.Wpf.VertexDrawer.MinimumRadius +
                    (0.1 *
                     Smrf.NodeXL.Visualization.Wpf.VertexDrawer.MaximumRadius
                     - Smrf.NodeXL.Visualization.Wpf.VertexDrawer.MinimumRadius)
                    * oRandom.NextDouble());

                oVertex.SetValue(ReservedMetadataKeys.PerVertexRadius, fRadius);
            #endif

                if (true && oRandom.Next(20) == 0) // Image
                {
                    oVertex.SetValue(ReservedMetadataKeys.PerVertexShape,
                                     VertexShape.Image);

                    oVertex.SetValue(ReservedMetadataKeys.PerVertexImage,
                                     new System.Windows.Media.Imaging.BitmapImage(
                                         new Uri(oRandom.Next(2) == 1 ?
                                                 "..\\..\\Images\\TestImage1.gif" :
                                                 "..\\..\\Images\\TestImage2.jpg",
                                                 UriKind.Relative)));
                }

                if (eShape == VertexShape.Label)
                {
                    String sLabel = "This is a label";

                    if (oRandom.Next(2) == 0)
                    {
                        sLabel = LongLabel;
                    }

                    oVertex.SetValue(ReservedMetadataKeys.PerVertexLabel, sLabel);

                    /*
                     * oVertex.SetValue( ReservedMetadataKeys.PerColor,
                     *  System.Windows.Media.Color.FromArgb(255, 0, 0, 0) );
                     *
                     * oVertex.SetValue(
                     *
                     *  ReservedMetadataKeys.PerVertexLabelFillColor,
                     *      System.Windows.Media.Color.FromArgb(255, 200, 200,
                     *          200) );
                     *
                     * oVertex.SetValue(ReservedMetadataKeys.PerAlpha, (Single)128);
                     */
                }
                else
                {
                    String sAnnotation = "This is an annotation.";

                    oVertex.SetValue(ReservedMetadataKeys.PerVertexLabel,
                                     sAnnotation);
                }

                if (true && oRandom.Next(1) == 1) // Vertex visibility.
                {
                    oVertex.SetValue(ReservedMetadataKeys.Visibility,
                                     VisibilityKeyValue.Filtered);
                }

            #if false  // Vertex alpha.
                oVertex.SetValue(
                    ReservedMetadataKeys.PerAlpha, (Single)oRandom.Next(256));
            #endif

            #if false  // Vertex IsSelected.
                oVertex.SetValue(ReservedMetadataKeys.IsSelected, null);
            #endif

                oVertex.Location = new System.Drawing.PointF(
                    (Single)(dWidth * oRandom.NextDouble()),
                    (Single)(dHeight * oRandom.NextDouble())
                    );


                IEdge oEdge = oEdges.Add(oFirstVertex, oVertex, true);

                oEdge.SetValue(ReservedMetadataKeys.PerEdgeLabel,
                               "This is an edge label");


            #if false  // Edge color.
                oEdge.SetValue(ReservedMetadataKeys.PerColor,
                               System.Windows.Media.Color.FromArgb(255,
                                                                   (Byte)oRandom.Next(256),
                                                                   (Byte)oRandom.Next(256),
                                                                   (Byte)oRandom.Next(256))
                               );
            #endif

            #if false  // Edge width.
                Double dEdgeWidth = EdgeDrawer.MinimumWidth +
                                    (EdgeDrawer.MaximumWidth - EdgeDrawer.MinimumWidth)
                                    * oRandom.NextDouble();

                oEdge.SetValue(ReservedMetadataKeys.PerEdgeWidth, dEdgeWidth);
            #endif

            #if true  // Edge visibility.
                oEdge.SetValue(ReservedMetadataKeys.Visibility,
                               VisibilityKeyValue.Visible);
            #endif

            #if true  // Edge alpha.
                oEdge.SetValue(ReservedMetadataKeys.PerAlpha,
                               (Single)oRandom.Next(256));
            #endif

            #if false  // Edge IsSelected.
                oEdge.SetValue(ReservedMetadataKeys.IsSelected, null);
            #endif


            #if true
                if (oRandom.Next(1) == 0)
                {
                    IEdge oRandomEdge = oEdges.Add(oPreviousVertex, oVertex, true);

                #if true  // Edge label.
                    oRandomEdge.SetValue(ReservedMetadataKeys.PerEdgeLabel,
                                         "This is a random edge label");
                #endif
                }
            #endif

                oPreviousVertex = oVertex;
            }

            AddToolTipsToVertices();
            SetBackgroundImage();

            m_oNodeXLControl.DrawGraph(true);
        }
Exemple #28
0
        //*************************************************************************
        //  Constructor: VertexDrawer()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="VertexDrawer" /> class.
        /// </summary>
        //*************************************************************************
        public VertexDrawer()
        {
            m_eShape = VertexShape.Disk;
            m_dRadius = 3.0;
            m_oLabelFillColor = SystemColors.WindowColor;
            m_eLabelPosition = VertexLabelPosition.TopRight;
            m_bLimitVerticesToBounds = true;

            AssertValid();
        }
Exemple #29
0
        /// <summary>
        /// Returns edge endpoint based on vertex math shape and rotation angle
        /// </summary>
        /// <param name="source">Vertex position</param>
        /// <param name="sourceSize">Vertex bounds</param>
        /// <param name="target">Opposing point of the edge</param>
        /// <param name="shape">Vertex math shape</param>
        /// <param name="angle">Vertex rotaion angle</param>
        public static Point GetEdgeEndpoint(Point source, Rect sourceSize, Point target, VertexShape shape, double angle = 0)
        {
            switch (shape)
            {
            case VertexShape.Circle:
                return(GetEdgeEndpointOnCircle(source, Math.Max(sourceSize.Height, sourceSize.Width) * .5, target, angle));

            case VertexShape.Ellipse:
                return(GetEdgeEndpointOnEllipse(source, sourceSize.Width * .5, sourceSize.Height * .5, target, angle));

            case VertexShape.Diamond:
                return(GetEdgeEndpointOnDiamond(source, sourceSize.Width * .5, target));

            case VertexShape.Triangle:
                return(GetEdgeEndpointOnTriangle(source, sourceSize.Width * .5, target));

            default:
                return(GetEdgeEndpointOnRectangle(source, sourceSize, target, angle));
            }
        }
    DrawSimpleShape
    (
        IVertex oVertex,
        VertexShape eShape,
        GraphDrawingContext oGraphDrawingContext,
        DrawingContext oDrawingContext,
        DrawingVisualPlus oDrawingVisual,
        VisibilityKeyValue eVisibility,
        Boolean bDrawAsSelected,
        String sAnnotation,
        VertexLabelDrawer oVertexLabelDrawer,
        CollapsedGroupDrawingManager oCollapsedGroupDrawingManager
    )
    {
        Debug.Assert(oVertex != null);
        Debug.Assert(oGraphDrawingContext != null);
        Debug.Assert(oDrawingContext != null);
        Debug.Assert(oDrawingVisual != null);
        Debug.Assert(oVertexLabelDrawer != null);
        Debug.Assert(oCollapsedGroupDrawingManager != null);
        AssertValid();

        Double dRadius = GetRadius(oVertex);
        Color oColor = GetColor(oVertex, eVisibility, bDrawAsSelected);
        Point oVertexLocation = GetVertexLocation(oVertex);

        oDrawingVisual.SetEffect( GetSimpleShapeEffect(
            oGraphDrawingContext, dRadius, oColor) );

        Rect oVertexBounds;

        if (eShape == VertexShape.Triangle ||
            eShape == VertexShape.SolidTriangle)
        {
            oVertexBounds =
                WpfGraphicsUtil.TriangleBoundsFromCenterAndHalfWidth(
                    oVertexLocation, dRadius);
        }
        else if (eShape == VertexShape.SolidTaperedDiamond)
        {
            // Note that the bounds of a tapered diamond can't be calculated
            // using simple equations.  Instead, create the tapered diamond and
            // let WPF compute the bounds.
            //
            // There is some inefficiency here, because the tapered diamond
            // gets created again before it is drawn, in its possibly-moved
            // location.

            oVertexBounds = WpfPathGeometryUtil.GetTaperedDiamond(
                oVertexLocation, dRadius).Bounds;
        }
        else if (eShape == VertexShape.SolidRoundedX)
        {
            // Note that the bounds of a rounded X can't be calculated
            // using simple equations.  Instead, create the rounded X and
            // let WPF compute the bounds.
            //
            // There is some inefficiency here, because the rounded X
            // gets created again before it is drawn, in its possibly-moved
            // location.

            oVertexBounds = WpfPathGeometryUtil.GetRoundedX(
                oVertexLocation, dRadius).Bounds;
        }
        else
        {
            oVertexBounds = WpfGraphicsUtil.SquareFromCenterAndHalfWidth(
                oVertexLocation, dRadius);
        }

        // Move the vertex if it falls outside the graph rectangle.

        MoveVertexIfNecessary(oVertex, oGraphDrawingContext,
            oCollapsedGroupDrawingManager, ref oVertexBounds);

        oVertexLocation = GetVertexLocation(oVertex);
        VertexDrawingHistory oVertexDrawingHistory = null;

        // Note that for the "hollow" shapes -- Circle, Square, Diamond, and
        // Triangle -- Brushes.Transparent is used instead of a null brush.
        // This allows the entire area of these shapes to be hit-tested.  Using
        // a null brush would cause hit-testing to fail if the shapes'
        // interiors were clicked.

        switch (eShape)
        {
            case VertexShape.Circle:
            case VertexShape.Disk:

                Boolean bIsDisk = (eShape == VertexShape.Disk);

                oDrawingContext.DrawEllipse(
                    bIsDisk ? GetBrush(oColor) : Brushes.Transparent,
                    bIsDisk ? null : GetPen(oColor, DefaultPenThickness),
                    oVertexLocation, dRadius, dRadius
                    );

                oVertexDrawingHistory = bIsDisk ?

                    new DiskVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new CircleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Sphere:

                RadialGradientBrush oRadialGradientBrush =
                    new RadialGradientBrush();

                oRadialGradientBrush.GradientOrigin =
                    oRadialGradientBrush.Center = new Point(0.3, 0.3);

                GradientStopCollection oGradientStops =
                    oRadialGradientBrush.GradientStops;

                oGradientStops.Add( new GradientStop(
                    WpfGraphicsUtil.SetWpfColorAlpha(Colors.White, oColor.A),
                    0.0) );

                oGradientStops.Add( new GradientStop(oColor, 1.0) );

                WpfGraphicsUtil.FreezeIfFreezable(oRadialGradientBrush);

                oDrawingContext.DrawEllipse(oRadialGradientBrush, null,
                    oVertexLocation, dRadius, dRadius);

                oVertexDrawingHistory = new SphereVertexDrawingHistory(
                    oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Square:

                WpfGraphicsUtil.DrawPixelAlignedRectangle(oDrawingContext,
                    Brushes.Transparent, GetPen(oColor, DefaultPenThickness),
                    oVertexBounds);

                oVertexDrawingHistory = new SquareVertexDrawingHistory(oVertex,
                    oDrawingVisual, bDrawAsSelected, oVertexBounds);

                break;

            case VertexShape.SolidSquare:

                oDrawingContext.DrawRectangle(GetBrush(oColor), null,
                    oVertexBounds);

                oVertexDrawingHistory = new SolidSquareVertexDrawingHistory(
                    oVertex, oDrawingVisual, bDrawAsSelected, oVertexBounds);

                break;

            case VertexShape.Diamond:
            case VertexShape.SolidDiamond:

                Boolean bIsSolidDiamond = (eShape == VertexShape.SolidDiamond);

                PathGeometry oDiamond =
                    WpfPathGeometryUtil.GetDiamond(oVertexLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidDiamond ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidDiamond ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oDiamond
                    );

                oVertexDrawingHistory = bIsSolidDiamond ?

                    new SolidDiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new DiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.Triangle:
            case VertexShape.SolidTriangle:

                Boolean bIsSolidTriangle =
                    (eShape == VertexShape.SolidTriangle);

                PathGeometry oTriangle =
                    WpfPathGeometryUtil.GetTriangle(oVertexLocation, dRadius);

                oDrawingContext.DrawGeometry(

                    bIsSolidTriangle ? GetBrush(oColor) : Brushes.Transparent,

                    bIsSolidTriangle ? null :
                        GetPen(oColor, DefaultPenThickness),

                    oTriangle
                    );

                oVertexDrawingHistory = bIsSolidTriangle ?

                    new SolidTriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius)
                    :
                    new TriangleVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.SolidTaperedDiamond:

                Geometry oTaperedDiamond =
                    WpfPathGeometryUtil.GetTaperedDiamond(
                        oVertexLocation, dRadius);

                // Note that as of August 2012, the tapered diamond shape is
                // used only for collapsed connector motifs.  Collapsed motifs
                // have an outline, so draw an outline here.

                oDrawingContext.DrawGeometry(GetBrush(oColor),

                    GetPen( CollapsedGroupDrawingManager
                        .GetCollapsedMotifOutlineColor(oColor.A),
                        DefaultPenThickness),

                    oTaperedDiamond);

                oVertexDrawingHistory =
                    new SolidTaperedDiamondVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            case VertexShape.SolidRoundedX:

                Geometry oRoundedX =
                    WpfPathGeometryUtil.GetRoundedX(
                        oVertexLocation, dRadius);

                // Note that as of August 2012, the rounded X shape is
                // used only for collapsed clique motifs.  Collapsed motifs
                // have an outline, so draw an outline here.

                oDrawingContext.DrawGeometry(GetBrush(oColor),

                    GetPen(CollapsedGroupDrawingManager
                        .GetCollapsedMotifOutlineColor(oColor.A),
                        DefaultPenThickness),

                    oRoundedX);

                oVertexDrawingHistory =
                    new SolidRoundedXVertexDrawingHistory(
                        oVertex, oDrawingVisual, bDrawAsSelected, dRadius);

                break;

            default:

                Debug.Assert(false);
                break;
        }

        if (sAnnotation != null)
        {
            oVertexLabelDrawer.DrawLabel(oDrawingContext,
                oGraphDrawingContext, oVertexDrawingHistory,

                CreateFormattedTextWithWrap(sAnnotation, oColor,
                    m_oFormattedTextManager.FontSize),

                oColor);
        }

        Debug.Assert(oVertexDrawingHistory != null);

        return (oVertexDrawingHistory);
    }