Example #1
0
        public void Constructor_Size()
        {
            var size = default(GraphvizSize);

            CheckSize(size, 0, 0, true);

            size = new GraphvizSize(0, 10);
            CheckSize(size, 0, 10, true);

            size = new GraphvizSize(10, 0);
            CheckSize(size, 10, 0, true);

            size = new GraphvizSize(10, 15);
            CheckSize(size, 10, 15, false);

            size = new GraphvizSize(30, 25);
            CheckSize(size, 30, 25, false);

            #region Local function

            void CheckSize(GraphvizSize s, int w, int h, bool empty)
            {
                Assert.AreEqual(w, s.Width);
                Assert.AreEqual(h, s.Height);
                Assert.AreEqual(empty, s.IsEmpty);
            }

            #endregion
        }
Example #2
0
        public static string DumpHtml(GraphvizSize size, [NotNull] string svgFilePath)
        {
            if (svgFilePath is null)
            {
                throw new ArgumentNullException(nameof(svgFilePath));
            }

            string outputFile = $"{svgFilePath}.html";

#if SUPPORTS_STREAM_FULL_FEATURES
            using (var html = new StreamWriter(outputFile))
#else
            var fileWriter = new FileStream(outputFile, FileMode.Create, FileAccess.Write);
            using (var html = new StreamWriter(fileWriter))
#endif
            {
                html.WriteLine("<html>");
                html.WriteLine("<body>");
                html.WriteLine($"<object data=\"{svgFilePath}\" type=\"image/svg+xml\" width=\"{size.Width}\" height=\"{size.Height}\">");
                html.WriteLine($"  <embed src=\"{svgFilePath}\" type=\"image/svg+xml\" width=\"{size.Width}\" height=\"{size.Height}\" />");
                html.WriteLine("If you see this, you need to install a SVG viewer");
                html.WriteLine("</object>");
                html.WriteLine("</body>");
                html.WriteLine("</html>");
            }

            return(outputFile);
        }
Example #3
0
        public void ToString_Size()
        {
            var size1 = default(GraphvizSize);
            var size2 = new GraphvizSize(12, 25);

            Assert.AreEqual("0x0", size1.ToString());
            Assert.AreEqual("12x25", size2.ToString());
        }
Example #4
0
        public void Serialization_Size()
        {
            var          size             = new GraphvizSize(150, 200);
            GraphvizSize deserializedSize = SerializeAndDeserialize(size);

            Assert.AreEqual(size.IsEmpty, deserializedSize.IsEmpty);
            Assert.AreEqual(size.Width, deserializedSize.Width);
            Assert.AreEqual(size.Height, deserializedSize.Height);
        }
        public void ParseSize()
        {
            GraphvizSize size = SvgHtmlWrapper.ParseSize(SampleSvg);

            Assert.AreEqual(new GraphvizSize(300, 200), size);

            // Size not found => fallback
            size = SvgHtmlWrapper.ParseSize(MissingSizeSampleSvg);
            Assert.AreEqual(new GraphvizSize(400, 400), size);
        }
Example #6
0
        public static string WrapSvg([NotNull] string svgFilePath)
        {
#if SUPPORTS_STREAM_FULL_FEATURES
            using (var reader = new StreamReader(svgFilePath))
            {
                GraphvizSize size = ParseSize(reader.ReadToEnd());
                reader.Close();
                return(DumpHtml(size, svgFilePath));
            }
#else
            GraphvizSize size;
            var          fileReader = new FileStream(svgFilePath, FileMode.Open, FileAccess.Read);
            using (var reader = new StreamReader(fileReader))
            {
                size = ParseSize(reader.ReadToEnd());
            }

            return(DumpHtml(size, svgFilePath));
#endif
        }
Example #7
0
        public static string DumpHtml(GraphvizSize size, string svgFileName)
        {
            string outputFile = String.Format("{0}.html", svgFileName);

            using (var html = new StreamWriter(outputFile))
            {
                html.WriteLine("<html>");
                html.WriteLine("<body>");
                html.WriteLine("<object data=\"{0}\" type=\"image/svg+xml\" width=\"{1}\" height=\"{2}\">",
                               svgFileName, size.Width, size.Height);
                html.WriteLine("  <embed src=\"{0}\" type=\"image/svg+xml\" width=\"{1}\" height=\"{2}\">",
                               svgFileName, size.Width, size.Height);
                html.WriteLine("If you see this, you need to install a SVG viewer");
                html.WriteLine("  </embed>");
                html.WriteLine("</object>");
                html.WriteLine("</body>");
                html.WriteLine("</html>");
            }

            return(outputFile);
        }