Skip to content

Commit

Permalink
fixed table move for nw and gotoh
Browse files Browse the repository at this point in the history
  • Loading branch information
domonik committed Nov 30, 2023
1 parent bee9575 commit 46bd991
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
41 changes: 41 additions & 0 deletions assets/js/gotoh.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,3 +547,44 @@ function previousCellsCorrect(seq1, seq2, scoring, dMatrix, pMatrix, qMatrix, ce
return prevCells;
}

function tableMove(event) {
const currentCell = event.target.parentElement;
const currentRow = currentCell.parentElement;
const currentRowIndex = currentRow.rowIndex;
const currentCellIndex = currentCell.cellIndex;
const table = currentRow.parentElement;

let nextCell;

switch (event.key) {
case 'ArrowUp':
nextCell = table.rows[currentRowIndex - 1]?.cells[currentCellIndex];
break;
case 'ArrowDown':
nextCell = table.rows[currentRowIndex + 1]?.cells[currentCellIndex];
break;
case 'ArrowLeft':
nextCell = currentCellIndex > 0 ? currentRow.cells[currentCellIndex - 1] : null;
break;
case 'ArrowRight':
nextCell = currentRow.cells[currentCellIndex + 1];
break;
default:
break;
}

if (nextCell && nextCell.querySelector('input')) {
nextCell.querySelector('input').focus();
event.preventDefault();
}
}


document.addEventListener('DOMContentLoaded', function () {
const tabled = document.getElementById('tableD');
tabled.addEventListener('keydown', tableMove);
const tableq = document.getElementById('tableQ');
tableq.addEventListener('keydown', tableMove);
const tablep = document.getElementById('tableP');
tablep.addEventListener('keydown', tableMove);
});
37 changes: 37 additions & 0 deletions assets/js/needlemanwunsch.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,40 @@ function needlemanWunsch(seqA, seqB, matchScore, mismatchScore, gapPenalty) {

return matrix;
}


document.addEventListener('DOMContentLoaded', function () {
const table = document.getElementById('table1');

table.addEventListener('keydown', function (event) {
const currentCell = event.target.parentElement;
const currentRow = currentCell.parentElement;
const currentRowIndex = currentRow.rowIndex;
const currentCellIndex = currentCell.cellIndex;

let nextCell;

switch (event.key) {
case 'ArrowUp':
nextCell = table.rows[currentRowIndex - 1]?.cells[currentCellIndex];
break;
case 'ArrowDown':
nextCell = table.rows[currentRowIndex + 1]?.cells[currentCellIndex];
break;
case 'ArrowLeft':
nextCell = currentCellIndex > 0 ? currentRow.cells[currentCellIndex - 1] : null;
break;
case 'ArrowRight':
nextCell = currentRow.cells[currentCellIndex + 1];
break;
default:
break;
}

if (nextCell && nextCell.querySelector('input')) {
nextCell.querySelector('input').focus();
event.preventDefault();
}
});
});

0 comments on commit 46bd991

Please sign in to comment.