Skip to content

Commit 0528ffa

Browse files
authored
Merge pull request #1322 from drgrice1/plots-fixes
Fix some issues with plots.pl and the graph tool.
2 parents cf2cf3b + f6692fa commit 0528ffa

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

htdocs/js/GraphTool/graphtool.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ window.graphTool = (containerId, options) => {
6969
if ('htmlInputId' in options) gt.html_input = document.getElementById(options.htmlInputId);
7070
const cfgOptions = {
7171
title: 'WeBWorK Graph Tool',
72-
description: options.ariaDescription ?? 'Interactively graph objects',
7372
showCopyright: false,
7473
pan: { enabled: false },
7574
zoom: { enabled: false },
@@ -116,6 +115,14 @@ window.graphTool = (containerId, options) => {
116115

117116
const setupBoard = () => {
118117
gt.board = JXG.JSXGraph.initBoard(`${containerId}_graph`, cfgOptions);
118+
119+
const descriptionSpan = document.createElement('span');
120+
descriptionSpan.id = `${containerId}_description`;
121+
descriptionSpan.classList.add('visually-hidden');
122+
descriptionSpan.textContent = options.ariaDescription ?? 'Interactively graph objects';
123+
gt.board.containerObj.after(descriptionSpan);
124+
gt.board.containerObj.setAttribute('aria-describedby', descriptionSpan.id);
125+
119126
gt.board.suspendUpdate();
120127

121128
// Move the axes defining points to the end so that the arrows go to the board edges.

lib/Plots/GD.pm

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ sub im_y {
6363
return unless defined($y);
6464
my $plots = $self->plots;
6565
my ($ymin, $ymax) = ($plots->axes->yaxis('min'), $plots->axes->yaxis('max'));
66-
return int(($ymax - $y) * $plots->{height} / ($ymax - $ymin));
66+
(undef, my $height) = $plots->size;
67+
return int(($ymax - $y) * $height / ($ymax - $ymin));
6768
}
6869

6970
sub moveTo {
@@ -217,12 +218,11 @@ sub draw_circle_stamp {
217218
}
218219

219220
sub draw {
220-
my $self = shift;
221-
my $plots = $self->plots;
222-
my $axes = $plots->axes;
223-
my $grid = $axes->grid;
224-
my $width = $plots->{width};
225-
my $height = $plots->{height};
221+
my $self = shift;
222+
my $plots = $self->plots;
223+
my $axes = $plots->axes;
224+
my $grid = $axes->grid;
225+
my ($width, $height) = $plots->size;
226226

227227
# Initialize image
228228
$self->im->interlaced('true');

lib/Plots/JSXGraph.pm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,6 @@ sub init_graph {
404404

405405
my $JSXOptions = Mojo::JSON::encode_json({
406406
title => $axes->style('aria_label'),
407-
description => $axes->style('aria_description'),
408407
boundingBox => [ $xmin, $ymax, $xmax, $ymin ],
409408
axis => 0,
410409
showNavigation => $allow_navigation,
@@ -497,6 +496,12 @@ sub init_graph {
497496
$self->{JSend} = '';
498497
$self->{JS} = <<~ "END_JS";
499498
const board = JXG.JSXGraph.initBoard(id, $JSXOptions);
499+
const descriptionSpan = document.createElement('span');
500+
descriptionSpan.id = `\${id}_description`;
501+
descriptionSpan.classList.add('visually-hidden');
502+
descriptionSpan.textContent = '${\($axes->style('aria_description'))}';
503+
board.containerObj.after(descriptionSpan);
504+
board.containerObj.setAttribute('aria-describedby', descriptionSpan.id);
500505
board.suspendUpdate();
501506
board.create('axis', [[$xmin, $xaxis_pos], [$xmax, $xaxis_pos]], $XAxisOptions);
502507
board.create('axis', [[$yaxis_pos, $ymin], [$yaxis_pos, $ymax]], $YAxisOptions);

lib/Plots/Tikz.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ sub get_plot_opts {
221221
}
222222
my $end_markers = ($start || $end) ? ", $start-$end" : '';
223223
$marks = $self->get_mark($marks);
224-
$marks = $marks ? $mark_size ? ", mark=$marks, mark size=${mark_size}px" : ", mark=$marks" : '';
224+
$marks = $marks ? $mark_size ? ", mark=$marks, mark size=${mark_size}pt" : ", mark=$marks" : '';
225225

226226
$linestyle =~ s/ /_/g;
227227
$linestyle = {

macros/core/PGbasicmacros.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2928,9 +2928,9 @@ sub image {
29282928
$image_item->{width} = $width if $out_options{width};
29292929
$image_item->{height} = $height if $out_options{height};
29302930
$image_item->{tex_size} = $tex_size if $out_options{tex_size};
2931-
$image_item->axes->style(aria_description => shift @alt_list) if $out_options{alt};
29322931

29332932
if ($image_item->ext eq 'html') {
2933+
$image_item->axes->style(aria_description => shift @alt_list) if $out_options{alt};
29342934
$image_item->{description_details} = $description_details;
29352935
push(@output_list, $image_item->draw);
29362936
next;

0 commit comments

Comments
 (0)