|
| 1 | +// accessible JavaScript tab switcher |
| 2 | +// modified from https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Roles/Tab_Role |
| 3 | + |
| 4 | +function getRandomInt(max) { |
| 5 | + return Math.floor(Math.random() * max); |
| 6 | +} |
| 7 | + |
| 8 | +var images_rotate = [ |
| 9 | + {"image": "sphx_glr_plot_001_2_00x.png", "caption": "plot(x, y)", "link": "plot_types/basic/plot.html"}, |
| 10 | + {"image": "sphx_glr_step_001_2_00x.png", "caption": "step(x, y)", "link": "plot_types/basic/step.html"}, |
| 11 | + {"image": "sphx_glr_scatter_plot_001_2_00x.png", "caption": "scatter(x, y)", "link": "plot_types/basic/scatter_plot.html"}, |
| 12 | + {"image": "sphx_glr_pcolormesh_001_2_00x.png", "caption": "pcolormesh(X, Y, Z)", "link": "plot_types/arrays/pcolormesh.html"}, |
| 13 | + {"image": "sphx_glr_contourf_001_2_00x.png", "caption": "contourf(X, Y, Z)", "link": "plot_types/arrays/contourf.html"}, |
| 14 | + {"image": "sphx_glr_step_001_2_00x.png", "caption": "step(x, y)", "link": "plot_types/basic/step.html"}, |
| 15 | + {"image": "sphx_glr_streamplot_001_2_00x.png", "caption": "streamplot(X, Y, U, V)", "link": "plot_types/arrays/streamplot.html"}, |
| 16 | + {"image": "sphx_glr_bar_001_2_00x.png", "caption": "bar(x, height) / barh(y, width)", "link": "plot_types/basic/bar.html"}, |
| 17 | + {"image": "sphx_glr_hist_plot_001_2_00x.png", "caption": "hist(x)", "link": "plot_types/stats/hist_plot.html"}, |
| 18 | + {"image": "sphx_glr_imshow_001_2_00x.png", "caption": "imshow(Z)", "link": "plot_types/arrays/imshow.html"}, |
| 19 | +]; |
| 20 | + |
| 21 | +document.addEventListener("DOMContentLoaded", function(event) { |
| 22 | + /////////////////////////////////////// |
| 23 | + // rotate images in images-rotate directory: |
| 24 | + var ind = getRandomInt(images_rotate.length); |
| 25 | + var info = images_rotate[ind]; |
| 26 | + var img_src = "../_images/" + info.image; |
| 27 | + var caption = info.caption; |
| 28 | + var link = "https://matplotlib.org/stable/" + info.link; |
| 29 | + var html = '<a href="' + link + '">' + |
| 30 | + '<img class="imrot-img" src="' + img_src + '" aria-labelledby="sample-plot-caption"/>' + |
| 31 | + '<div class="imrot-cap" id="sample-plot-caption">' + caption + '</div>' + |
| 32 | + '</a>'; |
| 33 | +document.getElementById('image_rotator').innerHTML = html; |
| 34 | + |
| 35 | + ind = getRandomInt(images_rotate.length); |
| 36 | + info = images_rotate[ind]; |
| 37 | + img_src = "../_images/" + info.image; |
| 38 | + caption = info.caption; |
| 39 | + link = "https://matplotlib.org/stable/" + info.link; |
| 40 | + html = '<a href="' + link + '">' + |
| 41 | + '<img class="imrot-img" src="' + img_src + '" aria-labelledby="sample-plot-caption"/>' + |
| 42 | + '<div class="imrot-cap" id="sample-plot-caption">' + caption + '</div>' + |
| 43 | + '</a>'; |
| 44 | +document.getElementById('image_rotator2').innerHTML = html; |
| 45 | + |
| 46 | +}); |
0 commit comments