Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit the labels on the x-axis #2732

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 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,21 @@ 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);
}

// Pick a nice round tickDelta and tickValues
var tickDelta = 15;
while (contest_duration_minutes / tickDelta > 15) {
tickDelta *= 2;
}
var tickValues = Array.from({ length: Math.ceil(contest_duration_minutes / tickDelta) + 1 }, (_, i) => i * tickDelta);

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 +424,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
Loading