Example #1
0
        /// <summary>
        /// Initializes the GraphViz renderer
        /// </summary>
        /// <param name="graphVizInstallPath">GraphViz install path</param>
        private void Initialize(string graphVizInstallPath)
        {
            GraphVizCore.AddEnvironmentPaths(graphVizInstallPath);
            GVContext = GraphVizCore.gvContext();

            LayoutEngine = GV_DEFAULT_LAYOUT;
        }
Example #2
0
 /// <summary>
 /// Free the layout
 /// </summary>
 protected void FreeLayout()
 {
     if (GraphVizCore.gvFreeLayout(GVContext, GVGraph) != 0)
     {
         throw new Exception("Error while freeing the layout");
     }
 }
Example #3
0
 /// <summary>
 /// Sets the layout that will be used to render the graph
 /// </summary>
 /// <param name="layout">Layout engine name</param>
 protected void SetLayout(string layout)
 {
     if (GraphVizCore.gvLayout(GVContext, GVGraph, layout) != 0)
     {
         throw new ArgumentException("Error while setting layout to \"" + layout + "\"");
     }
 }
Example #4
0
 /// <summary>
 /// Creates a graph from the given code
 /// </summary>
 /// <param name="dotGraphCode">GraphViz code</param>
 public void CreateGraph(String dotGraphCode)
 {
     // Create the graph from the string
     GVGraph = GraphVizCore.agmemread(dotGraphCode);
     // Did it succeed
     if (GVGraph == IntPtr.Zero)
     {
         throw new InvalidDataException("Unable to read the given data string");
     }
 }
Example #5
0
        /// <summary>
        /// Constructs a GraphVizRenderer by trying to automatically find the GraphViz install path
        /// </summary>
        public GraphVizRenderer()
        {
            // Get the install path
            string graphVizInstallPath = GraphVizCore.GetGraphVizPath();

            // If path has been found
            if (graphVizInstallPath != "")
            {
                Initialize(graphVizInstallPath);
            }
            else
            {
                throw new DirectoryNotFoundException("Unable to automatically find GraphViz install path. Use Graph constructor with explicit path instead, or check GraphViz is installed on your computer.");
            }
        }
Example #6
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (!disposed)
            {
                if (disposing)
                {
                }

                // Free the stream
                GraphVizCore.gvFreeRenderData(_pointer);

                disposed = true;
            }
        }
Example #7
0
        protected virtual void Dispose(bool disposing)
        {
            if (!disposed)
            {
                if (disposing)
                {
                    // Release managed resources
                }

                // Release unmanaged resources
                GraphVizCore.agclose(GVGraph);
                GraphVizCore.gvFreeContext(GVContext);

                disposed = true;
            }
        }
Example #8
0
        /// <summary>
        /// Renders a graph to a data stream
        /// </summary>
        /// <param name="gvContext">A GraphViz context pointer</param>
        /// <param name="gvGraph">A GraphViz graph pointer</param>
        /// <param name="format">The GraphViz renderer format string</param>
        /// <returns>The stream representing the rendered graph</returns>
        protected static GraphVizRenderStream Render(IntPtr gvContext, IntPtr gvGraph, string format)
        {
            unsafe
            {
                byte *result;
                uint  length;
                //  Render the graph to a byte stream
                if (GraphVizCore.gvRenderData(gvContext, gvGraph, format, out result, out length) != 0)
                {
                    throw new InvalidDataException("GraphViz gvRenderData function return empty pointer");
                }

                // Turn the byte stream to a "managed" stream
                return(new GraphVizRenderStream(result, length));
            }
        }