mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 19:20:55 +00:00
implement image size settings for image plugins #560
This commit is contained in:
parent
45a307f4d5
commit
9da8c452f2
@ -10,6 +10,9 @@ Other parameters can be left unspecified if the default value is acceptable.
|
||||
Parameter | Type | Default Value | Description
|
||||
----------|------|---------------|------------
|
||||
stimulus | string | undefined | The path of the image file to be displayed.
|
||||
stimulus_height | integer | null | Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height.
|
||||
stimulus_width | integer | null | Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width.
|
||||
maintain_aspect_ration | boolean | true | If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled to maintain the image's aspect ratio.
|
||||
choices | array of strings | [] | Labels for the buttons. Each different string in the array will generate a different button.
|
||||
button_html | HTML string | `'<button class="jspsych-btn">%choice%</button>'` | A template of HTML for generating the button elements. You can override this to create customized buttons of various kinds. The string `%choice%` will be changed to the corresponding element of the `choices` array. You may also specify an array of strings, if you need different HTML to render for each button. If you do specify an array, the `choices` array and this array must have the same length. The HTML from position 0 in the `button_html` array will be used to create the button for element 0 in the `choices` array, and so on.
|
||||
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g., which key to press).
|
||||
|
@ -10,6 +10,9 @@ Parameters with a default value of undefined must be specified. Other parameters
|
||||
Parameter | Type | Default Value | Description
|
||||
----------|------|---------------|------------
|
||||
stimulus | string | *undefined* | The path of the image file to be displayed.
|
||||
stimulus_height | integer | null | Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height.
|
||||
stimulus_width | integer | null | Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width.
|
||||
maintain_aspect_ration | boolean | true | If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled to maintain the image's aspect ratio.
|
||||
choices | array of keycodes | `jsPsych.ALL_KEYS` | This array contains the keys that the subject is allowed to press in order to respond to the stimulus. Keys can be specified as their [numeric key code](http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes) or as characters (e.g., `'a'`, `'q'`). The default value of `jsPsych.ALL_KEYS` means that all keys will be accepted as valid responses. Specifying `jsPsych.NO_KEYS` will mean that no responses are allowed.
|
||||
prompt | string | null | This string can contain HTML markup. Any content here will be displayed below the stimulus. The intention is that it can be used to provide a reminder about the action the subject is supposed to take (e.g., which key to press).
|
||||
stimulus_duration | numeric | null | How long to show the stimulus for in milliseconds. If the value is null, then the stimulus will be shown until the subject makes a response.
|
||||
|
@ -9,6 +9,9 @@ Parameters with a default value of *undefined* must be specified. Other paramete
|
||||
Parameter | Type | Default Value | Description
|
||||
----------|------|---------------|------------
|
||||
stimulus | string | *undefined* | The path to the image file to be displayed.
|
||||
stimulus_height | integer | null | Set the height of the image in pixels. If left null (no value specified), then the image will display at its natural height.
|
||||
stimulus_width | integer | null | Set the width of the image in pixels. If left null (no value specified), then the image will display at its natural width.
|
||||
maintain_aspect_ration | boolean | true | If setting *only* the width or *only* the height and this parameter is true, then the other dimension will be scaled to maintain the image's aspect ratio.
|
||||
labels | array of strings | [] | Labels displayed at equidistant locations on the slider. For example, two labels will be placed at the ends of the slider. Three labels would place two at the ends and one in the middle. Four will place two at the ends, and the other two will be at 33% and 67% of the slider width.
|
||||
button_label | string | 'Continue' | Label of the button to advance/submit
|
||||
min | integer | 0 | Sets the minimum value of the slider
|
||||
|
@ -23,6 +23,7 @@
|
||||
timeline.push({
|
||||
type: 'image-button-response',
|
||||
stimulus: 'img/happy_face_2.jpg',
|
||||
stimulus_height: 400,
|
||||
choices: ['Happy', 'Sad'],
|
||||
stimulus_duration: 1000,
|
||||
prompt: "<p>What emotion is this person showing? (image disappears after 1s)</p>"
|
||||
@ -31,6 +32,7 @@
|
||||
timeline.push({
|
||||
type: 'image-button-response',
|
||||
stimulus: 'img/happy_face_3.jpg',
|
||||
stimulus_width: 600,
|
||||
choices: ['Happy', 'Sad'],
|
||||
trial_duration: 2000,
|
||||
response_ends_trial: false,
|
||||
|
@ -24,6 +24,24 @@ jsPsych.plugins["image-button-response"] = (function() {
|
||||
default: undefined,
|
||||
description: 'The image to be displayed'
|
||||
},
|
||||
stimulus_height: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image height',
|
||||
default: null,
|
||||
description: 'Set the image height in pixels'
|
||||
},
|
||||
stimulus_width: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image width',
|
||||
default: null,
|
||||
description: 'Set the image width in pixels'
|
||||
},
|
||||
maintain_aspect_ratio: {
|
||||
type: jsPsych.plugins.parameterType.BOOL,
|
||||
pretty_name: 'Maintain aspect ratio',
|
||||
default: true,
|
||||
description: 'Maintain the aspect ratio after setting width or height'
|
||||
},
|
||||
choices: {
|
||||
type: jsPsych.plugins.parameterType.STRING,
|
||||
pretty_name: 'Choices',
|
||||
@ -79,15 +97,21 @@ jsPsych.plugins["image-button-response"] = (function() {
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
if(typeof trial.choices === 'undefined'){
|
||||
console.error('Required parameter "choices" missing in image-button-response');
|
||||
}
|
||||
if(typeof trial.stimulus === 'undefined'){
|
||||
console.error('Required parameter "stimulus" missing in image-button-response');
|
||||
}
|
||||
|
||||
// display stimulus
|
||||
var html = '<img src="'+trial.stimulus+'" id="jspsych-image-button-response-stimulus"></img>';
|
||||
var html = '<img src="'+trial.stimulus+'" id="jspsych-image-button-response-stimulus" style="';
|
||||
if(trial.stimulus_height !== null){
|
||||
html += 'height:'+trial.stimulus_height+'px; '
|
||||
if(trial.stimulus_width == null && trial.maintain_aspect_ratio){
|
||||
html += 'width: auto; ';
|
||||
}
|
||||
}
|
||||
if(trial.stimulus_width !== null){
|
||||
html += 'width:'+trial.stimulus_width+'px; '
|
||||
if(trial.stimulus_height == null && trial.maintain_aspect_ratio){
|
||||
html += 'height: auto; ';
|
||||
}
|
||||
}
|
||||
html +='"></img>';
|
||||
|
||||
//display buttons
|
||||
var buttons = [];
|
||||
|
@ -25,6 +25,24 @@ jsPsych.plugins["image-keyboard-response"] = (function() {
|
||||
default: undefined,
|
||||
description: 'The image to be displayed'
|
||||
},
|
||||
stimulus_height: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image height',
|
||||
default: null,
|
||||
description: 'Set the image height in pixels'
|
||||
},
|
||||
stimulus_width: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image width',
|
||||
default: null,
|
||||
description: 'Set the image width in pixels'
|
||||
},
|
||||
maintain_aspect_ratio: {
|
||||
type: jsPsych.plugins.parameterType.BOOL,
|
||||
pretty_name: 'Maintain aspect ratio',
|
||||
default: true,
|
||||
description: 'Maintain the aspect ratio after setting width or height'
|
||||
},
|
||||
choices: {
|
||||
type: jsPsych.plugins.parameterType.KEYCODE,
|
||||
array: true,
|
||||
@ -61,15 +79,29 @@ jsPsych.plugins["image-keyboard-response"] = (function() {
|
||||
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
var new_html = '<img src="'+trial.stimulus+'" id="jspsych-image-keyboard-response-stimulus"></img>';
|
||||
// display stimulus
|
||||
var html = '<img src="'+trial.stimulus+'" id="jspsych-image-keyboard-response-stimulus" style="';
|
||||
if(trial.stimulus_height !== null){
|
||||
html += 'height:'+trial.stimulus_height+'px; '
|
||||
if(trial.stimulus_width == null && trial.maintain_aspect_ratio){
|
||||
html += 'width: auto; ';
|
||||
}
|
||||
}
|
||||
if(trial.stimulus_width !== null){
|
||||
html += 'width:'+trial.stimulus_width+'px; '
|
||||
if(trial.stimulus_height == null && trial.maintain_aspect_ratio){
|
||||
html += 'height: auto; ';
|
||||
}
|
||||
}
|
||||
html +='"></img>';
|
||||
|
||||
// add prompt
|
||||
if (trial.prompt !== null){
|
||||
new_html += trial.prompt;
|
||||
html += trial.prompt;
|
||||
}
|
||||
|
||||
// draw
|
||||
display_element.innerHTML = new_html;
|
||||
// render
|
||||
display_element.innerHTML = html;
|
||||
|
||||
// store response
|
||||
var response = {
|
||||
|
@ -25,6 +25,24 @@ jsPsych.plugins['image-slider-response'] = (function() {
|
||||
default: undefined,
|
||||
description: 'The image to be displayed'
|
||||
},
|
||||
stimulus_height: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image height',
|
||||
default: null,
|
||||
description: 'Set the image height in pixels'
|
||||
},
|
||||
stimulus_width: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Image width',
|
||||
default: null,
|
||||
description: 'Set the image width in pixels'
|
||||
},
|
||||
maintain_aspect_ratio: {
|
||||
type: jsPsych.plugins.parameterType.BOOL,
|
||||
pretty_name: 'Maintain aspect ratio',
|
||||
default: true,
|
||||
description: 'Maintain the aspect ratio after setting width or height'
|
||||
},
|
||||
min: {
|
||||
type: jsPsych.plugins.parameterType.INT,
|
||||
pretty_name: 'Min slider',
|
||||
@ -93,7 +111,22 @@ jsPsych.plugins['image-slider-response'] = (function() {
|
||||
plugin.trial = function(display_element, trial) {
|
||||
|
||||
var html = '<div id="jspsych-image-slider-response-wrapper" style="margin: 100px 0px;">';
|
||||
html += '<div id="jspsych-image-slider-response-stimulus"><img src="' + trial.stimulus + '"></div>';
|
||||
html += '<div id="jspsych-image-slider-response-stimulus"></div>';
|
||||
var html = '<img src="'+trial.stimulus+'" style="';
|
||||
if(trial.stimulus_height !== null){
|
||||
html += 'height:'+trial.stimulus_height+'px; '
|
||||
if(trial.stimulus_width == null && trial.maintain_aspect_ratio){
|
||||
html += 'width: auto; ';
|
||||
}
|
||||
}
|
||||
if(trial.stimulus_width !== null){
|
||||
html += 'width:'+trial.stimulus_width+'px; '
|
||||
if(trial.stimulus_height == null && trial.maintain_aspect_ratio){
|
||||
html += 'height: auto; ';
|
||||
}
|
||||
}
|
||||
html += '"></img>';
|
||||
html += '</div>';
|
||||
html += '<div class="jspsych-image-slider-response-container" style="position:relative;">';
|
||||
html += '<input type="range" value="'+trial.start+'" min="'+trial.min+'" max="'+trial.max+'" step="'+trial.step+'" style="width: 100%;" id="jspsych-image-slider-response-response"></input>';
|
||||
html += '<div>'
|
||||
|
Loading…
Reference in New Issue
Block a user