Skip to content

Commit

Permalink
feat: allow shift select, select all, copy, in review mode (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellvix authored Sep 24, 2024
1 parent 5d9e0df commit 2a839f3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
7 changes: 5 additions & 2 deletions src/js/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,12 @@ class Control {
constants.review,
'keydown',
function (e) {
// allow arrow keys only. BTSR handled above
// allow arrow keys only, shift arrow keys, ctrl a and ctrl c
if (
!['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown'].includes(e.key)
!e.key.startsWith('Arrow') && // Arrow keys
!(e.shiftKey && e.key.startsWith('Arrow')) && // Shift + Arrow
!(e.ctrlKey && e.key === 'a') && // Ctrl + A
!(e.ctrlKey && e.key === 'c') // Ctrl + C
) {
e.preventDefault();
}
Expand Down
25 changes: 17 additions & 8 deletions src/js/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,25 +114,34 @@ function InitMaidr(thisMaidr) {

// once everything is set up, announce the chart name (or title as a backup) to the user
setTimeout(function () {
// this is hacky, but we delay just a tick so that the chart has time to load
if ('name' in singleMaidr) {
display.announceText(singleMaidr.name);
} else if ('title' in singleMaidr || 'labels' in singleMaidr && 'title' in singleMaidr.labels) {
let title = 'title' in singleMaidr ? singleMaidr.title : singleMaidr.labels.title;
} else if (
'title' in singleMaidr ||
('labels' in singleMaidr && 'title' in singleMaidr.labels)
) {
let title =
'title' in singleMaidr ? singleMaidr.title : singleMaidr.labels.title;

// Determine whether type is multiple or single. If multiple, put commas and "and" in between. If single, just put the type.
let plotTypeString = Array.isArray(singleMaidr.type)
? singleMaidr.type.slice(0, -1).join(', ') + ' and ' + singleMaidr.type.slice(-1)
let plotTypeString = Array.isArray(singleMaidr.type)
? singleMaidr.type.slice(0, -1).join(', ') +
' and ' +
singleMaidr.type.slice(-1)
: singleMaidr.type;

// Prepare the instruction text for multi-layered plot
let multiLayerInstruction = 'This is a multi-layered plot. Use PageUp and PageDown to switch between layers.';
let multiLayerInstruction =
'This is a multi-layered plot. Use PageUp and PageDown to switch between layers.';

// Check if plotTypeString has multiple types
let isMultiLayered = Array.isArray(singleMaidr.type) && singleMaidr.type.length > 1;
let isMultiLayered =
Array.isArray(singleMaidr.type) && singleMaidr.type.length > 1;

// Construct the final announceText string
let announceText = `${plotTypeString} plot of ${title}: Use Arrows to navigate data points. ${isMultiLayered ? multiLayerInstruction : ' '}Toggle B for Braille, T for Text, S for Sonification, and R for Review mode. Use H for Help.`;
let announceText = `${plotTypeString} plot of ${title}: Use Arrows to navigate data points. ${
isMultiLayered ? multiLayerInstruction : ' '
}Toggle B for Braille, T for Text, S for Sonification, and R for Review mode. Use H for Help.`;

// Display the announcement text
display.announceText(announceText);
Expand Down

0 comments on commit 2a839f3

Please sign in to comment.