Draws a graph's vertices.
This class is responsible for drawing a graph's vertices. The default vertex appearance is determined by this class's properties. The appearance of an individual vertex can be overridden by adding appropriate metadata to the vertex. The following metadata keys are honored: ReservedMetadataKeys.Visibility ReservedMetadataKeys.IsSelected ReservedMetadataKeys.PerColor ReservedMetadataKeys.PerAlpha ReservedMetadataKeys.PerVertexShape ReservedMetadataKeys.PerVertexRadius ReservedMetadataKeys.PerVertexLabel ReservedMetadataKeys.PerVertexLabelFillColor ReservedMetadataKeys.PerVertexLabelPosition ReservedMetadataKeys.PerVertexImage

If VertexAndEdgeDrawerBase.UseSelection is true, a vertex is drawn using VertexAndEdgeDrawerBase.Color or , depending on whether the vertex has been marked as selected. If is false, is used regardless of whether the vertex has been marked as selected.

If a vertex has the shape VertexShape.Label and has the ReservedMetadataKeys.PerVertexLabel key, the vertex is drawn as a rectangle containing the text specified by the key's value. The default color of the text and the rectangle's outline is , but can be overridden with the ReservedMetadataKeys.PerColor key. The default fill color of the rectangle is LabelFillColor, but can be overridden with the ReservedMetadataKeys.PerVertexLabelFillColor key.

If a vertex has a shape other than VertexShape.Label and has the ReservedMetadataKeys.PerVertexLabel key, the vertex is drawn as the specified shape, and the text specified by the key's value is drawn next to the vertex as an annotation at the position determined by .

If a vertex has the shape VertexShape.Image and has the key, the vertex is drawn as the image specified by the key's value.

The values of the ReservedMetadataKeys.PerColor and keys can be of type System.Windows.Media.Color or System.Drawing.Color.

When drawing the graph, call TryDrawVertex for each of the graph's vertices.

Inheritance: VertexAndEdgeDrawerBase
Ejemplo n.º 1
0
    //*************************************************************************
    //  Constructor: GraphDrawer()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="GraphDrawer" /> class.
    /// </summary>
    ///
    /// <param name="parentVisual">
    /// The parent of the contained <see
    /// cref="GraphDrawer.VisualCollection" />.  This is usually a
    /// FrameworkElement that is hosting the collection.
    /// </param>
    //*************************************************************************

    public GraphDrawer
    (
        Visual parentVisual
    )
    {
        Debug.Assert(parentVisual != null);

        m_oVisualCollection = new VisualCollection(parentVisual);
        m_oAllVertexDrawingVisuals = null;
        m_oUnselectedEdgeDrawingVisuals = null;
        m_oSelectedEdgeDrawingVisuals = null;
        m_oVertexDrawer = new VertexDrawer();
        m_oEdgeDrawer = new EdgeDrawer();
        m_oGroupDrawer = new GroupDrawer();
        m_oBackColor = SystemColors.WindowColor;
        m_oBackgroundImage = null;

        AssertValid();
    }
Ejemplo n.º 2
0
    CreateVisual
    (
        Point currentMouseLocation,
        Color backColor,
        VertexDrawer vertexDrawer
    )
    {
        Debug.Assert(vertexDrawer != null);
        Debug.Assert(m_bDragIsInProgress);
        AssertValid();

        // This method redraws the dragged vertices at an offset location, and
        // adds the resulting Visuals to a ContainerVisual.
        //
        // Figure out the offset.

        Double dOffsetX = currentMouseLocation.X - m_oMouseDownLocation.X;
        Double dOffsetY = currentMouseLocation.Y - m_oMouseDownLocation.Y;

        GraphDrawingContext oGraphDrawingContext = new GraphDrawingContext(
            m_oGraphRectangle, m_iMargin, backColor);

        ContainerVisual oContainerVisual = new ContainerVisual();

        foreach (IVertex oVertex in m_aoVertices)
        {
            System.Drawing.PointF oOriginalLocation =
                GetOriginalVertexLocation(oVertex);

            oVertex.Location = new System.Drawing.PointF(
                oOriginalLocation.X + (Single)dOffsetX,
                oOriginalLocation.Y + (Single)dOffsetY
                );

            VertexDrawingHistory oVertexDrawingHistory;

            if ( vertexDrawer.TryDrawVertex(oVertex, oGraphDrawingContext,
                out oVertexDrawingHistory) )
            {
                oContainerVisual.Children.Add(
                    oVertexDrawingHistory.DrawingVisual);
            }
        }

        m_oVisual = oContainerVisual;

        return (m_oVisual);
    }