From d6a9e103753cf13b95670709d14d3358ffd9d7ca Mon Sep 17 00:00:00 2001 From: Daksh Pokar Date: Tue, 18 Feb 2025 18:56:14 -0600 Subject: [PATCH] feat: maidr object handling with an attribute to svg or img tag --- .vscode/settings.json | 8 +- galleries/attributes/bar_plot.html | 1143 ++++++++++++++++++++++++++++ src/js/init.js | 35 +- 3 files changed, 1178 insertions(+), 8 deletions(-) create mode 100644 galleries/attributes/bar_plot.html diff --git a/.vscode/settings.json b/.vscode/settings.json index 4e7dfa55a..11997704b 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -53,19 +53,19 @@ "githubPullRequests.queries": [ { "label": "Waiting For My Review", - "query": "is:open review-requested:${user}" + "query": "repo:${owner}/${repository} is:open review-requested:${user}" }, { "label": "Assigned To Me", - "query": "is:open assignee:${user}" + "query": "repo:${owner}/${repository} is:open assignee:${user}" }, { "label": "Created By Me", - "query": "is:open author:${user}" + "query": "repo:${owner}/${repository} is:open author:${user}" }, { "label": "Mentioned Me", - "query": "is:open mentions:${user}" + "query": "repo:${owner}/${repository} is:open mentions:${user}" } ], "githubIssues.queries": [ diff --git a/galleries/attributes/bar_plot.html b/galleries/attributes/bar_plot.html new file mode 100644 index 000000000..8861f9cb1 --- /dev/null +++ b/galleries/attributes/bar_plot.html @@ -0,0 +1,1143 @@ + + + + Bar Plot + + + + + + + +
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + + + 5000 + + + + + + + + + 10000 + + + + + + + + + 15000 + + + + + + + + + 20000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Fair + + + + + + + + + Good + + + + + + + + + Very Good + + + + + + + + + Premium + + + + + + + + + Ideal + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Cut + + + + + + + + + + + + + + + + + + + + + Count + + + + + + + + + + + + + + + + + + + + + + + + + + + The Number of Diamonds by Cut. + + + + + + + + + + + + + + + + + + + + + +
+
+
+
+ + + + + + + + + + + + diff --git a/src/js/init.js b/src/js/init.js index 325f35191..ca948dc8e 100644 --- a/src/js/init.js +++ b/src/js/init.js @@ -10,13 +10,40 @@ document.addEventListener('DOMContentLoaded', function (e) { // set focus events for all charts matching maidr ids let maidrObjects = []; - if (typeof maidr != 'undefined') { - if (!Array.isArray(maidr)) { - maidrObjects.push(maidr); + + // First check for globally defined maidr variable (script tag method) + if (typeof window.maidr !== 'undefined') { + if (!Array.isArray(window.maidr)) { + maidrObjects.push(window.maidr); } else { - maidrObjects = maidr; + maidrObjects = maidrObjects.concat(window.maidr); } } + + // Then look for elements with maidr attribute + const elementsWithMaidrAttr = document.querySelectorAll('[maidr]'); + elementsWithMaidrAttr.forEach(element => { + try { + const maidrData = JSON.parse(element.getAttribute('maidr')); + // If id is not provided in the JSON, use the element's id + if (!maidrData.id) { + if (element.id) { + maidrData.id = element.id; + } else { + // Generate a random id if none exists + element.id = 'maidr-' + Math.random().toString(36).substr(2, 9); + maidrData.id = element.id; + } + } + // Check if this id already exists in maidrObjects to avoid duplicates + if (!maidrObjects.some(obj => obj.id === maidrData.id)) { + maidrObjects.push(maidrData); + } + } catch (e) { + console.error('Failed to parse maidr attribute:', e); + } + }); + // set focus events for all maidr ids DestroyMaidr(); // just in case window.maidrIds = [];