@@ -2737,10 +2737,10 @@ =head2 Macros for displaying images
2737
2737
2738
2738
Usage :
2739
2739
2740
- image($image , width => 200 , height => 200 , tex_size => 800 , valign => 'middle' , alt => 'alt text' , extra_html_tags => 'style="border:solid black 1pt"' );
2740
+ image($image , width => . .. , height => ... , tex_size => ... , valign => ... , alt => ..., long_description => ... );
2741
2741
2742
2742
where C <$image > can be a local file path , URL , WWPlot object , PGlateximage object ,
2743
- PGtikz object , or parser ::GraphTool object .
2743
+ PGtikz object , Plots :: Plot object , or parser ::GraphTool object .
2744
2744
2745
2745
C <width > and C <height > are positive integer pixel counts for HTML display . If both
2746
2746
are missing , C <width > will default to 200 and C <height > will remain undeclared ,
@@ -2757,10 +2757,29 @@ =head2 Macros for displaying images
2757
2757
C <valign > can be 'top' , 'middle' , or 'bottom' . This aligns the image relative to
2758
2758
the surrounding line of text .
2759
2759
2760
- image ([$image1 ,$image2 ], width => 200 , height => 200 , tex_size => 800 , alt => ['alt text 1' ,'alt text 2' ], extra_html_tags => 'style="border:solid black 1pt"' );
2761
- image([$image1 ,$image2 ], width => 200 , height => 200 , tex_size => 800 , alt => 'common alt text' , extra_html_tags => 'style="border:solid black 1pt"' );
2760
+ C <alt > should be a string , ideally with fewer than 125 characters , that describes the
2761
+ most important features of the image . This should always be used. If the image is
2762
+ decorative , C << alt => '' >> should be used .
2762
2763
2763
- this produces an array in array context and joins the elements with C <' ' > in scalar context
2764
+ C <long_description > provides an optional way to give a more complete description of
2765
+ an image . This may include a table (for example to describe complex data in a graph).
2766
+ It may be helpful to generate blocks of text and tables and store them in a variable ,
2767
+ and pass that variable to C <long_description >.
2768
+
2769
+ C <extra_html_tags > [DEPRECATED ] can be a string will directly be placed into the
2770
+ HTML img element . For example, C<< extra_html_tags => 'style="border:solid black 1pt"' >>.
2771
+
2772
+ The first argument to C <image()> can alternatively be an array of images :
2773
+
2774
+ image([$image1 , $image2 ], . ..);
2775
+
2776
+ If so then if C <alt > or C <long_description > are not arrays , they will be used
2777
+ repeatedly for each image . Each of C<alt> and C<long_description> can instead be
2778
+ arrays of the same length and their entries will be used with the corresponding
2779
+ image .
2780
+
2781
+ In array context , using C <image()> this way will produces an array in array context
2782
+ and join the elements with C <' ' > in scalar context .
2764
2783
2765
2784
=cut
2766
2785
@@ -2778,8 +2797,9 @@ sub image {
2778
2797
tex_size => '' ,
2779
2798
valign => 'middle' ,
2780
2799
# default value for alt is undef , since an empty string is the explicit indicator of a decorative image
2781
- alt => undef ,
2782
- extra_html_tags => '' ,
2800
+ alt => undef ,
2801
+ long_description => undef ,
2802
+ extra_html_tags => '' ,
2783
2803
);
2784
2804
# handle options
2785
2805
my %out_options = %known_options ;
@@ -2802,9 +2822,11 @@ sub image {
2802
2822
$tex_size = 1000 if $tex_size > 1000 ;
2803
2823
2804
2824
my $alt = $out_options {alt };
2825
+ my $desc = $out_options {long_description };
2805
2826
my $width_ratio = $tex_size * (.001 );
2806
2827
my @image_list = ();
2807
2828
my @alt_list = ();
2829
+ my @desc_list = ();
2808
2830
my $valign = 'middle' ;
2809
2831
$valign = 'top' if ($out_options {valign } eq 'top' );
2810
2832
$valign = 'bottom' if ($out_options {valign } eq 'bottom' );
@@ -2823,16 +2845,56 @@ sub image {
2823
2845
} else {
2824
2846
for my $i (@image_list ) { push(@alt_list , $alt ) }
2825
2847
}
2848
+ if (ref($desc ) =~ /ARRAY /) {
2849
+ @desc_list = @{$desc };
2850
+ } else {
2851
+ for my $i (@image_list ) { push(@desc_list , $desc ) }
2852
+ }
2826
2853
2827
2854
my @output_list = ();
2828
2855
while (@image_list ) {
2829
- my $image_item = shift @image_list ;
2856
+ my $image_item = shift @image_list ;
2857
+ my $description_details = '' ;
2858
+ if ($desc ) {
2859
+ $description_details = tag(
2860
+ 'details' ,
2861
+ 'aria-live' => 'polite' ,
2862
+ class => 'image-details' ,
2863
+ name => 'image-details' ,
2864
+ tag(
2865
+ 'summary' ,
2866
+ class => 'mt-1' ,
2867
+ title => 'details' ,
2868
+ tag(
2869
+ 'span' ,
2870
+ class => 'badge badge-info bg-secondary' ,
2871
+ 'aria-hidden' => 'true' ,
2872
+ maketext('image description' )
2873
+ )
2874
+ )
2875
+ . tag(
2876
+ 'div',
2877
+ id => 'LONG-DESCRIPTION-ID' ,
2878
+ class => 'image-details-content bg-white py-2 px-3 my-2 border' ,
2879
+ shift(@desc_list )
2880
+ . tag('br')
2881
+ . tag(
2882
+ 'button',
2883
+ class => 'image-details-dismiss badge badge-info bg-secondary' ,
2884
+ type => 'button' ,
2885
+ onclick => "this.parentElement.parentElement.removeAttribute('open')" ,
2886
+ maketext('Close image description' )
2887
+ )
2888
+ )
2889
+ );
2890
+ }
2830
2891
if (ref $image_item eq 'parser::GraphTool' ) {
2831
2892
push(
2832
2893
@output_list ,
2833
2894
$image_item ->generateAnswerGraph(
2834
- $out_options {width } || $out_options {height } ? (width => $width , height => $height ) : (),
2835
- $out_options {tex_size } || $out_options {width } ? (texSize => $tex_size ) : (),
2895
+ $out_options {width } || $out_options {height } ? (width => $width , height => $height ) : (),
2896
+ $out_options {tex_size } || $out_options {width } ? (texSize => $tex_size ) : (),
2897
+ $desc ? (longDescription => $description_details ) : (),
2836
2898
ariaDescription => shift @alt_list // ''
2837
2899
)
2838
2900
);
@@ -2846,6 +2908,7 @@ sub image {
2846
2908
$image_item->{ariaDescription} = shift @alt_list if $out_options{alt};
2847
2909
2848
2910
if ($image_item ->ext eq 'html' ) {
2911
+ $image_item ->{description_details } = $description_details ;
2849
2912
push(@output_list , $image_item ->draw );
2850
2913
next ;
2851
2914
}
@@ -2862,6 +2925,7 @@ sub image {
2862
2925
|| ref $image_item eq 'PGtikz' );
2863
2926
my $imageURL = alias($image_item ) // '' ;
2864
2927
$imageURL = ($envir {use_site_prefix }) ? $envir {use_site_prefix } . $imageURL : $imageURL;
2928
+ my $id = $main ::PG ->getUniqueName('img' );
2865
2929
my $out = "" ;
2866
2930
2867
2931
if ($displayMode eq 'TeX' ) {
@@ -2889,15 +2953,31 @@ sub image {
2889
2953
{
2890
2954
my $altattrib = '' ;
2891
2955
if (defined $alt_list [0 ]) { $altattrib = 'alt="' . encode_pg_and_html(shift @alt_list) . '"' }
2892
- $out =
2893
- qq !<IMG SRC ="$imageURL" class ="image-view-elt $valign" tabindex ="0" role ="button" $width_attrib $height_attrib $out_options {extra_html_tags } $altattrib >!;
2956
+ if ($desc ) {
2957
+ $out . = tag(
2958
+ 'div',
2959
+ class => 'image-container pb-2' ,
2960
+ qq !<img src ="$imageURL" class ="image-view-elt $valign" tabindex ="0" role ="button" !
2961
+ . qq!$width_attrib$height_attrib aria-details="${id}_details" $out_options{extra_html_tags} $altattrib>!
2962
+ . ($description_details =~ s/LONG-DESCRIPTION-ID/${id}_details/r)
2963
+ );
2964
+ } else {
2965
+ $out .= qq!<img src="$imageURL" class="image-view-elt $valign" tabindex="0" role="button"!
2966
+ . qq!$width_attrib$height_attrib $out_options{extra_html_tags} $altattrib>!;
2967
+ }
2894
2968
} elsif ($displayMode eq 'PTX') {
2895
2969
my $ptxwidth = ($width ? int($width / 6 ) : 80 );
2970
+ $out = qq !<image width ="$ptxwidth%" source ="$imageURL" >!;
2896
2971
if (defined $alt ) {
2897
- $out = qq !<image width ="$ptxwidth%" source ="$imageURL" ><description >$alt </description ></image >!;
2898
- } else {
2899
- $out = qq !<image width ="$ptxwidth%" source ="$imageURL" />!;
2972
+ $out . = "\n<shortdescription>$alt</shortdescription>";
2973
+ }
2974
+ if (defined $desc ) {
2975
+ $out . = "\n<description>\n" . PTX_cleanup($desc) . "\n</description>";
2976
+ }
2977
+ if (defined $alt || defined $desc ) {
2978
+ $out . = "\n";
2900
2979
}
2980
+ $out .= '</image>';
2901
2981
} else {
2902
2982
$out = "Error: PGbasicmacros: image: Unknown displayMode: $displayMode.\n";
2903
2983
}
0 commit comments