Using snap with jspsych

160 views
Skip to first unread message

omfi...@gmail.com

unread,
May 31, 2016, 5:45:26 AM5/31/16
to jsPsych
Hy Josh!

It's me again. I wonder, if and how I can combine jspsych with snap in a way that allows to render different svgs and present them.


Yours,
Marcel

Josh de Leeuw

unread,
May 31, 2016, 8:57:58 AM5/31/16
to omfi...@gmail.com, jsPsych
Yes. A generated SVG has a string version of the markup like any HTML element. You can capture this string in a variable and pass it to the single-stim plugin as the stimulus parameter.


--
You received this message because you are subscribed to the Google Groups "jsPsych" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jspsych+u...@googlegroups.com.
To post to this group, send email to jsp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jspsych/7372d0bf-acd9-4f6d-afa2-b5982c197aee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Philip Quinlan

unread,
Aug 11, 2016, 12:16:18 PM8/11/16
to jsPsych, omfi...@gmail.com
Hi I figured out how to do this now and it is 'working' but what I am trying to do is present a sequence of these kinds of displays and if I start with a fixation dot it seems to be painted to the same screen as the ensuing displays - so my question is how do you clear the screen so the dot does not reappear?

Thanks

Philip Quinlan

Josh de Leeuw

unread,
Aug 11, 2016, 12:18:03 PM8/11/16
to Philip Quinlan, jsPsych, omfi...@gmail.com
Try displaying the fixation dot as a trial. You can alternate between fixation trials and stimulus trials, setting the timing_post_trial parameter for the fixation trial to 0 if you want no gap between trials.

Philip Quinlan

unread,
Aug 11, 2016, 12:23:53 PM8/11/16
to jsPsych, philip....@york.ac.uk, omfi...@gmail.com
Here is a code snippet - showing what I am doing - the dot stays on.

Sorry still taking baby steps with this.

Philip. 

  var sp = Snap("#svg");

var sp_circ = sp.circle(x_cent,y_cent,5);

var fix_block = {
type: "single-stim",
is_html : true,
timing_response: 500,
timing_post_trial: 0,
stimulus: sp.toString()
};

timeline.push(fix_block);


var s = Snap("#svg");
var dis1_col = [];
dis1_col[0] = colors[0];
for (var jp =1; jp < 4; jp++){
dis1_col[jp] = colors[jp-1];
}

for (var ip=0; ip<n_el; ip++){
var s_circ = s.circle(x_val[ip],y_val[ip],10);
s_circ.attr({
fill: dis1_col[ip]
});

}

var presentation_block = {
type: "single-stim",
is_html : true,
timing_response: 100,
timing_post_trial: 600,
stimulus: s.toString()
};
timeline.push(presentation_block);

supposed to present a small simgle fixation followed by a new display containing four colored dots

Thanks

Philip.

Josh de Leeuw

unread,
Aug 11, 2016, 12:29:36 PM8/11/16
to Philip Quinlan, jsPsych, omfi...@gmail.com
When you create the Snap object and modify it, that probably create the stimulus on the page. You need to clear that before running the experiment. One way would be to add a couple lines after the first 2:

var sp = Snap("#svg");
var sp_circ = sp.circle(x_cent,y_cent,5);
var str = sp.toString();
$('#svg').remove(); // or other method to clear this from the DOM


Josh de Leeuw

unread,
Aug 11, 2016, 12:30:06 PM8/11/16
to Philip Quinlan, jsPsych, omfi...@gmail.com
(And then you can use the str variable as your stimulus, if that wasn't clear from the example...)

Philip Quinlan

unread,
Aug 11, 2016, 12:39:38 PM8/11/16
to jsPsych, philip....@york.ac.uk, omfi...@gmail.com
if I use 

$('#svg').remove();

this then appears to remove '#svg' completely and so cant re-use the definition

could you suggest an alternative?

Philip.

Josh de Leeuw

unread,
Aug 11, 2016, 12:45:45 PM8/11/16
to Philip Quinlan, jsPsych, omfi...@gmail.com
You could try .empty() instead.

Philip Quinlan

unread,
Aug 11, 2016, 12:50:39 PM8/11/16
to jsPsych, philip....@york.ac.uk, omfi...@gmail.com
Perfect

Thanks

Philp.

and thanks for this software it will revolutionize the way I now do research.

Philip Quinlan

unread,
Aug 12, 2016, 6:29:05 AM8/12/16
to jsPsych, philip....@york.ac.uk, omfi...@gmail.com
Hopefully, a final question...

I am struggling to position the svg on the page - Ideally I would like it centered horizontally and vertically but I cant seem to move it from being stuck in the top left hand corner.

Any advice gratefully received,

Philip.

Josh de Leeuw

unread,
Aug 12, 2016, 12:28:03 PM8/12/16
to Philip Quinlan, jsPsych, omfi...@gmail.com
This will be a bit easier in the next version of jsPsych. For now, you should look up information about CSS positioning. The new(ish) CSS flex layout makes vertical centering a lot easier than it used to be. This is a good starting point: https://philipwalton.github.io/solved-by-flexbox/demos/vertical-centering/

Reply all
Reply to author
Forward
0 new messages