Skip to content

Commit

Permalink
Add alt text to histograms on stats page.
Browse files Browse the repository at this point in the history
This adds alt text to the histogram images on the stats page which
fixes the issue mentioned in #2598.

In addition this fixes some issues I found with the stats page.
* Links on the problem bars weren't working so forced them to
  be a string.
* JitarSets - The adjusted status bars were reversed and didn't
  need to be and the adjusted scores were multiplet by 100 and
  didn't need to be.
  • Loading branch information
somiaj committed Nov 17, 2024
1 parent df4b848 commit b954ce6
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/WeBWorK/ContentGenerator/Instructor/Stats.pm
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ sub build_bar_chart ($c, $data, %options) {
mainTitle => 'ERROR: This must be set',
xTitle => '',
yTitle => '',
altText => '',
barWidth => 22,
barSep => 4,
barFill => 'rgb(0,153,198)',
Expand Down Expand Up @@ -581,6 +582,7 @@ sub build_bar_chart ($c, $data, %options) {
viewbox => '-2 -2 ' . ($imageWidth + 3) . ' ' . ($imageHeight + 3),
'aria-labelledby' => "bar_graph_title_$id",
role => 'img',
alt => $opts{altText},
-nocredits => 1
);

Expand Down Expand Up @@ -724,7 +726,7 @@ sub build_bar_chart ($c, $data, %options) {
class => 'bar_graph_bar',
);
}
my $tag = @{ $opts{barLinks} } ? $svg->anchor(-href => $opts{barLinks}->[$_]) : $svg;
my $tag = @{ $opts{barLinks} } ? $svg->anchor(-href => "$opts{barLinks}->[$_]") : $svg;
$tag->rect(
x => $xPos,
y => $opts{topMargin} + $opts{plotHeight} - $yHeight,
Expand Down
24 changes: 20 additions & 4 deletions templates/ContentGenerator/Instructor/Stats/problem_stats.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,36 @@
</div>
%
% # Histogram of total scores.
% my $bucketLabels = [ '90-100', '80-89', '70-79', '60-69', '50-59', '40-49', '30-39', '20-29', '10-19', '0-9' ];
<%= $c->build_bar_chart(
[ @$buckets ],
xAxisLabels => [ '90-100', '80-89', '70-79', '60-69', '50-59', '40-49', '30-39', '20-29', '10-19', '0-9' ],
$buckets,
xAxisLabels => $bucketLabels,
yMax => 5 * $maxCount,
yAxisLabels => [ map { $_ * $maxCount } 0 .. 5 ],
mainTitle => maketext('Active Students Problem [_1] Grades', $c->{prettyID}),
xTitle => maketext('Percent Ranges'),
yTitle => maketext('Number of Students'),
altText => $isJitarSet && $topLevelJitar
? maketext(
'Histogram showing the percent grade of active students for problem [_1] and the adjusted '
. 'percent grade with review. The number of students in each percent range is: [_2]. '
. 'The number of students in each percent range after review is: [_3].',
$c->{prettyID},
join(', ', map { "$bucketLabels->[$_]:$buckets->[$_]" } 0 .. scalar(@$buckets) - 1),
join(', ', map { "$bucketLabels->[$_]:$jitarBars->[$_]" } 0 .. scalar(@$buckets) - 1)
)
: maketext(
'Histogram showing the grades of active students for problem [_1], where the number of '
. 'students in each percent range is: [_2]',
$c->{prettyID},
join(', ', map { "$bucketLabels->[$_]:$buckets->[$_]" } 0 .. scalar(@$buckets) - 1),
),
barWidth => 35,
barSep => 5,
isPercent => 0,
leftMargin => 40 + 5 * length(5 * $maxCount),
isJitarSet => ($isJitarSet && $topLevelJitar),
jitarBars => [ reverse(@$jitarBars) ],
jitarBars => $jitarBars,
) =%>
%
% # Display overall statistics
Expand Down Expand Up @@ -64,7 +80,7 @@
% my @tableData = ($problemScores);
% if ($isJitarSet && $topLevelJitar) {
% push(@tableHeaders, maketext('% Score with Review'));
% push(@tableData, [ map { sprintf('%0.0f', 100 * $_) } @$adjustedScores ]);
% push(@tableData, [ map { sprintf('%0.0f', $_) } @$adjustedScores ]);
% }
% my $successIndexHeader = begin
<%= maketext('Success Index') =%>
Expand Down
24 changes: 23 additions & 1 deletion templates/ContentGenerator/Instructor/Stats/set_stats.html.ep
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,19 @@
<h2><%= maketext('Overall Results') %></h2>
%
% # Histogram of total scores.
% my $bucketLabels = [ '90-100', '80-89', '70-79', '60-69', '50-59', '40-49', '30-39', '20-29', '10-19', '0-9' ];
<%= $c->build_bar_chart(
$buckets,
xAxisLabels => [ '90-100', '80-89', '70-79', '60-69', '50-59', '40-49', '30-39', '20-29', '10-19', '0-9' ],
xAxisLabels => $bucketLabels,
yMax => 5 * $maxCount,
yAxisLabels => [ map { $_ * $maxCount } 0 .. 5 ],
mainTitle => maketext('Overall Set Grades'),
xTitle => maketext('Percent Ranges'),
yTitle => maketext('Number of Students'),
altText => maketext(
'Histogram showing the overall set grades, where the number of students in each percent range is: [_1].',
join(', ', map { "$bucketLabels->[$_]:$buckets->[$_]" } 0 .. scalar(@$buckets) - 1)
),
barWidth => 35,
barSep => 5,
isPercent => 0,
Expand Down Expand Up @@ -146,6 +151,23 @@
xAxisLabels => $svgProblemLabels,
mainTitle => maketext('Grade of Active Students'),
xTitle => maketext('Problem Number'),
altText => $isJitarSet
? maketext(
'Histogram showing the average percent grade of active students for each problem and the adjusted '
. 'percent grade on top level problems with review. The average percent grade (as a decimal) for '
. 'each problem is: [_1]. The adjusted percent grade for top level problems with review is: [_2].',
join(', ', map { "$svgProblemLabels->[$_]:$svgProblemData->[$_]" } 0 .. scalar(@$svgProblemData) - 1),
join(
', ',
map { $jitarBars->[$_] < 0 ? () : "$svgProblemLabels->[$_]:$jitarBars->[$_]" }
0 .. scalar(@$svgProblemData) - 1
)
)
: maketext(
'Histogram showing the average percent grade of active students for each problem, '
. 'where the average percent grade (as a decimal) for each problem is: [_1].',
join(', ', map { "$svgProblemLabels->[$_]:$svgProblemData->[$_]" } 0 .. scalar(@$svgProblemData) - 1)
),
isJitarSet => $isJitarSet,
jitarBars => $isJitarSet ? $jitarBars : [],
barLinks => [ map { $_->{statsLink} } @$problems ],
Expand Down

0 comments on commit b954ce6

Please sign in to comment.