maidr 2.25.1 → 2.26.0
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 +196 -4
- 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
|
|
@@ -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,197 @@ 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
|
+
document,
|
|
8898
|
+
'mousemove',
|
|
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 (
|
|
9008
|
+
position.x != Math.floor(index / plot.num_rows) ||
|
|
9009
|
+
position.y != plot.num_rows - (index % plot.num_rows) - 1
|
|
9010
|
+
) {
|
|
9011
|
+
position.x = Math.floor(index / plot.num_rows);
|
|
9012
|
+
position.y = plot.num_rows - (index % plot.num_rows) - 1;
|
|
9013
|
+
control.UpdateAll();
|
|
9014
|
+
}
|
|
9015
|
+
} else if (constants.chartType == 'line') {
|
|
9016
|
+
// compare coordinates and get the point we're closest to, if we're within 24px
|
|
9017
|
+
let chartBounds = constants.chart.getBoundingClientRect();
|
|
9018
|
+
let scaleX =
|
|
9019
|
+
constants.chart.viewBox.baseVal.width / chartBounds.width;
|
|
9020
|
+
let scaleY =
|
|
9021
|
+
constants.chart.viewBox.baseVal.height / chartBounds.height;
|
|
9022
|
+
|
|
9023
|
+
let closestDistance = Infinity;
|
|
9024
|
+
let closestIndex = -1;
|
|
9025
|
+
let clickX = (e.clientX - chartBounds.left) * scaleX;
|
|
9026
|
+
let clickY = (e.clientY - chartBounds.top) * scaleY;
|
|
9027
|
+
let pointX, pointY;
|
|
9028
|
+
for (let i = 0; i < plot.chartLineX.length; i++) {
|
|
9029
|
+
pointX = plot.chartLineX[i] - chartBounds.left;
|
|
9030
|
+
pointY = plot.chartLineY[i] - chartBounds.top;
|
|
9031
|
+
let distance = Math.sqrt(
|
|
9032
|
+
(pointX - clickX) ** 2 + (pointY - clickY) ** 2
|
|
9033
|
+
);
|
|
9034
|
+
//console.log( 'distance', distance, 'given clicked coords (', clickX, ', ', clickY, ') and target coords (', pointX, ', ', pointY, ')');
|
|
9035
|
+
if (distance < closestDistance) {
|
|
9036
|
+
closestDistance = distance;
|
|
9037
|
+
closestIndex = i;
|
|
9038
|
+
}
|
|
9039
|
+
}
|
|
9040
|
+
if (closestDistance < 24) {
|
|
9041
|
+
if (position.x != closestIndex) {
|
|
9042
|
+
position.x = closestIndex;
|
|
9043
|
+
control.UpdateAll();
|
|
9044
|
+
}
|
|
9045
|
+
}
|
|
9046
|
+
} else if (
|
|
9047
|
+
constants.chartType == 'stacked_bar' ||
|
|
9048
|
+
constants.chartType == 'stacked_normalized_bar' ||
|
|
9049
|
+
constants.chartType == 'dodged_bar'
|
|
9050
|
+
) {
|
|
9051
|
+
// check if we've hit a selector
|
|
9052
|
+
if (e.target.matches(singleMaidr.selector)) {
|
|
9053
|
+
outerLoop: for (let i = 0; i < plot.elements.length; i++) {
|
|
9054
|
+
for (let j = 0; j < plot.elements[i].length; j++) {
|
|
9055
|
+
if (plot.elements[i][j] == e.target) {
|
|
9056
|
+
if (position.x != i || position.y != j) {
|
|
9057
|
+
position.x = i;
|
|
9058
|
+
position.y = j;
|
|
9059
|
+
control.UpdateAll();
|
|
9060
|
+
}
|
|
9061
|
+
break outerLoop;
|
|
9062
|
+
}
|
|
9063
|
+
}
|
|
9064
|
+
}
|
|
9065
|
+
}
|
|
9066
|
+
}
|
|
9067
|
+
},
|
|
9068
|
+
]);
|
|
9069
|
+
}
|
|
9070
|
+
}
|
|
9071
|
+
}
|
|
9072
|
+
|
|
8881
9073
|
/**
|
|
8882
9074
|
* Sets up event listeners for main controls
|
|
8883
9075
|
* - Arrow keys: basic motion
|
|
@@ -8890,7 +9082,7 @@ class Control {
|
|
|
8890
9082
|
*
|
|
8891
9083
|
* @returns {void}
|
|
8892
9084
|
*/
|
|
8893
|
-
async
|
|
9085
|
+
async SetKeyControls() {
|
|
8894
9086
|
constants.events.push([
|
|
8895
9087
|
document,
|
|
8896
9088
|
'keydown',
|