mirror of
https://github.com/psychopy/psychojs.git
synced 2025-05-10 10:40:54 +00:00
commit
ab9d030717
2
.github/workflows/Automated Test (full).yml
vendored
2
.github/workflows/Automated Test (full).yml
vendored
@ -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:
|
||||
|
2
.github/workflows/Automated Test (short).yml
vendored
2
.github/workflows/Automated Test (short).yml
vendored
@ -45,7 +45,7 @@ jobs:
|
||||
- name: Setup node
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: '12'
|
||||
node-version: '15'
|
||||
|
||||
# START: install psychojs_testing
|
||||
- name: Checkout psychojs_testing
|
||||
|
@ -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",
|
||||
|
@ -362,6 +362,24 @@ export function shuffle(array, randomNumberGenerator = undefined, startIndex = u
|
||||
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.
|
||||
*
|
||||
|
@ -385,4 +385,29 @@ ShapeStim.KnownShapes = {
|
||||
[-0.39, 0.31],
|
||||
[-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],
|
||||
[-1/6, 0.0],
|
||||
[-1/6, -0.5],
|
||||
[1/6, -0.5],
|
||||
[1/6, 0.0],
|
||||
[0.5, 0.0],
|
||||
],
|
||||
};
|
||||
// Alias some names for convenience
|
||||
ShapeStim.KnownShapes['star'] = ShapeStim.KnownShapes['star7']
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
@ -1137,34 +1139,46 @@ export class Survey extends VisualStim
|
||||
this._lastPageSwitchHandledIdx = -1;
|
||||
}
|
||||
|
||||
_handleSignaturePadResize(entries)
|
||||
_handleWindowResize(e)
|
||||
{
|
||||
for (let i = 0; i < entries.length; i++)
|
||||
if (this._surveyModel)
|
||||
{
|
||||
// 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);
|
||||
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.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user