Skip to content

Commit

Permalink
version 1.2.2
Browse files Browse the repository at this point in the history
- bug fix: filled matrix elements vanished after resizing the matrix
- minor bug fixes
  • Loading branch information
andreas-schwenk committed Mar 15, 2024
1 parent 4e71eb0 commit 77127eb
Show file tree
Hide file tree
Showing 6 changed files with 510 additions and 484 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v1.2.2

- bug fix: filled matrix elements vanished after resizing the matrix
- minor bug fixes

# v1.2.1

- feedback for unfilled input fields
Expand Down
4 changes: 2 additions & 2 deletions docs/ex1.html

Large diffs are not rendered by default.

939 changes: 472 additions & 467 deletions sell.py

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion web/src/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export function evalQuestion(question) {
for (let j = 0; j < mat.n; j++) {
let idx = i * mat.n + j;
student = question.student[id + "-" + idx];
if (student.length == 0) isComplete = false;
if (student != undefined && student.length == 0) isComplete = false;
let e = mat.v[idx];
try {
let u = Term.parse(e);
Expand Down
40 changes: 28 additions & 12 deletions web/src/input.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,20 @@ export class GapInput {
* @param {string} solutionString -- the sample solution
*/
constructor(parent, question, inputId, solutionString) {
// initialize the students answer to "unset"
question.student[inputId] = "";
/** @type {Question} */
this.question = question;
/** @type {string} */
this.inputId = inputId;
if (inputId.length == 0) {
// generate a new id, if the input does not correspond to a variable,
// but the solution was given directly as string in the text.
this.inputId = "gap-" + question.gapIdx;
this.inputId = inputId = "gap-" + question.gapIdx;
question.types[this.inputId] = "string";
question.expected[this.inputId] = solutionString;
question.gapIdx++;
}
// initialize the students answer to "unset" in case it does not yet exist
if (inputId in question.student == false) question.student[inputId] = "";
// split the solution string into single answers
let expectedList = solutionString.split("|");
// get the maximum number of characters (to estimate the width of the input)
Expand Down Expand Up @@ -86,17 +86,19 @@ export class TermInput {
* @param {number} numChars -- number of characters for the width-estimation
* @param {string} solutionString -- the sample solution
* @param {boolean} integersOnly -- if true, then only numbers can be entered
* @param {boolean} forceSolution -- if true, the solution string will be set, regardless of question.showSolution
*/
constructor(
parent,
question,
inputId,
numChars,
solutionString,
integersOnly
integersOnly,
forceSolution = false
) {
// initialize the students answer to "unset"
question.student[inputId] = "";
// initialize the students answer to "unset" in case it does not yet exist
if (inputId in question.student == false) question.student[inputId] = "";
/** @type {Question} */
this.question = question;
/** @type {string} */
Expand Down Expand Up @@ -149,7 +151,7 @@ export class TermInput {
this.inputElement.style.width = "" + requiredWidth + "px";
});
// for debugging purposes
if (this.question.showSolution)
if (forceSolution || this.question.showSolution)
question.student[inputId] = this.inputElement.value = solutionString;
}

Expand Down Expand Up @@ -207,13 +209,14 @@ export class MatrixInput {
);
if (question.showSolution) this.matStudent.fromMatrix(this.matExpected);
// generate the DOM
this.genMatrixDom();
this.genMatrixDom(true);
}

/**
* Generate the DOM (HTMLTable and children)
* @param {boolean} initial -- true, iff generated the first time
*/
genMatrixDom() {
genMatrixDom(initial) {
// we need an additional HTMLDivElement that contains both the table for the
// matrix, as well as the resizing buttons ("+" and "-")
let div = genDiv();
Expand Down Expand Up @@ -247,7 +250,8 @@ export class MatrixInput {
elementId,
maxCellStrlen,
this.matStudent.v[idx],
false
false,
!initial
);
}
// insert a column for the right (rendered by a bordered HTMLDivElement)
Expand Down Expand Up @@ -290,12 +294,24 @@ export class MatrixInput {
btn.style.opacity = "0.5";
} else {
btn.addEventListener("click", () => {
// set values from input to matrix elements
for (let u = 0; u < this.matStudent.m; u++) {
for (let v = 0; v < this.matStudent.n; v++) {
let idx = u * this.matStudent.n + v;
let id = this.inputId + "-" + idx;
let value = this.question.student[id];
this.matStudent.v[idx] = value;
delete this.question.student[id];
}
}
// resize matrix (and reuse old values if feasible)
this.matStudent.resize(
this.matStudent.m + deltaM[i],
this.matStudent.n + deltaN[i],
"0"
""
);
this.genMatrixDom();
// generate DOM
this.genMatrixDom(false);
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions web/src/math.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ export class Matrix {
}

/**
* Returns the term of element (i,j), or "0" if the index is invalid.
* Returns the term of element (i,j), or "" if the index is invalid.
* @param {number} i
* @param {number} j
* @returns {string}
*/
getElement(i, j) {
if (i < 0 || i >= this.m || j < 0 || j >= this.n) return "0";
if (i < 0 || i >= this.m || j < 0 || j >= this.n) return "";
return this.v[i * this.n + j];
}

Expand Down

0 comments on commit 77127eb

Please sign in to comment.