Skip to content

[BUG?] Inconsistent Behavior of Slider's _ratingToPos in PsychoJS vs PsychoPy #603

@const7

Description

@const7

I've encountered inconsistent/incorrect behavior with the _ratingToPos function in PsychoJS compared to PsychoPy.

Possible Bug

In PsychoJS, _ratingToPos only returns the correct x or y position, with the other coordinate always being 0. If the slider's position is offset from the center (not at [0,0]), the resulting position returned by _ratingToPos will be incorrect.

psychojs/src/visual/Slider.js

Lines 1354 to 1403 in 9265fd8

_ratingToPos(ratings)
{
const range = this._ticks[this._ticks.length - 1] - this._ticks[0];
if (this._isHorizontal())
{
// in compact mode the circular markers of RADIO sliders must fit within the width:
if (this._compact && this._style.indexOf(Slider.Style.RADIO) > -1)
{
return ratings.map((v) => [
((v - this._ticks[0]) / range) * (this._size[0] - this._tickSize[1] * 2)
- (this._size[0] / 2) + this._tickSize[1],
0,
]);
}
else if (this._style.indexOf(Slider.Style.SLIDER) > -1)
{
return ratings.map((v) => [
((v - this._ticks[0]) / range - 0.5) * (this._size[0] - this._markerSize[0]),
0,
]);
}
else
{
return ratings.map((v) => [((v - this._ticks[0]) / range - 0.5) * this._size[0], 0]);
}
}
else
{
// in compact mode the circular markers of RADIO sliders must fit within the height:
if (this._compact && this._style.indexOf(Slider.Style.RADIO) > -1)
{
return ratings.map((v) => [
0,
((v - this._ticks[0]) / range) * (this._size[1] - this._tickSize[0] * 2)
- (this._size[1] / 2) + this._tickSize[0],
]);
}
else if (this._style.indexOf(Slider.Style.SLIDER) > -1)
{
return ratings.map((v) => [
0,
((v - this._ticks[0]) / range - 0.5) * (this._size[1] - this._markerSize[1]),
]);
}
else
{
return ratings.map((v) => [0, (1.0 - (v - this._ticks[0]) / range - 0.5) * this._size[1]]);
}
}
}

This issue does not occur in PsychoPy, where both x and y coordinates are correctly computed based on the slider's position.
https://github.com/psychopy/psychopy/blob/fa753ec368764989a557e57660adb5c8486c49da/psychopy/visual/slider.py#L586-L610

Feature vs Bug

In PsychoPy, _ratingToPos accepts both single numeric values and array-like inputs for ratings. However, in PsychoJS, the function only accepts arrays. I'm not sure if it's intentional or some other reason.

I would be happy to submit a PR to fix the first issue if you're open to that. As for the second point, perhaps it could be discussed further to determine whether this difference in input handling should be resolved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions