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" require "uuid"
class Handler 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 # Process the gnuplot output so it works in the page
# #
# buffer is the Ishi output # buffer is the Ishi output
# name is a string to replace for gnuplot_canvas so # 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 = buffer.to_s.split("\n")
html = html[html.index("<script type=\"text/javascript\">")..html.index("</script>")] 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"> <div class="gnuplot">
<canvas id="Tile" width="32" height="32" hidden></canvas> <canvas id="Tile" width="32" height="32" hidden></canvas>
<table class="plot"> <table class="plot">
@ -30,7 +31,7 @@ class Handler
</script> </script>
</div> </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 # we have 2 charts in the same page
html.gsub("gnuplot_canvas", canvas_name) html.gsub("gnuplot_canvas", canvas_name)
end end