Skip to content

Commit

Permalink
Merge branch 'main' into survey-plugin-rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
becky-gilbert committed Mar 14, 2024
2 parents 5b57978 + 3126fa9 commit 7558000
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 31 deletions.
53 changes: 53 additions & 0 deletions .github/workflows/publish-docs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Publish Docs

on:
workflow_dispatch:

jobs:
deploy-docs:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.8'

- name: Install poetry using pip
run: pipx install poetry==1.7.0

- name: Get current version
id: version
run: echo "version=$(node -p "require('./packages/jspsych/package.json').version")" >> "$GITHUB_ENV"

- name: Remove patch version
run: echo "version_major_minor=${{ env.version }}" | awk -F. '{print $1"."$2}' >> "$GITHUB_ENV"

- name: Config git
run: |
git config --global user.name docs-bot
git config --global user.email docs@jspsych.org
- name: Deploy docs
run: npm run docs:deploy ${{ env.version_major_minor }}

- name: Switch to gh-pages branch
run: git checkout gh-pages

- name: Push gh-pages branch
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages


2 changes: 1 addition & 1 deletion docs/demos/jspsych-visual-search-circle-demo1.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<script src="https://unpkg.com/@jspsych/plugin-preload@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.2.1"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" />
<link rel="stylesheet" href="docs-demo.css" type="text/css">
</head>
Expand Down
2 changes: 1 addition & 1 deletion docs/demos/jspsych-visual-search-circle-demo2.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<script src="https://unpkg.com/jspsych@7.3.4"></script>
<script src="https://unpkg.com/@jspsych/plugin-preload@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.2.1"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych@7.3.4/css/jspsych.css" />
<link rel="stylesheet" href="docs-demo.css" type="text/css">
</head>
Expand Down
5 changes: 3 additions & 2 deletions docs/plugins/visual-search-circle.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# visual-search-circle

Current version: 1.1.3. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-visual-search-circle/CHANGELOG.md).
Current version: 1.2.1. [See version history](https://github.com/jspsych/jsPsych/blob/main/packages/plugin-visual-search-circle/CHANGELOG.md).

This plugin presents a customizable visual-search task modelled after [Wang, Cavanagh, & Green (1994)](http://dx.doi.org/10.3758/BF03206946). The participant indicates whether or not a target is present among a set of distractors. The stimuli are displayed in a circle, evenly-spaced, equidistant from a fixation point. Here is an example using normal and backward Ns:

Expand Down Expand Up @@ -32,6 +32,7 @@ The `target_present` and `fixation_image` parameters must always be specified. O
| target_absent_key | string | 'f' | The key to press if the target is not present in the search array. |
| trial_duration | numeric | null | The maximum amount of time the participant is allowed to search before the trial will continue. A value of null will allow the participant to search indefinitely. |
| fixation_duration | numeric | 1000 | How long to show the fixation image for before the search array (in milliseconds). |
| response_ends_trial| boolean | true | If true, the trial will end when the participant makes a response. |

## Data Generated

Expand All @@ -51,7 +52,7 @@ In addition to the [default data collected by all plugins](../overview/plugins.m
Using the CDN-hosted JavaScript file:

```js
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.1.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-visual-search-circle@1.2.1"></script>
```

Using the JavaScript file downloaded from a GitHub release dist archive:
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"changeset": "changeset",
"changeset:version": "changeset version && npm install && npm run update-unpkg-links && npm run update-plugin-versions",
"changeset:publish": "npm run build && changeset publish",
"docs:deploy": "poetry install && poetry run mike deploy -u",
"docs:serve": "poetry install && poetry run mike serve"
"docs:deploy": "poetry install --no-root && poetry run mike deploy -u",
"docs:serve": "poetry install --no-root && poetry run mike serve"
},
"engines": {
"node": ">=18.0.0",
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-visual-search-circle/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# @jspsych/plugin-visual-search-circle

## 1.2.1

### Patch Changes

- [#3213](https://github.com/jspsych/jsPsych/pull/3213) [`7b797727`](https://github.com/jspsych/jsPsych/commit/7b797727fa3b2b384ef964eb53d74f474ec902ef) Thanks [@jodeleeuw](https://github.com/jodeleeuw)! - Fix display clearing problem introduced with version 1.2.0

## 1.2.0

### Minor Changes

- [#3211](https://github.com/jspsych/jsPsych/pull/3211) [`37430e13`](https://github.com/jspsych/jsPsych/commit/37430e13e9645d90e853471010bee0c95c895954) Thanks [@jodeleeuw](https://github.com/jodeleeuw)! - Adds response_ends_trial parameter, with a default value of `true`

## 1.1.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-visual-search-circle/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jspsych/plugin-visual-search-circle",
"version": "1.1.3",
"version": "1.2.1",
"description": "jsPsych visual search circle plugin",
"type": "module",
"main": "dist/index.cjs",
Expand Down
34 changes: 34 additions & 0 deletions packages/plugin-visual-search-circle/src/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,40 @@ describe("visual-search-circle", () => {
pressKey("a");
await expectFinished();

expect(displayElement.querySelectorAll("img").length).toBe(0);

expect(getData().values()[0].correct).toBe(true);
});

it("wait when response_ends_trial is false", async () => {
const { displayElement, expectFinished, expectRunning, getData } = await startTimeline([
{
type: visualSearchCircle,
target: "target.png",
foil: "foil.png",
fixation_image: "fixation.png",
set_size: 4,
target_present: true,
target_present_key: "a",
target_absent_key: "b",
response_ends_trial: false,
trial_duration: 1500,
},
]);

expect(displayElement.querySelectorAll("img").length).toBe(1);

jest.advanceTimersByTime(1000); // fixation duration

expect(displayElement.querySelectorAll("img").length).toBe(5);
pressKey("a");
await expectRunning();

jest.runAllTimers();
await expectFinished();

expect(displayElement.querySelectorAll("img").length).toBe(0);

expect(getData().values()[0].correct).toBe(true);
});
});
Expand Down
55 changes: 32 additions & 23 deletions packages/plugin-visual-search-circle/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ const info = <const>{
pretty_name: "Fixation duration",
default: 1000,
},
/** Whether a keyboard response ends the trial early */
response_ends_trial: {
type: ParameterType.BOOL,
pretty_name: "Response ends trial",
default: true,
},
},
};

Expand Down Expand Up @@ -153,12 +159,23 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
}, trial.fixation_duration);
};

const end_trial = (rt: number, correct: boolean, key_press: string) => {
const response = {
rt: null,
key: null,
correct: false,
};

const end_trial = () => {
display_element.innerHTML = "";

this.jsPsych.pluginAPI.clearAllTimeouts();
this.jsPsych.pluginAPI.cancelAllKeyboardResponses();

// data saving
var trial_data = {
correct: correct,
rt: rt,
response: key_press,
const trial_data = {
correct: response.correct,
rt: response.rt,
response: response.key,
locations: display_locs,
target_present: trial.target_present,
set_size: trial.set_size,
Expand Down Expand Up @@ -186,11 +203,7 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
"px;'></img>";
}

var trial_over = false;

const after_response = (info: { key: string; rt: number }) => {
trial_over = true;

var correct = false;

if (
Expand All @@ -202,12 +215,16 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {
correct = true;
}

clear_display();
response.rt = info.rt;
response.key = info.key;
response.correct = correct;

end_trial(info.rt, correct, info.key);
if (trial.response_ends_trial) {
end_trial();
}
};

var valid_keys = [trial.target_present_key, trial.target_absent_key];
const valid_keys = [trial.target_present_key, trial.target_absent_key];

const key_listener = this.jsPsych.pluginAPI.getKeyboardResponse({
callback_function: after_response,
Expand All @@ -219,19 +236,11 @@ class VisualSearchCirclePlugin implements JsPsychPlugin<Info> {

if (trial.trial_duration !== null) {
this.jsPsych.pluginAPI.setTimeout(() => {
if (!trial_over) {
if (!response.rt) {
this.jsPsych.pluginAPI.cancelKeyboardResponse(key_listener);

trial_over = true;

var rt = null;
var correct = false;
var key_press = null;

clear_display();

end_trial(rt, correct, key_press);
}

end_trial();
}, trial.trial_duration);
}

Expand Down

0 comments on commit 7558000

Please sign in to comment.