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
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