From 96903e0266d47727c9be617078169ee946a35497 Mon Sep 17 00:00:00 2001 From: RebeccaHirst <30597180+RebeccaHirst@users.noreply.github.com> Date: Thu, 6 Jan 2022 16:39:08 +0000 Subject: [PATCH 01/12] add linspace to util.js --- src/util/Util.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/util/Util.js b/src/util/Util.js index 2e01674..3d93bbf 100644 --- a/src/util/Util.js +++ b/src/util/Util.js @@ -358,6 +358,24 @@ export function shuffle(array, randomNumberGenerator = undefined) return array; } +/** + * linspace + * + * @name module:util.linspace + * @function + * @public + * @param {Object[]} startValue, stopValue, cardinality + * @return {Object[]} an array from startValue to stopValue with cardinality steps + */ +export function linspace(startValue, stopValue, cardinality) { + var arr = []; + var step = (stopValue - startValue) / (cardinality - 1); + for (var i = 0; i < cardinality; i++) { + arr.push(startValue + (step * i)); + } + return arr; +} + /** * Pick a random value from an array, uses `util.shuffle` to shuffle the array and returns the last value. * From 04669d28b3d484d2f016f1372f96d69851c6b747 Mon Sep 17 00:00:00 2001 From: Todd Parsons Date: Thu, 14 Jul 2022 11:08:53 +0100 Subject: [PATCH 02/12] NF: Add "arrow" as recognised named shape in ShapeStim --- src/visual/ShapeStim.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/visual/ShapeStim.js b/src/visual/ShapeStim.js index cb74cef..3439b70 100644 --- a/src/visual/ShapeStim.js +++ b/src/visual/ShapeStim.js @@ -371,4 +371,14 @@ ShapeStim.KnownShapes = { [-0.39, 0.31], [-0.09, 0.18], ], + + arrow: [ + [0.0, 0.5], + [-0.5, 0.0], + [-1/6, 0.0], + [-1/6, -0.5], + [1/6, -0.5], + [1/6, 0.0], + [0.5, 0.0], + ], }; From 11bddceb804517e4bf431a2a276ae854301d4855 Mon Sep 17 00:00:00 2001 From: Todd Parsons Date: Thu, 14 Jul 2022 11:09:12 +0100 Subject: [PATCH 03/12] ENH: Add other shapes from Python to ShapeStim --- src/visual/ShapeStim.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/visual/ShapeStim.js b/src/visual/ShapeStim.js index 3439b70..b5925e3 100644 --- a/src/visual/ShapeStim.js +++ b/src/visual/ShapeStim.js @@ -372,6 +372,19 @@ ShapeStim.KnownShapes = { [-0.09, 0.18], ], + triangle: [ + [+0.0, 0.5], // Point + [-0.5, -0.5], // Bottom left + [+0.5, -0.5], // Bottom right + ], + + rectangle: [ + [-.5, .5], // Top left + [ .5, .5], // Top right + [ .5, -.5], // Bottom left + [-.5, -.5], // Bottom right + ], + arrow: [ [0.0, 0.5], [-0.5, 0.0], From 2dbfc9c43c4a8e0c65c3273181f1b0671a064cb2 Mon Sep 17 00:00:00 2001 From: lgtst Date: Mon, 24 Oct 2022 13:19:44 +0100 Subject: [PATCH 04/12] xlsx upgrade due to a string parsing bug; --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 7a9b92c..6477532 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "pixi.js-legacy": "^6.0.4", "seedrandom": "^3.0.5", "tone": "^14.7.77", - "xlsx": "^0.17.0" + "xlsx": "^0.18.5" }, "devDependencies": { "csslint": "^1.0.5", From c4c7cd8747374f85d60bb1de44d040f06544d59e Mon Sep 17 00:00:00 2001 From: tpronk Date: Fri, 9 Dec 2022 16:19:30 +0000 Subject: [PATCH 05/12] Update node version to 16 --- .github/workflows/Automated Test (short).yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Automated Test (short).yml b/.github/workflows/Automated Test (short).yml index 7d6001b..1c2ccdd 100644 --- a/.github/workflows/Automated Test (short).yml +++ b/.github/workflows/Automated Test (short).yml @@ -45,7 +45,7 @@ jobs: - name: Setup node uses: actions/setup-node@v1 with: - node-version: '12' + node-version: '16' # START: install psychojs_testing - name: Checkout psychojs_testing From 4e3d11ff6c894b6bb03bd81460f13eb8aae54d6e Mon Sep 17 00:00:00 2001 From: tpronk Date: Mon, 12 Dec 2022 16:17:50 +0000 Subject: [PATCH 06/12] BF: Downgrade node version to 14 --- .github/workflows/Automated Test (short).yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Automated Test (short).yml b/.github/workflows/Automated Test (short).yml index 1c2ccdd..68bc285 100644 --- a/.github/workflows/Automated Test (short).yml +++ b/.github/workflows/Automated Test (short).yml @@ -45,7 +45,7 @@ jobs: - name: Setup node uses: actions/setup-node@v1 with: - node-version: '16' + node-version: '14' # START: install psychojs_testing - name: Checkout psychojs_testing From 49512063a73aa784f5d3bf255f3d1255c26cd3ed Mon Sep 17 00:00:00 2001 From: tpronk Date: Mon, 12 Dec 2022 16:27:36 +0000 Subject: [PATCH 07/12] Upgrade to node 15 --- .github/workflows/Automated Test (short).yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Automated Test (short).yml b/.github/workflows/Automated Test (short).yml index 68bc285..8d25449 100644 --- a/.github/workflows/Automated Test (short).yml +++ b/.github/workflows/Automated Test (short).yml @@ -45,7 +45,7 @@ jobs: - name: Setup node uses: actions/setup-node@v1 with: - node-version: '14' + node-version: '15' # START: install psychojs_testing - name: Checkout psychojs_testing From 941b4425b980f430de569cc65948f1e6c6a8a3e4 Mon Sep 17 00:00:00 2001 From: tpronk Date: Tue, 13 Dec 2022 19:49:13 +0000 Subject: [PATCH 08/12] Upgrade to node 15 --- .github/workflows/Automated Test (full).yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/Automated Test (full).yml b/.github/workflows/Automated Test (full).yml index cc81b62..3fc879a 100644 --- a/.github/workflows/Automated Test (full).yml +++ b/.github/workflows/Automated Test (full).yml @@ -53,7 +53,7 @@ jobs: - name: Setup node uses: actions/setup-node@v2 with: - node-version: '14' + node-version: '15' - name: Cache modules psychojs_testing uses: actions/cache@v2 env: From da9b892ead2abffd3bff12411d75a13cbe419d65 Mon Sep 17 00:00:00 2001 From: Todd Parsons Date: Fri, 13 Jan 2023 14:46:07 +0000 Subject: [PATCH 09/12] ENH: Alias "star" and "star7" --- src/visual/ShapeStim.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/visual/ShapeStim.js b/src/visual/ShapeStim.js index b5925e3..dad2807 100644 --- a/src/visual/ShapeStim.js +++ b/src/visual/ShapeStim.js @@ -395,3 +395,5 @@ ShapeStim.KnownShapes = { [0.5, 0.0], ], }; +// Alias some names for convenience +ShapeStim.KnownShapes['star'] = ShapeStim.KnownShapes['star7'] From c2be1a04ec74cb95ed54022e1f4a73aa7aa6c984 Mon Sep 17 00:00:00 2001 From: Todd Parsons Date: Thu, 26 Jan 2023 12:47:28 +0000 Subject: [PATCH 10/12] FF: Allow TextBox to accept "placeholder" as an input --- src/visual/TextBox.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/visual/TextBox.js b/src/visual/TextBox.js index 3930cbf..4d8e2bc 100644 --- a/src/visual/TextBox.js +++ b/src/visual/TextBox.js @@ -65,6 +65,7 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) opacity, depth, text, + placeholder, font, letterHeight, bold, @@ -98,7 +99,7 @@ export class TextBox extends util.mix(VisualStim).with(ColorMixin) ); this._addAttribute( "placeholder", - text, + placeholder, "", this._onChange(true, true), ); From bff887b79311d569e340f233c1c53959a32b44ed Mon Sep 17 00:00:00 2001 From: lgtst Date: Fri, 24 Mar 2023 13:20:34 +0000 Subject: [PATCH 11/12] src/visual --- src/visual/Survey.js | 58 +++++++++++++++++++++++++++++++++----------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/visual/Survey.js b/src/visual/Survey.js index b573e16..d761224 100644 --- a/src/visual/Survey.js +++ b/src/visual/Survey.js @@ -82,6 +82,10 @@ export class Survey extends VisualStim { super({ name, win, units, ori, depth, pos, size, autoDraw, autoLog }); + // Storing all existing signaturePad questions to properly handle their resize. + // Unfortunately signaturepad question type can't handle resizing properly by itself. + this._signaturePads = []; + // whether the user is done with the survey, independently of whether the survey is completed: this.isFinished = false; @@ -968,8 +972,6 @@ export class Survey extends VisualStim this.psychoJS.logger.warn(`Flag _isCompletedAll is false!`); } - this._detachResizeObservers(); - this._surveyRunningPromiseResolve(completionCode); } @@ -1017,6 +1019,10 @@ export class Survey extends VisualStim this._surveyModel.onTextMarkdown.add(this._onTextMarkdown.bind(this)); this._surveyModel.isInitialized = true; this._surveyModel.onAfterRenderQuestion.add(this._handleAfterQuestionRender.bind(this)); + this._surveyModel.onQuestionRemoved.add(() => + { + console.log("question removed") + }) } const completeText = surveyIdx < this._surveyData.surveys.length - 1 ? (this._surveyModel.pageNextText || Survey.CAPTIONS.NEXT) : undefined; @@ -1137,34 +1143,58 @@ export class Survey extends VisualStim this._lastPageSwitchHandledIdx = -1; } - _handleSignaturePadResize(entries) + _getQuestionByNameIncludingInDesign(questionName = "") { - for (let i = 0; i < entries.length; i++) + const allQuestions = this._surveyModel.getAllQuestions(false, true); + for (const question of allQuestions) { - // const signatureCanvas = entries[i].target.querySelector("canvas"); - const question = this._surveyModel.getQuestionByName(entries[i].target.dataset.name); - question.signatureWidth = Math.min(question.maxSignatureWidth, entries[i].contentBoxSize[0].inlineSize); + if (question.name === questionName) + { + return question; + } + } + } + + _handleWindowResize(e) + { + if (this._surveyModel) + { + for (let i = this._signaturePads.length - 1; i >= 0; i--) + { + // As of writing this (24.03.2023). SurveyJS doesn't have a proper event + // for question being removed from nested locations, such as dynamic panel. + // However, surveyJS will set .signaturePad property to null once the question is removed. + // Utilising this knowledge to sync our lists. + if (this._signaturePads[ i ].question.signaturePad) + { + this._signaturePads[ i ].question.signatureWidth = Math.min( + this._signaturePads[i].question.maxSignatureWidth, + this._signaturePads[ i ].htmlElement.getBoundingClientRect().width + ); + } + else + { + // Signature pad was removed. Syncing list. + this._signaturePads.splice(i, 1); + } + } } } _addEventListeners() { - this._signaturePadRO = new ResizeObserver(this._handleSignaturePadResize.bind(this)); + window.addEventListener("resize", (e) => this._handleWindowResize(e)); } _handleAfterQuestionRender (sender, options) { if (options.question.getType() === "signaturepad") { - this._signaturePadRO.observe(options.htmlElement); + this._signaturePads.push(options); + options.question.signatureWidth = Math.min(options.question.maxSignatureWidth, options.htmlElement.getBoundingClientRect().width); } } - _detachResizeObservers() - { - this._signaturePadRO.disconnect(); - } - /** * Init the SurveyJS.io library and various extensions, setup the theme. * From 5f32881be273542d8dab1bf15c7347ff1d9c1c91 Mon Sep 17 00:00:00 2001 From: lgtst Date: Fri, 24 Mar 2023 13:23:50 +0000 Subject: [PATCH 12/12] removed dead code. --- src/visual/Survey.js | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/src/visual/Survey.js b/src/visual/Survey.js index d761224..57bf41f 100644 --- a/src/visual/Survey.js +++ b/src/visual/Survey.js @@ -1019,10 +1019,6 @@ export class Survey extends VisualStim this._surveyModel.onTextMarkdown.add(this._onTextMarkdown.bind(this)); this._surveyModel.isInitialized = true; this._surveyModel.onAfterRenderQuestion.add(this._handleAfterQuestionRender.bind(this)); - this._surveyModel.onQuestionRemoved.add(() => - { - console.log("question removed") - }) } const completeText = surveyIdx < this._surveyData.surveys.length - 1 ? (this._surveyModel.pageNextText || Survey.CAPTIONS.NEXT) : undefined; @@ -1143,18 +1139,6 @@ export class Survey extends VisualStim this._lastPageSwitchHandledIdx = -1; } - _getQuestionByNameIncludingInDesign(questionName = "") - { - const allQuestions = this._surveyModel.getAllQuestions(false, true); - for (const question of allQuestions) - { - if (question.name === questionName) - { - return question; - } - } - } - _handleWindowResize(e) { if (this._surveyModel)