Sync format_buffer code

This commit is contained in:
Roberto Alsina 2023-06-04 17:43:51 -03:00
parent 823cc24e8a
commit 4c46cb2958

View File

@ -6,16 +6,17 @@ require "json"
require "uuid"
class Handler
def format_buffer(buffer, canvas_name)
def format_buffer(buffer, canvas_name, title)
# Process the gnuplot output so it works in the page
#
# buffer is the Ishi output
# name is a string to replace for gnuplot_canvas so
# we can have multiple charts in a page
# we can have multiple charts in a page
# title is added on top of the chart
html = buffer.to_s.split("\n")
html = html[html.index("<script type=\"text/javascript\">")..html.index("</script>")]
html = html.join("\n") + %(
html = "<b>#{title}</b>" + html.join("\n") + %(
<div class="gnuplot">
<canvas id="Tile" width="32" height="32" hidden></canvas>
<table class="plot">
@ -30,7 +31,7 @@ class Handler
</script>
</div>
)
# This ID needs to be unique in case
# This ID needs to be unique in case
# we have 2 charts in the same page
html.gsub("gnuplot_canvas", canvas_name)
end