Skip to content

Commit

Permalink
Limit the labels on the x-axis
Browse files Browse the repository at this point in the history
  • Loading branch information
as6325400 committed Oct 5, 2024
1 parent 6530dff commit fcde16f
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions webapp/templates/jury/analysis/contest_overview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ var submissions = [
var contest_duration_minutes = Math.ceil(({{ current_contest.endtime }} - {{ current_contest.starttime }}) / 60);
submission_stats.forEach(stat => {
stat.values = Array.from({ length: contest_duration_minutes }, (_, i) => [i, 0]);
stat.values = Array.from({ length: contest_duration_minutes + 1 }, (_, i) => [i, 0]);
});
const statMap = submission_stats.reduce((map, stat) => {
Expand All @@ -397,14 +397,30 @@ submissions.forEach(submission => {
}
});
for (let minute = 0; minute < contest_duration_minutes; minute++) {
for (let minute = 0; minute <= contest_duration_minutes; minute++) {
let this_minute_submission_nums = 0;
submission_stats.forEach(stat => {
this_minute_submission_nums += stat.values[minute][1];
});
max_submissions_per_minute = Math.max(max_submissions_per_minute, this_minute_submission_nums);
}
function generate_values(start_point, end_point, number_of_points) {
var values = [start_point]; // Initialize the array with the start point
var step = (end_point - start_point) / (number_of_points + 1); // Calculate the step size
for (var i = 1; i <= number_of_points; i++) {
values.push(Math.round(start_point + i * step)); // Generate evenly spaced values and round them to integers
}
values.push(end_point); // Add the end point to the array
return values;
}
var start_point = 0; // Starting value of the range
var end_point = contest_duration_minutes; // Ending value of the range
var number_of_points = 9; // Number of intermediate points to generate
var tickValues = generate_values(start_point, end_point, number_of_points);
nv.addGraph(function() {
var chart = nv.models.multiBarChart()
// .margin({left: 100}) //Adjust chart margins to give the x-axis some breathing room.
Expand All @@ -417,11 +433,13 @@ nv.addGraph(function() {
.y(function(d) { return d[1] }) //...in case your data is formatted differently.
.showYAxis(true) //Show the y-axis
.showXAxis(true) //Show the x-axis
.reduceXTicks(false)
;
chart.xAxis //Chart x-axis settings
.axisLabel('Contest Time(minutes)')
.ticks(tickValues.length)
.tickValues(tickValues)
.tickFormat(d3.format('d'));
chart.yAxis //Chart y-axis settings
.axisLabel('Total Submissions')
.tickFormat(d3.format('d'));
Expand Down

0 comments on commit fcde16f

Please sign in to comment.