Draws a NodeXL graph onto a collection of Visual objects.
This is used to draw a NodeXL graph in a WPF application. It contains a collection of Visual objects that represent the graph's vertices and edges. Call DrawGraph to draw a laid-out NodeXL graph onto the contained GraphDrawer.VisualCollection.

GraphDrawer does not lay out the graph. You should lay out the graph using one of the provided layout classes before calling .

A GraphDrawer cannot be directly rendered and is typically not used directly by an application. Applications typically use one of two other NodeXL graph-drawing classes:

NodeXLControl, which is a FrameworkElement that wraps a and hosts its . NodeXLControl is meant for use in WPF desktop applications. It automatically lays out the graph before drawing it. NodeXLVisual, which is a Visual that wraps a and hosts its . This is a lower-level alternative to NodeXLControl and can be used anywhere a Visual is more appropriate than a FrameworkElement. Like GraphDrawer, does not lay out the graph before drawing it.

If you do use GraphDrawer directly, rendering the graph requires a custom wrapper that hosts the GraphDrawer. object.

Inheritance: DrawerBase
Example #1
0
        SetGraphScale
        (
            Int32 bitmapWidthPx,
            Int32 bitmapHeightPx,
            Double screenDpi
        )
        {
            Debug.Assert(screenDpi > 0);
            Debug.Assert(bitmapWidthPx > 0);
            Debug.Assert(bitmapHeightPx > 0);
            AssertValid();

            GraphDrawer oGraphDrawer = m_oNodeXLControl.GraphDrawer;
            GroupDrawer oGroupDrawer = oGraphDrawer.GroupDrawer;

            // Note that group labels have their own scale, distinct from the scale
            // used by the other graph elements.

            m_dOriginalGraphScale      = oGraphDrawer.GraphScale;
            m_dOriginalGroupLabelScale = oGroupDrawer.LabelScale;

            // Get the actual control size, in units of 1/96".

            Double dActualWidthWpf  = m_oNodeXLControl.ActualWidth;
            Double dActualHeightWpf = m_oNodeXLControl.ActualHeight;

            // Convert this to pixels.

            Double dActualWidthPx = WpfGraphicsUtil.WpfToPx(
                dActualWidthWpf, screenDpi);

            Double dActualHeightPx = WpfGraphicsUtil.WpfToPx(
                dActualHeightWpf, screenDpi);

            // If the image is smaller (or larger) than the control, adjust the
            // GraphScale property to shrink (or enlarge) the graph's vertices and
            // edges accordingly.  Use the smaller of the two bitmap/actual ratio.

            Double dGraphScaleFactor = Math.Min(
                bitmapWidthPx / dActualWidthPx,
                bitmapHeightPx / dActualHeightPx
                );

            Double dGraphScale =
                PinScale(m_dOriginalGraphScale * dGraphScaleFactor);

            Double dGroupLabelScale =
                PinScale(m_dOriginalGroupLabelScale * dGraphScaleFactor);

            // Don't set the NodeXLControl.GraphScale property, which would cause
            // the NodeXLControl.GraphScaleChanged event to fire.  Set the property
            // on the GraphDrawer instead.

            oGraphDrawer.GraphScale = dGraphScale;

            oGroupDrawer.LabelScale = dGroupLabelScale;

            AssertValid();
        }
Example #2
0
        RestoreGraphScale()
        {
            AssertValid();

            GraphDrawer oGraphDrawer = m_oNodeXLControl.GraphDrawer;

            if (m_dOriginalGraphScale != 0)
            {
                oGraphDrawer.GraphScale = m_dOriginalGraphScale;
            }

            if (m_dOriginalGroupLabelScale != 0)
            {
                oGraphDrawer.GroupDrawer.LabelScale = m_dOriginalGroupLabelScale;
            }
        }
Example #3
0
        //*************************************************************************
        //  Constructor: NodeXLVisual()
        //
        /// <summary>
        /// Initializes a new instance of the <see cref="NodeXLVisual" /> class.
        /// </summary>
        //*************************************************************************

        public NodeXLVisual()
        {
            m_oGraphDrawer = new GraphDrawer(this);

            AssertValid();
        }
    CreateGraphDrawer()
    {
        m_oGraphDrawer = new GraphDrawer(this);

        m_oGraphDrawer.EdgeDrawer.CurveStyleChanged +=
            new EventHandler(EdgeDrawer_CurveStyleChanged);

        // AssertValid();
    }
    //*************************************************************************
    //  Constructor: NodeXLVisual()
    //
    /// <summary>
    /// Initializes a new instance of the <see cref="NodeXLVisual" /> class.
    /// </summary>
    //*************************************************************************

    public NodeXLVisual()
    {
        m_oGraphDrawer = new GraphDrawer(this);

        AssertValid();
    }
    TransferToGraphDrawer
    (
        GraphDrawer graphDrawer
    )
    {
        Debug.Assert(graphDrawer != null);
        AssertValid();

        Font oFont = this.Font;

        System.Windows.Media.Typeface oTypeface =
            WpfGraphicsUtil.FontToTypeface(oFont);

        Double dFontSize = WpfGraphicsUtil.SystemDrawingFontSizeToWpfFontSize(
            oFont.Size);

        VertexDrawer oVertexDrawer = graphDrawer.VertexDrawer;

        oVertexDrawer.SetFont(oTypeface, dFontSize);

        oVertexDrawer.LabelFillColor =
            WpfGraphicsUtil.ColorToWpfColor(this.VertexLabelFillColor);

        oVertexDrawer.LabelPosition = this.VertexLabelPosition;
        oVertexDrawer.MaximumLabelLength = this.VertexLabelMaximumLength;
        oVertexDrawer.LabelWrapText = this.VertexLabelWrapText;

        oVertexDrawer.LabelWrapMaxTextWidth =
            this.VertexLabelWrapMaxTextWidth;

        EdgeDrawer oEdgeDrawer = graphDrawer.EdgeDrawer;

        oEdgeDrawer.SetFont(oTypeface, dFontSize);

        oEdgeDrawer.LabelTextColor =
            WpfGraphicsUtil.ColorToWpfColor(this.EdgeLabelTextColor);

        oEdgeDrawer.MaximumLabelLength = this.EdgeLabelMaximumLength;

        GroupDrawer oGroupDrawer = graphDrawer.GroupDrawer;

        oGroupDrawer.SetFont(oTypeface, GroupLabelFontSize);

        oGroupDrawer.LabelTextColor = WpfGraphicsUtil.ColorToWpfColor(

            Color.FromArgb( (new AlphaConverter() ).WorkbookToGraphAsByte(
                this.GroupLabelTextAlpha),

                this.GroupLabelTextColor)
            );

        oGroupDrawer.LabelPosition = this.GroupLabelPosition;
    }
    TransferToGraphDrawer
    (
        GraphDrawer graphDrawer
    )
    {
        Debug.Assert(graphDrawer != null);
        AssertValid();

        this.LabelUserSettings.TransferToGraphDrawer(graphDrawer);

        graphDrawer.BackColor =
            WpfGraphicsUtil.ColorToWpfColor(this.BackColor);

        if ( !String.IsNullOrEmpty(this.BackgroundImageUri) )
        {
            graphDrawer.BackgroundImage = 
                ( new WpfImageUtil() ).GetImageSynchronousIgnoreDpi(
                    this.BackgroundImageUri);
        }
        else
        {
            graphDrawer.BackgroundImage = null;
        }

        EdgeDrawer oEdgeDrawer = graphDrawer.EdgeDrawer;
        VertexDrawer oVertexDrawer = graphDrawer.VertexDrawer;

        EdgeWidthConverter oEdgeWidthConverter = new EdgeWidthConverter();
        AlphaConverter oAlphaConverter = new AlphaConverter();

        oEdgeDrawer.Width =
            oEdgeWidthConverter.WorkbookToGraph(this.EdgeWidth);

        oEdgeDrawer.Color = WpfGraphicsUtil.ColorToWpfColor(

            Color.FromArgb(oAlphaConverter.WorkbookToGraphAsByte(
                this.EdgeAlpha),

            this.EdgeColor)
            );

        oEdgeDrawer.CurveStyle = this.EdgeCurveStyle;

        oEdgeDrawer.BezierDisplacementFactor =
            this.EdgeBezierDisplacementFactor;

        oEdgeDrawer.SelectedColor = WpfGraphicsUtil.ColorToWpfColor(
            this.SelectedEdgeColor);

        oEdgeDrawer.RelativeArrowSize = this.RelativeArrowSize;

        oVertexDrawer.Shape = this.VertexShape;

        oVertexDrawer.Radius = ( new VertexRadiusConverter() ).WorkbookToGraph(
            this.VertexRadius);

        oVertexDrawer.Effect = this.VertexEffect;
        oVertexDrawer.RelativeOuterGlowSize = this.VertexRelativeOuterGlowSize;

        oVertexDrawer.Color = WpfGraphicsUtil.ColorToWpfColor(

            Color.FromArgb(oAlphaConverter.WorkbookToGraphAsByte(
                this.VertexAlpha),

            this.VertexColor)
            );

        oVertexDrawer.SelectedColor = WpfGraphicsUtil.ColorToWpfColor(
            this.SelectedVertexColor);
    }