maidr 2.25.1 → 2.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/maidr.js +225 -11
- package/dist/maidr.min.js +1 -1
- package/package.json +1 -1
package/dist/maidr.js
CHANGED
|
@@ -1492,7 +1492,7 @@ class Menu {
|
|
|
1492
1492
|
}
|
|
1493
1493
|
|
|
1494
1494
|
if (constants.emailAuthKey && constants.clientToken) {
|
|
1495
|
-
console.log('email auth key and client token found');
|
|
1495
|
+
//console.log('email auth key and client token found');
|
|
1496
1496
|
for (let model in constants.LLMModels) {
|
|
1497
1497
|
document.getElementById(`LLM_model_${model}`).checked = true;
|
|
1498
1498
|
}
|
|
@@ -2731,7 +2731,7 @@ class ChatLLM {
|
|
|
2731
2731
|
const API_KEY = constants.geminiAuthKey;
|
|
2732
2732
|
const genAI = new GoogleGenerativeAI(API_KEY);
|
|
2733
2733
|
const model = genAI.getGenerativeModel({
|
|
2734
|
-
model: 'gemini-
|
|
2734
|
+
model: 'gemini-2.0-flash-exp',
|
|
2735
2735
|
}); // old model was 'gemini-pro-vision'
|
|
2736
2736
|
|
|
2737
2737
|
// Create the prompt
|
|
@@ -4812,7 +4812,7 @@ class Display {
|
|
|
4812
4812
|
}
|
|
4813
4813
|
verboseText += plot.pointValuesX[position.x] + ', ';
|
|
4814
4814
|
if (plot.plotLegend) {
|
|
4815
|
-
plot.plotLegend.y + ' is ';
|
|
4815
|
+
verboseText += plot.plotLegend.y + ' is ';
|
|
4816
4816
|
}
|
|
4817
4817
|
verboseText += plot.pointValuesY[position.x];
|
|
4818
4818
|
|
|
@@ -8615,7 +8615,8 @@ class Control {
|
|
|
8615
8615
|
this.InitChartClass();
|
|
8616
8616
|
this.SetBTSControls();
|
|
8617
8617
|
this.SetPrefixControls();
|
|
8618
|
-
this.
|
|
8618
|
+
this.SetKeyControls();
|
|
8619
|
+
this.SetMouseControls();
|
|
8619
8620
|
}
|
|
8620
8621
|
|
|
8621
8622
|
/**
|
|
@@ -8878,6 +8879,199 @@ class Control {
|
|
|
8878
8879
|
]);
|
|
8879
8880
|
}
|
|
8880
8881
|
|
|
8882
|
+
/**
|
|
8883
|
+
* Sets up event listeners for mouse controls
|
|
8884
|
+
* If you're on a chart, and within 24px of a point, set your position there and update the chart
|
|
8885
|
+
* If you're near multiple, figure it out.
|
|
8886
|
+
* This requires the selector to be set in the maidr object.
|
|
8887
|
+
* @returns {void}
|
|
8888
|
+
*/
|
|
8889
|
+
SetMouseControls() {
|
|
8890
|
+
// to set this up, we run the event at the document level, and then deal with what we've hovered on in individual chart types
|
|
8891
|
+
// for bar hist stacked, we check if we've hovered on an element of the selector
|
|
8892
|
+
// for box line, we use coordinates and find the closest point
|
|
8893
|
+
if ('selector' in singleMaidr) {
|
|
8894
|
+
let selectorElems = document.querySelectorAll(singleMaidr.selector);
|
|
8895
|
+
if (selectorElems.length > 0) {
|
|
8896
|
+
constants.events.push([
|
|
8897
|
+
constants.chart,
|
|
8898
|
+
['mousemove', 'touchmove'],
|
|
8899
|
+
function (e) {
|
|
8900
|
+
if (constants.chartType == 'bar' || constants.chartType == 'hist') {
|
|
8901
|
+
// check if we've hit a selector
|
|
8902
|
+
if (e.target.matches(singleMaidr.selector)) {
|
|
8903
|
+
let index = Array.from(selectorElems).indexOf(e.target);
|
|
8904
|
+
if (index != position.x) {
|
|
8905
|
+
position.x = index;
|
|
8906
|
+
control.UpdateAll();
|
|
8907
|
+
}
|
|
8908
|
+
}
|
|
8909
|
+
} else if (constants.chartType == 'box') {
|
|
8910
|
+
// here follows a nasty function where we use bounding boxes from the highlight feature compare to our hover coords
|
|
8911
|
+
let closestDistance = Infinity;
|
|
8912
|
+
let closestIndex = -1;
|
|
8913
|
+
let clickX = e.clientX;
|
|
8914
|
+
let clickY = e.clientY;
|
|
8915
|
+
let expandedBox = null;
|
|
8916
|
+
let padding = 15;
|
|
8917
|
+
const chartBounds = constants.chart.getBoundingClientRect();
|
|
8918
|
+
|
|
8919
|
+
// Iterate through plot.plotBounds using regular loops
|
|
8920
|
+
for (
|
|
8921
|
+
let groupIndex = 0;
|
|
8922
|
+
groupIndex < plot.plotBounds.length;
|
|
8923
|
+
groupIndex++
|
|
8924
|
+
) {
|
|
8925
|
+
const group = plot.plotBounds[groupIndex];
|
|
8926
|
+
|
|
8927
|
+
for (let boxIndex = 0; boxIndex < group.length; boxIndex++) {
|
|
8928
|
+
const box = group[boxIndex];
|
|
8929
|
+
|
|
8930
|
+
if (
|
|
8931
|
+
box.top === undefined ||
|
|
8932
|
+
box.left === undefined ||
|
|
8933
|
+
box.bottom === undefined ||
|
|
8934
|
+
box.right === undefined
|
|
8935
|
+
) {
|
|
8936
|
+
continue; // Skip invalid boxes
|
|
8937
|
+
}
|
|
8938
|
+
// Expand the bounding box by 15px
|
|
8939
|
+
let expandedBoxAdjustedCoords = {
|
|
8940
|
+
x: box.left - padding - chartBounds.left,
|
|
8941
|
+
y: box.top - padding - chartBounds.top,
|
|
8942
|
+
width: box.width + padding * 2,
|
|
8943
|
+
height: box.height + padding * 2,
|
|
8944
|
+
};
|
|
8945
|
+
expandedBox = {
|
|
8946
|
+
top: expandedBoxAdjustedCoords.y,
|
|
8947
|
+
left: expandedBoxAdjustedCoords.x,
|
|
8948
|
+
bottom:
|
|
8949
|
+
expandedBoxAdjustedCoords.y +
|
|
8950
|
+
expandedBoxAdjustedCoords.height,
|
|
8951
|
+
right:
|
|
8952
|
+
expandedBoxAdjustedCoords.x +
|
|
8953
|
+
expandedBoxAdjustedCoords.width,
|
|
8954
|
+
};
|
|
8955
|
+
// Calculate the center of the bounding box
|
|
8956
|
+
const centerX = (expandedBox.left + expandedBox.right) / 2;
|
|
8957
|
+
const centerY = (expandedBox.top + expandedBox.bottom) / 2;
|
|
8958
|
+
|
|
8959
|
+
// Calculate the Euclidean distance
|
|
8960
|
+
const distance = Math.sqrt(
|
|
8961
|
+
(centerX - clickX) ** 2 + (centerY - clickY) ** 2
|
|
8962
|
+
);
|
|
8963
|
+
|
|
8964
|
+
//console.log( 'clicked coords: (', clickX, ', ', clickY, ') | box coords: (', centerX, ', ', centerY, ') | distance: ', distance, 'array index: [', groupIndex, ',', boxIndex, ']');
|
|
8965
|
+
|
|
8966
|
+
// Update the closest box if this one is nearer, and is inside the bounding box
|
|
8967
|
+
if (distance < closestDistance) {
|
|
8968
|
+
if (
|
|
8969
|
+
clickX >= expandedBox.left &&
|
|
8970
|
+
clickX <= expandedBox.right &&
|
|
8971
|
+
clickY >= expandedBox.top &&
|
|
8972
|
+
clickY <= expandedBox.bottom
|
|
8973
|
+
) {
|
|
8974
|
+
closestDistance = distance;
|
|
8975
|
+
closestIndex = [groupIndex, boxIndex];
|
|
8976
|
+
}
|
|
8977
|
+
}
|
|
8978
|
+
}
|
|
8979
|
+
}
|
|
8980
|
+
|
|
8981
|
+
// did we get one?
|
|
8982
|
+
if (closestDistance < Infinity) {
|
|
8983
|
+
//console.log('found a box, index', closestIndex);
|
|
8984
|
+
if (constants.plotOrientation == 'horz') {
|
|
8985
|
+
if (
|
|
8986
|
+
position.x != closestIndex[0] ||
|
|
8987
|
+
position.y != closestIndex[1]
|
|
8988
|
+
) {
|
|
8989
|
+
position.x = closestIndex[1];
|
|
8990
|
+
position.y = closestIndex[0];
|
|
8991
|
+
control.UpdateAll();
|
|
8992
|
+
}
|
|
8993
|
+
} else {
|
|
8994
|
+
if (
|
|
8995
|
+
position.x != closestIndex[0] ||
|
|
8996
|
+
position.y != closestIndex[1]
|
|
8997
|
+
) {
|
|
8998
|
+
position.x = closestIndex[0];
|
|
8999
|
+
position.y = closestIndex[1];
|
|
9000
|
+
control.UpdateAll();
|
|
9001
|
+
}
|
|
9002
|
+
}
|
|
9003
|
+
}
|
|
9004
|
+
} else if (constants.chartType == 'heat') {
|
|
9005
|
+
// check if we've hit a selector
|
|
9006
|
+
let index = Array.from(selectorElems).indexOf(e.target);
|
|
9007
|
+
if (index != -1) {
|
|
9008
|
+
if (
|
|
9009
|
+
position.x != Math.floor(index / plot.num_rows) ||
|
|
9010
|
+
position.y != plot.num_rows - (index % plot.num_rows) - 1
|
|
9011
|
+
) {
|
|
9012
|
+
position.x = Math.floor(index / plot.num_rows);
|
|
9013
|
+
position.y = plot.num_rows - (index % plot.num_rows) - 1;
|
|
9014
|
+
control.UpdateAll();
|
|
9015
|
+
}
|
|
9016
|
+
}
|
|
9017
|
+
} else if (constants.chartType == 'line') {
|
|
9018
|
+
// compare coordinates and get the point we're closest to, if we're within 24px
|
|
9019
|
+
let chartBounds = constants.chart.getBoundingClientRect();
|
|
9020
|
+
let scaleX =
|
|
9021
|
+
constants.chart.viewBox.baseVal.width / chartBounds.width;
|
|
9022
|
+
let scaleY =
|
|
9023
|
+
constants.chart.viewBox.baseVal.height / chartBounds.height;
|
|
9024
|
+
|
|
9025
|
+
let closestDistance = Infinity;
|
|
9026
|
+
let closestIndex = -1;
|
|
9027
|
+
let clickX = (e.clientX - chartBounds.left) * scaleX;
|
|
9028
|
+
let clickY = (e.clientY - chartBounds.top) * scaleY;
|
|
9029
|
+
let pointX, pointY;
|
|
9030
|
+
for (let i = 0; i < plot.chartLineX.length; i++) {
|
|
9031
|
+
pointX = plot.chartLineX[i] - chartBounds.left;
|
|
9032
|
+
pointY = plot.chartLineY[i] - chartBounds.top;
|
|
9033
|
+
let distance = Math.sqrt(
|
|
9034
|
+
(pointX - clickX) ** 2 + (pointY - clickY) ** 2
|
|
9035
|
+
);
|
|
9036
|
+
//console.log( 'distance', distance, 'given clicked coords (', clickX, ', ', clickY, ') and target coords (', pointX, ', ', pointY, ')');
|
|
9037
|
+
if (distance < closestDistance) {
|
|
9038
|
+
closestDistance = distance;
|
|
9039
|
+
closestIndex = i;
|
|
9040
|
+
}
|
|
9041
|
+
}
|
|
9042
|
+
if (closestDistance < 24) {
|
|
9043
|
+
if (position.x != closestIndex) {
|
|
9044
|
+
position.x = closestIndex;
|
|
9045
|
+
control.UpdateAll();
|
|
9046
|
+
}
|
|
9047
|
+
}
|
|
9048
|
+
} else if (
|
|
9049
|
+
constants.chartType == 'stacked_bar' ||
|
|
9050
|
+
constants.chartType == 'stacked_normalized_bar' ||
|
|
9051
|
+
constants.chartType == 'dodged_bar'
|
|
9052
|
+
) {
|
|
9053
|
+
// check if we've hit a selector
|
|
9054
|
+
if (e.target.matches(singleMaidr.selector)) {
|
|
9055
|
+
outerLoop: for (let i = 0; i < plot.elements.length; i++) {
|
|
9056
|
+
for (let j = 0; j < plot.elements[i].length; j++) {
|
|
9057
|
+
if (plot.elements[i][j] == e.target) {
|
|
9058
|
+
if (position.x != i || position.y != j) {
|
|
9059
|
+
position.x = i;
|
|
9060
|
+
position.y = j;
|
|
9061
|
+
control.UpdateAll();
|
|
9062
|
+
}
|
|
9063
|
+
break outerLoop;
|
|
9064
|
+
}
|
|
9065
|
+
}
|
|
9066
|
+
}
|
|
9067
|
+
}
|
|
9068
|
+
}
|
|
9069
|
+
},
|
|
9070
|
+
]);
|
|
9071
|
+
}
|
|
9072
|
+
}
|
|
9073
|
+
}
|
|
9074
|
+
|
|
8881
9075
|
/**
|
|
8882
9076
|
* Sets up event listeners for main controls
|
|
8883
9077
|
* - Arrow keys: basic motion
|
|
@@ -8890,7 +9084,7 @@ class Control {
|
|
|
8890
9084
|
*
|
|
8891
9085
|
* @returns {void}
|
|
8892
9086
|
*/
|
|
8893
|
-
async
|
|
9087
|
+
async SetKeyControls() {
|
|
8894
9088
|
constants.events.push([
|
|
8895
9089
|
document,
|
|
8896
9090
|
'keydown',
|
|
@@ -11942,17 +12136,37 @@ function SetEvents() {
|
|
|
11942
12136
|
// add all events
|
|
11943
12137
|
for (let i = 0; i < constants.events.length; i++) {
|
|
11944
12138
|
if (Array.isArray(constants.events[i][0])) {
|
|
12139
|
+
// sometimes we have multiple elements to apply the same event to in the [i][0] spot
|
|
11945
12140
|
for (let j = 0; j < constants.events[i][0].length; j++) {
|
|
11946
|
-
|
|
12141
|
+
// and sometimes we have multiple event types in [i][1]
|
|
12142
|
+
if (Array.isArray(constants.events[i][1])) {
|
|
12143
|
+
for (let k = 0; k < constants.events[i][1].length; k++) {
|
|
12144
|
+
constants.events[i][0][j]?.addEventListener(
|
|
12145
|
+
constants.events[i][1][k],
|
|
12146
|
+
constants.events[i][2]
|
|
12147
|
+
);
|
|
12148
|
+
}
|
|
12149
|
+
} else {
|
|
12150
|
+
constants.events[i][0][j]?.addEventListener(
|
|
12151
|
+
constants.events[i][1],
|
|
12152
|
+
constants.events[i][2]
|
|
12153
|
+
);
|
|
12154
|
+
}
|
|
12155
|
+
}
|
|
12156
|
+
} else {
|
|
12157
|
+
if (Array.isArray(constants.events[i][1])) {
|
|
12158
|
+
for (let j = 0; j < constants.events[i][1].length; j++) {
|
|
12159
|
+
constants.events[i][0]?.addEventListener(
|
|
12160
|
+
constants.events[i][1][j],
|
|
12161
|
+
constants.events[i][2]
|
|
12162
|
+
);
|
|
12163
|
+
}
|
|
12164
|
+
} else {
|
|
12165
|
+
constants.events[i][0]?.addEventListener(
|
|
11947
12166
|
constants.events[i][1],
|
|
11948
12167
|
constants.events[i][2]
|
|
11949
12168
|
);
|
|
11950
12169
|
}
|
|
11951
|
-
} else {
|
|
11952
|
-
constants.events[i][0]?.addEventListener(
|
|
11953
|
-
constants.events[i][1],
|
|
11954
|
-
constants.events[i][2]
|
|
11955
|
-
);
|
|
11956
12170
|
}
|
|
11957
12171
|
}
|
|
11958
12172
|
// add all post load events
|