Fix broken charts with very long descriptions

This commit is contained in:
Dorian Niemiec 2024-08-26 19:41:07 +02:00
parent 36c5bed94e
commit 73bd63305b

View file

@ -24,10 +24,12 @@ var connection = mysql.createConnection(customvar1);
function plot(data) {
var dataToFeed = [];
Object.keys(data).sort().forEach(function (key) {
dataToFeed.push(dataToFeed.length + " \"" + key.replace(/"/g, "'") + "\" " + parseFloat(data[key]));
var feedKey = key.replace(/"/g, "'");
if (feedKey.length > 32) feedKey = feedKey.substring(0, 32) + "...";
dataToFeed.push(dataToFeed.length + " \"" + feedKey + "\" " + parseFloat(data[key]));
});
if (dataToFeed.length == 0) dataToFeed.push("0 \"\" 0");
var gnuplotObject = gnuplot().set("terminal png size 800,480").set("tics font \"Poppins,12\"").set("xtics rotate by 45 right").set("boxwidth 0.6").set("style fill solid").set("yrange [0:*]").set("grid ytics mytics").set("grid").plot("'-' using 1:3:xtic(2) notitle lc rgb \"#007000\" with boxes");
var gnuplotObject = gnuplot().set("terminal png size 800,480").set("tics font \"Poppins,12\"").set("xtics rotate by 45 right").set("rmargin 3").set("boxwidth 0.6").set("style fill solid").set("yrange [0:*]").set("grid ytics mytics").set("grid").plot("'-' using 1:3:xtic(2) notitle lc rgb \"#007000\" with boxes");
gnuplotObject.end(dataToFeed.join("\n"));
return gnuplotObject;
}