Call the TryDrawGroupRectangles, and methods to draw the group elements.
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(); }
//************************************************************************* // 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(); }