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(); }
RestoreGraphScale() { AssertValid(); GraphDrawer oGraphDrawer = m_oNodeXLControl.GraphDrawer; if (m_dOriginalGraphScale != 0) { oGraphDrawer.GraphScale = m_dOriginalGraphScale; } if (m_dOriginalGroupLabelScale != 0) { oGraphDrawer.GroupDrawer.LabelScale = m_dOriginalGroupLabelScale; } }
//************************************************************************* // 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); }