Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Interest Point and time measure

More
2 weeks 6 days ago #274619 by elissa
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.17.3
Own server or LimeSurvey hosting: own
Survey theme/template: Fruity TwentyThree
==================
Hello Team,

I'm going to use @tpartner's script, provided by @Joffm here: forums.limesurvey.org/forum/can-i-do-thi...too-locations#245460 , to record a point of interest on the picture.

I would like to measure the time elapsed between displaying the question and clicking on the picture. However, I'm aware that some respondents might click on the image several times before proceeding. Therefore, I would like to record the timestamp of the last click that corresponds to the recorded coordinates of the point.

Is there an easy way to add this functionality to the script?

Thank you!

Elzbieta Lesinska
LS voluntary Polish translator and supervisor

Please Log in to join the conversation.

More
2 weeks 5 days ago #274625 by Joffm
Hi,
my proposal is:
Use a queston of type "multiple short text" with two subquestions (to store the coords and the time elepsed)

There are only minor changes to the script
Code:
<script type="text/javascript" charset="utf-8">        
    $(document).ready(function() {    
 
        // Identify this question
        var thisQuestion = $('#question{QID}');
        // Time at start
        var starttime = Date.now();
 
        // Hide the text input - un-comment below
        $('.ls-answers', thisQuestion).hide();
 
        // Create the click "marker"
        $('.image-wrapper', thisQuestion).append('<div class="click-marker" />');
        var leftVal = 0;
        var topVal = 0;
        var displayVal = 'none';
        if($.trim($('input.text', thisQuestion).val()) != '') {
            leftVal = $.trim($('input.text', thisQuestion).val()).split(',')[0]+'%';
            topVal = $.trim($('input.text', thisQuestion).val()).split(',')[1]+'%'; 
            displayVal = 'block';
        }
        $('.click-marker', thisQuestion).css({
            'display': displayVal,
            'position': 'absolute',
            'left': leftVal,
            'top': topVal,
            'margin': '-10px 0 0 -10px',
            'width': '18px',
            'height': '18px',
            '-moz-border-radius': '10px',
            '-webkit-border-radius': '10px',
            'border-radius': '10px',
            'background': '#0C0',
            'border': '1px solid #090'
        });
 
        // Click event on the image
        $('.image-wrapper, img', thisQuestion).on('click', function(e) {
            var thisWidth = $(this).width();
            var thisHeight = $(this).height();
            var posX = $(this).offset().left;
            var posY = $(this).offset().top;
            var xCoord = e.pageX - posX;
            var yCoord = e.pageY - posY;
            var xCoordPercent = (xCoord/thisWidth)*100;
            var yCoordPercent = (yCoord/thisHeight)*100;
 
            // Load the click coordinates (as relative percentages)
            // Store the coordinates in the first subquestion
            $('input[type=text]:eq(0)', thisQuestion).val(xCoordPercent.toFixed(2)+','+yCoordPercent.toFixed(2));
            // Store the elapsed time in the second subquestion
            // Time is stored in milliseconds
            $('input[type=text]:eq(1)', thisQuestion).val(Date.now() - starttime);
 
            // Reposition the marker
            $('.click-marker', thisQuestion).css({
                'display': 'block',
                'left': xCoordPercent+'%',
                'top': yCoordPercent+'%'
            });
        });
 
        // Returning to the page
        if($('input:text', thisQuestion).val() != '') {
            var coords = $.trim($('input:text', thisQuestion).val()).split(',');
            $('.click-marker', thisQuestion).css({
                'display': 'block',
                'left': coords[0]+'%',
                'top': coords[1]+'%'
            });
        }
    });
</script>

After first click:
 
After a second click:
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: elissa

Please Log in to join the conversation.

More
2 weeks 5 days ago #274626 by elissa
Beautiful solution! Thank you very much, Joffm.

Elzbieta Lesinska
LS voluntary Polish translator and supervisor

Please Log in to join the conversation.

More
2 weeks 6 hours ago - 2 weeks 6 hours ago #274668 by elissa
One more issue: the image is in portrait format and I just want it to be fully visible without scrolling. It doesn't have to be 100% height - 80% should be fine to leave space for a one-line question above. I'm trying to fix this with max-height, but I must have messed up as the coordinates in the database look wrong.

I'd be grateful for any help with this issue too. Thanks!

The original code:
Code:
<div class="image-wrapper img-responsive center-block" style="border:2px solid #999; width: 100%;max-width: 500px; position:relative "> 
<img src="upload/surveys/{SID}/image/muskeln.jpg" style="border:0 none; width: 100%; height: auto;" />
</div>

Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Last edit: 2 weeks 6 hours ago by elissa.

Please Log in to join the conversation.

More
2 weeks 1 hour ago #274669 by Joffm
Hi,
you see that the click works on the image-wrapper, not on the image.
Just set the width of the image-wrapper accordingly.

Here set to 30%

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: elissa

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose