nitdoc: convert dot to svg instead of png
authorAlexandre Terrasa <alexandre@moz-code.org>
Thu, 11 Jun 2015 06:57:32 +0000 (02:57 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Wed, 24 Jun 2015 20:01:59 +0000 (16:01 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/doc_phases/doc_html.nit
src/doc/html_templates/html_templates.nit

index 6532a1d..afeba88 100644 (file)
@@ -585,15 +585,19 @@ end
 
 redef class GraphArticle
        redef fun init_html_render(v, doc, page) do
-               var output_dir = v.ctx.output_dir
-               var path = output_dir / graph_id
-               var path_sh = path.escape_to_sh
+               var path = v.ctx.output_dir / graph_id
                var file = new FileWriter.open("{path}.dot")
                file.write(dot)
                file.close
-               sys.system("\{ test -f {path_sh}.png && test -f {path_sh}.s.dot && diff -- {path_sh}.dot {path_sh}.s.dot >/dev/null 2>&1 ; \} || \{ cp -- {path_sh}.dot {path_sh}.s.dot && dot -Tpng -o{path_sh}.png -Tcmapx -o{path_sh}.map {path_sh}.s.dot ; \}")
-               var fmap = new FileReader.open("{path}.map")
-               self.map = fmap.read_all
-               fmap.close
+               var proc = new ProcessReader("dot", "-Tsvg", "-Tcmapx", "{path}.dot")
+               var svg = new Buffer
+               var i = 0
+               while not proc.eof do
+                       i += 1
+                       if i < 6 then continue # skip dot default header
+                       svg.append proc.read_line
+               end
+               proc.close
+               self.svg = svg.write_to_string
        end
 end
index ecff87f..bf14d90 100644 (file)
@@ -559,16 +559,15 @@ end
 redef class GraphArticle
        redef var html_title = null
 
-       # HTML map used to display link.
+       # Graph in SVG with clickable map.
        #
        # This attribute is set by the `doc_render` phase who knows the context.
-       var map: String is noinit, writable
+       var svg: nullable String = null is writable
 
        redef fun render_body do
                addn "<div class=\"text-center\">"
-               addn " <img src='{graph_id}.png' usemap='#{graph_id}' style='margin:auto'"
-               addn "  alt='{title or else ""}'/>"
-               add map
+               var svg = self.svg
+               if svg != null then add svg
                addn "</div>"
        end
 end