diff --git a/docs/markdown_docs/plugins/jspsych-resize.md b/docs/markdown_docs/plugins/jspsych-resize.md new file mode 100644 index 00000000..d8b05d7c --- /dev/null +++ b/docs/markdown_docs/plugins/jspsych-resize.md @@ -0,0 +1,30 @@ +# jspsych-resize + +This plugin displays a resizable div container that allows the user to drag until the container is the same size as the item being measured. Once the user measures the item as close as possible, clicking the button sets a scaling factor for the div containing jsPsych content. This causes the stimuli that follow to have a known size, independent of monitor resolution. + +## Parameters + +This table lists the parameters associated with this plugin. Parameters with a default value of *undefined* must be specified. Other parameters can be left unspecified if the default value is acceptable. + +Parameter | Type | Default Value | Description +----------|------|---------------|------------ +item_height | numeric | 1 | The height of the item to be measured. Any units can be used as long as you are consistent with using the same units for all parameters. +item_width | numeric | 1 | The width of the item to be measured. +pixels_per_unit | numeric | 100 | After the scaling factor is applied, this many pixels will equal one unit of measurement. +prompt | string | `''` | HTML content to display below the resizable box, and above the button. +button_text | string | `'Done'` | Label to display on the button to complete calibration. +starting_size | numeric | 100 | The initial size of the box, in pixels, along the largest dimension. The aspect ratio will be set automatically to match the item width and height. + +## Examples + +#### Measuring a credit card and resizing the display to have 150 pixels equal an inch. + +```javascript +var inputs = { + type: 'resize', + item_width: 3 + 3/8, + item_height: 2 + 1/8, + prompt: "
Click and drag the lower right corner of the box until the box is the same size as a credit card held up to the screen.
", + pixels_per_unit: 150 +}; +``` diff --git a/docs/markdown_docs/plugins/overview.md b/docs/markdown_docs/plugins/overview.md index 402bbd91..7f837a1e 100644 --- a/docs/markdown_docs/plugins/overview.md +++ b/docs/markdown_docs/plugins/overview.md @@ -75,7 +75,8 @@ This table is a description of all plugins that are currently bundled with jsPsy [jspsych‑instructions](jspsych-instructions) | For displaying instructions to the subject. [jspsych‑multi‑stim‑multi‑response](jspsych-multi-stim-multi-response) | A more generalized version of the single-stim plugin. Can display multiple stimuli in a single trial, and collect multiple responses in a single trial. [jspsych‑palmer](jspsych-palmer) | Shows grid-like stimuli inspired by Stephen Palmer's work. The stimuli are editable: subjects can add and subtract parts interactively. Also contains a method for generating the HTML code to render the stimuli, allowing them to be used in other plugins. - [jspsych‑reconstruction](jspsych-reconstruction) | The subject interacts with a stimulus by modifying a parameter of the stimulus and observing the change in the stimulus in real-time. + [jspsych‑reconstruction](jspsych-reconstruction) | The subject interacts with a stimulus by modifying a parameter of the stimulus and observing the change in the stimulus in real-time. + [jspsych‑resize](jspsych-resize) | Calibrate the display so that materials display with a known physical size. [jspsych‑same‑different](jspsych-same-different) | A same-different judgment task. A stimulus is shown, followed by a brief gap, and then another stimulus is shown. The subject indicates whether the stimuli are the same or different. [jspsych‑similarity](jspsych-similarity) | Two stimuli are shown sequentially, and the subject indicates how similar they are by dragging a slider object. [jspsych‑single‑audio](jspsych-single-audio) | A basic plugin for playing an audio stimulus and getting a keyboard response. diff --git a/docs/mkdocs.yml b/docs/mkdocs.yml index 6a223683..89cdcf2e 100644 --- a/docs/mkdocs.yml +++ b/docs/mkdocs.yml @@ -46,6 +46,7 @@ pages: - 'jspsych-multi-stim-multi-response': 'plugins/jspsych-multi-stim-multi-response.md' - 'jspsych-palmer': 'plugins/jspsych-palmer.md' - 'jspsych-reconstruction': 'plugins/jspsych-reconstruction.md' + - 'jspsych-resize': 'plugins/jspsych-resize.md' - 'jspsych-same-different': 'plugins/jspsych-same-different.md' - 'jspsych-similarity': 'plugins/jspsych-similarity.md' - 'jspsych-single-audio': 'plugins/jspsych-single-audio.md' diff --git a/examples/jspsych-resize.html b/examples/jspsych-resize.html new file mode 100644 index 00000000..2b8bf251 --- /dev/null +++ b/examples/jspsych-resize.html @@ -0,0 +1,34 @@ + + + + + + + + + + + + diff --git a/plugins/jspsych-resize.js b/plugins/jspsych-resize.js new file mode 100644 index 00000000..5590c905 --- /dev/null +++ b/plugins/jspsych-resize.js @@ -0,0 +1,135 @@ +/** +* jspsych-resize +* Steve Chao +* +* plugin for controlling the real world size of the display +* +* documentation: docs.jspsych.org +* +**/ + +jsPsych.plugins["resize"] = (function() { + + var plugin = {}; + + plugin.trial = function(display_element, trial) { + + // if any trial variables are functions + // this evaluates the function and replaces + // it with the output of the function + trial = jsPsych.pluginAPI.evaluateFunctionParameters(trial); + + // default trial paramters + trial.item_height = trial.item_height || 1; + trial.item_width = trial.item_width || 1; + trial.prompt = trial.prompt || ' '; + trial.pixels_per_unit = trial.pixels_per_unit || 100; + trial.starting_size = trial.starting_size || 100; + trial.button_text = trial.button_text || "Done"; + + var aspect_ratio = trial.item_width / trial.item_height; + + // variables to determine div size + if(trial.item_width >= trial.item_height){ + var start_div_width = trial.starting_size; + var start_div_height = Math.round(trial.starting_size / aspect_ratio); + } else { + var start_div_height = trial.starting_size; + var start_div_width = Math.round(trial.starting_size * aspect_ratio); + } + + // create html for display + var html ='