Skip to content

Commit

Permalink
fix: update maidr attribute to maidr-data for py-maidr to handle it p…
Browse files Browse the repository at this point in the history
…roperly
  • Loading branch information
dakshpokar committed Feb 20, 2025
1 parent cd644e0 commit 9ecbe97
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions galleries/attributes/bar_plot.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
version="1.1"
id="barplot1"
tabindex="0"
maidr="{"type":"bar","id":"barplot1","title":"The Number of Diamonds by Cut.","selector":"g[id^=\"geom_rect\"] > rect","axes":{"x":{"label":"Cut","level":["Fair","Good","Very Good","Premium","Ideal"]},"y":{"label":"Count"}},"data":[1610,4906,12082,13791,21551]}"
>
maidr-data='{"type":"bar","id":"barplot1","title":"The Number of Diamonds by Cut.","selector":"g[id^=\"geom_rect\"] > rect","axes":{"x":{"label":"Cut","level":["Fair","Good","Very Good","Premium","Ideal"]},"y":{"label":"Count"}},"data":[1610,4906,12082,13791,21551]}'
>
<metadata
xmlns:gridsvg="http://www.stat.auckland.ac.nz/~paul/R/gridSVG/"
>
Expand Down
10 changes: 5 additions & 5 deletions src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ document.addEventListener('DOMContentLoaded', function (e) {

// set focus events for all charts matching maidr ids
let maidrObjects = [];

// First check for globally defined maidr variable (script tag method)
if (typeof window.maidr !== 'undefined') {
if (!Array.isArray(window.maidr)) {
Expand All @@ -21,10 +21,10 @@ document.addEventListener('DOMContentLoaded', function (e) {
}

// Then look for elements with maidr attribute
const elementsWithMaidrAttr = document.querySelectorAll('[maidr]');
elementsWithMaidrAttr.forEach(element => {
const elementsWithMaidrAttr = document.querySelectorAll('[maidr-data]');
elementsWithMaidrAttr.forEach((element) => {
try {
const maidrData = JSON.parse(element.getAttribute('maidr'));
const maidrData = JSON.parse(element.getAttribute('maidr-data'));
// If id is not provided in the JSON, use the element's id
if (!maidrData.id) {
if (element.id) {
Expand All @@ -36,7 +36,7 @@ document.addEventListener('DOMContentLoaded', function (e) {
}
}
// Check if this id already exists in maidrObjects to avoid duplicates
if (!maidrObjects.some(obj => obj.id === maidrData.id)) {
if (!maidrObjects.some((obj) => obj.id === maidrData.id)) {
maidrObjects.push(maidrData);
}
} catch (e) {
Expand Down

0 comments on commit 9ecbe97

Please sign in to comment.