generated images showing just one dot

Feb 24, 2011 at 10:50 PM

I'm trying to generate images form graphs with the API. The images get generated but showing  just a single black dot. I debugged teh code and the graphs have edges and vertices inside but for some reason it looks like that everything ends up in one single point.

I used code I found here in the discussions:

            const Int32 GraphWidth = 800;
            const Int32 GraphHeight = 800;
            
            ILayout oLayout = new FruchtermanReingoldLayout();

            LayoutContext oLayoutContext = new LayoutContext(
            new System.Drawing.Rectangle(0, 0, GraphWidth, GraphHeight));

            NodeXLVisual oNodeXLVisual = new NodeXLVisual();
            GraphDrawingContext oGraphDrawingContext = new GraphDrawingContext(
           new Rect(0, 0, GraphWidth, GraphHeight), oLayout.Margin,
           System.Windows.Media.Color.FromRgb(255, 255, 255));

            oNodeXLVisual.GraphDrawer.DrawGraph(subGraph, oGraphDrawingContext);
            RenderTargetBitmap oRenderTargetBitmap = new RenderTargetBitmap(
           GraphWidth, GraphHeight, 96, 96, PixelFormats.Default);

            oRenderTargetBitmap.Render(oNodeXLVisual);
            BmpBitmapEncoder oBmpBitmapEncoder = new BmpBitmapEncoder();
            oBmpBitmapEncoder.Frames.Add(BitmapFrame.Create(oRenderTargetBitmap));
            MemoryStream oMemoryStream = new MemoryStream();
            oBmpBitmapEncoder.Save(oMemoryStream);
            Bitmap oBitmap = new Bitmap(oMemoryStream);

            FileInfo fi = new FileInfo(commfile);
            string fileName = fi.FullName.Replace(fi.Extension, ".png");
            FileStream fs = File.Create(fileName);
            oBitmap.Save(fs, System.Drawing.Imaging.ImageFormat.Png);

            fs.Flush();
            fs.Close();
Thanks
Jan
Feb 24, 2011 at 11:28 PM

Jan:

You aren't laying out the graph.  Every vertex location is set to the origin by default, so in your case they are all stacked on top of each other.

I assume you found the code at http://nodexl.codeplex.com/discussions/58563.  If so, look for the line "oLayout.LayOutGraph(oGraph, oLayoutContext)", which you forgot to copy.

As an aside, if your application is console- or Web-based, then your technique of using NodeXLVisual is fine.  If it is a desktop Windows Forms or WPF application, however, you would be better off using NodeXLControl.  Unlike NodeXLVisual, the NodeXLControl lays out the graph for you, and it provides a simple CopyGraphToBitmap() method.

-- Tony

Feb 25, 2011 at 12:36 AM

Tony, you rock. The best discussion board ever.

Yep, it's and console app.