From 28bbd8807a6558e0951ca569773989147ae1b2b5 Mon Sep 17 00:00:00 2001 From: Tobias Werth Date: Thu, 23 Nov 2023 12:29:30 +0100 Subject: [PATCH] Improve y-axis of the submission graph format. Found when looking at https://github.com/DOMjudge/domjudge/issues/2191 This changes the following things: - Reduce amount of ticks for submissions with high runtimes - Use integer ticks when higher precision only clutters the y-axis - Add `s` to the labels to clearly indicate the unit --- .../templates/jury/partials/submission_graph.html.twig | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/webapp/templates/jury/partials/submission_graph.html.twig b/webapp/templates/jury/partials/submission_graph.html.twig index f66d69e338..6a74534f57 100644 --- a/webapp/templates/jury/partials/submission_graph.html.twig +++ b/webapp/templates/jury/partials/submission_graph.html.twig @@ -32,13 +32,14 @@ 'output-limit': 'black', } %} function create_chart(data, maxY) { - var tickStep = 1; + var tickStep = Math.floor(maxY/5); if (maxY <= 2) { tickStep = 0.2; } else if (maxY <= 5) { tickStep = 0.5; } maxY += tickStep; + maxY = Math.floor(maxY/tickStep) * tickStep; var chart = nv.models.multiBarChart() .x(function (d) { return d.label @@ -58,7 +59,12 @@ } chart.yAxis .tickValues(tickValues) - .axisLabel('Runtime (in s)'); + .axisLabel('Runtime'); + if (tickStep >= 1) { + chart.yAxis.tickFormat(function(d) { return d3.format(',f')(d) + 's' }); + } else { + chart.yAxis.tickFormat(function(d) { return d3.format(',.1f')(d) + 's' }); + } return chart; }